Sha256: 4bd8155a7bfe3940e09e15f7dc938efd49c9c03801a0a75e5d3530d77c3e846a

Contents?: true

Size: 1.13 KB

Versions: 20

Compression:

Stored size: 1.13 KB

Contents

module Ecm
  module Cms
    module Importers
      class Page
        def initialize(yaml, _option = {})
          @pages = nil
          @yaml = YAML.load(yaml)
        end

        def build_pages
          pages = []
          @yaml.each do |page_data|
            navigation_items = extract_navigation_items(page_data.delete('navigation_items'))
            page = Ecm::Cms::Page.new(page_data)
            page.ecm_cms_navigation_item_ids = navigation_items.map(&:id)
            pages << page
          end if @yaml.respond_to?(:each)
          pages
        end

        def extract_navigation_items(navigation_item_data)
          navigation_items = []
          navigation_item_data.each do |nid|
            navigation = Ecm::Cms::Navigation.where(locale: nid['navigation_locale'], name: nid['navigation_name']).first
            navigation_items << navigation.ecm_cms_navigation_items.where(name: nid['name']).first if navigation.respond_to?(:ecm_cms_navigation_items)
          end
          navigation_items
        end

        def pages
          @pages ||= build_pages
        end

        attr_reader :yaml
      end
    end
  end
end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
ecm_cms2-5.1.2 lib/ecm/cms/importers/page.rb
ecm_cms2-5.1.1 lib/ecm/cms/importers/page.rb
ecm_cms2-5.1.0 lib/ecm/cms/importers/page.rb
ecm_cms2-5.0.0 lib/ecm/cms/importers/page.rb
ecm_cms2-4.1.1 lib/ecm/cms/importers/page.rb
ecm_cms2-4.1.0 lib/ecm/cms/importers/page.rb
ecm_cms2-4.0.1 lib/ecm/cms/importers/page.rb
ecm_cms2-4.0.0 lib/ecm/cms/importers/page.rb
ecm_cms2-3.0.3 lib/ecm/cms/importers/page.rb
ecm_cms2-3.0.2 lib/ecm/cms/importers/page.rb
ecm_cms2-3.0.1 lib/ecm/cms/importers/page.rb
ecm_cms2-3.0.0 lib/ecm/cms/importers/page.rb
ecm_cms2-2.1.4 lib/ecm/cms/importers/page.rb
ecm_cms2-2.1.3 lib/ecm/cms/importers/page.rb
ecm_cms2-2.1.2 lib/ecm/cms/importers/page.rb
ecm_cms2-2.1.1 lib/ecm/cms/importers/page.rb
ecm_cms2-2.1.0 lib/ecm/cms/importers/page.rb
ecm_cms2-2.0.4 lib/ecm/cms/importers/page.rb
ecm_cms2-2.0.3 lib/ecm/cms/importers/page.rb
ecm_cms2-2.0.2 lib/ecm/cms/importers/page.rb