Sha256: ea606a16d53faeb251be2c06edf608c83e6af8d00794fab468a42e42078556cf
Contents?: true
Size: 1.39 KB
Versions: 1
Compression:
Stored size: 1.39 KB
Contents
require_relative '../commands/context' module ContentfulMiddleman module Mapper class Base def map(context, entry) context.id = entry.id entry.fields.each {|k, v| map_field context, k, v} end private def map_field(context, field_name, field_value) value_mapping = map_value(field_value) context.set(field_name, value_mapping) end def map_value(value) case value when Contentful::Asset map_asset(value) when Contentful::Location map_location(value) when Contentful::Link map_link(value) when Contentful::DynamicEntry map_entry(value) when Array map_array(value) else value end end def map_asset(asset) context = Context.new context.title = asset.title context.url = asset.file.url context end def map_entry(entry) context = Context.new context.id = entry.id entry.fields.each {|k, v| map_field context, k, v} context end def map_location(location) location.properties end def map_link(link) context = Context.new context.id = link.id context end def map_array(array) array.map {|element| map_value(element)} end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
contentful_middleman-1.0.4 | lib/contentful_middleman/mappers/base.rb |