Hey Chris,
Of course, you can do what you wrote. Actually, creating you own tag
is pretty simple. The key is to write the right regexp to parse your
options (in your case, key1="value1", ...). I suggest you to use
rubular.com to write it.
Oh, you misspelled the call to your tag: the right syntax is {% ... %}
and not {{ }} (used instead for displaying variables or drop
attributes).
In your case, you would have something like that:
class MyTag < Tag
Syntax = /(#{VariableSignature}+)\s*(.*)/
def initialize(tag_name, markup, tokens)
if markup =~ Syntax
@first_param = $1
@keys = keys_from_string($2)
...
end
...
end
private
def keys_from_string(str)
str.split(' ').inject({}) do |map, couple| # your keys are space
separated
# here, key contains <name of your key>="<value>". Write the
right regexp to get both name and value
# and add it to map. As a result, you will have a nice
hashmap.
...
map.merge!(key.to_sym => value)
end
end
end
My code is not tested but it gives you enough information to begin.
Hope it helps anyway.
Did
On 23 sep, 05:42, "chris.parrish" <chris.parrish-