lib/musterb/musterbifier.rb in musterb-0.0.3 vs lib/musterb/musterbifier.rb in musterb-0.0.4

- old
+ new

@@ -1,27 +1,38 @@ class Musterb::Musterbifier def initialize(template) @template = template end + def fetch(tokens) + tokens = tokens.strip.split(".") + last_token = tokens.pop + fetch_command = tokens.inject("musterb") do |str, token| + "#{str}.chain('#{token}')" + end + "#{fetch_command}['#{last_token}']" + end + def to_erb @template.gsub(/\{\{(\{?[^\}]*\}?)\}\}/) do |match| match = $1 case match[0] when '#' - "<% musterb.block '#{match[1..-1].strip}' do %>" + "<% musterb.block_if #{fetch match[1..-1]} do %>" when '^' - "<% musterb.block_unless '#{match[1..-1].strip}' do %>" + "<% musterb.block_unless #{fetch match[1..-1]} do %>" when "/" "<% end %>" when '{' - "<%= musterb['#{match[1..-2].strip}'] %>" + "<%= #{fetch match[1..-2]} %>" when '&' - "<%= musterb['#{match[1..-1].strip}'] %>" + "<%= #{fetch match[1..-1]} %>" when '!' "" + when '.' + "<%== musterb.current %>" else - "<%== musterb['#{match.strip}'] %>" + "<%== #{fetch match} %>" end end end end \ No newline at end of file