class Trekky::HamlSource

Attributes

regions[R]

Public Class Methods

new(context, path) click to toggle source
Calls superclass method
# File lib/trekky/haml_source.rb, line 9
def initialize(context, path)
  super
  @regions = {}
  @env = {}
end

Public Instance Methods

content_for(name, &block) click to toggle source
# File lib/trekky/haml_source.rb, line 46
def content_for(name, &block)
  return unless block_given?
  regions[name] = capture_haml(&block)
end
partial(name) click to toggle source
# File lib/trekky/haml_source.rb, line 37
def partial(name)
  source = context.find_partial(name)
  if source
    source.render(layout: false)
  else
    STDERR.puts "[ERROR] Can't find partial: #{name}"
  end
end
render(options = {}, &block) click to toggle source
# File lib/trekky/haml_source.rb, line 15
def render(options = {}, &block)
  clear_errors
  @output = if block_given? || options[:layout] == false
    render_input(&block)
  else
    buffer = render_input
    if layout
      layout.render do |name|
        if region.nil?
          buffer
        elsif regions.has_key?(name)
          regions[name]
        end
      end
    else
      buffer
    end
  end
rescue Exception => error
  add_error error
end
type() click to toggle source
# File lib/trekky/haml_source.rb, line 51
def type
  :haml
end

Private Instance Methods

layout() click to toggle source
# File lib/trekky/haml_source.rb, line 65
def layout
  @context.layouts.first
end
locals() click to toggle source
# File lib/trekky/haml_source.rb, line 61
def locals
  {}
end
render_input(&block) click to toggle source
# File lib/trekky/haml_source.rb, line 57
def render_input(&block)
  Haml::Engine.new(input).render(self, locals, &block)
end