squirrellyjs / squirrelly

Semi-embedded JS template engine that supports helpers, filters, partials, and template inheritance. 4KB minzipped, written in TypeScript ⛺
https://squirrelly.js.org
MIT License
634 stars 83 forks source link

Squirrelly v8: miscellaneous thoughts & todo items #154

Closed nebrelbug closed 4 years ago

nebrelbug commented 4 years ago

This is an issue for me (as a maintainer) to keep track of To-do items and random ideas.

nebrelbug commented 4 years ago

Note: these are taken from "TODO.md" and "Thoughts.md"

(?:[^]*?|(?:'(?:\\[\s\w"'\\`]|[^\n\r'\\])*?'|`(?:\\[\s\w"'\\`]|[^\\`])*?`|"(?:\\[\s\w"'\\`]|[^\n\r"\\])*?"))*?(?:([|()]|=>)|\/\*[^]*?\*\/|((\/)?(-|_)?}}))

(?:(?:'(?:\\[\s\w"'\\`]|[^\n\r'\\])*?'|`(?:\\[\s\w"'\\`]|[^\\`])*?`|"(?:\\[\s\w"'\\`]|[^\n\r"\\])*?")|\/\*[^]*?\*\/|[^])*?(?:([|()]|=>)|((\/)?(-|_)?}}))
insider777 commented 4 years ago

What about the ability to parse like this {{~i18n`hello ${world}`/}} its nothing major i currently just use {{~i18n('hello ' + world)/}} or {{ 'Template string' | i18n }}

nebrelbug commented 4 years ago

@insider777 hmm that would be really nice, but I don't think there's an easy way to add that behavior exactly. You could pass in i18n as data though and then do

{{it.i18n`hello ${world}`}}

By the way, quick question: it looks like you're using the beta of Squirrelly v8. Recently, I've considered changing the default helper "prefix" to @ instead of ~, to make it easier to type for people with international keyboards. I would then allow prefixes to be customized.

Do you have any feedback on this? Would you prefer to type {{@i18n('hello ' + world)/}} rather than {{~i18n('hello ' + world)/}}?

Thanks for the feedback!

w3hr commented 4 years ago

The version 8.0.4 seems not working with express

res.render('index', { name: "test"})

ReferenceError: name is not defined

i tested with version 7.0.4, 7.9.2 and it works, it does also not working with version 8.0.0

nebrelbug commented 4 years ago

Hi @w3hr! There have been some significant changes to Squirrelly's syntax since version 7, so your Squirrelly v7 templates most likely will not work with Squirrelly v8.

The new Squirrelly docs are at https://squirrelly.js.org

Let me know if you have any questions! :grin:

w3hr commented 4 years ago

ok my bad, thx

jmclean-cnexus commented 4 years ago

@nebrelbug is it possible to pass in the entire it context and append any key=>value pairs? There is a ton of customizations with data transformations that take place based on logic which would be much easier to do in native js/ts. something like

/* it context
{
 name: "Jon",
 title: "not-awesome"
}
*/
// this is a helper 
transform(it, cb)

cb(context) {
  if(context.name === "Jon") return { _realTitle: "not-too-shabby", ...context }
  else return context
}  
nebrelbug commented 4 years ago

@jmclean-cnexus I don't quite understand what your problem is. Do you want to modify it before rendering your template?

jmclean-cnexus commented 4 years ago

@nebrelbug no problem at all...just thinking out loud really. I work in Fintech and we have a lot of rules. I was thinking for one of my use cases, that if I could just render a value (which is adding together a principal amount + interest) and attach it to the context before rendering my template, I could just use something like it.calculated.

So, in short...yes! Feel free to toss this aside, just thinking out loud and there may be more graceful ways to do this

nebrelbug commented 4 years ago

@jmclean-cnexus ok, that makes sense. On first thought, I think it's probably best to leave this up to the user to handle before they render their templates so as to keep bundle size low.

I'm open to suggestions though :), so if you think this feature would be helpful feel free to open an issue or PR.