Class: Argyle::Blueprint
- Inherits:
-
Object
- Object
- Argyle::Blueprint
- Defined in:
- lib/argyle/blueprint.rb
Instance Attribute Summary collapse
- #pages ⇒ Hash{Symbol=>Argyle::Page} readonly
Instance Method Summary collapse
- #add_page(page_klass) ⇒ Object
-
#initialize(layout_factory: nil, layout_registry: nil, page_factory: nil, renderer: nil) ⇒ Blueprint
constructor
A new instance of Blueprint.
- #render ⇒ Object
Constructor Details
#initialize(layout_factory: nil, layout_registry: nil, page_factory: nil, renderer: nil) ⇒ Blueprint
Returns a new instance of Blueprint.
12 13 14 15 16 17 18 19 20 |
# File 'lib/argyle/blueprint.rb', line 12 def initialize(layout_factory: nil, layout_registry: nil, page_factory: nil, renderer: nil) @pages = {} @layouts = [] @current_page = nil @layout_factory = layout_factory || Argyle::Layout::Factory.new @layout_registry = layout_registry || create_layout_registry @page_factory = page_factory || Argyle::Page::Factory.new(@layout_registry) @renderer = renderer || Argyle::Renderer.new end |
Instance Attribute Details
#pages ⇒ Hash{Symbol=>Argyle::Page} (readonly)
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/argyle/blueprint.rb', line 4 class Argyle::Blueprint attr_reader :pages # @param layout_factory [Argyle::Layout::Factory] # @param layout_registry [Argyle::Layout::Registry] # @param page_factory [Argyle::Page::Factory] # @param renderer [Argyle::Renderer] # def initialize(layout_factory: nil, layout_registry: nil, page_factory: nil, renderer: nil) @pages = {} @layouts = [] @current_page = nil @layout_factory = layout_factory || Argyle::Layout::Factory.new @layout_registry = layout_registry || create_layout_registry @page_factory = page_factory || Argyle::Page::Factory.new(@layout_registry) @renderer = renderer || Argyle::Renderer.new end private def create_layout_registry registry = Argyle::Layout::Registry.new registry.add(@layout_factory.create(Argyle::Layout::Default)) registry end public # @param page_klass [Class<Argyle::Page::Base>] Subclass of Argyle::Page::Base # def add_page(page_klass) raise Argyle::Error::ArgumentError.new("Page #{page_klass} has no id") if page_klass.identifier.nil? page = @page_factory.create(page_klass) @pages[page_klass.identifier] = page @current_page = page if @current_page.nil? end # @note Renders the current page # def render raise Argyle::Error::NotFound.new('No pages defined yet') if @pages.empty? @renderer.render(@current_page) end end |
Instance Method Details
#add_page(page_klass) ⇒ Object
35 36 37 38 39 40 41 42 |
# File 'lib/argyle/blueprint.rb', line 35 def add_page(page_klass) raise Argyle::Error::ArgumentError.new("Page #{page_klass} has no id") if page_klass.identifier.nil? page = @page_factory.create(page_klass) @pages[page_klass.identifier] = page @current_page = page if @current_page.nil? end |