class NThrut
Public Class Methods
new(parent)
click to toggle source
# File lib/nthrut.rb, line 13 def initialize(parent) @parent = parent @templates = {} end
Public Instance Methods
haml(name,options={})
click to toggle source
# File lib/nthrut.rb, line 25 def haml(name,options={}) render name, :haml, options end
slim(name,options={})
click to toggle source
# File lib/nthrut.rb, line 29 def slim(name,options={}) render name, :slim, options end
template(name, type=nil, &blk)
click to toggle source
# File lib/nthrut.rb, line 33 def template(name, type=nil, &blk) @templates.merge!({name => {content: blk.call, type: type}}) @templates[name] end
transform(xsl, xml)
click to toggle source
jr 140616 not yet used and still needs to be tested
# File lib/nthrut.rb, line 21 def transform(xsl, xml) Rexslt.new(xsl, xml).to_s end
Private Instance Methods
render(name, type, opt={})
click to toggle source
# File lib/nthrut.rb, line 41 def render(name, type, opt={}) options = {locals: {}}.merge!(opt) locals = options.delete :locals unless @templates[:layout] then template(:layout, type) { File.read('views/layout.' + type.to_s) } end layout = Tilt[type.to_s].new(options) {|x| @templates[:layout][:content]} unless @templates[name] then template(name, type) { File.read("views/%s.%s" % [name.to_s, type.to_s])} end template = Tilt[type.to_s].new(options) {|x| @templates[name][:content]} layout.render{ template.render(@parent, locals)} end
tilt(name, options={})
click to toggle source
# File lib/nthrut.rb, line 60 def tilt(name, options={}) options = {locals: {}}.merge!(opt) locals = options.delete :locals layout = Tilt[@templates[:layout][:type].to_s].new(options)\ {|x| @templates[:layout][:content]} template = Tilt[@templates[name][:type].to_s].new(options) \ {|x| @templates[name][:content]} layout.render{ template.render(@parent, locals)} end