jekyll-contentful-data-import 1.4.3 → 1.5.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 50fa600dbbf4c6ac9235bf8e440dfbbda08d5cf7
4
- data.tar.gz: 2cf3e07eca850d26feff0aa892c409091f0a2e6a
3
+ metadata.gz: b070683edf1ce2aaac689f088b6913804b8cc6be
4
+ data.tar.gz: 957112e98c2d0318336e8b709a1900c9a9fc752c
5
5
  SHA512:
6
- metadata.gz: 87d4845489e419e741b65b0410d977b8961b10d06ab7bcbc2b435d0745c3bcededdac3678cdd05b7fdd94efdaf29e52b99015df3a6d4354136dca7ccdce115ef
7
- data.tar.gz: 14ca204c5cbfa850a351be792ef194a5e6a6bc156ed0bfcca0579aa687dba1a205f7516a2bade109f145b7bec01874429663ccb10df7b7c778fd56512698ca4e
6
+ metadata.gz: c2ddbe6c4e3a7bfb1d85de3f720100e4d3603b1b573647f9f5419da341cbea327df443e112f894f25568a9496374b314a40943ef57b03518d7c97ed4f17ea0e7
7
+ data.tar.gz: f01b63f3eef1da47fb685eb713ce44d03ed30d2a7ee5cb969f0a17d9d19a97aaf17aa42732bafdae54ddcfc31d68633c432213e976508c6b4e442cef608115d8
@@ -0,0 +1 @@
1
+ inherit_from: .rubocop_todo.yml
@@ -0,0 +1,38 @@
1
+ # This configuration was generated by
2
+ # `rubocop --auto-gen-config`
3
+ # on 2017-04-11 11:57:26 -0300 using RuboCop version 0.47.1.
4
+ # The point is for the user to remove these configuration records
5
+ # one by one as the offenses are removed from the code base.
6
+ # Note that changes in the inspected code, or installation of new
7
+ # versions of RuboCop, may require this file to be generated again.
8
+
9
+ # Offense count: 2
10
+ Metrics/AbcSize:
11
+ Max: 20
12
+
13
+ # Offense count: 1
14
+ # Configuration parameters: CountComments.
15
+ Metrics/ClassLength:
16
+ Max: 120
17
+
18
+ # Offense count: 1
19
+ Metrics/CyclomaticComplexity:
20
+ Max: 8
21
+
22
+ # Offense count: 3
23
+ # Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
24
+ # URISchemes: http, https
25
+ Metrics/LineLength:
26
+ Max: 100
27
+
28
+ # Offense count: 3
29
+ # Configuration parameters: CountComments.
30
+ Metrics/MethodLength:
31
+ Max: 25
32
+
33
+ # Offense count: 1
34
+ # Configuration parameters: ExpectMatchingDefinition, Regex, IgnoreExecutableScripts, AllowedAcronyms.
35
+ # AllowedAcronyms: CLI, DSL, ACL, API, ASCII, CPU, CSS, DNS, EOF, GUID, HTML, HTTP, HTTPS, ID, IP, JSON, LHS, QPS, RAM, RHS, RPC, SLA, SMTP, SQL, SSH, TCP, TLS, TTL, UDP, UI, UID, UUID, URI, URL, UTF8, VM, XML, XMPP, XSRF, XSS
36
+ Style/FileName:
37
+ Exclude:
38
+ - 'lib/jekyll-contentful-data-import.rb'
@@ -1,7 +1,18 @@
1
1
  # Change Log
2
2
 
3
3
  ## Unreleased
4
+
5
+ ## v1.5.0
6
+
7
+ ### Changed
8
+ * Updated CDA SDK to 2.0
9
+
4
10
  ### Added
11
+ * Added more metadata to `sys` attributes in entries
12
+ * Added `sys` attributes for serialized assets
13
+
14
+ ### Fixed
15
+ * Updated code to match style guide
5
16
 
6
17
  ### v1.4.3
7
18
  * Added use of `map_field` without localizing for custom mappers that map `sys` properties when `locale='*'` is being sent.
data/Guardfile CHANGED
@@ -1,5 +1,10 @@
1
- guard :rspec, cmd: 'rspec --format documentation --color' do
2
- watch(%r{^spec/.+_spec\.rb$})
3
- watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
4
- watch('spec/spec_helper.rb') { "spec" }
1
+ group :green_red_refactor, halt_on_fail: true do
2
+ guard :rspec, cmd: 'rspec --format documentation --color' do
3
+ watch(%r{^spec/.+_spec\.rb$})
4
+ watch(%r{^lib/.+\.rb$}) { "spec" }
5
+ watch('spec/spec_helper.rb') { "spec" }
6
+ end
7
+
8
+ guard :rubocop, cmd: "rubocop", cli: 'lib' do
9
+ end
5
10
  end
data/README.md CHANGED
@@ -67,7 +67,7 @@ all_entries_page_size | Integer, the amount of maximum entries per CDA Request w
67
67
  content_types | Hash describing the mapping applied to entries of the imported content types
68
68
  client_options | Hash describing Contentful::Client configuration. See [contentful.rb](https://github.com/contentful/contentful.rb) for more info.
69
69
  base_path | String with path to your Jekyll Application, defaults to current directory. Path is relative to your current location.
70
- destination | String with path within _data under which to store the output yaml file. Defaults to contentful/spaces
70
+ destination | String with path within `_data` under which to store the output yaml file. Defaults to contentful/spaces
71
71
 
72
72
  You can add multiple spaces to your configuration
73
73
 
@@ -123,33 +123,35 @@ Then proceed to run: `bundle exec rake contentful`
123
123
  In most cases you may want to avoid including your credentials in publicly available sites,
124
124
  therefore you can do the following:
125
125
 
126
- 1. `bundle update`—make sure your gem version supports ENV_ variables
126
+ 1. `bundle update`—make sure your gem version supports `ENV_` variables
127
127
 
128
- 2. Set up your _config like so:
128
+ 2. Set up your `_config` like so:
129
129
 
130
- ```yaml
131
- contentful:
132
- spaces:
133
- - example:
134
- space: ENV_CONTENTFUL_SPACE_ID
135
- access_token: ENV_CONTENTFUL_ACCESS_TOKEN
136
- ```
137
- (Your Space ID will be looked upon on `ENV['CONTENTFUL_SPACE_ID']` and your Access Token
138
- on `ENV['CONTENTFUL_ACCESS_TOKEN']`.)
130
+ ```yaml
131
+ contentful:
132
+ spaces:
133
+ - example:
134
+ space: ENV_CONTENTFUL_SPACE_ID
135
+ access_token: ENV_CONTENTFUL_ACCESS_TOKEN
136
+ ```
137
+
138
+ (Your Space ID will be looked upon on `ENV['CONTENTFUL_SPACE_ID']` and your Access Token on `ENV['CONTENTFUL_ACCESS_TOKEN']`.)
139
139
 
140
140
  3. Either add the following variables to your shell's configuration file (.bashrc or .bash_profile, for example):
141
141
 
142
- ```bash
143
- export CONTENTFUL_ACCESS_TOKEN=abc123
144
- export CONTENTFUL_SPACE_ID=abc123
145
- ```
146
- (And run `source ~/.bashrc` or open new terminal to enable changes.)
142
+ ```bash
143
+ export CONTENTFUL_ACCESS_TOKEN=abc123
144
+ export CONTENTFUL_SPACE_ID=abc123
145
+ ```
146
+
147
+ (And run `source ~/.bashrc` or open new terminal to enable changes.)
148
+
149
+ Or specify them on the command line:
147
150
 
148
- Or specify them on the command line:
151
+ ```bash
152
+ CONTENTFUL_ACCESS_TOKEN=abc123 CONTENTFUL_SPACE_ID=abc123 jekyll contentful
153
+ ```
149
154
 
150
- ```bash
151
- CONTENTFUL_ACCESS_TOKEN=abc123 CONTENTFUL_SPACE_ID=abc123 jekyll contentful
152
- ```
153
155
  4. Party.
154
156
 
155
157
  This way, it is safe to share your code without having to worry
@@ -22,15 +22,18 @@ Gem::Specification.new do |s|
22
22
  s.add_dependency("jekyll", ">= 2.5.0", "< 4")
23
23
 
24
24
  # Additional dependencies
25
- s.add_dependency("contentful", '~> 1.0')
25
+ s.add_dependency("contentful", '>= 2.0.1', '~> 2.0')
26
26
 
27
27
  s.add_development_dependency 'rubygems-tasks', '~> 0.2'
28
28
  s.add_development_dependency "guard"
29
29
  s.add_development_dependency "guard-rspec"
30
+ s.add_development_dependency 'guard-rubocop'
30
31
  s.add_development_dependency "bundler", "~> 1.6"
31
32
  s.add_development_dependency "rake"
32
33
  s.add_development_dependency "rspec", "~> 3.0"
33
34
  s.add_development_dependency "vcr"
34
35
  s.add_development_dependency "webmock"
35
36
  s.add_development_dependency "pry"
37
+ s.add_development_dependency "simplecov"
38
+ s.add_development_dependency "rubocop"
36
39
  end
@@ -1,5 +1,5 @@
1
1
  require 'jekyll-contentful-data-import/version'
2
2
 
3
- %w{contentful}.each do |file|
3
+ %w(contentful).each do |file|
4
4
  require File.expand_path("jekyll/commands/#{file}.rb", File.dirname(__FILE__))
5
5
  end
@@ -2,10 +2,13 @@ require 'jekyll-contentful-data-import/serializer'
2
2
 
3
3
  module Jekyll
4
4
  module Contentful
5
+ # Data Exporter Class
6
+ #
7
+ # Serializes Contentful data into YAML files
5
8
  class DataExporter
6
- DATA_FOLDER = '_data'
7
- CONTENTFUL_FOLDER = 'contentful'
8
- SPACES_FOLDER = 'spaces'
9
+ DATA_FOLDER = '_data'.freeze
10
+ CONTENTFUL_FOLDER = 'contentful'.freeze
11
+ SPACES_FOLDER = 'spaces'.freeze
9
12
 
10
13
  attr_reader :name, :entries, :config
11
14
 
@@ -19,20 +22,37 @@ module Jekyll
19
22
  setup_directory
20
23
 
21
24
  File.open(destination_file, 'w') do |file|
22
- file.write(::Jekyll::Contentful::Serializer.new(entries, config).to_yaml)
25
+ file.write(
26
+ ::Jekyll::Contentful::Serializer.new(
27
+ entries,
28
+ config
29
+ ).to_yaml
30
+ )
23
31
  end
24
32
  end
25
33
 
26
34
  def base_directory
27
35
  directory = File.expand_path(Dir.pwd)
28
- directory = File.join(directory, config['base_path']) if config.key?('base_path')
36
+ if config.key?('base_path')
37
+ directory = File.join(
38
+ directory,
39
+ config['base_path']
40
+ )
41
+ end
29
42
 
30
43
  directory
31
44
  end
32
45
 
33
46
  def destination_directory
34
- destination_dir = File.join(base_directory, DATA_FOLDER, CONTENTFUL_FOLDER, SPACES_FOLDER)
35
- destination_dir = File.join(base_directory, DATA_FOLDER, config['destination']) if config.key?('destination')
47
+ destination_dir = File.join(
48
+ base_directory, DATA_FOLDER,
49
+ CONTENTFUL_FOLDER, SPACES_FOLDER
50
+ )
51
+ if config.key?('destination')
52
+ destination_dir = File.join(
53
+ base_directory, DATA_FOLDER, config['destination']
54
+ )
55
+ end
36
56
 
37
57
  destination_dir
38
58
  end
@@ -3,6 +3,9 @@ require 'jekyll-contentful-data-import/data_exporter'
3
3
 
4
4
  module Jekyll
5
5
  module Contentful
6
+ # Importer class
7
+ #
8
+ # Entry fetching logic
6
9
  class Importer
7
10
  attr_reader :config
8
11
 
@@ -18,14 +21,18 @@ module Jekyll
18
21
  client_options(options.fetch('client_options', {}))
19
22
  )
20
23
 
21
- Jekyll::Contentful::DataExporter.new(
22
- name,
23
- get_entries(space_client, options),
24
- options
25
- ).run
24
+ export_data(name, space_client, options)
26
25
  end
27
26
  end
28
27
 
28
+ def export_data(name, space_client, options)
29
+ Jekyll::Contentful::DataExporter.new(
30
+ name,
31
+ get_entries(space_client, options),
32
+ options
33
+ ).run
34
+ end
35
+
29
36
  def value_for(options, key)
30
37
  potential_value = options[key]
31
38
  return ENV[potential_value.gsub('ENV_', '')] if potential_value.start_with?('ENV_')
@@ -33,7 +40,7 @@ module Jekyll
33
40
  end
34
41
 
35
42
  def spaces
36
- config['spaces'].map { |space_data| space_data.first }
43
+ config['spaces'].map(&:first)
37
44
  end
38
45
 
39
46
  def get_entries(space_client, options)
@@ -70,7 +77,11 @@ module Jekyll
70
77
  private
71
78
 
72
79
  def client_options(options)
73
- options = options.each_with_object({}){|(k,v), memo| memo[k.to_sym] = v; memo}
80
+ options = options.each_with_object({}) do |(k, v), memo|
81
+ memo[k.to_sym] = v
82
+ memo
83
+ end
84
+
74
85
  options.delete(:dynamic_entries)
75
86
  options.delete(:raise_errors)
76
87
  options
@@ -2,7 +2,11 @@ require 'contentful'
2
2
 
3
3
  module Jekyll
4
4
  module Contentful
5
+ # Mappers module
5
6
  module Mappers
7
+ # Base Mapper Class
8
+ #
9
+ # Logic for mapping entries into simplified serialized representations
6
10
  class Base
7
11
  def self.mapper_for(entry, config)
8
12
  ct = entry.content_type
@@ -23,20 +27,30 @@ module Jekyll
23
27
  @config = config
24
28
  end
25
29
 
30
+ def map_entry_metadata
31
+ content_type = entry.sys.fetch(:content_type, nil)
32
+ {
33
+ 'id' => entry.sys.fetch(:id, nil),
34
+ 'created_at' => entry.sys.fetch(:created_at, nil),
35
+ 'updated_at' => entry.sys.fetch(:updated_at, nil),
36
+ 'content_type_id' => content_type.nil? ? nil : content_type.id
37
+ }
38
+ end
39
+
26
40
  def map
27
- result = {'sys' => {'id' => entry.id}}
41
+ result = { 'sys' => map_entry_metadata }
28
42
 
29
- fields = has_multiple_locales? ? entry.fields_with_locales : entry.fields
43
+ fields = multiple_locales? ? entry.fields_with_locales : entry.fields
30
44
 
31
45
  fields.each do |k, v|
32
- name, value = map_field(k, v, has_multiple_locales?)
46
+ name, value = map_field(k, v, multiple_locales?)
33
47
  result[name] = value
34
48
  end
35
49
 
36
50
  result
37
51
  end
38
52
 
39
- def has_multiple_locales?
53
+ def multiple_locales?
40
54
  config.fetch('cda_query', {}).fetch('locale', nil) == '*'
41
55
  end
42
56
 
@@ -52,7 +66,7 @@ module Jekyll
52
66
  value_mapping = map_value(field_value)
53
67
  end
54
68
 
55
- return field_name.to_s, value_mapping
69
+ [field_name.to_s, value_mapping]
56
70
  end
57
71
 
58
72
  def map_value(value, locale = nil)
@@ -63,7 +77,7 @@ module Jekyll
63
77
  map_location(value)
64
78
  when ::Contentful::Link
65
79
  map_link(value)
66
- when ::Contentful::DynamicEntry
80
+ when ::Contentful::Entry
67
81
  map_entry(value)
68
82
  when ::Array
69
83
  map_array(value, locale)
@@ -80,12 +94,21 @@ module Jekyll
80
94
  end
81
95
  end
82
96
 
97
+ def map_asset_metadata(asset)
98
+ {
99
+ 'id' => asset.id,
100
+ 'created_at' => asset.sys.fetch(:created_at, nil),
101
+ 'updated_at' => asset.sys.fetch(:updated_at, nil)
102
+ }
103
+ end
104
+
83
105
  def map_asset(asset, locale = nil)
84
106
  if locale
85
107
  file = asset.fields(locale)[:file]
86
108
  file_url = file.nil? ? '' : file.url
87
109
 
88
110
  return {
111
+ 'sys' => map_asset_metadata(asset),
89
112
  'title' => asset.fields(locale)[:title],
90
113
  'description' => asset.fields(locale)[:description],
91
114
  'url' => file_url
@@ -96,6 +119,7 @@ module Jekyll
96
119
  file_url = file.nil? ? '' : file.url
97
120
 
98
121
  {
122
+ 'sys' => map_asset_metadata(asset),
99
123
  'title' => asset.title,
100
124
  'description' => asset.description,
101
125
  'url' => file_url
@@ -115,11 +139,15 @@ module Jekyll
115
139
  end
116
140
 
117
141
  def map_link(link)
118
- {'sys' => {'id' => link.id}}
142
+ {
143
+ 'sys' => {
144
+ 'id' => link.id
145
+ }
146
+ }
119
147
  end
120
148
 
121
149
  def map_array(array, locale)
122
- array.map {|element| map_value(element, locale)}
150
+ array.map { |element| map_value(element, locale) }
123
151
  end
124
152
  end
125
153
  end
@@ -3,6 +3,9 @@ require 'jekyll-contentful-data-import/mappers'
3
3
 
4
4
  module Jekyll
5
5
  module Contentful
6
+ # Serializer class
7
+ #
8
+ # Transforms the serialized entries to YAML
6
9
  class Serializer
7
10
  attr_reader :entries, :config
8
11
 
@@ -1,5 +1,5 @@
1
1
  module Jekyll
2
2
  module Contentful
3
- VERSION = "1.4.3"
3
+ VERSION = '1.5.0'.freeze
4
4
  end
5
5
  end
@@ -1,41 +1,51 @@
1
1
  require 'jekyll-contentful-data-import/importer'
2
2
 
3
3
  module Jekyll
4
+ # Module for Jekyll Commands
4
5
  module Commands
6
+ # jekyll contentful Command
5
7
  class Contentful < Command
6
8
  def self.init_with_program(prog)
7
9
  prog.command(:contentful) do |c|
8
10
  c.syntax 'contentful [OPTIONS]'
9
11
  c.description 'Imports data from Contentful'
10
12
 
11
- options.each {|opt| c.option(*opt) }
13
+ options.each { |opt| c.option(*opt) }
12
14
 
13
- c.action do |args, options|
14
- contentful_config = Jekyll.configuration['contentful']
15
- process args, options, contentful_config
16
- end
15
+ add_build_options(c)
16
+
17
+ command_action(c)
17
18
  end
18
19
  end
19
20
 
20
21
  def self.options
21
22
  [
22
- ['rebuild', '-r', '--rebuild', 'Rebuild Jekyll Site after fetching data'],
23
+ [
24
+ 'rebuild', '-r', '--rebuild',
25
+ 'Rebuild Jekyll Site after fetching data'
26
+ ]
23
27
  ]
24
28
  end
25
29
 
30
+ def self.command_action(command)
31
+ command.action do |args, options|
32
+ jekyll_options = configuration_from_options(options)
33
+ contentful_config = jekyll_options['contentful']
34
+ process args, options, contentful_config
35
+ end
36
+ end
26
37
 
27
- def self.process(args = [], options = {}, contentful_config = {})
38
+ def self.process(_args = [], options = {}, contentful_config = {})
28
39
  Jekyll.logger.info 'Starting Contentful import'
29
40
 
30
41
  Jekyll::Contentful::Importer.new(contentful_config).run
31
42
 
32
43
  Jekyll.logger.info 'Contentful import finished'
33
44
 
34
- if options['rebuild']
35
- Jekyll.logger.info 'Starting Jekyll Rebuild'
45
+ return unless options['rebuild']
36
46
 
37
- Jekyll::Commands::Build.process(options)
38
- end
47
+ Jekyll.logger.info 'Starting Jekyll Rebuild'
48
+ Jekyll::Commands::Build.process(options)
39
49
  end
40
50
  end
41
51
  end
@@ -34,10 +34,11 @@ describe Jekyll::Contentful::Mappers::Base do
34
34
 
35
35
  class AssetDouble < Contentful::Asset
36
36
  attr_reader :title, :description, :file
37
- def initialize(title, description, url, fields = nil)
37
+ def initialize(title, description, url, sys = {}, fields = nil)
38
38
  @title = title
39
39
  @description = description
40
40
  @file = FileDouble.new(url)
41
+ @sys = sys
41
42
  @fields = {
42
43
  'en-US' => {
43
44
  title: title,
@@ -49,6 +50,10 @@ describe Jekyll::Contentful::Mappers::Base do
49
50
  @fields ||= fields
50
51
  end
51
52
 
53
+ def id
54
+ @sys[:id]
55
+ end
56
+
52
57
  def fields(locale = nil)
53
58
  return { title: title, description: description, file: file } if locale.nil?
54
59
  @fields[locale]
@@ -75,13 +80,20 @@ describe Jekyll::Contentful::Mappers::Base do
75
80
  end
76
81
 
77
82
  it 'maps a simple entry' do
78
- expected = { 'sys' => { 'id' => 'foo' } }
83
+ expected = {
84
+ 'sys' => {
85
+ 'id' => 'foo',
86
+ 'created_at' => nil,
87
+ 'updated_at' => nil,
88
+ 'content_type_id' => 'content_type'
89
+ }
90
+ }
79
91
  expect(subject.map).to eq expected
80
92
  end
81
93
 
82
94
  it 'maps a complete entry' do
83
95
  entry = EntryDouble.new('foo', ContentTypeDouble.new, {
84
- 'asset' => AssetDouble.new('some_title', 'foo', 'some_url'),
96
+ 'asset' => AssetDouble.new('some_title', 'foo', 'some_url', {id: 'asset'}),
85
97
  'location' => LocationDouble.new(12.32, 43.34),
86
98
  'link' => LinkDouble.new('bar'),
87
99
  'entry' => EntryDouble.new('baz'),
@@ -95,8 +107,18 @@ describe Jekyll::Contentful::Mappers::Base do
95
107
  subject.instance_variable_set(:@entry, entry)
96
108
 
97
109
  expected = {
98
- 'sys' => { 'id' => 'foo' },
110
+ 'sys' => {
111
+ 'id' => 'foo',
112
+ 'created_at' => nil,
113
+ 'updated_at' => nil,
114
+ 'content_type_id' => 'content_type'
115
+ },
99
116
  'asset' => {
117
+ 'sys' => {
118
+ 'id' => 'asset',
119
+ 'created_at' => nil,
120
+ 'updated_at' => nil,
121
+ },
100
122
  'title' => 'some_title',
101
123
  'description' => 'foo',
102
124
  'url' => 'some_url'
@@ -109,7 +131,12 @@ describe Jekyll::Contentful::Mappers::Base do
109
131
  'sys' => { 'id' => 'bar' }
110
132
  },
111
133
  'entry' => {
112
- 'sys' => { 'id' => 'baz' }
134
+ 'sys' => {
135
+ 'id' => 'baz',
136
+ 'created_at' => nil,
137
+ 'updated_at' => nil,
138
+ 'content_type_id' => 'content_type'
139
+ },
113
140
  },
114
141
  'array' => [
115
142
  { 'sys' => { 'id' => 'foobar' } },
@@ -135,7 +162,12 @@ describe Jekyll::Contentful::Mappers::Base do
135
162
  mapper = described_class.new(entry, config)
136
163
 
137
164
  expected = {
138
- 'sys' => { 'id' => 'foo' },
165
+ 'sys' => {
166
+ 'id' => 'foo',
167
+ 'created_at' => nil,
168
+ 'updated_at' => nil,
169
+ 'content_type_id' => 'content_type'
170
+ },
139
171
  'foo' => {
140
172
  'en-US' => 'bar',
141
173
  'de-DE' => 'baz'
@@ -154,7 +186,7 @@ describe Jekyll::Contentful::Mappers::Base do
154
186
  'asset' => AssetDouble.new('some_title', 'foo', 'some_url')
155
187
  },
156
188
  'de-DE' => {
157
- 'asset' => AssetDouble.new('some_title', 'foo', 'some_url', {
189
+ 'asset' => AssetDouble.new('some_title', 'foo', 'some_url', {id: 'foo'}, {
158
190
  'de-DE' => {
159
191
  title: 'other_title',
160
192
  description: 'other description',
@@ -167,14 +199,29 @@ describe Jekyll::Contentful::Mappers::Base do
167
199
  mapper = described_class.new(entry, config)
168
200
 
169
201
  expected = {
170
- 'sys' => { 'id' => 'foo' },
202
+ 'sys' => {
203
+ 'id' => 'foo',
204
+ 'created_at' => nil,
205
+ 'updated_at' => nil,
206
+ 'content_type_id' => 'content_type'
207
+ },
171
208
  'asset' => {
172
209
  "en-US" => {
210
+ "sys" => {
211
+ "id" => nil,
212
+ "created_at" => nil,
213
+ "updated_at" => nil
214
+ },
173
215
  "title" => "some_title",
174
216
  "description" => "foo",
175
217
  "url" => 'some_url'
176
218
  },
177
219
  "de-DE" => {
220
+ "sys" => {
221
+ "id" => "foo",
222
+ "created_at" => nil,
223
+ "updated_at" => nil
224
+ },
178
225
  "title" => "other_title",
179
226
  "description" => "other description",
180
227
  "url" => 'other_url'
@@ -23,14 +23,37 @@ describe Jekyll::Contentful::Serializer do
23
23
  end
24
24
 
25
25
  it 'serializes a single entry without fields' do
26
- expected = {'content_type' => [{'sys' => {'id' => 'foo'}}]}
26
+ expected = {
27
+ 'content_type' => [
28
+ {
29
+ 'sys' => {
30
+ 'id' => 'foo',
31
+ 'created_at' => nil,
32
+ 'updated_at' => nil,
33
+ 'content_type_id' => 'content_type'
34
+ }
35
+ }
36
+ ]
37
+ }
27
38
  expect(subject.serialize).to eq(expected)
28
39
  end
29
40
 
30
41
  it 'serializes a single entry with fields' do
31
42
  subject.instance_variable_set(:@entries, [EntryDouble.new('foo', ContentTypeDouble.new, {'foobar' => 'bar'})])
32
43
 
33
- expected = {'content_type' => [{'sys' => {'id' => 'foo'}, 'foobar' => 'bar'}]}
44
+ expected = {
45
+ 'content_type' => [
46
+ {
47
+ 'sys' => {
48
+ 'id' => 'foo',
49
+ 'created_at' => nil,
50
+ 'updated_at' => nil,
51
+ 'content_type_id' => 'content_type'
52
+ },
53
+ 'foobar' => 'bar'
54
+ }
55
+ ]
56
+ }
34
57
  expect(subject.serialize).to eq(expected)
35
58
  end
36
59
 
@@ -43,7 +66,27 @@ describe Jekyll::Contentful::Serializer do
43
66
  })
44
67
  ])
45
68
 
46
- expected = {'content_type' => [{'sys' => {'id' => 'foo'}, 'foobar' => {'sys' => {'id' => 'foobar'}, 'baz' => 1}}]}
69
+ expected = {
70
+ 'content_type' => [
71
+ {
72
+ 'sys' => {
73
+ 'id' => 'foo',
74
+ 'created_at' => nil,
75
+ 'updated_at' => nil,
76
+ 'content_type_id' => 'content_type'
77
+ },
78
+ 'foobar' => {
79
+ 'sys' => {
80
+ 'id' => 'foobar',
81
+ 'created_at' => nil,
82
+ 'updated_at' => nil,
83
+ 'content_type_id' => 'content_type'
84
+ },
85
+ 'baz' => 1
86
+ }
87
+ }
88
+ ]
89
+ }
47
90
  expect(subject.serialize).to eq(expected)
48
91
  end
49
92
 
@@ -55,8 +98,24 @@ describe Jekyll::Contentful::Serializer do
55
98
 
56
99
  expected = {
57
100
  'content_type' => [
58
- {'sys' => {'id' => 'foo'}, 'foobar' => 'bar'},
59
- {'sys' => {'id' => 'bar'}, 'foobar' => 'baz'}
101
+ {
102
+ 'sys' => {
103
+ 'id' => 'foo',
104
+ 'created_at' => nil,
105
+ 'updated_at' => nil,
106
+ 'content_type_id' => 'content_type'
107
+ },
108
+ 'foobar' => 'bar'
109
+ },
110
+ {
111
+ 'sys' => {
112
+ 'id' => 'bar',
113
+ 'created_at' => nil,
114
+ 'updated_at' => nil,
115
+ 'content_type_id' => 'content_type'
116
+ },
117
+ 'foobar' => 'baz'
118
+ }
60
119
  ]
61
120
  }
62
121
  expect(subject.serialize).to match(expected)
@@ -1,3 +1,6 @@
1
+ require 'simplecov'
2
+ SimpleCov.start
3
+
1
4
  $LOAD_PATH.unshift File.expand_path('lib', __FILE__)
2
5
 
3
6
  require 'vcr'
@@ -37,13 +40,15 @@ class ContentTypeDouble
37
40
  end
38
41
  end
39
42
 
40
- class EntryDouble < Contentful::DynamicEntry
43
+ class EntryDouble < Contentful::Entry
41
44
  attr_reader :id, :content_type
42
45
 
43
46
  def initialize(id = '', content_type = ContentTypeDouble.new, fields = {}, locales = false)
44
47
  @id = id
45
48
  @content_type = content_type
46
49
 
50
+ @sys = { id: id, content_type: content_type, locale: 'en-US' }
51
+
47
52
  if locales
48
53
  @fields = fields
49
54
  else
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jekyll-contentful-data-import
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.3
4
+ version: 1.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Contentful GmbH
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-12-19 00:00:00.000000000 Z
11
+ date: 2017-04-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jekyll
@@ -34,16 +34,22 @@ dependencies:
34
34
  name: contentful
35
35
  requirement: !ruby/object:Gem::Requirement
36
36
  requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: 2.0.1
37
40
  - - "~>"
38
41
  - !ruby/object:Gem::Version
39
- version: '1.0'
42
+ version: '2.0'
40
43
  type: :runtime
41
44
  prerelease: false
42
45
  version_requirements: !ruby/object:Gem::Requirement
43
46
  requirements:
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ version: 2.0.1
44
50
  - - "~>"
45
51
  - !ruby/object:Gem::Version
46
- version: '1.0'
52
+ version: '2.0'
47
53
  - !ruby/object:Gem::Dependency
48
54
  name: rubygems-tasks
49
55
  requirement: !ruby/object:Gem::Requirement
@@ -86,6 +92,20 @@ dependencies:
86
92
  - - ">="
87
93
  - !ruby/object:Gem::Version
88
94
  version: '0'
95
+ - !ruby/object:Gem::Dependency
96
+ name: guard-rubocop
97
+ requirement: !ruby/object:Gem::Requirement
98
+ requirements:
99
+ - - ">="
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ type: :development
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ requirements:
106
+ - - ">="
107
+ - !ruby/object:Gem::Version
108
+ version: '0'
89
109
  - !ruby/object:Gem::Dependency
90
110
  name: bundler
91
111
  requirement: !ruby/object:Gem::Requirement
@@ -170,6 +190,34 @@ dependencies:
170
190
  - - ">="
171
191
  - !ruby/object:Gem::Version
172
192
  version: '0'
193
+ - !ruby/object:Gem::Dependency
194
+ name: simplecov
195
+ requirement: !ruby/object:Gem::Requirement
196
+ requirements:
197
+ - - ">="
198
+ - !ruby/object:Gem::Version
199
+ version: '0'
200
+ type: :development
201
+ prerelease: false
202
+ version_requirements: !ruby/object:Gem::Requirement
203
+ requirements:
204
+ - - ">="
205
+ - !ruby/object:Gem::Version
206
+ version: '0'
207
+ - !ruby/object:Gem::Dependency
208
+ name: rubocop
209
+ requirement: !ruby/object:Gem::Requirement
210
+ requirements:
211
+ - - ">="
212
+ - !ruby/object:Gem::Version
213
+ version: '0'
214
+ type: :development
215
+ prerelease: false
216
+ version_requirements: !ruby/object:Gem::Requirement
217
+ requirements:
218
+ - - ">="
219
+ - !ruby/object:Gem::Version
220
+ version: '0'
173
221
  description: Load blog posts and other managed content into Jekyll
174
222
  email:
175
223
  - david.litvak@contentful.com
@@ -178,6 +226,8 @@ extensions: []
178
226
  extra_rdoc_files: []
179
227
  files:
180
228
  - ".gitignore"
229
+ - ".rubocop.yml"
230
+ - ".rubocop_todo.yml"
181
231
  - ".travis.yml"
182
232
  - ".yardopts"
183
233
  - CHANGELOG.md