Class: Pakyow::Presenter::Views::Page

Inherits:
Pakyow::Presenter::View show all
Defined in:
lib/pakyow/presenter/views/page.rb

Constant Summary collapse

DEFAULT_CONTAINER =
:main

Constants inherited from Pakyow::Presenter::View

Pakyow::Presenter::View::INFO_MERGER

Instance Attribute Summary collapse

Attributes inherited from Pakyow::Presenter::View

#logical_path, #object

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Pakyow::Presenter::View

#==, #add_info, #after, #append, #attributes, #attributes=, #before, #bind, #binding?, #binding_name, #binding_prop?, #binding_props, #binding_scope?, #binding_scopes, #body, #channeled_binding_name, #channeled_binding_scope?, #clear, #component, #components, #container?, #each_binding, #each_binding_prop, #each_binding_scope, #find, #find_all, #find_partials, #form, #form?, #forms, from_object, from_view_or_string, #head, #html=, #info, #partial?, #plural_binding_name, #plural_channeled_binding_name, #prepend, #remove, #replace, #singular_binding_name, #singular_channeled_binding_name, #soft_copy, #title, #to_html, #to_s, #transform, #version, #with

Constructor Details

#initialize(name, html = "", path: nil, info: {}, **args) ⇒ Page



19
20
21
22
23
24
25
# File 'lib/pakyow/presenter/views/page.rb', line 19

def initialize(name, html = "", path: nil, info: {}, **args)
  @containers = {}
  parse_content(html)
  @name, @path = name, path
  info[:layout] ||= :default
  super(html, info: info, **args)
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



11
12
13
# File 'lib/pakyow/presenter/views/page.rb', line 11

def name
  @name
end

#pathObject (readonly)

Returns the value of attribute path.



11
12
13
# File 'lib/pakyow/presenter/views/page.rb', line 11

def path
  @path
end

Class Method Details

.load(path, content: nil, **args) ⇒ Object



14
15
16
# File 'lib/pakyow/presenter/views/page.rb', line 14

def load(path, content: nil, **args)
  self.new(File.basename(path, ".*").to_sym, content || File.read(path), **args, path: path)
end

Instance Method Details

#container_viewsObject



55
56
57
# File 'lib/pakyow/presenter/views/page.rb', line 55

def container_views
  [View.from_object(@object)].concat(@containers.values)
end

#content(container) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
# File 'lib/pakyow/presenter/views/page.rb', line 35

def content(container)
  container = container.to_sym

  if container == DEFAULT_CONTAINER
    @object
  elsif @containers.key?(container)
    @containers[container].object
  else
    nil
  end
end

#initialize_copy(_) ⇒ Object



27
28
29
30
31
32
33
# File 'lib/pakyow/presenter/views/page.rb', line 27

def initialize_copy(_)
  super

  @containers = Hash[@containers.map { |key, value|
    [key, value.dup]
  }]
end

#mixin(partials) ⇒ Object



47
48
49
50
51
52
53
# File 'lib/pakyow/presenter/views/page.rb', line 47

def mixin(partials)
  super

  @containers.values.each do |view|
    view.mixin(partials)
  end
end