Class: PageFactory::Base

Inherits:
Object
  • Object
show all
Includes:
Annotatable
Defined in:
lib/page_factory/base.rb

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.partsObject

Returns the value of attribute parts.



8
9
10
# File 'lib/page_factory/base.rb', line 8

def parts
  @parts
end

Class Method Details

.descendantsObject



47
48
49
50
# File 'lib/page_factory/base.rb', line 47

def descendants
  load_descendants
  super
end

.inherited(subclass) ⇒ Object



10
11
12
13
14
15
# File 'lib/page_factory/base.rb', line 10

def inherited(subclass)
  subclass.parts = @parts.dup
  subclass.layout = layout
  subclass.page_class = page_class
  subclass.template_name = subclass.name.to_name('Factory')
end

.part(name, attrs = {}) ⇒ Object

Add a part to this PageFactory

Examples:

Add a part with default content and some help text

part 'Sidebar', :content => "Lorem ipsum dolor",
                :description => "This appears in the right-hand sidebar."

Parameters:

  • name (String)

    The name of the page part

  • attrs (Hash) (defaults to: {})

    A hash of attributes used to construct this part.

Options Hash (attrs):

  • :description (String)

    Some additional text that will be shown in the part’s tab on the page editing screen. This is used to display a part description or helper text to editors.



29
30
31
32
# File 'lib/page_factory/base.rb', line 29

def part(name, attrs={})
  remove name
  @parts << PagePart.new(attrs.merge(:name => name))
end

.remove(*names) ⇒ Object

Remove a part from this PageFactory

Examples:

remove 'body'
remove 'body', 'extended'

Parameters:

  • names (<String>)

    Any number of part names to remove.



42
43
44
45
# File 'lib/page_factory/base.rb', line 42

def remove(*names)
  names = names.map(&:downcase)
  @parts.delete_if { |p| names.include? p.name.downcase }
end