Discussion:
[twdev] [TW5] Template for saving application/javascript tiddler in .js format?
(too old to reply)
TheDiveO
2014-09-21 16:46:04 UTC
Permalink
At the moment when I work with my Third Flow plugin creation process the
existing file system sync adaptor doesn't understand application/javascript
and thus saves TW5 modules in normal .tid format (that is, fields first,
empty line, then code).

This is okay and works, but of course this means that editing a JavaScript
module outside TW5 itself falls back to editing ordinary text. While you
may stop reading now saying "I said so!" my idea of the Third Flow is that
at some time later we will probably have a TW5-built-in JavaScript editor,
so see my question as my contribution to this future.

So I would like to make the file system sync adaptor to handle
application/javascript correctly. If I understand the current TW5 mechanics
correctly, then this could be done using a save template. Unfortunately,
the existing javascript-tiddler template isn't suitable for this: it saves
a TW5 module in form of a <script> script. To my understanding, the
existing TW5 widgets are insufficient to correctly handle "real" javascript
source code files ... there is no mechanism to replace the meta-data fields
that are inserted into a comment at the beginning of any JavaScript source
code.

Before trying to implement an extension I would like to ask for feedback:

- did I miss something so that the existing TW5 infrastructure can
properly save application/javascript tiddlers as .js source code files
including updated meta-data fields?
- if not, would it be better to either...
- ...introduce a new widget (say "$sourcecode")
- ...or to extend the existing $view widget?

The benefit of this would be that TW5 becomes able to save source code in
the same form as it is done when using "externally" developed source code.

Best regards,
-- TheDiveO
--
You received this message because you are subscribed to the Google Groups "TiddlyWikiDev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to tiddlywikidev+***@googlegroups.com.
To post to this group, send email to ***@googlegroups.com.
Visit this group at http://groups.google.com/group/tiddlywikidev.
For more options, visit https://groups.google.com/d/optout.
Andreas Hahn
2014-09-21 17:38:55 UTC
Permalink
Hi TheDiveO
Post by TheDiveO
At the moment when I work with my Third Flow plugin creation process
the existing file system sync adaptor doesn't understand
application/javascript and thus saves TW5 modules in normal .tid
format (that is, fields first, empty line, then code).
Which is the format it should be since the .tid format is homogeneous
among all saved files and can easily be parsed and modifed by any third
party program.
Post by TheDiveO
This is okay and works, but of course this means that editing a
JavaScript module outside TW5 itself falls back to editing ordinary
text. While you may stop reading now saying "I said so!" my idea of
the Third Flow is that at some time later we will probably have a
TW5-built-in JavaScript editor, so see my question as my contribution
to this future.
Wait, what's wrong with CodeMirror ? (Except that its huge and
javascript tiddlers don't get syntax highlighted by default)
Post by TheDiveO
So I would like to make the file system sync adaptor to handle
application/javascript correctly. If I understand the current TW5
mechanics correctly, then this could be done using a save template.
Unfortunately, the existing javascript-tiddler template isn't suitable
for this: it saves a TW5 module in form of a <script> script. To my
understanding, the existing TW5 widgets are insufficient to correctly
handle "real" javascript source code files ... there is no mechanism
to replace the meta-data fields that are inserted into a comment at
the beginning of any JavaScript source code.
I think having js files saved as real js files would be an excellent
extension to ThirdFlow and with the current template mechanism it should
be possible to do that (its not that different from
$:/core/templates/tid-tiddler)

I also don't understand what you mean with "replace meta-data", maybe
you can elaborate a little bit on that and post some examples of what
you tried.

/Andreas
--
You received this message because you are subscribed to the Google Groups "TiddlyWikiDev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to tiddlywikidev+***@googlegroups.com.
To post to this group, send email to ***@googlegroups.com.
Visit this group at http://groups.google.com/group/tiddlywikidev.
For more options, visit https://groups.google.com/d/optout.
TheDiveO
2014-09-21 17:59:31 UTC
Permalink
Post by Andreas Hahn
Hi TheDiveO
Post by TheDiveO
At the moment when I work with my Third Flow plugin creation process
the existing file system sync adaptor doesn't understand
application/javascript and thus saves TW5 modules in normal .tid
format (that is, fields first, empty line, then code).
Which is the format it should be since the .tid format is homogeneous
among all saved files and can easily be parsed and modifed by any third
party program.
If you look at the TiddlyWiki5 github repository then you'll see that
JavaScript tiddlers get generated from .js source code files directly
instead of from .tid files. So no, .tid is not necessarily as uniformly in
use as it may seem.

For instance, images may be directly included using associated .meta files.
So there is more than .tid. But the .tid format is more uniform and is
really great while staying inside the TW system. But for general import and
export it is a good choice, but not under any circumstances.
Post by Andreas Hahn
Post by TheDiveO
This is okay and works, but of course this means that editing a
JavaScript module outside TW5 itself falls back to editing ordinary
text. While you may stop reading now saying "I said so!" my idea of
the Third Flow is that at some time later we will probably have a
TW5-built-in JavaScript editor, so see my question as my contribution
to this future.
Wait, what's wrong with CodeMirror ? (Except that its huge and
javascript tiddlers don't get syntax highlighted by default)
There is nothing wrong with CodeMirror. I was hinting at source code
completion some day.
Post by Andreas Hahn
Post by TheDiveO
So I would like to make the file system sync adaptor to handle
application/javascript correctly. If I understand the current TW5
mechanics correctly, then this could be done using a save template.
Unfortunately, the existing javascript-tiddler template isn't suitable
for this: it saves a TW5 module in form of a <script> script. To my
understanding, the existing TW5 widgets are insufficient to correctly
handle "real" javascript source code files ... there is no mechanism
to replace the meta-data fields that are inserted into a comment at
the beginning of any JavaScript source code.
I think having js files saved as real js files would be an excellent
extension to ThirdFlow and with the current template mechanism it should
be possible to do that (its not that different from
$:/core/templates/tid-tiddler)
Yes, it seems to be different and most probably cannot be produced at this
time. If you look at one of the .js files in the TW5 repo you'll notice
that they all start with a specially crafted comment section. This comment
section then contains the meta data, that is, tiddler fields. The templates
cannot replace these commented fields with updated values.
Post by Andreas Hahn
I also don't understand what you mean with "replace meta-data", maybe
you can elaborate a little bit on that and post some examples of what
you tried.
Please see how .js files are stored in the TW5 repository. It should become
clear then that tiddler fields can be embedded into a special comment
section at the beginning of JS files. There is no save template that can
replace the outdated fields with their current values when saving a
Javascript tiddler.
Post by Andreas Hahn
/Andreas
--
You received this message because you are subscribed to the Google Groups "TiddlyWikiDev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to tiddlywikidev+***@googlegroups.com.
To post to this group, send email to ***@googlegroups.com.
Visit this group at http://groups.google.com/group/tiddlywikidev.
For more options, visit https://groups.google.com/d/optout.
PMario
2014-09-21 18:01:33 UTC
Permalink
Post by TheDiveO
This is okay and works, but of course this means that editing a JavaScript
module outside TW5 itself falls back to editing ordinary text.
With most editors, you can just select a highlight mode, that should be
used. So that's not a real problem. ...
Post by TheDiveO
While you may stop reading now saying "I said so!" my idea of the Third
Flow is that at some time later we will probably have a TW5-built-in
JavaScript editor, so see my question as my contribution to this future.
I think it would be nice if ThirdFlow could write .js and .meta files if
needed. ...

Also have a look at the $:/core/templates/tiddler-metadata template.
and the ginsu.sh command. There may be some hints.

-mario
--
You received this message because you are subscribed to the Google Groups "TiddlyWikiDev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to tiddlywikidev+***@googlegroups.com.
To post to this group, send email to ***@googlegroups.com.
Visit this group at http://groups.google.com/group/tiddlywikidev.
For more options, visit https://groups.google.com/d/optout.
TheDiveO
2014-09-21 18:20:00 UTC
Permalink
Post by PMario
Post by TheDiveO
This is okay and works, but of course this means that editing a
JavaScript module outside TW5 itself falls back to editing ordinary text.
With most editors, you can just select a highlight mode, that should be
used. So that's not a real problem. ...
Post by TheDiveO
While you may stop reading now saying "I said so!" my idea of the Third
Flow is that at some time later we will probably have a TW5-built-in
JavaScript editor, so see my question as my contribution to this future.
I think it would be nice if ThirdFlow could write .js and .meta files if
needed. ...
.js files are an exception in that they normally don't use .meta files. You
can, but it's not common.
Post by PMario
Also have a look at the $:/core/templates/tiddler-metadata template.
and the ginsu.sh command. There may be some hints.
All these templates are different in that they never need to modify the
text field of a tiddler. Saving to .js without .meta is different: the
contents needs to be modified ... but only if a specially crafted comment
section is present.
Post by PMario
-mario
--
You received this message because you are subscribed to the Google Groups "TiddlyWikiDev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to tiddlywikidev+***@googlegroups.com.
To post to this group, send email to ***@googlegroups.com.
Visit this group at http://groups.google.com/group/tiddlywikidev.
For more options, visit https://groups.google.com/d/optout.
Jeremy Ruston
2014-09-22 11:00:25 UTC
Permalink
Hi TheDiveO
Post by TheDiveO
So I would like to make the file system sync adaptor to handle
application/javascript correctly. If I understand the current TW5 mechanics
correctly, then this could be done using a save template. Unfortunately,
the existing javascript-tiddler template isn't suitable for this: it saves
a TW5 module in form of a <script> script. To my understanding, the
existing TW5 widgets are insufficient to correctly handle "real" javascript
source code files ... there is no mechanism to replace the meta-data fields
that are inserted into a comment at the beginning of any JavaScript source
code.

That's a reasonable goal. As you note, there would need to be some
additional special handling for it. Rather than overload the
filesystemadaptor, I think we need to introduce a pluggable means of
applying special templates to saving tiddlers of certain types. We'd ship
the new .js handler as part of the core, of course.

Writing .js/.js.meta files would of course be easier than writing JS files
with integrated metadata, and may be a reasonable way forward.

- > did I miss something so that the existing TW5 infrastructure can
properly save application/javascript tiddlers as .js source code files
including updated meta-data fields?

No, there's currently no capability to write JS files with integrated
metadata

- if not, would it be better to either...
- ...introduce a new widget (say "$sourcecode")
- ...or to extend the existing $view widget?

Given that the view widget subtypes are not currently pluggable it would
probably make more sense to introduce a new widget.

Best wishes

Jeremy.
Post by TheDiveO
Post by PMario
Post by TheDiveO
This is okay and works, but of course this means that editing a
JavaScript module outside TW5 itself falls back to editing ordinary text.
With most editors, you can just select a highlight mode, that should be
used. So that's not a real problem. ...
Post by TheDiveO
While you may stop reading now saying "I said so!" my idea of the Third
Flow is that at some time later we will probably have a TW5-built-in
JavaScript editor, so see my question as my contribution to this future.
I think it would be nice if ThirdFlow could write .js and .meta files if
needed. ...
.js files are an exception in that they normally don't use .meta files.
You can, but it's not common.
Post by PMario
Also have a look at the $:/core/templates/tiddler-metadata template.
and the ginsu.sh command. There may be some hints.
All these templates are different in that they never need to modify the
text field of a tiddler. Saving to .js without .meta is different: the
contents needs to be modified ... but only if a specially crafted comment
section is present.
Post by PMario
-mario
--
You received this message because you are subscribed to the Google Groups
"TiddlyWikiDev" group.
To unsubscribe from this group and stop receiving emails from it, send an
Visit this group at http://groups.google.com/group/tiddlywikidev.
For more options, visit https://groups.google.com/d/optout.
--
Jeremy Ruston
mailto:***@gmail.com
--
You received this message because you are subscribed to the Google Groups "TiddlyWikiDev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to tiddlywikidev+***@googlegroups.com.
To post to this group, send email to ***@googlegroups.com.
Visit this group at http://groups.google.com/group/tiddlywikidev.
For more options, visit https://groups.google.com/d/optout.
TheDiveO
2014-09-22 17:32:10 UTC
Permalink
Post by Jeremy Ruston
That's a reasonable goal. As you note, there would need to be some
additional special handling for it. Rather than overload the
filesystemadaptor, I think we need to introduce a pluggable means of
applying special templates to saving tiddlers of certain types. We'd ship
the new .js handler as part of the core, of course.
What isn't yet exactly clear to me is where's the border line between sync
adaptors and template formatting?
Post by Jeremy Ruston
Writing .js/.js.meta files would of course be easier than writing JS files
with integrated metadata, and may be a reasonable way forward.
But I find the dual .js and .js.meta combo somehow more clumsy, albeit it
avoids the general problem where the tiddler content (text) nover correctly
represents its content when made persistent.
Post by Jeremy Ruston
- > did I miss something so that the existing TW5 infrastructure can
properly save application/javascript tiddlers as .js source code files
including updated meta-data fields?
No, there's currently no capability to write JS files with integrated
metadata
- if not, would it be better to either...
- ...introduce a new widget (say "$sourcecode")
- ...or to extend the existing $view widget?
Given that the view widget subtypes are not currently pluggable it would
probably make more sense to introduce a new widget.
So I'll try to come up with a versatile $viewwithfields widget. My idea is
to design it in an open way that may allow us to use it in more contexts
than .js tiddlers.
--
You received this message because you are subscribed to the Google Groups "TiddlyWikiDev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to tiddlywikidev+***@googlegroups.com.
To post to this group, send email to ***@googlegroups.com.
Visit this group at http://groups.google.com/group/tiddlywikidev.
For more options, visit https://groups.google.com/d/optout.
Jeremy Ruston
2014-09-22 17:51:39 UTC
Permalink
By "JS files with integrated metadata", I meant the arrangement of embedding the tiddler metadata in the specially formatted comment, not the arrangement with a separate .meta file.


Best wishes




Jeremy
—
Post by TheDiveO
Post by Jeremy Ruston
That's a reasonable goal. As you note, there would need to be some
additional special handling for it. Rather than overload the
filesystemadaptor, I think we need to introduce a pluggable means of
applying special templates to saving tiddlers of certain types. We'd ship
the new .js handler as part of the core, of course.
What isn't yet exactly clear to me is where's the border line between sync
adaptors and template formatting?
Post by Jeremy Ruston
Writing .js/.js.meta files would of course be easier than writing JS files
with integrated metadata, and may be a reasonable way forward.
But I find the dual .js and .js.meta combo somehow more clumsy, albeit it
avoids the general problem where the tiddler content (text) nover correctly
represents its content when made persistent.
Post by Jeremy Ruston
- > did I miss something so that the existing TW5 infrastructure can
properly save application/javascript tiddlers as .js source code files
including updated meta-data fields?
No, there's currently no capability to write JS files with integrated
metadata
- if not, would it be better to either...
- ...introduce a new widget (say "$sourcecode")
- ...or to extend the existing $view widget?
Given that the view widget subtypes are not currently pluggable it would
probably make more sense to introduce a new widget.
So I'll try to come up with a versatile $viewwithfields widget. My idea is
to design it in an open way that may allow us to use it in more contexts
than .js tiddlers.
--
You received this message because you are subscribed to the Google Groups "TiddlyWikiDev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to tiddlywikidev+***@googlegroups.com.
To post to this group, send email to ***@googlegroups.com.
Visit this group at http://groups.google.com/group/tiddlywikidev.
For more options, visit https://groups.google.com/d/optout.
TheDiveO
2014-09-23 06:28:03 UTC
Permalink
Post by Jeremy Ruston
By "JS files with integrated metadata", I meant the arrangement of
embedding the tiddler metadata in the specially formatted comment, not the
arrangement with a separate .meta file
Ah, thank you for this clarification. This avoids a third representation,
like the current .js.tid.
--
You received this message because you are subscribed to the Google Groups "TiddlyWikiDev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to tiddlywikidev+***@googlegroups.com.
To post to this group, send email to ***@googlegroups.com.
Visit this group at http://groups.google.com/group/tiddlywikidev.
For more options, visit https://groups.google.com/d/optout.
Jeremy Ruston
2014-09-24 10:02:17 UTC
Permalink
Hi TheDiveO

Apologies, I've spent the last couple of days away from my computer.

I think we need to make sure that we only save integrated metadata for
application/javascript tiddlers that are already in that format. It should
be sufficient to check for the first four characters being `/*\` followed
by a newline.

Best wishes

Jeremy
Post by TheDiveO
Post by Jeremy Ruston
By "JS files with integrated metadata", I meant the arrangement of
embedding the tiddler metadata in the specially formatted comment, not the
arrangement with a separate .meta file
Ah, thank you for this clarification. This avoids a third representation,
like the current .js.tid.
--
You received this message because you are subscribed to the Google Groups
"TiddlyWikiDev" group.
To unsubscribe from this group and stop receiving emails from it, send an
Visit this group at http://groups.google.com/group/tiddlywikidev.
For more options, visit https://groups.google.com/d/optout.
--
Jeremy Ruston
mailto:***@gmail.com
--
You received this message because you are subscribed to the Google Groups "TiddlyWikiDev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to tiddlywikidev+***@googlegroups.com.
To post to this group, send email to ***@googlegroups.com.
Visit this group at http://groups.google.com/group/tiddlywikidev.
For more options, visit https://groups.google.com/d/optout.
TheDiveO
2014-09-27 17:50:10 UTC
Permalink
For those interested: there's a branch
https://github.com/TheDiveO/ThirdFlow/tree/js-tiddler-support in my Third
Flow github repo that is switched to correct .js handling. That is, this
branch now understands application/javascript tiddlers and saves them
optimized as a .js file with meta data in the special comment section. No
more .js.tid mix&match.

I would like to hear feedback, in particular on the metafy widget. It may
need some polish maybe?

Enjoy,
-- TheDiveO
--
You received this message because you are subscribed to the Google Groups "TiddlyWikiDev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to tiddlywikidev+***@googlegroups.com.
To post to this group, send email to ***@googlegroups.com.
Visit this group at http://groups.google.com/group/tiddlywikidev.
For more options, visit https://groups.google.com/d/optout.
Loading...