Sha256: 998de0060006d947f5aa5c92631b9fde39c31448c2a3d1210f1b89ce3517854f

Contents?: true

Size: 1.52 KB

Versions: 28

Compression:

Stored size: 1.52 KB

Contents

module Tilt
  # 
  # Include it into your template context class for :output, :capture and :concat support
  # 
  module ContextExt
    def output
      _tilt_template.class.output(self)
    end
  
    def capture *args, &block
      _tilt_template.class.capture self, &block      
    end
  
    def concat value
      _tilt_template.class.concat self, value
    end
  end  
  
  class Template
    def self.get_output context
      raise "Output variable for #{self.class} not defined!"
    end
    
    def self.capture context, &block
      raise "capture not implemented for #{self.class}!"
    end
    
    def self.concat context, value
      raise "concat not implemented for #{self.class}!"
    end
  end
  
  class ERBTemplate
    def self.get_output context
      context.instance_variable_get "@output"
    end
    
    def self.capture context, &block
      begin
        old_output = context.instance_variable_get "@output"
        old_output.must_be.defined
        context.instance_variable_set "@output", ""
        block.call
        context.instance_variable_get "@output"
      ensure
        context.instance_variable_set "@output", old_output
      end      
    end
    
    def self.concat context, value
      get_output(context) << value
    end    
  end
  
  class HamlTemplate
    def self.get_output context
      context.haml_buffer.buffer
    end
    
    def self.capture context, &block
      context.capture_haml &block
    end
    
    def self.concat context, value
      context.haml_concat value
    end
  end
end

Version data entries

28 entries across 28 versions & 3 rubygems

Version Path
rad_core-0.2.6 lib/rad/template/_support/tilt.rb
rad_core-0.2.5 lib/rad/template/_support/tilt.rb
rad_core-0.2.4 lib/rad/template/_support/tilt.rb
rad_core-0.2.3 lib/rad/template/_support/tilt.rb
rad_core-0.2.2 lib/rad/template/_support/tilt.rb
rad_core-0.2.1 lib/rad/template/_support/tilt.rb
rad_core-0.2.0 lib/rad/template/_support/tilt.rb
rad_core-0.0.30 lib/rad/template/_support/tilt.rb
rad_core-0.0.29 lib/rad/template/_support/tilt.rb
rad_core-0.0.28 lib/rad/template/_support/tilt.rb
rad_core-0.0.27 lib/rad/template/_support/tilt.rb
rad_core-0.0.26 lib/rad/template/_support/tilt.rb
rad_core-0.0.25 lib/rad/template/_support/tilt.rb
rad_core-0.0.24 lib/rad/template/_support/tilt.rb
rad_core-0.0.23 lib/rad/template/_support/tilt.rb
rad_core-0.0.22 lib/rad/template/_support/tilt.rb
rad_core-0.0.21 lib/rad/template/_support/tilt.rb
rad_core-0.0.20 lib/rad/template/_support/tilt.rb
rad_core-0.0.19 lib/rad/template/_support/tilt.rb
rad_core-0.0.18 lib/rad/template/_support/tilt.rb