Sha256: 81c127549e676350a71ed4f4d853ffcf6eeeccfad27a5e3831a003e3c1043255
Contents?: true
Size: 1.07 KB
Versions: 1
Compression:
Stored size: 1.07 KB
Contents
module ExpressTemplates module Compiler def compile(template_or_src=nil, &block) template, src = _normalize(template_or_src) expander = Expander.new(template) Thread.current[:first_whitepace_removed] ||= 0 Thread.current[:first_whitepace_removed] += 1 begin compiled = expander.expand(src, &block).map(&:compile) compiled.first.sub!(/^"\n+/, '"') if Thread.current[:first_whitepace_removed].eql?(1) Thread.current[:first_whitepace_removed] -= 1 ensure Thread.current[:first_whitepace_removed] = nil if Thread.current[:first_whitepace_removed].eql?(0) end return compiled.join("+").gsub('"+"', '').tap do |s| puts("\n"+template.inspect+"\n"+s) if ENV['DEBUG'].eql?('true') end end private def _normalize(template_or_src) template, src = nil, nil if template_or_src.respond_to?(:source) template = template_or_src src = template_or_src.source else src = template_or_src end return template, src end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
express_templates-0.3.0 | lib/express_templates/compiler.rb |