Sha256: 787a22b552bfdb432e56898f210114c20c883d4254a61d94a9eba8405154e589

Contents?: true

Size: 1.1 KB

Versions: 51

Compression:

Stored size: 1.1 KB

Contents

module Cmor
  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 = Cmor::Cms::Page.new(page_data)
            page.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 = Cmor::Cms::Navigation.where(locale: nid['navigation_locale'], name: nid['navigation_name']).first
            navigation_items << navigation.navigation_items.where(name: nid['name']).first if navigation.respond_to?(:navigation_items)
          end
          navigation_items
        end

        def pages
          @pages ||= build_pages
        end

        attr_reader :yaml
      end
    end
  end
end

Version data entries

51 entries across 51 versions & 1 rubygems

Version Path
cmor_cms-0.0.60.pre app/importers/cmor/cms/importers/page.rb
cmor_cms-0.0.59.pre app/importers/cmor/cms/importers/page.rb
cmor_cms-0.0.58.pre app/importers/cmor/cms/importers/page.rb
cmor_cms-0.0.57.pre app/importers/cmor/cms/importers/page.rb
cmor_cms-0.0.56.pre app/importers/cmor/cms/importers/page.rb
cmor_cms-0.0.55.pre app/importers/cmor/cms/importers/page.rb
cmor_cms-0.0.54.pre app/importers/cmor/cms/importers/page.rb
cmor_cms-0.0.53.pre app/importers/cmor/cms/importers/page.rb
cmor_cms-0.0.52.pre app/importers/cmor/cms/importers/page.rb
cmor_cms-0.0.51.pre app/importers/cmor/cms/importers/page.rb
cmor_cms-0.0.50.pre app/importers/cmor/cms/importers/page.rb
cmor_cms-0.0.49.pre app/importers/cmor/cms/importers/page.rb
cmor_cms-0.0.48.pre app/importers/cmor/cms/importers/page.rb
cmor_cms-0.0.45.pre app/importers/cmor/cms/importers/page.rb
cmor_cms-0.0.44.pre app/importers/cmor/cms/importers/page.rb
cmor_cms-0.0.43.pre app/importers/cmor/cms/importers/page.rb
cmor_cms-0.0.42.pre app/importers/cmor/cms/importers/page.rb
cmor_cms-0.0.41.pre app/importers/cmor/cms/importers/page.rb
cmor_cms-0.0.40.pre app/importers/cmor/cms/importers/page.rb
cmor_cms-0.0.39.pre app/importers/cmor/cms/importers/page.rb