class Rodakase::View::Layout

Constants

DEFAULT_DIR
DEFAULT_SCOPE
Scope

Attributes

config[R]
layout_dir[R]
layout_path[R]
renderer[R]
scope[R]
template_path[R]

Public Class Methods

configure() { |config| ... } click to toggle source
Calls superclass method
# File lib/rodakase/view/layout.rb, line 26
def self.configure(&block)
  super do |config|
    yield(config)

    unless config.renderer
      config.renderer = Renderer.new(config.root, engine: config.engine)
    end
  end
end
new() click to toggle source
# File lib/rodakase/view/layout.rb, line 39
def initialize
  @config = self.class.config
  @renderer = @config.renderer
  @layout_dir = DEFAULT_DIR
  @layout_path = "#{layout_dir}/#{config.name}"
  @template_path = config.template
  @scope = config.scope
end

Public Instance Methods

call(options = {}) click to toggle source
# File lib/rodakase/view/layout.rb, line 48
def call(options = {})
  renderer.(layout_path, layout_scope(options)) do
    renderer.(template_path, template_scope(options))
  end
end
layout_part(name, value) click to toggle source
# File lib/rodakase/view/layout.rb, line 85
def layout_part(name, value)
  part(layout_dir, name => value)
end
layout_scope(options) click to toggle source
# File lib/rodakase/view/layout.rb, line 54
def layout_scope(options)
  Scope.new(layout_part(:page, options.fetch(:scope, scope)))
end
locals(options) click to toggle source
# File lib/rodakase/view/layout.rb, line 62
def locals(options)
  options.fetch(:locals, {})
end
part(dir, value) click to toggle source
# File lib/rodakase/view/layout.rb, line 93
def part(dir, value)
  Part.new(renderer.chdir(dir), value)
end
parts(locals) click to toggle source
# File lib/rodakase/view/layout.rb, line 66
def parts(locals)
  return DEFAULT_SCOPE unless locals.any?

  part_hash = locals.each_with_object({}) do |(key, value), result|
    part =
      case value
      when Array
        el_key = Inflecto.singularize(key).to_sym
        template_part(key, value.map { |element| template_part(el_key, element) })
      else
        template_part(key, value)
      end

    result[key] = part
  end

  part(template_path, part_hash)
end
template_part(name, value) click to toggle source
# File lib/rodakase/view/layout.rb, line 89
def template_part(name, value)
  part(template_path, name => value)
end
template_scope(options) click to toggle source
# File lib/rodakase/view/layout.rb, line 58
def template_scope(options)
  parts(locals(options))
end