class Locomotive::Wagon::PullPagesCommand

Attributes

fullpaths[R]

Public Instance Methods

_pull() click to toggle source
# File lib/locomotive/wagon/commands/pull_sub_commands/pull_pages_command.rb, line 7
def _pull
  @fullpaths = {}

  locales.each do |locale|
    api_client.pages.all(locale).each do |page|
      fullpaths[page._id] = page.fullpath if locale == default_locale
      write_page(page, locale)
    end
  end
end
write_page(page, locale = nil) click to toggle source
# File lib/locomotive/wagon/commands/pull_sub_commands/pull_pages_command.rb, line 18
    def write_page(page, locale = nil)
      write_to_file(page_filepath(page, locale)) do
<<-EOF
#{yaml_attributes(page, locale)}---
#{replace_asset_urls(page.template)}
EOF
        .gsub(/\n$/, '')
      end
    end

Private Instance Methods

page_filepath(page, locale) click to toggle source
# File lib/locomotive/wagon/commands/pull_sub_commands/pull_pages_command.rb, line 52
def page_filepath(page, locale)
  fullpath = locale == default_locale ? page.fullpath : "#{fullpaths[page._id]}.#{locale}"
  File.join('app', 'views', 'pages', fullpath + '.liquid')
end
yaml_attributes(page, locale) click to toggle source
# File lib/locomotive/wagon/commands/pull_sub_commands/pull_pages_command.rb, line 30
def yaml_attributes(page, locale)
  keys = ['title', 'slug', 'handle', 'position', 'listed', 'published', 'redirect_url', 'is_layout', 'content_type', 'seo_title', 'meta_description', 'meta_keywords', 'display_settings']

  keys << 'response_type' if page.attributes['response_type'] != 'text/html'

  attributes = page.attributes.slice(*keys)

  if locale != default_locale
    attributes.delete_if { |k, _| %w(handle position listed published is_layout content_type).include?(k) }
  end

  # editable elements
  attributes['editable_elements'] = page.editable_elements.inject({}) do |hash, el|
    hash["#{el['block']}/#{el['slug']}"] = replace_asset_urls(el['content']) if el['content']
    hash
  end

  clean_attributes(attributes)

  attributes.to_yaml
end