jekyll-contentful-data-import 1.7.0 → 1.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.rubocop_todo.yml +2 -2
- data/CHANGELOG.md +5 -0
- data/README.md +58 -25
- data/jekyll-contentful.gemspec +1 -0
- data/lib/jekyll-contentful-data-import.rb +1 -0
- data/lib/jekyll-contentful-data-import/helpers.rb +35 -0
- data/lib/jekyll-contentful-data-import/importer.rb +13 -2
- data/lib/jekyll-contentful-data-import/version.rb +1 -1
- data/lib/jekyll/commands/contentful.rb +3 -4
- data/spec/jekyll-contentful/helpers_spec.rb +695 -0
- data/spec/jekyll-contentful/importer_spec.rb +54 -12
- data/spec/jekyll/commands/contentful_spec.rb +4 -0
- metadata +19 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 462c56e5cdfd73612d643ab860e3390149fc360462ab6027d63b54106fb99894
|
4
|
+
data.tar.gz: 1926f296f8fc998dceec8b221c1000b610a25c5167713a15e1764f719ee1d08d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8b7a6998dc83466dc49f0058b3341901342d687c2c9abe6e5033425e11543f999cc6e60a769d1a471af08fb6bcf0094b552b8aa8bf9d1fe4b404c4d08f1fa7ce
|
7
|
+
data.tar.gz: bbe933c2c443d34ab33efdcca9fb2d97b3a22ebd8aec23aa2503473a18c228919b719ce9e5a134ad3993477c85336a1f4d4bd0d083f8339b2165430b9b917d4c
|
data/.rubocop_todo.yml
CHANGED
@@ -23,7 +23,7 @@ Metrics/CyclomaticComplexity:
|
|
23
23
|
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
|
24
24
|
# URISchemes: http, https
|
25
25
|
Metrics/LineLength:
|
26
|
-
Max:
|
26
|
+
Max: 120
|
27
27
|
|
28
28
|
# Offense count: 3
|
29
29
|
# Configuration parameters: CountComments.
|
@@ -33,6 +33,6 @@ Metrics/MethodLength:
|
|
33
33
|
# Offense count: 1
|
34
34
|
# Configuration parameters: ExpectMatchingDefinition, Regex, IgnoreExecutableScripts, AllowedAcronyms.
|
35
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
|
-
|
36
|
+
Naming/FileName:
|
37
37
|
Exclude:
|
38
38
|
- 'lib/jekyll-contentful-data-import.rb'
|
data/CHANGELOG.md
CHANGED
@@ -2,6 +2,11 @@
|
|
2
2
|
|
3
3
|
## Unreleased
|
4
4
|
|
5
|
+
## v1.8.0
|
6
|
+
### Added
|
7
|
+
* Added capability to autoload mappers [#22](https://github.com/contentful/jekyll-contentful-data-import/issues/22)
|
8
|
+
* *This feature is currently in BETA state, changes may occur as patch fixes* Added support for RichText and added the `rich_text` view filter.
|
9
|
+
|
5
10
|
## v1.7.0
|
6
11
|
### Added
|
7
12
|
* Added top-level environment assignment, with support for `ENV_` access [#61](https://github.com/contentful/jekyll-contentful-data-import/issues/61)
|
data/README.md
CHANGED
@@ -43,23 +43,25 @@ To configure the extension, add the following configuration block to Jekyll's `_
|
|
43
43
|
```yaml
|
44
44
|
contentful:
|
45
45
|
spaces:
|
46
|
-
- example:
|
47
|
-
space: cfexampleapi
|
48
|
-
access_token: b4c0n73n7fu1
|
49
|
-
environment: master
|
50
|
-
cda_query:
|
46
|
+
- example: # Jekyll _data folder identifier - Required
|
47
|
+
space: cfexampleapi # Required
|
48
|
+
access_token: b4c0n73n7fu1 # Required
|
49
|
+
environment: master # Optional
|
50
|
+
cda_query: # Optional
|
51
51
|
include: 2
|
52
52
|
limit: 100
|
53
|
-
all_entries: true
|
54
|
-
all_entries_page_size: 1000
|
55
|
-
content_types:
|
53
|
+
all_entries: true # Optional - Defaults to false, only grabbing the amount set on CDA Query
|
54
|
+
all_entries_page_size: 1000 # Optional - Defaults to 1000, maximum amount of entries per CDA Request for all_entries
|
55
|
+
content_types: # Optional
|
56
56
|
cat: MyCoolMapper
|
57
|
-
client_options:
|
57
|
+
client_options: # Optional
|
58
58
|
api_url: 'preview.contentful.com' # Defaults to 'api.contentful.com' which is Production
|
59
|
-
max_include_resolution_depth: 5
|
60
|
-
base_path: app_path
|
61
|
-
destination: destination_in_data
|
62
|
-
individual_entry_files: true
|
59
|
+
max_include_resolution_depth: 5 # Optional - Defaults to 20, maximum amount of levels to resolve includes
|
60
|
+
base_path: app_path # Optional - Defaults to Current directory
|
61
|
+
destination: destination_in_data # Optional - Defaults to _data/contentful/spaces
|
62
|
+
individual_entry_files: true # Optional - Defaults to false
|
63
|
+
rich_text_mappings: # Optional - Defaults to {}
|
64
|
+
embedded-entry-block: MyEntryRenderer
|
63
65
|
```
|
64
66
|
|
65
67
|
Parameter | Description
|
@@ -71,10 +73,11 @@ cda_query | Hash describing query configuration. See [contentful.rb
|
|
71
73
|
all_entries | Boolean, if true will run multiple queries to the API until it fetches all entries for the space
|
72
74
|
all_entries_page_size | Integer, the amount of maximum entries per CDA Request when fetching :all_entries
|
73
75
|
content_types | Hash describing the mapping applied to entries of the imported content types
|
74
|
-
client_options | Hash describing Contentful::Client configuration. See [contentful.rb](https://github.com/contentful/contentful.rb) for more info.
|
76
|
+
client_options | Hash describing `Contentful::Client` configuration. See [contentful.rb](https://github.com/contentful/contentful.rb) for more info.
|
75
77
|
base_path | String with path to your Jekyll Application, defaults to current directory. Path is relative to your current location.
|
76
78
|
destination | String with path within `_data` under which to store the output yaml file. Defaults to contentful/spaces
|
77
79
|
individual_entry_files | Boolean, if true will create an individual file per entry separated in folders by content type, file path will be `{space_alias}/{content_type_id}/{entry_id}.yaml`. Default behavior is to create a file per space. Usage is affected when this is set to true, please look in the section below.
|
80
|
+
rich_text_mappings | Hash with `'nodeTyoe' => RendererClass` pairs determining overrides for the [`RichTextRenderer` library](https://github.com/contentful/rich-text-renderer.rb) configuration.
|
78
81
|
|
79
82
|
You can add multiple spaces to your configuration
|
80
83
|
|
@@ -109,21 +112,51 @@ end
|
|
109
112
|
|
110
113
|
#### Caveats
|
111
114
|
|
112
|
-
|
113
|
-
Therefore we need to use a custom [Rakefile](https://github.com/contentful/contentful_jekyll_examples/blob/master/examples/custom_mapper/example/Rakefile) to import the mapper and required files:
|
115
|
+
**Note:** This has changed since previous version.
|
114
116
|
|
115
|
-
|
116
|
-
|
117
|
-
require 'jekyll-contentful-data-import'
|
118
|
-
require './_plugins/mappers'
|
117
|
+
When creating custom mappers, you should create them in a file under `#{source_dir}/_plugins/mappers/`.
|
118
|
+
This will allow the autoload mechanism that has been included in the latest version.
|
119
119
|
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
120
|
+
With the autoload mechanism, there is no longer a need to create a `rake` task for importing using custom mappers.
|
121
|
+
|
122
|
+
If you already have a custom `rake` task, the new autoload mechanism will not affect it from working as it was working previously.
|
123
|
+
|
124
|
+
### Rich Text *Beta*
|
125
|
+
|
126
|
+
To render rich text in your views, you can use the `rich_text` filter:
|
127
|
+
|
128
|
+
```liquid
|
129
|
+
{{ entry.rich_text_field | rich_text }}
|
130
|
+
```
|
131
|
+
|
132
|
+
This will output the generated HTML generated by the [`RichTextRenderer` library](https://github.com/contentful/rich-text-renderer.rb).
|
133
|
+
|
134
|
+
#### Adding custom renderers
|
135
|
+
|
136
|
+
When using rich text, if you're planning to embed entries, then you need to create your custom renderer for them. You can read how create your own renderer classes [here](https://github.com/contentful/rich-text-renderer.rb#using-different-renderers).
|
137
|
+
|
138
|
+
To configure the mappings, you need to add them in your `contentful` block like follows:
|
139
|
+
|
140
|
+
```yaml
|
141
|
+
contentful:
|
142
|
+
spaces:
|
143
|
+
- example:
|
144
|
+
# ... all the regular config ...
|
145
|
+
rich_text_mappings:
|
146
|
+
embedded-entry-block: MyCustomRenderer
|
124
147
|
```
|
125
148
|
|
126
|
-
|
149
|
+
You can also add renderers for all other types of nodes if you want to have more granular control over the rendering.
|
150
|
+
|
151
|
+
This will use the same autoload strategy included for custom entry mappers, therefore, you should include your mapper classes in `#{source_dir}/_plugins/mappers/`.
|
152
|
+
|
153
|
+
#### Using the helper with multiple Contentful spaces
|
154
|
+
|
155
|
+
In case you have multiple configured spaces, and have different mapping configurations for them. You can specify which space you want to pull the configuration from when using the helper.
|
156
|
+
|
157
|
+
The helper receives an additional optional parameter for the space name. By default it is `nil`, indicating the first available space.
|
158
|
+
|
159
|
+
So, if for example you have 2 spaces with different configurations, to use the space called `foo`, you should call the helper as: `{{ entry.field | rich_text: "foo" }}`.
|
127
160
|
|
128
161
|
### Hiding Space and Access Token in Public Repositories
|
129
162
|
|
data/jekyll-contentful.gemspec
CHANGED
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'rich_text_renderer'
|
2
|
+
|
3
|
+
module Jekyll
|
4
|
+
module Contentful
|
5
|
+
# Liquid filter for the RichText field.
|
6
|
+
module RichTextFilter
|
7
|
+
def rich_text(field, space = nil)
|
8
|
+
return if field.nil?
|
9
|
+
|
10
|
+
RichTextRenderer::Renderer.new(mappings_for(space)).render(field)
|
11
|
+
end
|
12
|
+
|
13
|
+
private
|
14
|
+
|
15
|
+
def mappings_for(space)
|
16
|
+
mappings = {}
|
17
|
+
config_for(space).fetch('rich_text_mappings', {}).each do |k, v|
|
18
|
+
mappings[k.to_s] = Module.const_get(v)
|
19
|
+
end
|
20
|
+
|
21
|
+
mappings
|
22
|
+
end
|
23
|
+
|
24
|
+
def config_for(space)
|
25
|
+
config = @context.registers[:site].config['contentful']['spaces']
|
26
|
+
|
27
|
+
# Spaces is a list of hashes indexed by space alias
|
28
|
+
return config.first.first[1] if space.nil? # Return the first available configuration
|
29
|
+
config.find { |sc| sc.key?(space) }[space]
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
Liquid::Template.register_filter(Jekyll::Contentful::RichTextFilter)
|
@@ -10,8 +10,11 @@ module Jekyll
|
|
10
10
|
class Importer
|
11
11
|
attr_reader :config
|
12
12
|
|
13
|
-
def initialize(
|
14
|
-
@
|
13
|
+
def initialize(jekyll_config)
|
14
|
+
@jekyll_config = jekyll_config
|
15
|
+
@config = jekyll_config['contentful']
|
16
|
+
|
17
|
+
autoload_mappers!
|
15
18
|
end
|
16
19
|
|
17
20
|
def run
|
@@ -117,6 +120,14 @@ module Jekyll
|
|
117
120
|
options.delete(:raise_errors)
|
118
121
|
options
|
119
122
|
end
|
123
|
+
|
124
|
+
def autoload_mappers!
|
125
|
+
mapper_search_path = File.join(@jekyll_config['source'], @jekyll_config['plugins_dir'], 'mappers')
|
126
|
+
mapper_files = Jekyll::Utils.safe_glob(mapper_search_path, File.join('**', '*.rb'))
|
127
|
+
Jekyll::External.require_with_graceful_fail(mapper_files)
|
128
|
+
rescue StandardError
|
129
|
+
Jekyll.logger.debug "Couldn't find custom mappers"
|
130
|
+
end
|
120
131
|
end
|
121
132
|
end
|
122
133
|
end
|
@@ -30,15 +30,14 @@ module Jekyll
|
|
30
30
|
def self.command_action(command)
|
31
31
|
command.action do |args, options|
|
32
32
|
jekyll_options = configuration_from_options(options)
|
33
|
-
|
34
|
-
process args, options, contentful_config
|
33
|
+
process args, options, jekyll_options
|
35
34
|
end
|
36
35
|
end
|
37
36
|
|
38
|
-
def self.process(_args = [], options = {},
|
37
|
+
def self.process(_args = [], options = {}, config = {})
|
39
38
|
Jekyll.logger.info 'Starting Contentful import'
|
40
39
|
|
41
|
-
Jekyll::Contentful::Importer.new(
|
40
|
+
Jekyll::Contentful::Importer.new(config).run
|
42
41
|
|
43
42
|
Jekyll.logger.info 'Contentful import finished'
|
44
43
|
|
@@ -0,0 +1,695 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
class MockSite
|
4
|
+
attr_reader :config
|
5
|
+
|
6
|
+
def initialize(config)
|
7
|
+
@config = config
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
class MockContext
|
12
|
+
attr_reader :registers
|
13
|
+
def initialize(config)
|
14
|
+
@registers = {
|
15
|
+
site: MockSite.new(config)
|
16
|
+
}
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
class MockSiteContext
|
21
|
+
include Jekyll::Contentful::RichTextFilter
|
22
|
+
|
23
|
+
def initialize(config)
|
24
|
+
@context = MockContext.new(config)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
class MyRenderer < RichTextRenderer::BaseNodeRenderer
|
29
|
+
def render(node)
|
30
|
+
return "<div>I eat nodes for breakfast</div>"
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
describe Jekyll::Contentful::RichTextFilter do
|
35
|
+
let(:config) do
|
36
|
+
{
|
37
|
+
'contentful' => {
|
38
|
+
'spaces' => [
|
39
|
+
'foo' => {
|
40
|
+
'rich_text_mappings' => {
|
41
|
+
'embedded-entry-block' => 'MyRenderer'
|
42
|
+
}
|
43
|
+
},
|
44
|
+
'bar' => {
|
45
|
+
}
|
46
|
+
]
|
47
|
+
}
|
48
|
+
}
|
49
|
+
end
|
50
|
+
|
51
|
+
let(:rt_field) do
|
52
|
+
{
|
53
|
+
"content" => [
|
54
|
+
{
|
55
|
+
"data" => {
|
56
|
+
},
|
57
|
+
"content" => [
|
58
|
+
{
|
59
|
+
"marks" => [
|
60
|
+
|
61
|
+
],
|
62
|
+
"value" => "Some heading",
|
63
|
+
"nodeType" => "text",
|
64
|
+
"nodeClass" => "text"
|
65
|
+
}
|
66
|
+
],
|
67
|
+
"nodeType" => "heading-1",
|
68
|
+
"nodeClass" => "block"
|
69
|
+
},
|
70
|
+
{
|
71
|
+
"data" => {
|
72
|
+
},
|
73
|
+
"content" => [
|
74
|
+
{
|
75
|
+
"marks" => [
|
76
|
+
|
77
|
+
],
|
78
|
+
"value" => "",
|
79
|
+
"nodeType" => "text",
|
80
|
+
"nodeClass" => "text"
|
81
|
+
}
|
82
|
+
],
|
83
|
+
"nodeType" => "paragraph",
|
84
|
+
"nodeClass" => "block"
|
85
|
+
},
|
86
|
+
{
|
87
|
+
"data" => {
|
88
|
+
"sys" => {
|
89
|
+
"id" => "49rofLvvxCOiIMIi6mk8ai",
|
90
|
+
"created_at" => "2018-08-22T10:45:20+00:00",
|
91
|
+
"updated_at" => "2018-08-22T10:45:20+00:00",
|
92
|
+
"content_type_id" => "embedded",
|
93
|
+
"revision" => 1
|
94
|
+
},
|
95
|
+
"body" => "Embedded 1"
|
96
|
+
},
|
97
|
+
"content" => [
|
98
|
+
{
|
99
|
+
"marks" => [
|
100
|
+
|
101
|
+
],
|
102
|
+
"value" => "",
|
103
|
+
"nodeType" => "text",
|
104
|
+
"nodeClass" => "text"
|
105
|
+
}
|
106
|
+
],
|
107
|
+
"nodeType" => "embedded-entry-block",
|
108
|
+
"nodeClass" => "block"
|
109
|
+
},
|
110
|
+
{
|
111
|
+
"data" => {
|
112
|
+
},
|
113
|
+
"content" => [
|
114
|
+
{
|
115
|
+
"marks" => [
|
116
|
+
|
117
|
+
],
|
118
|
+
"value" => "Some subheading",
|
119
|
+
"nodeType" => "text",
|
120
|
+
"nodeClass" => "text"
|
121
|
+
}
|
122
|
+
],
|
123
|
+
"nodeType" => "heading-2",
|
124
|
+
"nodeClass" => "block"
|
125
|
+
},
|
126
|
+
{
|
127
|
+
"data" => {
|
128
|
+
},
|
129
|
+
"content" => [
|
130
|
+
{
|
131
|
+
"marks" => [
|
132
|
+
{
|
133
|
+
"data" => {
|
134
|
+
},
|
135
|
+
"type" => "bold",
|
136
|
+
"object" => "mark"
|
137
|
+
}
|
138
|
+
],
|
139
|
+
"value" => "Some bold",
|
140
|
+
"nodeType" => "text",
|
141
|
+
"nodeClass" => "text"
|
142
|
+
}
|
143
|
+
],
|
144
|
+
"nodeType" => "paragraph",
|
145
|
+
"nodeClass" => "block"
|
146
|
+
},
|
147
|
+
{
|
148
|
+
"data" => {
|
149
|
+
},
|
150
|
+
"content" => [
|
151
|
+
{
|
152
|
+
"marks" => [
|
153
|
+
{
|
154
|
+
"data" => {
|
155
|
+
},
|
156
|
+
"type" => "italic",
|
157
|
+
"object" => "mark"
|
158
|
+
}
|
159
|
+
],
|
160
|
+
"value" => "Some italics",
|
161
|
+
"nodeType" => "text",
|
162
|
+
"nodeClass" => "text"
|
163
|
+
}
|
164
|
+
],
|
165
|
+
"nodeType" => "paragraph",
|
166
|
+
"nodeClass" => "block"
|
167
|
+
},
|
168
|
+
{
|
169
|
+
"data" => {
|
170
|
+
},
|
171
|
+
"content" => [
|
172
|
+
{
|
173
|
+
"marks" => [
|
174
|
+
{
|
175
|
+
"data" => {
|
176
|
+
},
|
177
|
+
"type" => "underline",
|
178
|
+
"object" => "mark"
|
179
|
+
}
|
180
|
+
],
|
181
|
+
"value" => "Some underline",
|
182
|
+
"nodeType" => "text",
|
183
|
+
"nodeClass" => "text"
|
184
|
+
}
|
185
|
+
],
|
186
|
+
"nodeType" => "paragraph",
|
187
|
+
"nodeClass" => "block"
|
188
|
+
},
|
189
|
+
{
|
190
|
+
"data" => {
|
191
|
+
},
|
192
|
+
"content" => [
|
193
|
+
{
|
194
|
+
"marks" => [
|
195
|
+
|
196
|
+
],
|
197
|
+
"value" => "",
|
198
|
+
"nodeType" => "text",
|
199
|
+
"nodeClass" => "text"
|
200
|
+
}
|
201
|
+
],
|
202
|
+
"nodeType" => "paragraph",
|
203
|
+
"nodeClass" => "block"
|
204
|
+
},
|
205
|
+
{
|
206
|
+
"data" => {
|
207
|
+
},
|
208
|
+
"content" => [
|
209
|
+
{
|
210
|
+
"marks" => [
|
211
|
+
|
212
|
+
],
|
213
|
+
"value" => "",
|
214
|
+
"nodeType" => "text",
|
215
|
+
"nodeClass" => "text"
|
216
|
+
}
|
217
|
+
],
|
218
|
+
"nodeType" => "paragraph",
|
219
|
+
"nodeClass" => "block"
|
220
|
+
},
|
221
|
+
{
|
222
|
+
"data" => {
|
223
|
+
"sys" => {
|
224
|
+
"id" => "5ZF9Q4K6iWSYIU2OUs0UaQ",
|
225
|
+
"created_at" => "2018-08-22T10:45:29+00:00",
|
226
|
+
"updated_at" => "2018-08-22T10:45:29+00:00",
|
227
|
+
"content_type_id" => "embedded",
|
228
|
+
"revision" => 1
|
229
|
+
},
|
230
|
+
"body" => "Embedded 2"
|
231
|
+
},
|
232
|
+
"content" => [
|
233
|
+
{
|
234
|
+
"marks" => [
|
235
|
+
|
236
|
+
],
|
237
|
+
"value" => "",
|
238
|
+
"nodeType" => "text",
|
239
|
+
"nodeClass" => "text"
|
240
|
+
}
|
241
|
+
],
|
242
|
+
"nodeType" => "embedded-entry-block",
|
243
|
+
"nodeClass" => "block"
|
244
|
+
},
|
245
|
+
{
|
246
|
+
"data" => {
|
247
|
+
},
|
248
|
+
"content" => [
|
249
|
+
{
|
250
|
+
"marks" => [
|
251
|
+
|
252
|
+
],
|
253
|
+
"value" => "",
|
254
|
+
"nodeType" => "text",
|
255
|
+
"nodeClass" => "text"
|
256
|
+
}
|
257
|
+
],
|
258
|
+
"nodeType" => "paragraph",
|
259
|
+
"nodeClass" => "block"
|
260
|
+
},
|
261
|
+
{
|
262
|
+
"data" => {
|
263
|
+
},
|
264
|
+
"content" => [
|
265
|
+
{
|
266
|
+
"marks" => [
|
267
|
+
|
268
|
+
],
|
269
|
+
"value" => "Some raw content",
|
270
|
+
"nodeType" => "text",
|
271
|
+
"nodeClass" => "text"
|
272
|
+
}
|
273
|
+
],
|
274
|
+
"nodeType" => "paragraph",
|
275
|
+
"nodeClass" => "block"
|
276
|
+
},
|
277
|
+
{
|
278
|
+
"data" => {
|
279
|
+
},
|
280
|
+
"content" => [
|
281
|
+
{
|
282
|
+
"marks" => [
|
283
|
+
|
284
|
+
],
|
285
|
+
"value" => "",
|
286
|
+
"nodeType" => "text",
|
287
|
+
"nodeClass" => "text"
|
288
|
+
}
|
289
|
+
],
|
290
|
+
"nodeType" => "paragraph",
|
291
|
+
"nodeClass" => "block"
|
292
|
+
},
|
293
|
+
{
|
294
|
+
"data" => {
|
295
|
+
},
|
296
|
+
"content" => [
|
297
|
+
{
|
298
|
+
"marks" => [
|
299
|
+
|
300
|
+
],
|
301
|
+
"value" => "An unpublished embed:",
|
302
|
+
"nodeType" => "text",
|
303
|
+
"nodeClass" => "text"
|
304
|
+
}
|
305
|
+
],
|
306
|
+
"nodeType" => "paragraph",
|
307
|
+
"nodeClass" => "block"
|
308
|
+
},
|
309
|
+
{
|
310
|
+
"data" => {
|
311
|
+
},
|
312
|
+
"content" => [
|
313
|
+
{
|
314
|
+
"marks" => [
|
315
|
+
|
316
|
+
],
|
317
|
+
"value" => "",
|
318
|
+
"nodeType" => "text",
|
319
|
+
"nodeClass" => "text"
|
320
|
+
}
|
321
|
+
],
|
322
|
+
"nodeType" => "paragraph",
|
323
|
+
"nodeClass" => "block"
|
324
|
+
},
|
325
|
+
{
|
326
|
+
"data" => {
|
327
|
+
},
|
328
|
+
"content" => [
|
329
|
+
{
|
330
|
+
"marks" => [
|
331
|
+
|
332
|
+
],
|
333
|
+
"value" => "Some more content",
|
334
|
+
"nodeType" => "text",
|
335
|
+
"nodeClass" => "text"
|
336
|
+
}
|
337
|
+
],
|
338
|
+
"nodeType" => "paragraph",
|
339
|
+
"nodeClass" => "block"
|
340
|
+
},
|
341
|
+
{
|
342
|
+
"data" => {
|
343
|
+
},
|
344
|
+
"content" => [
|
345
|
+
{
|
346
|
+
"marks" => [
|
347
|
+
{
|
348
|
+
"data" => {
|
349
|
+
},
|
350
|
+
"type" => "code",
|
351
|
+
"object" => "mark"
|
352
|
+
}
|
353
|
+
],
|
354
|
+
"value" => "Some code",
|
355
|
+
"nodeType" => "text",
|
356
|
+
"nodeClass" => "text"
|
357
|
+
}
|
358
|
+
],
|
359
|
+
"nodeType" => "paragraph",
|
360
|
+
"nodeClass" => "block"
|
361
|
+
},
|
362
|
+
{
|
363
|
+
"data" => {
|
364
|
+
},
|
365
|
+
"content" => [
|
366
|
+
{
|
367
|
+
"marks" => [
|
368
|
+
|
369
|
+
],
|
370
|
+
"value" => "",
|
371
|
+
"nodeType" => "text",
|
372
|
+
"nodeClass" => "text"
|
373
|
+
},
|
374
|
+
{
|
375
|
+
"data" => {
|
376
|
+
"uri" => "https://www.contentful.com"
|
377
|
+
},
|
378
|
+
"content" => [
|
379
|
+
{
|
380
|
+
"marks" => [
|
381
|
+
|
382
|
+
],
|
383
|
+
"value" => "A hyperlink",
|
384
|
+
"nodeType" => "text",
|
385
|
+
"nodeClass" => "text"
|
386
|
+
}
|
387
|
+
],
|
388
|
+
"nodeType" => "hyperlink",
|
389
|
+
"nodeClass" => "inline"
|
390
|
+
},
|
391
|
+
{
|
392
|
+
"marks" => [
|
393
|
+
|
394
|
+
],
|
395
|
+
"value" => "",
|
396
|
+
"nodeType" => "text",
|
397
|
+
"nodeClass" => "text"
|
398
|
+
}
|
399
|
+
],
|
400
|
+
"nodeType" => "paragraph",
|
401
|
+
"nodeClass" => "block"
|
402
|
+
},
|
403
|
+
{
|
404
|
+
"data" => {
|
405
|
+
},
|
406
|
+
"content" => [
|
407
|
+
{
|
408
|
+
"data" => {
|
409
|
+
},
|
410
|
+
"content" => [
|
411
|
+
{
|
412
|
+
"data" => {
|
413
|
+
},
|
414
|
+
"content" => [
|
415
|
+
{
|
416
|
+
"marks" => [
|
417
|
+
|
418
|
+
],
|
419
|
+
"value" => "Ul list",
|
420
|
+
"nodeType" => "text",
|
421
|
+
"nodeClass" => "text"
|
422
|
+
}
|
423
|
+
],
|
424
|
+
"nodeType" => "paragraph",
|
425
|
+
"nodeClass" => "block"
|
426
|
+
}
|
427
|
+
],
|
428
|
+
"nodeType" => "list-item",
|
429
|
+
"nodeClass" => "block"
|
430
|
+
},
|
431
|
+
{
|
432
|
+
"data" => {
|
433
|
+
},
|
434
|
+
"content" => [
|
435
|
+
{
|
436
|
+
"data" => {
|
437
|
+
},
|
438
|
+
"content" => [
|
439
|
+
{
|
440
|
+
"marks" => [
|
441
|
+
|
442
|
+
],
|
443
|
+
"value" => "A few ",
|
444
|
+
"nodeType" => "text",
|
445
|
+
"nodeClass" => "text"
|
446
|
+
},
|
447
|
+
{
|
448
|
+
"marks" => [
|
449
|
+
{
|
450
|
+
"data" => {
|
451
|
+
},
|
452
|
+
"type" => "bold",
|
453
|
+
"object" => "mark"
|
454
|
+
}
|
455
|
+
],
|
456
|
+
"value" => "items",
|
457
|
+
"nodeType" => "text",
|
458
|
+
"nodeClass" => "text"
|
459
|
+
}
|
460
|
+
],
|
461
|
+
"nodeType" => "paragraph",
|
462
|
+
"nodeClass" => "block"
|
463
|
+
},
|
464
|
+
{
|
465
|
+
"data" => {
|
466
|
+
},
|
467
|
+
"content" => [
|
468
|
+
{
|
469
|
+
"data" => {
|
470
|
+
},
|
471
|
+
"content" => [
|
472
|
+
{
|
473
|
+
"data" => {
|
474
|
+
},
|
475
|
+
"content" => [
|
476
|
+
{
|
477
|
+
"marks" => [
|
478
|
+
|
479
|
+
],
|
480
|
+
"value" => "Ordered list nested inside an Unordered list item",
|
481
|
+
"nodeType" => "text",
|
482
|
+
"nodeClass" => "text"
|
483
|
+
}
|
484
|
+
],
|
485
|
+
"nodeType" => "paragraph",
|
486
|
+
"nodeClass" => "block"
|
487
|
+
}
|
488
|
+
],
|
489
|
+
"nodeType" => "list-item",
|
490
|
+
"nodeClass" => "block"
|
491
|
+
}
|
492
|
+
],
|
493
|
+
"nodeType" => "ordered-list",
|
494
|
+
"nodeClass" => "block"
|
495
|
+
}
|
496
|
+
],
|
497
|
+
"nodeType" => "list-item",
|
498
|
+
"nodeClass" => "block"
|
499
|
+
}
|
500
|
+
],
|
501
|
+
"nodeType" => "unordered-list",
|
502
|
+
"nodeClass" => "block"
|
503
|
+
},
|
504
|
+
{
|
505
|
+
"data" => {
|
506
|
+
},
|
507
|
+
"content" => [
|
508
|
+
{
|
509
|
+
"data" => {
|
510
|
+
},
|
511
|
+
"content" => [
|
512
|
+
{
|
513
|
+
"data" => {
|
514
|
+
},
|
515
|
+
"content" => [
|
516
|
+
{
|
517
|
+
"marks" => [
|
518
|
+
|
519
|
+
],
|
520
|
+
"value" => "Ol list",
|
521
|
+
"nodeType" => "text",
|
522
|
+
"nodeClass" => "text"
|
523
|
+
}
|
524
|
+
],
|
525
|
+
"nodeType" => "paragraph",
|
526
|
+
"nodeClass" => "block"
|
527
|
+
}
|
528
|
+
],
|
529
|
+
"nodeType" => "list-item",
|
530
|
+
"nodeClass" => "block"
|
531
|
+
},
|
532
|
+
{
|
533
|
+
"data" => {
|
534
|
+
},
|
535
|
+
"content" => [
|
536
|
+
{
|
537
|
+
"data" => {
|
538
|
+
},
|
539
|
+
"content" => [
|
540
|
+
{
|
541
|
+
"marks" => [
|
542
|
+
|
543
|
+
],
|
544
|
+
"value" => "two",
|
545
|
+
"nodeType" => "text",
|
546
|
+
"nodeClass" => "text"
|
547
|
+
}
|
548
|
+
],
|
549
|
+
"nodeType" => "paragraph",
|
550
|
+
"nodeClass" => "block"
|
551
|
+
}
|
552
|
+
],
|
553
|
+
"nodeType" => "list-item",
|
554
|
+
"nodeClass" => "block"
|
555
|
+
},
|
556
|
+
{
|
557
|
+
"data" => {
|
558
|
+
},
|
559
|
+
"content" => [
|
560
|
+
{
|
561
|
+
"data" => {
|
562
|
+
},
|
563
|
+
"content" => [
|
564
|
+
{
|
565
|
+
"marks" => [
|
566
|
+
|
567
|
+
],
|
568
|
+
"value" => "three",
|
569
|
+
"nodeType" => "text",
|
570
|
+
"nodeClass" => "text"
|
571
|
+
}
|
572
|
+
],
|
573
|
+
"nodeType" => "paragraph",
|
574
|
+
"nodeClass" => "block"
|
575
|
+
}
|
576
|
+
],
|
577
|
+
"nodeType" => "list-item",
|
578
|
+
"nodeClass" => "block"
|
579
|
+
}
|
580
|
+
],
|
581
|
+
"nodeType" => "ordered-list",
|
582
|
+
"nodeClass" => "block"
|
583
|
+
},
|
584
|
+
{
|
585
|
+
"data" => {
|
586
|
+
},
|
587
|
+
"content" => [
|
588
|
+
{
|
589
|
+
"marks" => [
|
590
|
+
|
591
|
+
],
|
592
|
+
"value" => "",
|
593
|
+
"nodeType" => "text",
|
594
|
+
"nodeClass" => "text"
|
595
|
+
}
|
596
|
+
],
|
597
|
+
"nodeType" => "hr",
|
598
|
+
"nodeClass" => "block"
|
599
|
+
},
|
600
|
+
{
|
601
|
+
"data" => {
|
602
|
+
},
|
603
|
+
"content" => [
|
604
|
+
{
|
605
|
+
"marks" => [
|
606
|
+
|
607
|
+
],
|
608
|
+
"value" => "",
|
609
|
+
"nodeType" => "text",
|
610
|
+
"nodeClass" => "text"
|
611
|
+
}
|
612
|
+
],
|
613
|
+
"nodeType" => "paragraph",
|
614
|
+
"nodeClass" => "block"
|
615
|
+
},
|
616
|
+
{
|
617
|
+
"data" => {
|
618
|
+
},
|
619
|
+
"content" => [
|
620
|
+
{
|
621
|
+
"data" => {
|
622
|
+
},
|
623
|
+
"content" => [
|
624
|
+
{
|
625
|
+
"marks" => [
|
626
|
+
|
627
|
+
],
|
628
|
+
"value" => "An inspirational quote",
|
629
|
+
"nodeType" => "text",
|
630
|
+
"nodeClass" => "text"
|
631
|
+
}
|
632
|
+
],
|
633
|
+
"nodeType" => "paragraph",
|
634
|
+
"nodeClass" => "block"
|
635
|
+
},
|
636
|
+
{
|
637
|
+
"data" => {
|
638
|
+
},
|
639
|
+
"content" => [
|
640
|
+
{
|
641
|
+
"marks" => [
|
642
|
+
|
643
|
+
],
|
644
|
+
"value" => "",
|
645
|
+
"nodeType" => "text",
|
646
|
+
"nodeClass" => "text"
|
647
|
+
}
|
648
|
+
],
|
649
|
+
"nodeType" => "paragraph",
|
650
|
+
"nodeClass" => "block"
|
651
|
+
}
|
652
|
+
],
|
653
|
+
"nodeType" => "blockquote",
|
654
|
+
"nodeClass" => "block"
|
655
|
+
},
|
656
|
+
{
|
657
|
+
"data" => {
|
658
|
+
},
|
659
|
+
"content" => [
|
660
|
+
{
|
661
|
+
"marks" => [
|
662
|
+
|
663
|
+
],
|
664
|
+
"value" => "",
|
665
|
+
"nodeType" => "text",
|
666
|
+
"nodeClass" => "text"
|
667
|
+
}
|
668
|
+
],
|
669
|
+
"nodeType" => "paragraph",
|
670
|
+
"nodeClass" => "block"
|
671
|
+
}
|
672
|
+
],
|
673
|
+
"nodeType" => "document",
|
674
|
+
"nodeClass" => "document"
|
675
|
+
}
|
676
|
+
end
|
677
|
+
|
678
|
+
subject { MockSiteContext.new(config) }
|
679
|
+
|
680
|
+
describe 'renders rich text' do
|
681
|
+
it 'by defaults uses first available config' do
|
682
|
+
result = subject.rich_text(rt_field)
|
683
|
+
|
684
|
+
expect(result).to include("<div>I eat nodes for breakfast</div>")
|
685
|
+
end
|
686
|
+
|
687
|
+
it 'can define which space configuration to use' do
|
688
|
+
result = subject.rich_text(rt_field, 'foo')
|
689
|
+
expect(result).to include("<div>I eat nodes for breakfast</div>")
|
690
|
+
|
691
|
+
result = subject.rich_text(rt_field, 'bar')
|
692
|
+
expect(result).not_to include("<div>I eat nodes for breakfast</div>")
|
693
|
+
end
|
694
|
+
end
|
695
|
+
end
|
@@ -21,8 +21,12 @@ class ExporterDouble
|
|
21
21
|
end
|
22
22
|
|
23
23
|
describe Jekyll::Contentful::Importer do
|
24
|
+
before :each do
|
25
|
+
allow(Jekyll.logger).to receive(:debug).with("Couldn't find custom mappers")
|
26
|
+
end
|
27
|
+
|
24
28
|
let(:config) do
|
25
|
-
{
|
29
|
+
{ 'contentful' => {
|
26
30
|
'spaces' => [
|
27
31
|
{
|
28
32
|
'example' => {
|
@@ -31,7 +35,7 @@ describe Jekyll::Contentful::Importer do
|
|
31
35
|
}
|
32
36
|
}
|
33
37
|
]
|
34
|
-
}
|
38
|
+
}}
|
35
39
|
end
|
36
40
|
subject { described_class.new(config) }
|
37
41
|
|
@@ -94,27 +98,29 @@ describe Jekyll::Contentful::Importer do
|
|
94
98
|
it 'runs exporter with correct arguments' do
|
95
99
|
allow(subject).to receive(:client).and_return(ClientDouble.new)
|
96
100
|
|
97
|
-
expect(Jekyll::Contentful::SingleFileDataExporter).to receive(:new).with('example', [], config['spaces'].first['example']).and_return(ExporterDouble.new)
|
101
|
+
expect(Jekyll::Contentful::SingleFileDataExporter).to receive(:new).with('example', [], config['contentful']['spaces'].first['example']).and_return(ExporterDouble.new)
|
98
102
|
|
99
103
|
subject.run
|
100
104
|
end
|
101
105
|
|
102
106
|
it 'runs multifile exporter when passed :individual_entry_files flag' do
|
103
107
|
config = {
|
104
|
-
'
|
105
|
-
|
106
|
-
|
107
|
-
'
|
108
|
-
|
109
|
-
|
108
|
+
'contentful' => {
|
109
|
+
'spaces' => [
|
110
|
+
{
|
111
|
+
'example' => {
|
112
|
+
'space' => 'cfexampleapi',
|
113
|
+
'access_token' => 'b4c0n73n7fu1',
|
114
|
+
'individual_entry_files' => true
|
115
|
+
}
|
110
116
|
}
|
111
|
-
|
112
|
-
|
117
|
+
]
|
118
|
+
}
|
113
119
|
}
|
114
120
|
subject = described_class.new(config)
|
115
121
|
allow(subject).to receive(:client).and_return(ClientDouble.new)
|
116
122
|
|
117
|
-
expect(Jekyll::Contentful::MultiFileDataExporter).to receive(:new).with('example', [], config['spaces'].first['example']).and_return(ExporterDouble.new)
|
123
|
+
expect(Jekyll::Contentful::MultiFileDataExporter).to receive(:new).with('example', [], config['contentful']['spaces'].first['example']).and_return(ExporterDouble.new)
|
118
124
|
|
119
125
|
subject.run
|
120
126
|
end
|
@@ -143,4 +149,40 @@ describe Jekyll::Contentful::Importer do
|
|
143
149
|
end
|
144
150
|
end
|
145
151
|
end
|
152
|
+
|
153
|
+
describe 'mappers are autoloaded' do
|
154
|
+
let(:jekyll_config) do
|
155
|
+
{ 'contentful' => {
|
156
|
+
'spaces' => [
|
157
|
+
{
|
158
|
+
'example' => {
|
159
|
+
'space' => 'cfexampleapi',
|
160
|
+
'access_token' => 'b4c0n73n7fu1'
|
161
|
+
}
|
162
|
+
}
|
163
|
+
]
|
164
|
+
}}
|
165
|
+
end
|
166
|
+
|
167
|
+
it 'custom mappers are autoloaded' do
|
168
|
+
config = jekyll_config.merge('source' => '.', 'plugins_dir' => '_plugins')
|
169
|
+
|
170
|
+
allow(subject).to receive(:spaces).and_return([['foo', {'space' => 'foo', 'access_token' => 'bar'}], ['bar', {'space' => 'bar', 'access_token' => 'foo'}]])
|
171
|
+
allow(subject).to receive(:client).and_return(ClientDouble.new)
|
172
|
+
|
173
|
+
expect(Jekyll::Utils).to receive(:safe_glob).with(File.join('.', '_plugins', 'mappers'), File.join('**', '*.rb')) { ['some_mapper.rb'] }
|
174
|
+
expect(Jekyll::External).to receive(:require_with_graceful_fail).with(['some_mapper.rb'])
|
175
|
+
|
176
|
+
described_class.new(config)
|
177
|
+
end
|
178
|
+
|
179
|
+
it 'raises a warning if no mappers found' do
|
180
|
+
allow(subject).to receive(:spaces).and_return([['foo', {'space' => 'foo', 'access_token' => 'bar'}], ['bar', {'space' => 'bar', 'access_token' => 'foo'}]])
|
181
|
+
allow(subject).to receive(:client).and_return(ClientDouble.new)
|
182
|
+
|
183
|
+
expect(Jekyll.logger).to receive(:debug).with("Couldn't find custom mappers")
|
184
|
+
|
185
|
+
described_class.new(config)
|
186
|
+
end
|
187
|
+
end
|
146
188
|
end
|
@@ -1,6 +1,10 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Jekyll::Commands::Contentful do
|
4
|
+
before :each do
|
5
|
+
allow(Jekyll.logger).to receive(:debug).with("Couldn't find custom mappers")
|
6
|
+
end
|
7
|
+
|
4
8
|
describe 'class methods' do
|
5
9
|
describe '::init_with_program' do
|
6
10
|
it 'implements jekyll command interface' do
|
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
|
+
version: 1.8.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: 2018-
|
11
|
+
date: 2018-10-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: jekyll
|
@@ -44,6 +44,20 @@ dependencies:
|
|
44
44
|
- - "~>"
|
45
45
|
- !ruby/object:Gem::Version
|
46
46
|
version: '2.1'
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: rich_text_renderer
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - "~>"
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0.1'
|
54
|
+
type: :runtime
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - "~>"
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '0.1'
|
47
61
|
- !ruby/object:Gem::Dependency
|
48
62
|
name: rubygems-tasks
|
49
63
|
requirement: !ruby/object:Gem::Requirement
|
@@ -234,6 +248,7 @@ files:
|
|
234
248
|
- jekyll-contentful.gemspec
|
235
249
|
- lib/jekyll-contentful-data-import.rb
|
236
250
|
- lib/jekyll-contentful-data-import/base_data_exporter.rb
|
251
|
+
- lib/jekyll-contentful-data-import/helpers.rb
|
237
252
|
- lib/jekyll-contentful-data-import/importer.rb
|
238
253
|
- lib/jekyll-contentful-data-import/mappers.rb
|
239
254
|
- lib/jekyll-contentful-data-import/mappers/base.rb
|
@@ -243,6 +258,7 @@ files:
|
|
243
258
|
- lib/jekyll-contentful-data-import/version.rb
|
244
259
|
- lib/jekyll/commands/contentful.rb
|
245
260
|
- spec/fixtures/vcr_fixtures/entries.yml
|
261
|
+
- spec/jekyll-contentful/helpers_spec.rb
|
246
262
|
- spec/jekyll-contentful/importer_spec.rb
|
247
263
|
- spec/jekyll-contentful/mappers/base_spec.rb
|
248
264
|
- spec/jekyll-contentful/multi_file_data_exporter_spec.rb
|
@@ -277,6 +293,7 @@ summary: Include mangablable content from the Contentful CMS and API into your J
|
|
277
293
|
projects
|
278
294
|
test_files:
|
279
295
|
- spec/fixtures/vcr_fixtures/entries.yml
|
296
|
+
- spec/jekyll-contentful/helpers_spec.rb
|
280
297
|
- spec/jekyll-contentful/importer_spec.rb
|
281
298
|
- spec/jekyll-contentful/mappers/base_spec.rb
|
282
299
|
- spec/jekyll-contentful/multi_file_data_exporter_spec.rb
|