Sha256: 469dd5109a1516e1db2b0ea8219d4e0edb71024b1315df87214c4580298e2b7a
Contents?: true
Size: 1.65 KB
Versions: 15
Compression:
Stored size: 1.65 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] || Tilt['txt'] if tilt.nil? content else content = tilt.new{ content }.render(node) end 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 = begin ::Pygments.highlight(code, :lexer => language, :options => {:encoding => 'utf-8'}) rescue content end 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
15 entries across 15 versions & 1 rubygems