Sha256: 8f0d6cf2b54d5d2a123ea2fa706965dfdc2ee706d2f530582d397cc55e90fc96
Contents?: true
Size: 1.47 KB
Versions: 2
Compression:
Stored size: 1.47 KB
Contents
module Ro class Template def Template.render(path, node = nil) parts = File.basename(path).split('.') base = parts.shift exts = parts.reverse content = IO.binread(path).force_encoding('utf-8') loop do break if exts.empty? ext = exts.shift case ext.to_s.downcase when 'erb', 'eruby' content = Ro.erb(content, node) when 'yml' content = YAML.load(content) else tilt = Tilt[ext].new{ content } content = tilt.render(node) end end content end def Template.render_source(path, node = nil) parts = File.basename(path).split('.') base = parts.shift exts = parts.reverse content = IO.binread(path).force_encoding('utf-8') loop do break if exts.empty? ext = exts.shift if exts.empty? code = content language = ext content = ::Pygments.highlight(code, :lexer => language, :options => {:encoding => 'utf-8'}) else case ext.to_s.downcase when 'erb', 'eruby' content = Ro.erb(content, node) when 'yml' content = YAML.load(content) else tilt = Tilt[ext].new{ content } content = tilt.render(node) end end end content end fattr :path def initialize(path) @path = Ro.realpath(path) end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
ro-1.1.1 | lib/ro/template.rb |
ro-1.1.0 | lib/ro/template.rb |