Class: Locomotive::Mounter::Writer::Api::PagesWriter

Inherits:
Base
  • Object
show all
Defined in:
lib/locomotive/mounter/writer/api/pages_writer.rb

Overview

Push pages to a remote LocomotiveCMS engine.

New pages are created and existing ones are partially updated.

If the :force option is passed, the existing pages are fully updated (title, …etc). But in any cases, the content of the page will be destroyed, unless the layout of the page changes.

Instance Attribute Summary collapse

Attributes inherited from Base

#mounting_point, #runner

Instance Method Summary collapse

Methods inherited from Base

#absolute_path, #data?, #each_locale, #get, #initialize, #path_to_file, #post, #put, #replace_content_assets!, #safe_attributes

Constructor Details

This class inherits a constructor from Locomotive::Mounter::Writer::Api::Base

Instance Attribute Details

#new_pagesObject

Returns the value of attribute new_pages.



16
17
18
# File 'lib/locomotive/mounter/writer/api/pages_writer.rb', line 16

def new_pages
  @new_pages
end

#remote_translationsObject

Returns the value of attribute remote_translations.



17
18
19
# File 'lib/locomotive/mounter/writer/api/pages_writer.rb', line 17

def remote_translations
  @remote_translations
end

Instance Method Details

#prepareObject



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/locomotive/mounter/writer/api/pages_writer.rb', line 19

def prepare
  super

  self.new_pages, self.remote_translations = [], {}

  # set the unique identifier to each local page
  self.get(:pages, nil, true).each do |attributes|
    page = self.pages[attributes['fullpath'].dasherize]

    self.remote_translations[attributes['fullpath']] = attributes['translated_in']

    page._id = attributes['id'] if page
  end

  # assign the parent_id and the content_type_id to all the pages
  self.pages.values.each do |page|
    next if page.index_or_404?

    page.parent_id = page.parent._id
  end
end

#writeObject

Write all the pages to the remote destination



42
43
44
45
46
47
48
49
50
51
52
# File 'lib/locomotive/mounter/writer/api/pages_writer.rb', line 42

def write
  self.each_locale do |locale|
    self.output_locale

    # first write the pages which are layouts for others
    self.layouts.each { |page| self.write_page(page) }

    # and proceed the others
    self.other_than_layouts.each { |page| self.write_page(page) }
  end
end