Class: Rodakase::View::Layout
- Inherits:
-
Object
- Object
- Rodakase::View::Layout
- Extended by:
- Dry::Configurable
- Defined in:
- lib/rodakase/view/layout.rb
Defined Under Namespace
Classes: Scope
Constant Summary collapse
- DEFAULT_SCOPE =
Object.new.freeze
- DEFAULT_DIR =
'layouts'.freeze
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#layout_dir ⇒ Object
readonly
Returns the value of attribute layout_dir.
-
#layout_path ⇒ Object
readonly
Returns the value of attribute layout_path.
-
#renderer ⇒ Object
readonly
Returns the value of attribute renderer.
-
#scope ⇒ Object
readonly
Returns the value of attribute scope.
-
#template_path ⇒ Object
readonly
Returns the value of attribute template_path.
Class Method Summary collapse
Instance Method Summary collapse
- #call(options = {}) ⇒ Object
-
#initialize ⇒ Layout
constructor
A new instance of Layout.
- #layout_part(name, value) ⇒ Object
- #layout_scope(options) ⇒ Object
- #locals(options) ⇒ Object
- #part(dir, value) ⇒ Object
- #parts(locals) ⇒ Object
- #template_part(name, value) ⇒ Object
- #template_scope(options) ⇒ Object
Constructor Details
#initialize ⇒ Layout
Returns a new instance of Layout.
39 40 41 42 43 44 45 46 |
# 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 |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
36 37 38 |
# File 'lib/rodakase/view/layout.rb', line 36 def config @config end |
#layout_dir ⇒ Object (readonly)
Returns the value of attribute layout_dir.
36 37 38 |
# File 'lib/rodakase/view/layout.rb', line 36 def layout_dir @layout_dir end |
#layout_path ⇒ Object (readonly)
Returns the value of attribute layout_path.
36 37 38 |
# File 'lib/rodakase/view/layout.rb', line 36 def layout_path @layout_path end |
#renderer ⇒ Object (readonly)
Returns the value of attribute renderer.
36 37 38 |
# File 'lib/rodakase/view/layout.rb', line 36 def renderer @renderer end |
#scope ⇒ Object (readonly)
Returns the value of attribute scope.
36 37 38 |
# File 'lib/rodakase/view/layout.rb', line 36 def scope @scope end |
#template_path ⇒ Object (readonly)
Returns the value of attribute template_path.
36 37 38 |
# File 'lib/rodakase/view/layout.rb', line 36 def template_path @template_path end |
Class Method Details
Instance Method Details
#call(options = {}) ⇒ Object
48 49 50 51 52 |
# File 'lib/rodakase/view/layout.rb', line 48 def call( = {}) renderer.(layout_path, layout_scope()) do renderer.(template_path, template_scope()) end end |
#layout_part(name, value) ⇒ Object
85 86 87 |
# File 'lib/rodakase/view/layout.rb', line 85 def layout_part(name, value) part(layout_dir, name => value) end |
#layout_scope(options) ⇒ Object
54 55 56 |
# File 'lib/rodakase/view/layout.rb', line 54 def layout_scope() Scope.new(layout_part(:page, .fetch(:scope, scope))) end |
#locals(options) ⇒ Object
62 63 64 |
# File 'lib/rodakase/view/layout.rb', line 62 def locals() .fetch(:locals, {}) end |
#part(dir, value) ⇒ Object
93 94 95 |
# File 'lib/rodakase/view/layout.rb', line 93 def part(dir, value) Part.new(renderer.chdir(dir), value) end |
#parts(locals) ⇒ Object
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# 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) ⇒ Object
89 90 91 |
# File 'lib/rodakase/view/layout.rb', line 89 def template_part(name, value) part(template_path, name => value) end |
#template_scope(options) ⇒ Object
58 59 60 |
# File 'lib/rodakase/view/layout.rb', line 58 def template_scope() parts(locals()) end |