Sha256: 959dcb2c2fac60b9d3d51fcc67c74be325a22fd39c7e899e5e8c6f59715bb990

Contents?: true

Size: 1.4 KB

Versions: 1

Compression:

Stored size: 1.4 KB

Contents

module Rad
  class TemplateContext
    include Tilt::CompileSite, Tilt::ContextExt
    
    # 
    # System
    #
    attr_accessor :options, :_tilt_template     
       
    # for saving :format, :current_dir and others
    # def scope_variables; @scope_variables ||= OpenObject.new end
    attr_accessor :scope_variables
    
    
    # 
    # Helpers
    # 
    inject(
      workspace: :workspace,
      router: :router,
      config: :config
    )
    
    delegate :render, to: ::Rad::Template
    delegate :url_for, to: :router        

    
    def j obj
      obj.to_s.json_escape
    end
    
    
    # 
    # Content Variables
    # 
    attr_accessor :content_block
    def content_variables; @content_variables ||= {}.to_openobject end    
    def content_for name, content = nil, &block
      content ||= capture(&block)
      (content_variables[name.to_s] ||= "") << content
      nil
    end        
    def prepend_to name, content = nil, &block
      content ||= capture(&block)
      (content_variables[name.to_s] ||= "").insert 0, content
      nil
    end
    def wrap_content_for name, &block
      block.must_be.defined
      content = capture((content_variables[name.to_s] || ""), &block)
      content_variables[name.to_s] ||= content
      nil
    end
    def has_content_for? name
      content_variables.include? name.to_s
    end    
        
    def params
      workspace.params
    end        
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rad_core-0.0.13 lib/rad/template/template_context.rb