Sha256: 2cc1db3eca4986aa8511ebace6b363444b619b9698971c8214eacbe89dc028e6

Contents?: true

Size: 679 Bytes

Versions: 1

Compression:

Stored size: 679 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)
      self.application = application
      self.env = env
    end

    def request
      @_request ||= Rack::Request.new(env)
    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

1 entries across 1 versions & 1 rubygems

Version Path
brochure-0.2.0 lib/brochure/context.rb