module MasterView module Directives # takes the attr_value and parses it as a hash :foo => 'bar', :baz => 'cat' # it sets/overrides the tag's attribute values for each value. # To use erb output simply wrap the content in #{ foo } for example :foo => #{h product.name} class Attr < MasterView::DirectiveBase # substitution to make it easy to parse erb in attr SubstForErb = '#'+InlineErbStart+'= \1 '+InlineErbEnd+'#' def priority DirectivePriorities::MediumLow end def stag(dcs) attr_value.gsub!( /#\{([^}]*)\}/, SubstForErb ) #taking #{h product.name} and changing to #{{{= h product.name}}}# for easy parsing arr = attr_value.scan( /:(\w+)\s*=>\s*(['"#])([^,\2]*)\2,?/ ) arr.each do |scn| n = scn[0] v = scn[2] dcs.context[:tag].attributes[n] = v end dcs.render end end end end