Sha256: 9867a44150bd7492cba83957459304b5364366346d29fb6df148a2e1b82f6245

Contents?: true

Size: 1.36 KB

Versions: 3

Compression:

Stored size: 1.36 KB

Contents

module Crystal
  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 => ::Crystal::Template
    delegate :url_for, :to => :router        
    
    
    # 
    # Content Variables
    # 
    attr_accessor :content_block
    def content_variables; @content_variables ||= {} 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

3 entries across 3 versions & 2 rubygems

Version Path
crystal-0.0.13 lib/crystal/template/template_context.rb
crystal-0.0.12 lib/crystal/template/template_context.rb
crystal_ext-0.0.11 lib/crystal/template/template_context.rb