lib/hmote.rb in hmote-1.2.0 vs lib/hmote.rb in hmote-1.3.0
- old
+ new
@@ -1,22 +1,22 @@
require "hache"
class HMote
- PATTERN = /^(\n)| # newlines.
- ^\s*(%)\s*(.*?)(?:\n|\Z)| # % single-line code
- (<\?)\s+(.*?)\s+\?>| # <? multi-line code ?>
- (\{\{!?)(.*?)\}\} # {{ escape }} or {{! unescape }}
+ PATTERN = /
+ ^[^\S\n]*(%)[^\S\n]*(.*?)(?:\n|\z) | # % single-line code
+ (<\?)\s+(.*?)\s+\?> | # <? multi-line code ?>
+ (\{\{!?)(.*?)\}\} # {{ escape }} or {{! unescape }}
/mx
def self.parse(template, context = self, vars = [])
terms = template.split(PATTERN)
parts = "Proc.new do |params, __o|\n params ||= {}; __o ||= ''\n"
vars.each do |var|
- parts << "%s = params[%s]\n" % [var, var.inspect]
+ parts << sprintf("%s = params[%p]\n", var, var)
end
- while term = terms.shift
+ while (term = terms.shift)
case term
when "<?" then parts << "#{terms.shift}\n"
when "%" then parts << "#{terms.shift}\n"
when "{{" then parts << "__o << Hache.h((#{terms.shift}).to_s)\n"
when "{{!" then parts << "__o << (#{terms.shift}).to_s\n"