contentful_bootstrap 1.1.0 → 1.2.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: a1889695468ff7c1a8250d9fa14e88d81167df6a
4
- data.tar.gz: 5e6634f55c894b036d5580d8b31d9d5e8f207d13
3
+ metadata.gz: 6c9318c79de37f2e341ff2790568f262ae743c6f
4
+ data.tar.gz: 027e2f1d2f813dd7474bb60fc9513f90ad01a9bc
5
5
  SHA512:
6
- metadata.gz: 81a56b64246f4b7bea76a0161d7d8c361090f643a8d0b2e8f0fa63c5dec0cc394560b940d0ba1d6b5d1e76f817bdf880fa61d63a99f6d121f21df50c04803ebb
7
- data.tar.gz: 00d5ab1fb4dc4a68e4a97f421875c7b6d3422c0a2d5fe8255844b4e3cb70b3115ecc8640b18544c7329eb67f001edace299bcc87d96ccd940706a5dd3d0f0f98
6
+ metadata.gz: 157d290ee057532caa5a4973d453950fc8396245ee206df3f2469e23debf5bcc9c042e709684670fe8807655db5e2d5ba624267ab06ef4a748566a149ca37829
7
+ data.tar.gz: bfaf280b578495afa0d746cc6037dcaf9d6e0f1b9599066177a4a2bed341f54c98b102667a0fc936815e267c0cfabfcb35fe1e882290f10f98679c1920d6702e
data/CHANGELOG.md CHANGED
@@ -1,6 +1,15 @@
1
1
  # Change Log
2
2
  ## Unreleased
3
3
 
4
+ ## v1.2.0
5
+ ### Added
6
+ * JSON Template Parser
7
+ * `catalogue.json` Template Example
8
+
9
+ ### Changed
10
+ * Changed existing templates from using `Symbol` entries as keys to `String`
11
+ * Changed command optional parameters to `Hash` to allow better flexibility in commands
12
+
4
13
  ## v1.1.0
5
14
  ### Removed
6
15
  * Removed `init` command as `v1.0.0` refactor removed it's necessity
data/README.md CHANGED
@@ -25,7 +25,7 @@ $ gem install contentful_bootstrap
25
25
  You can create spaces by doing
26
26
 
27
27
  ```bash
28
- $ contentful_bootstrap create_space <space_name> [--template template_name] [--config CONFIG_PATH]
28
+ $ contentful_bootstrap create_space <space_name> [--template template_name] [--json-template template_path] [--config CONFIG_PATH]
29
29
  ```
30
30
 
31
31
 
@@ -65,13 +65,34 @@ require 'contentful/bootstrap'
65
65
  To Create a new Space
66
66
 
67
67
  ```ruby
68
- Contentful::Bootstrap::Commands.new.create_space("space_name", "template_name") # Template Name is optional
68
+ Contentful::Bootstrap::Commands.new.create_space("space_name")
69
+ ```
70
+
71
+ Additionally, you can send an options hash with the following keys:
72
+
73
+ ```ruby
74
+ options = {
75
+ template: "blog", # Will use one of the predefined templates and create Content Types, Assets and Entries
76
+ json_template: "/path/to/template.json", # Will use the JSON file specified as a Template
77
+ trigger_oauth: true # if true will trigger OAuth process
78
+ }
79
+ Contentful::Bootstrap::Commands.new.create_space("space_name", options)
69
80
  ```
70
81
 
71
82
  To Create a new Delivery API Token
72
83
 
73
84
  ```ruby
74
- Contentful::Bootstrap::Commands.new.generate_token("space_id", "token_name") # Token Name is optional
85
+ Contentful::Bootstrap::Commands.new.generate_token("space_id")
86
+ ```
87
+
88
+ Additionally, you can send an options hash with the following keys:
89
+
90
+ ```ruby
91
+ options = {
92
+ name: "Some Nice Token Name", # Will Create the Delivery API Token with the specified name
93
+ trigger_oauth: true # if true will trigger OAuth process
94
+ }
95
+ Contentful::Bootstrap::Commands.new.create_space("space_name", options)
75
96
  ```
76
97
 
77
98
  Optionally, `Commands#new` will take a parameter for specifying a configuration path
@@ -93,6 +114,10 @@ CONTENTFUL_MANAGEMENT_ACCESS_TOKEN = a_management_access_token
93
114
  CONTENTFUL_DELIVERY_ACCESS_TOKEN = a_delivery_acces_token ; Delivery Access Token is not required for this tool, but can be generated by it
94
115
  ```
95
116
 
117
+ ### JSON Templates
118
+
119
+ You can find a complete example [here](./examples/templates/catalogue.json)
120
+
96
121
  ## Contributing
97
122
 
98
123
  Feel free to improve this tool by submitting a Pull Request. For more information,
@@ -5,7 +5,7 @@ require 'contentful/bootstrap/commands'
5
5
 
6
6
  options = {}
7
7
  global = OptionParser.new do |opts|
8
- opts.banner = "Usage: contentful_bootstrap <command> <space_name> [--template TEMPLATE_NAME] [--config CONFIG_PATH]"
8
+ opts.banner = "Usage: contentful_bootstrap <command> <space_name> [options]"
9
9
  opts.separator ""
10
10
  opts.separator <<-HELP
11
11
  Available commands are:
@@ -16,16 +16,19 @@ end
16
16
 
17
17
  subcommands = {
18
18
  'create_space' => OptionParser.new do |opts|
19
- opts.banner = "Usage: init <space_name> [--template TEMPLATE_NAME]"
19
+ opts.banner = "Usage: init <space_name> [--template TEMPLATE_NAME] [--json-template JSON_PATH] [--config CONFIG_PATH]"
20
20
  opts.on("-t TEMPLATE", "--template TEMPLATE", "Specify Template", "blog, catalogue, gallery") do |t|
21
- options[:name] = t
21
+ options[:template] = t
22
+ end
23
+ opts.on("-j JSON_PATH", "--json-template JSON_PATH", "Specify JSON Template Path") do |j|
24
+ options[:json_template] = j
22
25
  end
23
26
  opts.on("-c CONFIG_PATH", "--config CONFIG_PATH", "Specify Configuration Path") do |c|
24
27
  options[:config_path] = c
25
28
  end
26
29
  end,
27
30
  'generate_token' => OptionParser.new do |opts|
28
- opts.banner = "Usage: generate_token <space_id> [--name TOKEN_NAME]"
31
+ opts.banner = "Usage: generate_token <space_id> [--name TOKEN_NAME] [--config CONFIG_PATH]"
29
32
  opts.on("-n NAME", "--name TEMPLATE", "Specify Token Name") do |n|
30
33
  options[:name] = n
31
34
  end
@@ -49,7 +52,9 @@ if subcommands.has_key? command
49
52
  exit
50
53
  end
51
54
 
52
- Contentful::Bootstrap::Commands.new(options.fetch(:config_path, "")).send(command, space, options.fetch(:name, nil))
55
+ options[:trigger_oauth] = true
56
+
57
+ Contentful::Bootstrap::Commands.new(options.fetch(:config_path, "")).send(command, space, options)
53
58
  else
54
59
  puts "Usage: contentful_bootstrap <command> <space> [options]"
55
60
  puts
@@ -0,0 +1,221 @@
1
+ {
2
+ "content_types": [
3
+ {
4
+ "id": "brand",
5
+ "name": "Brand",
6
+ "display_field": "name",
7
+ "fields": [
8
+ {
9
+ "id": "name",
10
+ "name": "Company Name",
11
+ "type": "Symbol"
12
+ },
13
+ {
14
+ "id": "website",
15
+ "name": "Website",
16
+ "type": "Symbol"
17
+ },
18
+ {
19
+ "id": "logo",
20
+ "name": "Logo",
21
+ "type": "Link",
22
+ "link_type": "Asset"
23
+ }
24
+ ]
25
+ },
26
+ {
27
+ "id": "category",
28
+ "name": "Category",
29
+ "display_field": "title",
30
+ "fields": [
31
+ {
32
+ "id": "title",
33
+ "name": "Title",
34
+ "type": "Symbol"
35
+ },
36
+ {
37
+ "id": "description",
38
+ "name": "Description",
39
+ "type": "Text"
40
+ },
41
+ {
42
+ "id": "icon",
43
+ "name": "Icon",
44
+ "type": "Link",
45
+ "link_type": "Asset"
46
+ }
47
+ ]
48
+ },
49
+ {
50
+ "id": "product",
51
+ "name": "Product",
52
+ "display_field": "name",
53
+ "fields": [
54
+ {
55
+ "id": "name",
56
+ "name": "name",
57
+ "type": "Symbol"
58
+ },
59
+ {
60
+ "id": "description",
61
+ "name": "Description",
62
+ "type": "Text"
63
+ },
64
+ {
65
+ "id": "image",
66
+ "name": "Image",
67
+ "type": "Link",
68
+ "link_type": "Asset"
69
+ },
70
+ {
71
+ "id": "brand",
72
+ "name": "Brand",
73
+ "type": "Link",
74
+ "link_type": "Entry"
75
+ },
76
+ {
77
+ "id": "category",
78
+ "name": "Category",
79
+ "type": "Link",
80
+ "link_type": "Entry"
81
+ },
82
+ {
83
+ "id": "url",
84
+ "name": "Available at",
85
+ "type": "Symbol"
86
+ }
87
+ ]
88
+ }
89
+ ],
90
+ "assets": [
91
+ {
92
+ "id": "playsam_image",
93
+ "title": "Playsam",
94
+ "file": {
95
+ "filename": "playsam_image",
96
+ "url": "https://images.contentful.com/liicpxzmg1q0/4zj1ZOfHgQ8oqgaSKm4Qo2/3be82d54d45b5297e951aee9baf920da/playsam.jpg?h=250&"
97
+ }
98
+ },
99
+ {
100
+ "id": "normann_image",
101
+ "title": "Normann",
102
+ "file": {
103
+ "filename": "normann_image",
104
+ "url": "https://images.contentful.com/liicpxzmg1q0/3wtvPBbBjiMKqKKga8I2Cu/75c7c92f38f7953a741591d215ad61d4/zJYzDlGk.jpeg?h=250&"
105
+ }
106
+ },
107
+ {
108
+ "id": "toy_image",
109
+ "title": "Toys",
110
+ "file": {
111
+ "filename": "toy_image",
112
+ "url": "https://images.contentful.com/liicpxzmg1q0/6t4HKjytPi0mYgs240wkG/866ef53a11af9c6bf5f3808a8ce1aab2/toys_512pxGREY.png?h=250&"
113
+ }
114
+ },
115
+ {
116
+ "id": "kitchen_image",
117
+ "title": "Kitchen and Home",
118
+ "file": {
119
+ "filename": "kitchen_image",
120
+ "url": "https://images.contentful.com/liicpxzmg1q0/6m5AJ9vMPKc8OUoQeoCS4o/ffc20f5a8f2a71cca4801bc9c51b966a/1418244847_Streamline-18-256.png?h=250&"
121
+ }
122
+ },
123
+ {
124
+ "id": "toy_car",
125
+ "title": "Playsam Toy Car",
126
+ "file": {
127
+ "filename": "toy_car",
128
+ "url": "https://images.contentful.com/liicpxzmg1q0/wtrHxeu3zEoEce2MokCSi/acef70d12fe019228c4238aa791bdd48/quwowooybuqbl6ntboz3.jpg?h=250&"
129
+ }
130
+ },
131
+ {
132
+ "id": "whiskers",
133
+ "title": "Normann Whisk Beaters",
134
+ "file": {
135
+ "filename": "whiskers",
136
+ "url": "https://images.contentful.com/liicpxzmg1q0/10TkaLheGeQG6qQGqWYqUI/d510dde5e575d40288cf75b42383aa53/ryugj83mqwa1asojwtwb.jpg?h=250&"
137
+ }
138
+ }
139
+ ],
140
+ "entries": {
141
+ "brand": [
142
+ {
143
+ "id": "playsam",
144
+ "name": "Playsam, Inc",
145
+ "website": "http://www.playsam.com",
146
+ "logo": {
147
+ "link_type": "Asset",
148
+ "id": "playsam_image"
149
+ }
150
+ },
151
+ {
152
+ "id": "normann",
153
+ "name": "Normann Copenhagen, Inc",
154
+ "website": "http://www.normann-copenhagen.com/",
155
+ "logo": {
156
+ "link_type": "Asset",
157
+ "id": "normann_image"
158
+ }
159
+ }
160
+ ],
161
+ "category": [
162
+ {
163
+ "id": "toys",
164
+ "title": "Toys",
165
+ "description": "Toys for children",
166
+ "icon": {
167
+ "link_type": "Asset",
168
+ "id": "toy_image"
169
+ }
170
+ },
171
+ {
172
+ "id": "kitchen",
173
+ "title": "House and Kitchen",
174
+ "description": "House and Kitchen accessories",
175
+ "icon": {
176
+ "link_type": "Asset",
177
+ "id": "kitchen_image"
178
+ }
179
+ }
180
+ ],
181
+ "product": [
182
+ {
183
+ "id": "playsam_car",
184
+ "name": "Playsam Streamliner Classic Car, Espresso",
185
+ "description": "A classic Playsam design, the Streamliner Classic Car has been selected as Swedish Design Classic by the Swedish National Museum for its inventive style and sleek surface. It's no wonder that this wooden car has also been a long-standing favorite for children both big and small!",
186
+ "image": {
187
+ "link_type": "Asset",
188
+ "id": "toy_car"
189
+ },
190
+ "brand": {
191
+ "link_type": "Entry",
192
+ "id": "playsam"
193
+ },
194
+ "category": {
195
+ "link_type": "Entry",
196
+ "id": "toys"
197
+ },
198
+ "url": "http://www.amazon.com/dp/B001R6JUZ2/"
199
+ },
200
+ {
201
+ "id": "whisk_beater",
202
+ "name": "Whisk Beater",
203
+ "description": "A creative little whisk that comes in 8 different colors. Handy and easy to clean after use. A great gift idea.",
204
+ "image": {
205
+ "link_type": "Asset",
206
+ "id": "whiskers"
207
+ },
208
+ "brand": {
209
+ "link_type": "Entry",
210
+ "id": "normann"
211
+ },
212
+ "category": {
213
+ "link_type": "Entry",
214
+ "id": "kitchen"
215
+ },
216
+ "url": "http://www.amazon.com/dp/B0081F2CCK/"
217
+ }
218
+ ]
219
+ }
220
+ }
221
+
@@ -17,8 +17,12 @@ module Contentful
17
17
  Token.set_path!(config_path)
18
18
  end
19
19
 
20
- def create_space(space_name, template_name = nil, from_command = true)
21
- get_configuration if from_command
20
+ def create_space(space_name, options = {})
21
+ template_name = options.fetch(:template, nil)
22
+ json_template = options.fetch(:json_template, nil)
23
+ trigger_oauth = options.fetch(:trigger_oauth, true)
24
+
25
+ get_configuration if trigger_oauth
22
26
 
23
27
  management_client_init
24
28
 
@@ -45,9 +49,21 @@ module Contentful
45
49
  else
46
50
  puts "Template '#{template_name}' not found. Valid templates are '#{templates.keys.map(&:to_s).join('\', \'')}'"
47
51
  end
52
+ puts
53
+ end
54
+
55
+ unless json_template.nil?
56
+ if File.exist?(json_template)
57
+ puts "Creating JSON Template '#{json_template}'"
58
+ Templates::JsonTemplate.new(space, json_template).run
59
+ puts "JSON Template '#{json_template}' created!"
60
+ else
61
+ puts "JSON Template '#{json_template}' does not exist. Please check that you specified the correct file name."
62
+ end
63
+ puts
48
64
  end
49
65
 
50
- token = generate_token(space, "Bootstrap Token", false)
66
+ token = generate_token(space, trigger_oauth: false)
51
67
  puts
52
68
  puts "Space ID: '#{space.id}'"
53
69
  puts "Access Token: '#{token}'"
@@ -55,9 +71,12 @@ module Contentful
55
71
  puts "You can now insert those values into your configuration blocks"
56
72
  end
57
73
 
58
- def generate_token(space, token_name = "Bootstrap Token", from_command = true)
59
- get_configuration if from_command
60
- management_client_init if from_command
74
+ def generate_token(space, options = {})
75
+ token_name = options.fetch(:name, "Bootstrap Token")
76
+ trigger_oauth = options.fetch(:trigger_oauth, true)
77
+
78
+ get_configuration if trigger_oauth
79
+ management_client_init if trigger_oauth
61
80
 
62
81
  if space.is_a?(String)
63
82
  space = Contentful::Management::Space.find(space)
@@ -1,3 +1,4 @@
1
1
  require "contentful/bootstrap/templates/blog"
2
2
  require "contentful/bootstrap/templates/catalogue"
3
3
  require "contentful/bootstrap/templates/gallery"
4
+ require "contentful/bootstrap/templates/json_template"
@@ -40,25 +40,25 @@ module Contentful
40
40
  private
41
41
  def create_content_types
42
42
  content_types.each do |ct|
43
- puts "Creating Content Type '#{ct[:name]}'"
43
+ puts "Creating Content Type '#{ct["name"]}'"
44
44
 
45
45
  fields = []
46
46
  content_type = space.content_types.new
47
- content_type.id = ct[:id]
48
- content_type.name = ct[:name]
49
- content_type.display_field = ct[:display_field]
47
+ content_type.id = ct["id"]
48
+ content_type.name = ct["name"]
49
+ content_type.display_field = ct["display_field"]
50
50
 
51
- ct[:fields].each do |f|
51
+ ct["fields"].each do |f|
52
52
  field = Contentful::Management::Field.new
53
- field.id = f[:id]
54
- field.name = f[:name]
55
- field.type = f[:type]
56
- field.link_type = f[:link_type] if is_link?(f)
53
+ field.id = f["id"]
54
+ field.name = f["name"]
55
+ field.type = f["type"]
56
+ field.link_type = f["link_type"] if is_link?(f)
57
57
 
58
58
  if is_array?(f)
59
59
  array_field = Contentful::Management::Field.new
60
- array_field.type = f[:items][:type]
61
- array_field.link_type = f[:items][:link_type]
60
+ array_field.type = f["items"]["type"]
61
+ array_field.link_type = f["items"]["link_type"]
62
62
  field.items = array_field
63
63
  end
64
64
 
@@ -72,17 +72,21 @@ module Contentful
72
72
  end
73
73
 
74
74
  def is_link?(field)
75
- field.has_key?(:link_type)
75
+ field.has_key?("link_type")
76
76
  end
77
77
 
78
78
  def is_array?(field)
79
- field.has_key?(:items)
79
+ field.has_key?("items")
80
80
  end
81
81
 
82
82
  def create_assets
83
83
  assets.each do |asset|
84
- puts "Creating Asset '#{asset[:title]}'"
85
- asset = space.assets.create(asset)
84
+ puts "Creating Asset '#{asset["title"]}'"
85
+ asset = space.assets.create(
86
+ id: asset["id"],
87
+ title: asset["title"],
88
+ file: asset["file"]
89
+ )
86
90
  asset.process_file
87
91
  sleep(1) # Wait for Process
88
92
  asset.publish
@@ -96,14 +100,21 @@ module Contentful
96
100
  puts "Creating Entry #{index} for #{content_type_id.capitalize}"
97
101
 
98
102
  array_fields = []
99
- e.each_pair do |field_name, value|
103
+ regular_fields = []
104
+ e.each do |field_name, value|
100
105
  array_fields << field_name if value.is_a? Array
106
+ regular_fields << field_name
101
107
  end
102
108
 
103
109
  array_fields.each do |af|
104
110
  e[af].map! do |f|
105
111
  space.send(f.kind).find(f.id)
106
112
  end
113
+ e[af.to_sym] = e.delete(af)
114
+ end
115
+
116
+ regular_fields.each do |rf|
117
+ e[rf.to_sym] = e.delete(rf)
107
118
  end
108
119
 
109
120
  entry = content_type.entries.create(e)
@@ -8,37 +8,37 @@ module Contentful
8
8
  def content_types
9
9
  [
10
10
  {
11
- id: 'author',
12
- name: 'Author',
13
- display_field: 'name',
14
- fields: [
11
+ "id" => 'author',
12
+ "name" => 'Author',
13
+ "display_field" => 'name',
14
+ "fields" => [
15
15
  {
16
- id: 'name',
17
- name: "Author Name",
18
- type: "Symbol"
16
+ "id" => 'name',
17
+ "name" => "Author Name",
18
+ "type" => "Symbol"
19
19
  }
20
20
  ]
21
21
  },
22
22
  {
23
- id: 'post',
24
- name: 'Post',
25
- display_field: 'title',
26
- fields: [
23
+ "id" => 'post',
24
+ "name" => 'Post',
25
+ "display_field" => 'title',
26
+ "fields" => [
27
27
  {
28
- id: 'title',
29
- name: "Post Title",
30
- type: "Symbol"
28
+ "id" => 'title',
29
+ "name" => "Post Title",
30
+ "type" => "Symbol"
31
31
  },
32
32
  {
33
- id: 'content',
34
- name: "Content",
35
- type: "Text"
33
+ "id" => 'content',
34
+ "name" => "Content",
35
+ "type" => "Text"
36
36
  },
37
37
  {
38
- id: 'author',
39
- name: "Author",
40
- type: "Link",
41
- link_type: "Entry"
38
+ "id" => 'author',
39
+ "name" => "Author",
40
+ "type" => "Link",
41
+ "link_type" => "Entry"
42
42
  }
43
43
  ]
44
44
  }
@@ -49,24 +49,24 @@ module Contentful
49
49
  {
50
50
  'author' => [
51
51
  {
52
- id: "dan_brown",
53
- name: "Dan Brown"
52
+ "id" => "dan_brown",
53
+ "name" => "Dan Brown"
54
54
  },
55
55
  {
56
- id: "pablo_neruda",
57
- name: "Pablo Neruda"
56
+ "id" => "pablo_neruda",
57
+ "name" => "Pablo Neruda"
58
58
  }
59
59
  ],
60
60
  'post' => [
61
61
  {
62
- title: "Inferno",
63
- content: "Inferno is the last book in Dan Brown's collection...",
64
- author: Links::Entry.new("dan_brown")
62
+ "title" => "Inferno",
63
+ "content" => "Inferno is the last book in Dan Brown's collection...",
64
+ "author" => Links::Entry.new("dan_brown")
65
65
  },
66
66
  {
67
- title: "Alturas de Macchu Picchu",
68
- content: "Alturas de Macchu Picchu is one of Pablo Neruda's most famous poetry books...",
69
- author: Links::Entry.new("pablo_neruda")
67
+ "title" => "Alturas de Macchu Picchu",
68
+ "content" => "Alturas de Macchu Picchu is one of Pablo Neruda's most famous poetry books...",
69
+ "author" => Links::Entry.new("pablo_neruda")
70
70
  }
71
71
  ]
72
72
  }
@@ -8,88 +8,88 @@ module Contentful
8
8
  def content_types
9
9
  [
10
10
  {
11
- id: 'brand',
12
- name: 'Brand',
13
- display_field: 'name',
14
- fields: [
11
+ "id" => 'brand',
12
+ "name" => 'Brand',
13
+ "display_field" => 'name',
14
+ "fields" => [
15
15
  {
16
- id: 'name',
17
- name: "Company Name",
18
- type: "Symbol"
16
+ "id" => 'name',
17
+ "name" => "Company Name",
18
+ "type" => "Symbol"
19
19
  },
20
20
  {
21
- id: 'website',
22
- name: "Website",
23
- type: "Symbol"
21
+ "id" => 'website',
22
+ "name" => "Website",
23
+ "type" => "Symbol"
24
24
  },
25
25
  {
26
- id: 'logo',
27
- name: "Logo",
28
- type: "Link",
29
- link_type: "Asset"
26
+ "id" => 'logo',
27
+ "name" => "Logo",
28
+ "type" => "Link",
29
+ "link_type" => "Asset"
30
30
  }
31
31
  ]
32
32
  },
33
33
  {
34
- id: 'category',
35
- name: 'Category',
36
- display_field: 'title',
37
- fields: [
34
+ "id" => 'category',
35
+ "name" => 'Category',
36
+ "display_field" => 'title',
37
+ "fields" => [
38
38
  {
39
- id: 'title',
40
- name: "Title",
41
- type: "Symbol"
39
+ "id" => 'title',
40
+ "name" => "Title",
41
+ "type" => "Symbol"
42
42
  },
43
43
  {
44
- id: 'description',
45
- name: "Description",
46
- type: "Text"
44
+ "id" => 'description',
45
+ "name" => "Description",
46
+ "type" => "Text"
47
47
  },
48
48
  {
49
- id: 'icon',
50
- name: "Icon",
51
- type: "Link",
52
- link_type: "Asset"
49
+ "id" => 'icon',
50
+ "name" => "Icon",
51
+ "type" => "Link",
52
+ "link_type" => "Asset"
53
53
  }
54
54
  ]
55
55
  },
56
56
  {
57
- id: 'product',
58
- name: 'Product',
59
- display_field: 'name',
60
- fields: [
57
+ "id" => 'product',
58
+ "name" => 'Product',
59
+ "display_field" => 'name',
60
+ "fields" => [
61
61
  {
62
- id: 'name',
63
- name: "name",
64
- type: "Symbol"
62
+ "id" => 'name',
63
+ "name" => "name",
64
+ "type" => "Symbol"
65
65
  },
66
66
  {
67
- id: 'description',
68
- name: "Description",
69
- type: "Text"
67
+ "id" => 'description',
68
+ "name" => "Description",
69
+ "type" => "Text"
70
70
  },
71
71
  {
72
- id: 'image',
73
- name: "Image",
74
- type: "Link",
75
- link_type: "Asset"
72
+ "id" => 'image',
73
+ "name" => "Image",
74
+ "type" => "Link",
75
+ "link_type" => "Asset"
76
76
  },
77
77
  {
78
- id: 'brand',
79
- name: "Brand",
80
- type: "Link",
81
- link_type: "Entry"
78
+ "id" => 'brand',
79
+ "name" => "Brand",
80
+ "type" => "Link",
81
+ "link_type" => "Entry"
82
82
  },
83
83
  {
84
- id: 'category',
85
- name: "Category",
86
- type: "Link",
87
- link_type: "Entry"
84
+ "id" => 'category',
85
+ "name" => "Category",
86
+ "type" => "Link",
87
+ "link_type" => "Entry"
88
88
  },
89
89
  {
90
- id: 'url',
91
- name: "Available at",
92
- type: "Symbol"
90
+ "id" => 'url',
91
+ "name" => "Available at",
92
+ "type" => "Symbol"
93
93
  }
94
94
  ]
95
95
  }
@@ -99,34 +99,34 @@ module Contentful
99
99
  def assets
100
100
  [
101
101
  {
102
- id: 'playsam_image',
103
- title: 'Playsam',
104
- file: create_image('playsam_image', 'https://images.contentful.com/liicpxzmg1q0/4zj1ZOfHgQ8oqgaSKm4Qo2/3be82d54d45b5297e951aee9baf920da/playsam.jpg?h=250&')
102
+ "id" => 'playsam_image',
103
+ "title" => 'Playsam',
104
+ "file" => create_image('playsam_image', 'https://images.contentful.com/liicpxzmg1q0/4zj1ZOfHgQ8oqgaSKm4Qo2/3be82d54d45b5297e951aee9baf920da/playsam.jpg?h=250&')
105
105
  },
106
106
  {
107
- id: 'normann_image',
108
- title: 'Normann',
109
- file: create_image('normann_image', 'https://images.contentful.com/liicpxzmg1q0/3wtvPBbBjiMKqKKga8I2Cu/75c7c92f38f7953a741591d215ad61d4/zJYzDlGk.jpeg?h=250&')
107
+ "id" => 'normann_image',
108
+ "title" => 'Normann',
109
+ "file" => create_image('normann_image', 'https://images.contentful.com/liicpxzmg1q0/3wtvPBbBjiMKqKKga8I2Cu/75c7c92f38f7953a741591d215ad61d4/zJYzDlGk.jpeg?h=250&')
110
110
  },
111
111
  {
112
- id: 'toy_image',
113
- title: 'Toys',
114
- file: create_image('toy_image', 'https://images.contentful.com/liicpxzmg1q0/6t4HKjytPi0mYgs240wkG/866ef53a11af9c6bf5f3808a8ce1aab2/toys_512pxGREY.png?h=250&')
112
+ "id" => 'toy_image',
113
+ "title" => 'Toys',
114
+ "file" => create_image('toy_image', 'https://images.contentful.com/liicpxzmg1q0/6t4HKjytPi0mYgs240wkG/866ef53a11af9c6bf5f3808a8ce1aab2/toys_512pxGREY.png?h=250&')
115
115
  },
116
116
  {
117
- id: 'kitchen_image',
118
- title: 'Kitchen and Home',
119
- file: create_image('kitchen_image', 'https://images.contentful.com/liicpxzmg1q0/6m5AJ9vMPKc8OUoQeoCS4o/ffc20f5a8f2a71cca4801bc9c51b966a/1418244847_Streamline-18-256.png?h=250&')
117
+ "id" => 'kitchen_image',
118
+ "title" => 'Kitchen and Home',
119
+ "file" => create_image('kitchen_image', 'https://images.contentful.com/liicpxzmg1q0/6m5AJ9vMPKc8OUoQeoCS4o/ffc20f5a8f2a71cca4801bc9c51b966a/1418244847_Streamline-18-256.png?h=250&')
120
120
  },
121
121
  {
122
- id: 'toy_car',
123
- title: 'Playsam Toy Car',
124
- file: create_image('toy_car', 'https://images.contentful.com/liicpxzmg1q0/wtrHxeu3zEoEce2MokCSi/acef70d12fe019228c4238aa791bdd48/quwowooybuqbl6ntboz3.jpg?h=250&')
122
+ "id" => 'toy_car',
123
+ "title" => 'Playsam Toy Car',
124
+ "file" => create_image('toy_car', 'https://images.contentful.com/liicpxzmg1q0/wtrHxeu3zEoEce2MokCSi/acef70d12fe019228c4238aa791bdd48/quwowooybuqbl6ntboz3.jpg?h=250&')
125
125
  },
126
126
  {
127
- id: 'whiskers',
128
- title: 'Normann Whisk Beaters',
129
- file: create_image('whiskers', 'https://images.contentful.com/liicpxzmg1q0/10TkaLheGeQG6qQGqWYqUI/d510dde5e575d40288cf75b42383aa53/ryugj83mqwa1asojwtwb.jpg?h=250&')
127
+ "id" => 'whiskers',
128
+ "title" => 'Normann Whisk Beaters',
129
+ "file" => create_image('whiskers', 'https://images.contentful.com/liicpxzmg1q0/10TkaLheGeQG6qQGqWYqUI/d510dde5e575d40288cf75b42383aa53/ryugj83mqwa1asojwtwb.jpg?h=250&')
130
130
  }
131
131
  ]
132
132
  end
@@ -135,50 +135,50 @@ module Contentful
135
135
  {
136
136
  'brand' => [
137
137
  {
138
- id: 'playsam',
139
- name: 'Playsam, Inc',
140
- website: 'http://www.playsam.com',
141
- logo: Links::Asset.new('playsam_image')
138
+ "id" => 'playsam',
139
+ "name" => 'Playsam, Inc',
140
+ "website" => 'http://www.playsam.com',
141
+ "logo" => Links::Asset.new('playsam_image')
142
142
  },
143
143
  {
144
- id: 'normann',
145
- name: "Normann Copenhagen, Inc",
146
- website: 'http://www.normann-copenhagen.com/',
147
- logo: Links::Asset.new('normann_image')
144
+ "id" => 'normann',
145
+ "name" => "Normann Copenhagen, Inc",
146
+ "website" => 'http://www.normann-copenhagen.com/',
147
+ "logo" => Links::Asset.new('normann_image')
148
148
  }
149
149
  ],
150
150
  'category' => [
151
151
  {
152
- id: 'toys',
153
- title: 'Toys',
154
- description: 'Toys for children',
155
- icon: Links::Asset.new('toy_image')
152
+ "id" => 'toys',
153
+ "title" => 'Toys',
154
+ "description" => 'Toys for children',
155
+ "icon" => Links::Asset.new('toy_image')
156
156
  },
157
157
  {
158
- id: 'kitchen',
159
- title: 'House and Kitchen',
160
- description: 'House and Kitchen accessories',
161
- icon: Links::Asset.new('kitchen_image')
158
+ "id" => 'kitchen',
159
+ "title" => 'House and Kitchen',
160
+ "description" => 'House and Kitchen accessories',
161
+ "icon" => Links::Asset.new('kitchen_image')
162
162
  }
163
163
  ],
164
164
  'product' => [
165
165
  {
166
- id: 'playsam_car',
167
- name: 'Playsam Streamliner Classic Car, Espresso',
168
- description: "A classic Playsam design, the Streamliner Classic Car has been selected as Swedish Design Classic by the Swedish National Museum for its inventive style and sleek surface. It's no wonder that this wooden car has also been a long-standing favorite for children both big and small!",
169
- image: Links::Asset.new('toy_car'),
170
- brand: Links::Entry.new('playsam'),
171
- category: Links::Entry.new('toys'),
172
- url: 'http://www.amazon.com/dp/B001R6JUZ2/'
166
+ "id" => 'playsam_car',
167
+ "name" => 'Playsam Streamliner Classic Car, Espresso',
168
+ "description" => "A classic Playsam design, the Streamliner Classic Car has been selected as Swedish Design Classic by the Swedish National Museum for its inventive style and sleek surface. It's no wonder that this wooden car has also been a long-standing favorite for children both big and small!",
169
+ "image" => Links::Asset.new('toy_car'),
170
+ "brand" => Links::Entry.new('playsam'),
171
+ "category" => Links::Entry.new('toys'),
172
+ "url" => 'http://www.amazon.com/dp/B001R6JUZ2/'
173
173
  },
174
174
  {
175
- id: 'whisk_beater',
176
- name: 'Whisk Beater',
177
- description: "A creative little whisk that comes in 8 different colors. Handy and easy to clean after use. A great gift idea.",
178
- image: Links::Asset.new('whiskers'),
179
- brand: Links::Entry.new('normann'),
180
- category: Links::Entry.new('kitchen'),
181
- url: 'http://www.amazon.com/dp/B0081F2CCK/'
175
+ "id" => 'whisk_beater',
176
+ "name" => 'Whisk Beater',
177
+ "description" => "A creative little whisk that comes in 8 different colors. Handy and easy to clean after use. A great gift idea.",
178
+ "image" => Links::Asset.new('whiskers'),
179
+ "brand" => Links::Entry.new('normann'),
180
+ "category" => Links::Entry.new('kitchen'),
181
+ "url" => 'http://www.amazon.com/dp/B0081F2CCK/'
182
182
  }
183
183
  ]
184
184
  }
@@ -8,58 +8,58 @@ module Contentful
8
8
  def content_types
9
9
  [
10
10
  {
11
- id: 'author',
12
- name: "Author",
13
- display_field: "name",
14
- fields: [
11
+ "id" => 'author',
12
+ "name" => "Author",
13
+ "display_field" => "name",
14
+ "fields" => [
15
15
  {
16
- name: "Name",
17
- id: "name",
18
- type: "Symbol"
16
+ "name" => "Name",
17
+ "id" => "name",
18
+ "type" => "Symbol"
19
19
  }
20
20
  ]
21
21
  },
22
22
  {
23
- id: 'image',
24
- name: 'Image',
25
- display_field: 'title',
26
- fields: [
23
+ "id" => 'image',
24
+ "name" => 'Image',
25
+ "display_field" => 'title',
26
+ "fields" => [
27
27
  {
28
- id: 'title',
29
- name: 'Title',
30
- type: 'Symbol'
28
+ "id" => 'title',
29
+ "name" => 'Title',
30
+ "type" => 'Symbol'
31
31
  },
32
32
  {
33
- id: 'photo',
34
- name: 'Photo',
35
- type: 'Link',
36
- link_type: 'Asset'
33
+ "id" => 'photo',
34
+ "name" => 'Photo',
35
+ "type" => 'Link',
36
+ "link_type" => 'Asset'
37
37
  }
38
38
  ]
39
39
  },
40
40
  {
41
- id: 'gallery',
42
- name: 'Gallery',
43
- display_field: 'title',
44
- fields: [
41
+ "id" => 'gallery',
42
+ "name" => 'Gallery',
43
+ "display_field" => 'title',
44
+ "fields" => [
45
45
  {
46
- id: 'title',
47
- name: 'Title',
48
- type: 'Symbol'
46
+ "id" => 'title',
47
+ "name" => 'Title',
48
+ "type" => 'Symbol'
49
49
  },
50
50
  {
51
- id: 'author',
52
- name: 'Author',
53
- type: 'Link',
54
- link_type: 'Entry'
51
+ "id" => 'author',
52
+ "name" => 'Author',
53
+ "type" => 'Link',
54
+ "link_type" => 'Entry'
55
55
  },
56
56
  {
57
- id: 'images',
58
- name: 'Images',
59
- type: 'Array',
60
- items: {
61
- type: 'Link',
62
- link_type: 'Entry'
57
+ "id" => 'images',
58
+ "name" => 'Images',
59
+ "type" => 'Array',
60
+ "items" => {
61
+ "type" => 'Link',
62
+ "link_type" => 'Entry'
63
63
  }
64
64
  }
65
65
  ]
@@ -70,14 +70,14 @@ module Contentful
70
70
  def assets
71
71
  [
72
72
  {
73
- id: 'pie',
74
- title: 'Pie in the Sky',
75
- file: create_image('pie', 'https://c2.staticflickr.com/6/5245/5335909339_d307a7cbcf_b.jpg')
73
+ "id" => 'pie',
74
+ "title" => 'Pie in the Sky',
75
+ "file" => create_image('pie', 'https://c2.staticflickr.com/6/5245/5335909339_d307a7cbcf_b.jpg')
76
76
  },
77
77
  {
78
- id: 'flower',
79
- title: 'The Flower',
80
- file: create_image('flower', 'http://c2.staticflickr.com/4/3922/15045568809_b24591e318_b.jpg')
78
+ "id" => 'flower',
79
+ "title" => 'The Flower',
80
+ "file" => create_image('flower', 'http://c2.staticflickr.com/4/3922/15045568809_b24591e318_b.jpg')
81
81
  }
82
82
  ]
83
83
  end
@@ -86,28 +86,28 @@ module Contentful
86
86
  {
87
87
  'author' => [
88
88
  {
89
- id: 'dave',
90
- name: 'Dave'
89
+ "id" => 'dave',
90
+ "name" => 'Dave'
91
91
  }
92
92
  ],
93
93
  'image' => [
94
94
  {
95
- id: 'pie_entry',
96
- title: 'A Pie in the Sky',
97
- photo: Links::Asset.new('pie')
95
+ "id" => 'pie_entry',
96
+ "title" => 'A Pie in the Sky',
97
+ "photo" => Links::Asset.new('pie')
98
98
  },
99
99
  {
100
- id: 'flower_entry',
101
- title: 'The Flower',
102
- photo: Links::Asset.new('flower')
100
+ "id" => 'flower_entry',
101
+ "title" => 'The Flower',
102
+ "photo" => Links::Asset.new('flower')
103
103
  }
104
104
  ],
105
105
  'gallery' => [
106
106
  {
107
- id: 'gallery',
108
- title: 'Photo Gallery',
109
- author: Links::Entry.new('dave'),
110
- images: [Links::Entry.new('pie_entry'), Links::Entry.new('flower_entry')]
107
+ "id" => 'gallery',
108
+ "title" => 'Photo Gallery',
109
+ "author" => Links::Entry.new('dave'),
110
+ "images" => [Links::Entry.new('pie_entry'), Links::Entry.new('flower_entry')]
111
111
  }
112
112
  ]
113
113
  }
@@ -0,0 +1,77 @@
1
+ require "json"
2
+ require "contentful/bootstrap/templates/base"
3
+ require "contentful/bootstrap/templates/links"
4
+
5
+ module Contentful
6
+ module Bootstrap
7
+ module Templates
8
+ class JsonTemplate < Base
9
+ def initialize(space, file)
10
+ @space = space
11
+ @file = file
12
+ @assets = nil
13
+ @entries = nil
14
+ json
15
+ end
16
+
17
+ def content_types
18
+ json.fetch("content_types", [])
19
+ end
20
+
21
+ def assets
22
+ @assets ||= process_assets
23
+ end
24
+
25
+ def entries
26
+ @entries ||= process_entries
27
+ end
28
+
29
+ private
30
+ def json
31
+ @json ||= JSON.parse(File.read(@file))
32
+ end
33
+
34
+ def process_assets
35
+ unprocessed_assets = json.fetch("assets", [])
36
+ unprocessed_assets.map do |asset|
37
+ asset["file"] = create_image(
38
+ asset["file"]["filename"],
39
+ asset["file"]["url"]
40
+ )
41
+ asset
42
+ end
43
+ end
44
+
45
+ def process_entries
46
+ processed_entries = {}
47
+ unprocessed_entries = json.fetch("entries", {})
48
+ unprocessed_entries.each do |content_type_id, entry_list|
49
+ entries_for_content_type = []
50
+ entry_list.each do |entry|
51
+ link_fields = []
52
+ entry.each do |field, value|
53
+ link_fields << field if value.is_a? Hash
54
+ end
55
+
56
+ link_fields.each do |lf|
57
+ entry[lf] = create_link(entry[lf])
58
+ end
59
+
60
+ entries_for_content_type << entry
61
+ end
62
+
63
+ processed_entries[content_type_id] = entries_for_content_type
64
+ end
65
+
66
+ processed_entries
67
+ end
68
+
69
+ def create_link(link_properties)
70
+ link_type = link_properties["link_type"].capitalize
71
+ id = link_properties["id"]
72
+ Object.const_get("Contentful::Bootstrap::Templates::Links::#{link_type}").new(id)
73
+ end
74
+ end
75
+ end
76
+ end
77
+ end
@@ -1,5 +1,5 @@
1
1
  module Contentful
2
2
  module Bootstrap
3
- VERSION = "1.1.0"
3
+ VERSION = "1.2.0"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: contentful_bootstrap
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Litvak Bruno
@@ -97,6 +97,7 @@ files:
97
97
  - Rakefile
98
98
  - bin/contentful_bootstrap
99
99
  - contentful_bootstrap.gemspec
100
+ - examples/templates/catalogue.json
100
101
  - lib/contentful/bootstrap.rb
101
102
  - lib/contentful/bootstrap/commands.rb
102
103
  - lib/contentful/bootstrap/constants.rb
@@ -107,6 +108,7 @@ files:
107
108
  - lib/contentful/bootstrap/templates/blog.rb
108
109
  - lib/contentful/bootstrap/templates/catalogue.rb
109
110
  - lib/contentful/bootstrap/templates/gallery.rb
111
+ - lib/contentful/bootstrap/templates/json_template.rb
110
112
  - lib/contentful/bootstrap/templates/links.rb
111
113
  - lib/contentful/bootstrap/templates/links/asset.rb
112
114
  - lib/contentful/bootstrap/templates/links/base.rb