Class: Refinerycms::PageSeeder::Seeder

Inherits:
Object
  • Object
show all
Defined in:
lib/refinerycms-page_seeder/seeder.rb

Class Method Summary collapse

Class Method Details

.create_page(name, options = nil) ⇒ Object

Create a page if it does not already exist



7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/refinerycms-page_seeder/seeder.rb', line 7

def self.create_page(name, options=nil)
  unless ::Refinery::Page.find_by_title(name)
    options ||= {}
    options.merge!(:title => name)
    page = ::Refinery::Page.create(options)

    ::Refinery::Pages.config.default_parts.each do |default_page_part|
      page.parts.create(:title => default_page_part, :body => nil)
    end

    page
  end
end

.create_parent_and_children(parent_name, children_names = nil) ⇒ Object

Create a parent page with an array of children (optional)



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/refinerycms-page_seeder/seeder.rb', line 22

def self.create_parent_and_children(parent_name, children_names=nil)
  unless ::Refinery::Page.find_by_title(parent_name)
    parent_page = ::Refinery::Page.create(:title => parent_name)

    ::Refinery::Pages.config.default_parts.each do |default_page_part|
      parent_page.parts.create(:title => default_page_part, :body => nil)
    end

    if children_names.present?
      children_names.each do |child|
        unless ::Refinery::Page.find_by_title(child)
          child_page = parent_page.children.create(:title => child)

          ::Refinery::Pages.config.default_parts.each do |default_page_part|
            child_page.parts.create(:title => default_page_part, :body => nil)
          end
        end
      end
    end
  end
end