class Pakyow::Presenter::Views::Page
Constants
- DEFAULT_CONTAINER
- WITHIN_REGEX
Attributes
name[R]
path[R]
Public Class Methods
load(path, content: nil, **args)
click to toggle source
# 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
new(name, html = "", path: nil, info: {}, **args)
click to toggle source
Calls superclass method
Pakyow::Presenter::View::new
# 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
Public Instance Methods
container_views()
click to toggle source
# File lib/pakyow/presenter/views/page.rb, line 55 def container_views [View.from_object(@object)].concat(@containers.values) end
content(container)
click to toggle source
# 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(_)
click to toggle source
Calls superclass method
Pakyow::Presenter::View#initialize_copy
# 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)
click to toggle source
Calls superclass method
Pakyow::Presenter::View#mixin
# File lib/pakyow/presenter/views/page.rb, line 47 def mixin(partials) super @containers.values.each do |view| view.mixin(partials) end end
Private Instance Methods
parse_content(html)
click to toggle source
# File lib/pakyow/presenter/views/page.rb, line 63 def parse_content(html) html.scan(WITHIN_REGEX) do |match| container_name = match[0].to_sym @containers[container_name] = View.from_object(StringDoc.new(match[1])) end html.gsub!(WITHIN_REGEX, "") end