Sha256: 8f22f5f0583768c4b507cdd7b0ebba8135e3b0399c564d05c89601b2605ef332
Contents?: true
Size: 1.34 KB
Versions: 1
Compression:
Stored size: 1.34 KB
Contents
module Rcurse class Engine def self.render content, context = Context.new content.gsub /{({|%=|%)(.+?)[}|%]}/ do |s| result = s case $1 when "{" s = $2.chomp.split(" ") name = s[0] args = s[1..s.length] if Rcurse::helpers[name].is_a? Rcurse::Helper then result = Rcurse::helpers[name].callback.call(args, context) end when "%" context.eval($2) result = "" when "%=" result = context.eval($2) end result end end def self.render_file filename, out_filename, context = Context.new content = File.read(filename) context.path = File.dirname(filename) rendered_content = self.render(content, context) File.open(out_filename, "w+") do |file| file.write(rendered_content) end end end def self.render content, context = Context.new Rcurse::Engine.render content, context end def self.render_file filename, out_filename, context = Context.new Rcurse::Engine.render_file filename, out_filename, context end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
rcurse-0.5.1 | lib/rcurse/engine.rb |