Here’s a proof-of-concept extension that I’ve been working on. I
originally
hoped to have polished this all up but haven’t had the time for
development.
So, rather than stick it on a shelf, I thought I’d toss it out there in
case
it could benefit anyone. Besides, I want to find out what others in the
Radiant community think =^D.
http://swankinnovations.svnrepository.com/svn/open/radiant/extensions/vars_if/
SVN Repository Location
Quickie Overview:
This extension is essentially two extensions rolled into one. I just
put
them together for now for simplicity. It consists of:
1.) Abstracted Conditionals - instead of <r:if_myWhatever> I’ve created
generic <r:if> and <r:unless> tags that let you build your own
conditional
statements. Existing Radiant tags can be rewritten as such:
<r:if_content part=“my page part”> becomes…
<r:if cond=“page.part[my page Part]”>
and
<r:if_url matches=“regexp”> becomes…
<r:if cond=“page[url] matches regexp”>
But more importantly, a wider range of conditionals becomes possible
such
as:
<r:if cond=“page.part[my page Part] blank?”> , or
<r:if cond=“page.part[my page Part] matches /myKeyword/”>, or
<r:unless cond=“children[count] > 10”>
And, more important still, the goal is to allow extension developers to
easily hook into this so that their own custom values can be used in
conditionals. So, instead of creating new <r:if_newTagName> tags, they
could enable:
<r:if cond=“myExtension[value] empty?”> or
<r:if cond=“myCustomQuery[results] != myCustom[value]”>
All they’d have to do is provide a method in their extension to resolve
“myExtension[value]” for the conditionals to use.
2.) Abstracted ‘Puts’ Tag - because the conditionals must resolve
symbols
such as page[url] or MyExtension[value], I’ve also created a:
<r:puts value="page[url] /> (which is functionally the same as <r:url
/>,
or
<r:puts value="page[title] /> (which is functionally the same as
<r:title/>
and, of course, the extension developer can now instantly offer:
<r:puts value=“myExtension[value]” />
3.) Variable Declaration - This one could be its own extenson. It
provides
a method to declare (store) variables in a local or global context
(depending on whether its a single or double tag). These variables can
then
be displayed elsewhere (via <r:puts>) or evaluated (via <r:if> or
<r:unless>).
Examples:
Put it all together and the following becomes possible:
– in page body –
<r:store vars=“class:myClass; quote:‘my important string of text for
quotation’; author:‘Chris P.’” />
<r:snippet name=“quote” />
– in snippet: quote –
– output –
my important string of text for quotation
Chris P.
To learn more, check out the README file and the tag descriptions (in
code
or via Radiant). Plus I’ve tried to put extra comments in the code.
What I’m hoping for:
1.) Feedback - does anybody else think that this would be useful or am I
just out in left field.
2.) Suggestions - I have some blatant unresolved issues here that
someone
might see a good way to address (see the README for more). Ideas
anyone?
3.) Improvements - at the moment the repository is read only but I’ll
gladly
accept patches, or even grant access for those that truly want to
contribute.
View this message in context:
http://www.nabble.com/-ANN--Variables---Conditionals-Extension-tf4580441.html#a13075290
Sent from the Radiant - User mailing list archive at Nabble.com.