[tw] Re: [TW5] More JavaScript macro questions
Hi Mark, if I do get your code right you create a "list" of author names without commas? In my code I join them together and remove the trailing comma and whitespace pair with a slice before returning the text. So far this works for my usecase but yours is way more compact which is nice I guess :) Thanks a lot for your help and effort I am sure I will ask for more when I dig deeper in my e-book management plugin. Cheers Tristan Am Donnerstag, 14. April 2016 18:02:44 UTC+2 schrieb Mark S.: > > Hi Tristan, > > This was the export part of the code I came up with for testing: > > exports.run = function(text) { > > var vartext = "[["+text.split(",").join("]] [[")+"]]" ; > return vartext ; > > }; > > Both our approaches probably need something in there to squeeze out spaces > after commas. > > Have fun! > Mark > > > On Wednesday, April 13, 2016 at 11:49:29 PM UTC-7, Tristan Kohl wrote: >> >> Hi Mark, >> >> here is my macro code: >> /*\ >> >> title: $:/plugins/mirodin/ebooks/linklist.js >> type: application/javascript >> module-type: macro >> >> \*/ >> (function() { >> >> "use strict"; >> >> /* >> List all field values as comma separated list of clickable links. >> */ >> >> exports.name = "linklist"; >> >> exports.params = []; >> >> /* >> Run the macro >> */ >> exports.run = function(field) { >> if (typeof field === "undefined") { >> return "''Please pass field.''"; >> } >> var elements = field.split(","); >> var result = ""; >> for (var i = 0; i < elements.length; i++) { >> result += "[[" + elements[i] + "]], "; >> } >> result = result.slice(0, -2); >> return result; >> }; >> >> })(); >> >> Thanks for your hint, that works for me too and the whole call is way >> more readable. >> >> Cheers >> Tristan >> > -- You received this message because you are subscribed to the Google Groups "TiddlyWiki" group. To unsubscribe from this group and stop receiving emails from it, send an email to tiddlywiki+unsubscr...@googlegroups.com. To post to this group, send email to tiddlywiki@googlegroups.com. Visit this group at https://groups.google.com/group/tiddlywiki. To view this discussion on the web visit https://groups.google.com/d/msgid/tiddlywiki/bb756d54-063e-4c76-9ac1-b2a275061b89%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[tw] Re: [TW5] More JavaScript macro questions
Hi Tristan, This was the export part of the code I came up with for testing: exports.run = function(text) { var vartext = "[["+text.split(",").join("]] [[")+"]]" ; return vartext ; }; Both our approaches probably need something in there to squeeze out spaces after commas. Have fun! Mark On Wednesday, April 13, 2016 at 11:49:29 PM UTC-7, Tristan Kohl wrote: > > Hi Mark, > > here is my macro code: > /*\ > > title: $:/plugins/mirodin/ebooks/linklist.js > type: application/javascript > module-type: macro > > \*/ > (function() { > > "use strict"; > > /* > List all field values as comma separated list of clickable links. > */ > > exports.name = "linklist"; > > exports.params = []; > > /* > Run the macro > */ > exports.run = function(field) { > if (typeof field === "undefined") { > return "''Please pass field.''"; > } > var elements = field.split(","); > var result = ""; > for (var i = 0; i < elements.length; i++) { > result += "[[" + elements[i] + "]], "; > } > result = result.slice(0, -2); > return result; > }; > > })(); > > Thanks for your hint, that works for me too and the whole call is way more > readable. > > Cheers > Tristan > -- You received this message because you are subscribed to the Google Groups "TiddlyWiki" group. To unsubscribe from this group and stop receiving emails from it, send an email to tiddlywiki+unsubscr...@googlegroups.com. To post to this group, send email to tiddlywiki@googlegroups.com. Visit this group at https://groups.google.com/group/tiddlywiki. To view this discussion on the web visit https://groups.google.com/d/msgid/tiddlywiki/2d34c21f-dcf2-4301-919c-a08f9baf9b19%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[tw] Re: [TW5] More JavaScript macro questions
Hi Mark, here is my macro code: /*\ title: $:/plugins/mirodin/ebooks/linklist.js type: application/javascript module-type: macro \*/ (function() { "use strict"; /* List all field values as comma separated list of clickable links. */ exports.name = "linklist"; exports.params = []; /* Run the macro */ exports.run = function(field) { if (typeof field === "undefined") { return "''Please pass field.''"; } var elements = field.split(","); var result = ""; for (var i = 0; i < elements.length; i++) { result += "[[" + elements[i] + "]], "; } result = result.slice(0, -2); return result; }; })(); Thanks for your hint, that works for me too and the whole call is way more readable. Cheers Tristan -- You received this message because you are subscribed to the Google Groups "TiddlyWiki" group. To unsubscribe from this group and stop receiving emails from it, send an email to tiddlywiki+unsubscr...@googlegroups.com. To post to this group, send email to tiddlywiki@googlegroups.com. Visit this group at https://groups.google.com/group/tiddlywiki. To view this discussion on the web visit https://groups.google.com/d/msgid/tiddlywiki/44475e17-e08a-4306-8e4e-d3fa349ccd95%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[tw] Re: [TW5] More JavaScript macro questions
You might try invoking it like this: <$macrocall $name="listlinks" text={{!!authors}}/> Where "text" is whatever you have set up as your parameter variable name. That seemed to work on my quick test. Mark On Wednesday, April 13, 2016 at 8:26:20 AM UTC-7, Tristan Kohl wrote: > > Hey guys, > > i started creating my e-book management with TW a couple days ago. But > there are still some things I do not get right away so I hope you can help > me out with them. > > First a short explanation of my "design": I have a template tiddler which > is used to show the details of a book. In this template a call my custom > macro to make a comma separated list of links from a field with comma > separated author names. So i.e. field "authors" contains *Mark Twain* and > *J.R.R. > Tolkien* separated by comma. My macro produces links like *[[Mark > Twain]], [[J.R.R. Tolkien]]* so I can find books for every author via > backlinks. > > My problem is that I can not figure out, how to use the value of "authors" > within my JavaScript macro. At the moment I use the *set* widget to > create a variable authors: > <$set name=authors value={{!!authors}}><$macrocall $name="linklist" field=< > > /> > > But this looks like overkill for me and is not that readable, so I wonder > if it Is possible to replace this whole setup with something like (which > does not work for me): > <> > > There is another question that bothers me. As I am not a native English > speaker I do not get the difference between substitution and transclusion. > I figure one is *before* the macro call and the other one *after* that? > But which is when and how do I use substitution at all? Unfortunately the > documentation is very short and abstract about this I feel. > > Thanks for your help > Tristan > -- You received this message because you are subscribed to the Google Groups "TiddlyWiki" group. To unsubscribe from this group and stop receiving emails from it, send an email to tiddlywiki+unsubscr...@googlegroups.com. To post to this group, send email to tiddlywiki@googlegroups.com. Visit this group at https://groups.google.com/group/tiddlywiki. To view this discussion on the web visit https://groups.google.com/d/msgid/tiddlywiki/611c5898-cc13-43b7-94a6-2ac17124e9f4%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[tw] Re: [TW5] More JavaScript macro questions
Hi Tristan, Your English is great -- the documentation is indeed short and abstract. I've never had much luck passing things to a javascript macro without using a <$set> variable. I'm thinking it might be possible to use another standard macro to wrap the <$set> process. Could you provide the javascript macro and template for testing purposes? Mark On Wednesday, April 13, 2016 at 8:26:20 AM UTC-7, Tristan Kohl wrote: > > Hey guys, > > i started creating my e-book management with TW a couple days ago. But > there are still some things I do not get right away so I hope you can help > me out with them. > > First a short explanation of my "design": I have a template tiddler which > is used to show the details of a book. In this template a call my custom > macro to make a comma separated list of links from a field with comma > separated author names. So i.e. field "authors" contains *Mark Twain* and > *J.R.R. > Tolkien* separated by comma. My macro produces links like *[[Mark > Twain]], [[J.R.R. Tolkien]]* so I can find books for every author via > backlinks. > > My problem is that I can not figure out, how to use the value of "authors" > within my JavaScript macro. At the moment I use the *set* widget to > create a variable authors: > <$set name=authors value={{!!authors}}><$macrocall $name="linklist" field=< > > /> > > But this looks like overkill for me and is not that readable, so I wonder > if it Is possible to replace this whole setup with something like (which > does not work for me): > <> > > There is another question that bothers me. As I am not a native English > speaker I do not get the difference between substitution and transclusion. > I figure one is *before* the macro call and the other one *after* that? > But which is when and how do I use substitution at all? Unfortunately the > documentation is very short and abstract about this I feel. > > Thanks for your help > Tristan > -- You received this message because you are subscribed to the Google Groups "TiddlyWiki" group. To unsubscribe from this group and stop receiving emails from it, send an email to tiddlywiki+unsubscr...@googlegroups.com. To post to this group, send email to tiddlywiki@googlegroups.com. Visit this group at https://groups.google.com/group/tiddlywiki. To view this discussion on the web visit https://groups.google.com/d/msgid/tiddlywiki/2efece31-0525-44f2-810d-a50192eeff63%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.