Sha256: cbc9b3e122f5825ad58f41aab7de3e194d4a4981a5bb1d905bad42f2a74a6534
Contents?: true
Size: 916 Bytes
Versions: 2
Compression:
Stored size: 916 Bytes
Contents
module Brochure class Context include Tilt::CompileSite def self.for(helpers) context = Class.new(self) context.send(:include, *helpers) if helpers.any? context end attr_accessor :application, :env def initialize(application, env, assigns = {}) self.application = application self.env = env load_assigns(assigns) end def load_assigns(assigns) assigns.each do |name, value| instance_variable_set("@#{name}", value) end end def request @_request ||= Rack::Request.new(env) end def h(html) Rack::Utils.escape_html(html) end def render(logical_path, locals = {}) if template = @application.find_partial(logical_path) @application.render_template(template, env, locals) else raise TemplateNotFound, "no such template '#{logical_path}'" end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
brochure-0.3.1 | lib/brochure/context.rb |
brochure-0.3.0 | lib/brochure/context.rb |