Welcome Guest, Not a member yet? Register   Sign In
Parser extras
#1

(This post was last modified: 10-31-2017, 06:39 PM by orionstar.)

Hi guys!

I need a way to map automatically all public variable and methods of an object as plugins.
Also it would be nice if I can access the vars and methods on the objects namespace.

For example:
I have a blog plugin class with methods posts, categories, authors, comments etc... then I would like to access these this way:

Code:
{+ blog:posts +}
{title}
{+ /blog:posts +}

The ":" should be configurable, just like the delimeter. Also I suggest to get rid of the "+" as the plugin marker, it makes harder to the end users to understand the system (or if its not easy to merge the simple parsing of a variable and a plugin, then at least it should be configurable). 
I will give access my users to edit email templates so I should be able to remove all plugin and add only the selected few (of course I can achieve this if I make a new parser instance and add the plugins again but this is not the best solution, because in preview mode I would like to compile the email templates with the rest of the page).
Is it possible now to add plugins globally for all parser instances that exists or will be instantianeted later?
Is it possible to pass "collections" as data to the parser or I have to create associate arrays all the time? (in the parser code I only see the latter)
Can I call other vars or plugins in a template? for example {+ blogPosts postsPerPage={ postsPerPage } +} or should I create a filter for this or those can only be used for scalar values?

Based on the previous questions and requests should I use another Parser solution? Big Grin I wish lex for CI4 or something with the same syntax...

Best regards,
orionstar
Reply
#2

Sounds like you are looking for something like

https://github.com/pyrocms/lex

Cheers!
Reply
#3

Nice to see someone giving the Parser a good tire-kicking! When I worked on the Parser, I was looking at Lex, Twig, and ModX for inspiration. So - there is some Lex in there Smile

Quote:The ":" should be configurable, just like the delimeter. Also I suggest to get rid of the "+" as the plugin marker, it makes harder to the end users to understand the system (or if its not easy to merge the simple parsing of a variable and a plugin, then at least it should be configurable).

I would accept a PR to make those configurable.

Quote:I will give access my users to edit email templates so I should be able to remove all plugin and add only the selected few (of course I can achieve this if I make a new parser instance and add the plugins again but this is not the best solution, because in preview mode I would like to compile the email templates with the rest of the page).

For restricting plugins, your best bet is probably to extend the Parser class with your own that has access to an approved list of plugins and go from there. You can create your own parser() entry in Config/Services and that will be used in place of the system one automatically.

Quote:Is it possible now to add plugins globally for all parser instances that exists or will be instantianeted later?

There is the addPlugin() and removePlugins methods on the Parser that can be used to add them at runtime. Only applies to a single instance, obviously.

Quote:Is it possible to pass "collections" as data to the parser or I have to create associate arrays all the time? (in the parser code I only see the latter)

Not sure what you mean by "collections", unless you're referring to something like Laravel's collection class, in which case the answer is no. Especially since CodeIgniter doesn't provide any standardized Collection type class. However, if you're using Laravel's, you can simply use a ->toArray() on the collection. Smile

Quote:Can I call other vars or plugins in a template? for example {+ blogPosts postsPerPage={ postsPerPage } +} or should I create a filter for this or those can only be used for scalar values?[/url]

Of course you can use multiple vars and plugins in a template, but what you're example is showing is something different. You're trying to use a var inside the calling of a plugin. Currently that's not possible since plugins are ran prior to parsing the vars. I was on the fence about the ordering of those two, and landed on running plugins first, since they might generate or modify other code that would affect where a var was displayed.

For your specific example, there's no reason that postsPerPage couldn't be a system setting that the plugin could access, either from a Config file or the database, though.

[quote]Based on the previous questions and requests should I use another Parser solution? Big Grin I wish lex for CI4 or something with the same syntax...

Sorry - you won't get the exact syntax. I started from Lex and then added additional features it didn't have. If you're more comfortable with Lex, then you should use Lex, or contribute to CodeIgniter and help improve the current Parser. Smile
Reply
#4

(10-31-2017, 07:43 PM)dmyers Wrote: Sounds like you are looking for something like

https://github.com/pyrocms/lex

Cheers!

Thanks for the suggestion, in my previous CMS I used Lex with CI 3, but it was abandoned years ago and nobody forked it to continue the development.

(10-31-2017, 08:11 PM)kilishan Wrote: So - there is some Lex in there Smile

Yes I know about it, it was discussed in the forum maybe a year ago. Smile

(10-31-2017, 08:11 PM)kilishan Wrote: Not sure what  you mean by "collections", unless you're referring to something like Laravel's collection class, in which case the answer is no. Especially since CodeIgniter doesn't provide any standardized Collection type class. However, if you're using Laravel's, you can simply use a ->toArray() on the collection. Smile
As collection I meant two concepts in one: The first is simple php array of objects and the second is iteratable objects. I am not using Laravel, I dont like it since L4. But ok I understand, I have to use arrays. Smile

(10-31-2017, 08:11 PM)kilishan Wrote: For your specific example, there's no reason that postsPerPage couldn't be a system setting that the plugin could access, either from a Config file or the database, though.
That is not possible since, I would like to use the same plugin for 3 different places for 3 different postscounts, but then I can hardcode the number to the template. xD
But the hardcoding is only a solution for this specific case.

(10-31-2017, 08:11 PM)kilishan Wrote: If you're more comfortable with Lex, then you should use Lex, or contribute to CodeIgniter and help improve the current Parser. Smile

Huge thanks for your time to answer me and of couse for CI4. I am not too familiar with regexps and template parsing so I cannot rlly help with it. Also there is a real project ahead when I would like to use CI4 but before that I should port over lots of stuff from my CMS and/or find replacements (Assets, Phil's Template layout lib, Ben's Ion auth, old Sparks xD etc...). So I should search for a different parser too or stuck with the old Lex for the time being and replace it later but I dont like the idea to use it further especially in a new project...
Reply




Theme © iAndrew 2016 - Forum software by © MyBB