Sha256: f423a03e93ba215b37219e6d3bb5a1a1fad9241f2572a7b4d7d4dcadde1c1b9f

Contents?: true

Size: 1.44 KB

Versions: 19

Compression:

Stored size: 1.44 KB

Contents

module Locomotive::Wagon

  class PullPagesCommand < PullBaseCommand

    attr_reader :fullpaths

    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

    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
      end
    end

    private

    def yaml_attributes(page, locale)
      attributes = page.attributes.slice('title', 'slug', 'handle', 'position', 'listed', 'published', 'redirect_url', 'is_layout', 'content_type', 'seo_title', 'meta_description', 'meta_keywords')

      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

    def page_filepath(page, locale)
      fullpath = locale == default_locale ? page.fullpath : "#{fullpaths[page._id]}.#{locale}"
      File.join('app', 'views', 'pages', fullpath + '.liquid')
    end

  end

end

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
locomotivecms_wagon-2.2.0.rc1 lib/locomotive/wagon/commands/pull_sub_commands/pull_pages_command.rb
locomotivecms_wagon-2.2.0.beta1 lib/locomotive/wagon/commands/pull_sub_commands/pull_pages_command.rb
locomotivecms_wagon-2.1.1 lib/locomotive/wagon/commands/pull_sub_commands/pull_pages_command.rb
locomotivecms_wagon-2.1.0 lib/locomotive/wagon/commands/pull_sub_commands/pull_pages_command.rb
locomotivecms_wagon-2.1.0.rc5 lib/locomotive/wagon/commands/pull_sub_commands/pull_pages_command.rb
locomotivecms_wagon-2.1.0.rc4 lib/locomotive/wagon/commands/pull_sub_commands/pull_pages_command.rb
locomotivecms_wagon-2.1.0.rc3 lib/locomotive/wagon/commands/pull_sub_commands/pull_pages_command.rb
locomotivecms_wagon-2.0.1 lib/locomotive/wagon/commands/pull_sub_commands/pull_pages_command.rb
locomotivecms_wagon-2.0.0 lib/locomotive/wagon/commands/pull_sub_commands/pull_pages_command.rb
locomotivecms_wagon-2.0.0.rc8 lib/locomotive/wagon/commands/pull_sub_commands/pull_pages_command.rb
locomotivecms_wagon-2.0.0.rc7 lib/locomotive/wagon/commands/pull_sub_commands/pull_pages_command.rb
locomotivecms_wagon-2.0.0.rc6 lib/locomotive/wagon/commands/pull_sub_commands/pull_pages_command.rb
locomotivecms_wagon-2.0.0.rc5 lib/locomotive/wagon/commands/pull_sub_commands/pull_pages_command.rb
locomotivecms_wagon-2.0.0.rc4 lib/locomotive/wagon/commands/pull_sub_commands/pull_pages_command.rb
locomotivecms_wagon-2.0.0.rc3 lib/locomotive/wagon/commands/pull_sub_commands/pull_pages_command.rb
locomotivecms_wagon-2.0.0.rc2 lib/locomotive/wagon/commands/pull_sub_commands/pull_pages_command.rb
locomotivecms_wagon-2.0.0.rc1 lib/locomotive/wagon/commands/pull_sub_commands/pull_pages_command.rb
locomotivecms_wagon-2.0.0.pre.beta.2 lib/locomotive/wagon/commands/pull_sub_commands/pull_pages_command.rb
locomotivecms_wagon-2.0.0.pre.beta.1 lib/locomotive/wagon/commands/pull_sub_commands/pull_pages_command.rb