Class: Contentful::MiddlemanPages::Extension

Inherits:
Middleman::Extension
  • Object
show all
Includes:
UriTemplate
Defined in:
lib/contentful/middleman-pages/extension.rb

Constant Summary collapse

SOURCE_PATH =
'source'

Instance Method Summary collapse

Methods included from UriTemplate

#apply_uri_template

Constructor Details

#initialize(app, options, &block) ⇒ Extension

Returns a new instance of Extension.



61
62
63
64
65
# File 'lib/contentful/middleman-pages/extension.rb', line 61

def initialize(app, options, &block)
  super

  @contentful_resources = []
end

Instance Method Details

#after_configurationObject

Middleman hooks



70
71
72
# File 'lib/contentful/middleman-pages/extension.rb', line 70

def after_configuration
  massage_options
end

#manipulate_resource_list(resources) ⇒ Object



74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/contentful/middleman-pages/extension.rb', line 74

def manipulate_resource_list(resources)
  new_resources_list = resources
  @contentful_resources += options.data.map do |entry_id, entry_data|
    expanded_permalink = expand_permalink entry_data
    resource           = ::Middleman::Sitemap::Resource.new(
      @app.sitemap,
      expanded_permalink,
      options.template
    )

    resource.extend ResourceInstanceMethods
    resource.data = entry_data
    resource. locals: entry_data

    if (index = is_existing_resource?(resource, new_resources_list))
      new_resources_list[index] = resource
    else
      new_resources_list << resource
    end

    resource
  end

  (resources + @contentful_resources).map do |resource|
        = resource..fetch(:locals).fetch(:contentful, {}.to_hashugar)
     [@space_name] = {@content_type_name => @contentful_resources}.to_hashugar
     resource. locals: {contentful: }
     resource
  end

  new_resources_list
end