Method: Pageflow::Seeds#sample_entry

Defined in:
lib/pageflow/seeds.rb

#sample_entry(attributes) {|entry| ... } ⇒ Entry

Create a sample Entry with some chapter, pages, and optional text if no entry with that title exists in the given account.

Parameters:

  • attributes (Hash)

    attributes to override defaults

Options Hash (attributes):

  • :account (Account)

    required

  • :title (String)

    required

  • :text (String)

    optional

Yields:

  • (entry)

    a block to be called before the entry is saved

Returns:

  • (Entry)

    newly created entry



109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
# File 'lib/pageflow/seeds.rb', line 109

def sample_entry(attributes)
  entry = Entry.where(attributes.slice(:account, :title)).first
  page_text = attributes.delete(:text) { |_| '' }

  if entry.nil?
    entry = Entry.create!(attributes) do |created_entry|
      created_entry.site = attributes.fetch(:account).default_site

      say_creating_entry(created_entry)
      yield(created_entry) if block_given?
    end

    storyline = entry.draft.storylines.first
    chapter = storyline.chapters.create!(title: 'Chapter 1', position: 0)
    chapter.pages.create!(template: 'background_image',
                          configuration: {text: page_text})
    chapter.pages.create!(template: 'background_image',
                          configuration: {text: page_text})

    chapter = storyline.chapters.create!(title: 'Chapter 2', position: 1)
    chapter.pages.create!(template: 'video', configuration: {text: page_text})
  end

  entry
end