Sha256: 49fecf8e2a83e609fe0ec9d61b3e43aecafc7965f3ff83bb4f43a32502328e11

Contents?: true

Size: 1.15 KB

Versions: 19

Compression:

Stored size: 1.15 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

        def yaml
          @yaml
        end
      end
    end
  end
end

Version data entries

19 entries across 19 versions & 2 rubygems

Version Path
ecm_cms2-1.1.1 lib/ecm/cms/importers/page.rb
ecm_cms2-1.1.0 lib/ecm/cms/importers/page.rb
ecm_cms2-1.0.1 lib/ecm/cms/importers/page.rb
ecm_cms-1.0.5.pre lib/ecm/cms/importers/page.rb
ecm_cms2-1.0.0 lib/ecm/cms/importers/page.rb
ecm_cms-1.0.4.pre lib/ecm/cms/importers/page.rb
ecm_cms-1.0.3.pre lib/ecm/cms/importers/page.rb
ecm_cms-1.0.2.pre lib/ecm/cms/importers/page.rb
ecm_cms-1.0.1.pre lib/ecm/cms/importers/page.rb
ecm_cms-1.0.0.pre lib/ecm/cms/importers/page.rb
ecm_cms-0.0.13.pre lib/ecm/cms/importers/page.rb
ecm_cms-0.0.11.pre lib/ecm/cms/importers/page.rb
ecm_cms-0.0.10.pre lib/ecm/cms/importers/page.rb
ecm_cms-0.0.8.pre lib/ecm/cms/importers/page.rb
ecm_cms-0.0.7.pre lib/ecm/cms/importers/page.rb
ecm_cms-0.0.6.pre lib/ecm/cms/importers/page.rb
ecm_cms-0.0.5.pre lib/ecm/cms/importers/page.rb
ecm_cms-0.0.4.pre lib/ecm/cms/importers/page.rb
ecm_cms-0.0.3.pre lib/ecm/cms/importers/page.rb