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
592 stars 82 forks source link

Filter chaining not working correctly. #113

Closed sonnylloyd closed 4 years ago

sonnylloyd commented 5 years ago

Describe the bug For some reason chaining filters seems to be getting the original string and not the filtered string.

Here is my defined filters also i swapped the tags due to my previous custom code engine (simple replace).

Sqrl.defaultTags(["{","}"]); Sqrl.defineFilter("excerpt", function (str) { return str.substring(0,55); }); Sqrl.defineFilter("length", function (str) { return str.length });

Here is the render code

stringIn = Sqrl.Render("{preset.description|excerpt|length}", { preset: { description: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas felis dui, efficitur id erat id, suscipit dignissim orci. Vivamus at aliquet ex, non faucibus arcu. Ut posuere tempus imperdiet. Vestibulum dapibus justo sit amet semper aliquet. Pellentesque consequat eros bibendum semper sodales. Nunc ut mi eu magna elementum lobortis ut eget lacus. Suspendisse tincidunt lectus lacus, nec gravida turpis blandit in. Phasellus auctor finibus nisl vel luctus. Aliquam posuere placerat justo at egestas. Quisque aliquet risus quis pulvinar suscipit. Curabitur dapibus massa malesuada, blandit quam luctus, viverra augue. Fusce sapien mi, aliquet et est in, vestibulum sagittis nisl. Sed efficitur.', } });

it should return the number 55 but it returns 697 and the string it got in was not the string returned by the excerpt filter.

I cut this down as my application is a bit more complex. am i doing something wrong or is this a bug

nebrelbug commented 5 years ago

Hi @sonnylloyd, thanks for the question!

Right now, filter chaining is unfortunately actually broken. For now, the best solution would just be to create one filter that does the job of both filters (return str.substring(0,55).length), until we push a fix.

Any more questions?

nebrelbug commented 4 years ago

Fix is coming out in the next week :)

nebrelbug commented 4 years ago

Fixed in Squirrelly 7.5.0!