contentful_bootstrap 0.0.7 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (39) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +21 -0
  3. data/Gemfile +1 -0
  4. data/README.md +28 -19
  5. data/bin/contentful_bootstrap +10 -11
  6. data/contentful_bootstrap.gemspec +3 -2
  7. data/lib/contentful/bootstrap.rb +5 -0
  8. data/lib/contentful/bootstrap/commands.rb +135 -0
  9. data/lib/contentful/bootstrap/constants.rb +8 -0
  10. data/lib/contentful/bootstrap/server.rb +97 -0
  11. data/lib/contentful/bootstrap/support.rb +14 -0
  12. data/lib/contentful/bootstrap/templates.rb +3 -0
  13. data/lib/contentful/bootstrap/templates/base.rb +118 -0
  14. data/lib/contentful/bootstrap/templates/blog.rb +77 -0
  15. data/lib/contentful/bootstrap/templates/catalogue.rb +189 -0
  16. data/lib/contentful/bootstrap/templates/gallery.rb +119 -0
  17. data/lib/contentful/bootstrap/templates/links.rb +2 -0
  18. data/lib/contentful/bootstrap/templates/links/asset.rb +15 -0
  19. data/lib/contentful/bootstrap/templates/links/base.rb +18 -0
  20. data/lib/contentful/bootstrap/templates/links/entry.rb +15 -0
  21. data/lib/contentful/bootstrap/token.rb +58 -0
  22. data/lib/contentful/bootstrap/version.rb +5 -0
  23. metadata +32 -18
  24. data/lib/contentful_bootstrap.rb +0 -5
  25. data/lib/contentful_bootstrap/commands.rb +0 -120
  26. data/lib/contentful_bootstrap/constants.rb +0 -6
  27. data/lib/contentful_bootstrap/server.rb +0 -95
  28. data/lib/contentful_bootstrap/support.rb +0 -12
  29. data/lib/contentful_bootstrap/templates.rb +0 -3
  30. data/lib/contentful_bootstrap/templates/base.rb +0 -116
  31. data/lib/contentful_bootstrap/templates/blog.rb +0 -75
  32. data/lib/contentful_bootstrap/templates/catalogue.rb +0 -187
  33. data/lib/contentful_bootstrap/templates/gallery.rb +0 -117
  34. data/lib/contentful_bootstrap/templates/links.rb +0 -2
  35. data/lib/contentful_bootstrap/templates/links/asset.rb +0 -13
  36. data/lib/contentful_bootstrap/templates/links/base.rb +0 -16
  37. data/lib/contentful_bootstrap/templates/links/entry.rb +0 -13
  38. data/lib/contentful_bootstrap/token.rb +0 -23
  39. data/lib/contentful_bootstrap/version.rb +0 -3
@@ -1,116 +0,0 @@
1
- require "contentful/management"
2
-
3
- module ContentfulBootstrap
4
- module Templates
5
- class Base
6
- attr_reader :space
7
-
8
- def initialize(space)
9
- @space = space
10
- end
11
-
12
- def run
13
- create_content_types
14
- create_assets
15
- create_entries
16
- end
17
-
18
- def content_types
19
- []
20
- end
21
-
22
- def entries
23
- {}
24
- end
25
-
26
- def assets
27
- []
28
- end
29
-
30
- protected
31
- def create_image(name, url)
32
- image = Contentful::Management::File.new
33
- image.properties[:contentType] = 'image/jpeg'
34
- image.properties[:fileName] = "#{name}.jpg"
35
- image.properties[:upload] = url
36
- image
37
- end
38
-
39
- private
40
- def create_content_types
41
- content_types.each do |ct|
42
- puts "Creating Content Type '#{ct[:name]}'"
43
-
44
- fields = []
45
- content_type = space.content_types.new
46
- content_type.id = ct[:id]
47
- content_type.name = ct[:name]
48
- content_type.display_field = ct[:display_field]
49
-
50
- ct[:fields].each do |f|
51
- field = Contentful::Management::Field.new
52
- field.id = f[:id]
53
- field.name = f[:name]
54
- field.type = f[:type]
55
- field.link_type = f[:link_type] if is_link?(f)
56
-
57
- if is_array?(f)
58
- array_field = Contentful::Management::Field.new
59
- array_field.type = f[:items][:type]
60
- array_field.link_type = f[:items][:link_type]
61
- field.items = array_field
62
- end
63
-
64
- fields << field
65
- end
66
-
67
- content_type.fields = fields
68
- content_type.save
69
- content_type.activate
70
- end
71
- end
72
-
73
- def is_link?(field)
74
- field.has_key?(:link_type)
75
- end
76
-
77
- def is_array?(field)
78
- field.has_key?(:items)
79
- end
80
-
81
- def create_assets
82
- assets.each do |asset|
83
- puts "Creating Asset '#{asset[:title]}'"
84
- asset = space.assets.create(asset)
85
- asset.process_file
86
- sleep(1) # Wait for Process
87
- asset.publish
88
- end
89
- end
90
-
91
- def create_entries
92
- entries.each do |content_type_id, entry_list|
93
- content_type = space.content_types.find(content_type_id)
94
- entry_list.each_with_index do |e, index|
95
- puts "Creating Entry #{index} for #{content_type_id.capitalize}"
96
-
97
- array_fields = []
98
- e.each_pair do |field_name, value|
99
- array_fields << field_name if value.is_a? Array
100
- end
101
-
102
- array_fields.each do |af|
103
- e[af].map! do |f|
104
- space.send(f.kind).find(f.id)
105
- end
106
- end
107
-
108
- entry = content_type.entries.create(e)
109
- entry.save
110
- entry.publish
111
- end
112
- end
113
- end
114
- end
115
- end
116
- end
@@ -1,75 +0,0 @@
1
- require "contentful_bootstrap/templates/base"
2
- require "contentful_bootstrap/templates/links"
3
-
4
- module ContentfulBootstrap
5
- module Templates
6
- class Blog < Base
7
- def content_types
8
- [
9
- {
10
- id: 'author',
11
- name: 'Author',
12
- display_field: 'name',
13
- fields: [
14
- {
15
- id: 'name',
16
- name: "Author Name",
17
- type: "Symbol"
18
- }
19
- ]
20
- },
21
- {
22
- id: 'post',
23
- name: 'Post',
24
- display_field: 'title',
25
- fields: [
26
- {
27
- id: 'title',
28
- name: "Post Title",
29
- type: "Symbol"
30
- },
31
- {
32
- id: 'content',
33
- name: "Content",
34
- type: "Text"
35
- },
36
- {
37
- id: 'author',
38
- name: "Author",
39
- type: "Link",
40
- link_type: "Entry"
41
- }
42
- ]
43
- }
44
- ]
45
- end
46
-
47
- def entries
48
- {
49
- 'author' => [
50
- {
51
- id: "dan_brown",
52
- name: "Dan Brown"
53
- },
54
- {
55
- id: "pablo_neruda",
56
- name: "Pablo Neruda"
57
- }
58
- ],
59
- 'post' => [
60
- {
61
- title: "Inferno",
62
- content: "Inferno is the last book in Dan Brown's collection...",
63
- author: Links::Entry.new("dan_brown")
64
- },
65
- {
66
- title: "Alturas de Macchu Picchu",
67
- content: "Alturas de Macchu Picchu is one of Pablo Neruda's most famous poetry books...",
68
- author: Links::Entry.new("pablo_neruda")
69
- }
70
- ]
71
- }
72
- end
73
- end
74
- end
75
- end
@@ -1,187 +0,0 @@
1
- require "contentful_bootstrap/templates/base"
2
- require "contentful_bootstrap/templates/links"
3
-
4
- module ContentfulBootstrap
5
- module Templates
6
- class Catalogue < Base
7
- def content_types
8
- [
9
- {
10
- id: 'brand',
11
- name: 'Brand',
12
- display_field: 'name',
13
- fields: [
14
- {
15
- id: 'name',
16
- name: "Company Name",
17
- type: "Symbol"
18
- },
19
- {
20
- id: 'website',
21
- name: "Website",
22
- type: "Symbol"
23
- },
24
- {
25
- id: 'logo',
26
- name: "Logo",
27
- type: "Link",
28
- link_type: "Asset"
29
- }
30
- ]
31
- },
32
- {
33
- id: 'category',
34
- name: 'Category',
35
- display_field: 'title',
36
- fields: [
37
- {
38
- id: 'title',
39
- name: "Title",
40
- type: "Symbol"
41
- },
42
- {
43
- id: 'description',
44
- name: "Description",
45
- type: "Text"
46
- },
47
- {
48
- id: 'icon',
49
- name: "Icon",
50
- type: "Link",
51
- link_type: "Asset"
52
- }
53
- ]
54
- },
55
- {
56
- id: 'product',
57
- name: 'Product',
58
- display_field: 'name',
59
- fields: [
60
- {
61
- id: 'name',
62
- name: "name",
63
- type: "Symbol"
64
- },
65
- {
66
- id: 'description',
67
- name: "Description",
68
- type: "Text"
69
- },
70
- {
71
- id: 'image',
72
- name: "Image",
73
- type: "Link",
74
- link_type: "Asset"
75
- },
76
- {
77
- id: 'brand',
78
- name: "Brand",
79
- type: "Link",
80
- link_type: "Entry"
81
- },
82
- {
83
- id: 'category',
84
- name: "Category",
85
- type: "Link",
86
- link_type: "Entry"
87
- },
88
- {
89
- id: 'url',
90
- name: "Available at",
91
- type: "Symbol"
92
- }
93
- ]
94
- }
95
- ]
96
- end
97
-
98
- def assets
99
- [
100
- {
101
- id: 'playsam_image',
102
- title: 'Playsam',
103
- file: create_image('playsam_image', 'https://images.contentful.com/liicpxzmg1q0/4zj1ZOfHgQ8oqgaSKm4Qo2/3be82d54d45b5297e951aee9baf920da/playsam.jpg?h=250&')
104
- },
105
- {
106
- id: 'normann_image',
107
- title: 'Normann',
108
- file: create_image('normann_image', 'https://images.contentful.com/liicpxzmg1q0/3wtvPBbBjiMKqKKga8I2Cu/75c7c92f38f7953a741591d215ad61d4/zJYzDlGk.jpeg?h=250&')
109
- },
110
- {
111
- id: 'toy_image',
112
- title: 'Toys',
113
- file: create_image('toy_image', 'https://images.contentful.com/liicpxzmg1q0/6t4HKjytPi0mYgs240wkG/866ef53a11af9c6bf5f3808a8ce1aab2/toys_512pxGREY.png?h=250&')
114
- },
115
- {
116
- id: 'kitchen_image',
117
- title: 'Kitchen and Home',
118
- file: create_image('kitchen_image', 'https://images.contentful.com/liicpxzmg1q0/6m5AJ9vMPKc8OUoQeoCS4o/ffc20f5a8f2a71cca4801bc9c51b966a/1418244847_Streamline-18-256.png?h=250&')
119
- },
120
- {
121
- id: 'toy_car',
122
- title: 'Playsam Toy Car',
123
- file: create_image('toy_car', 'https://images.contentful.com/liicpxzmg1q0/wtrHxeu3zEoEce2MokCSi/acef70d12fe019228c4238aa791bdd48/quwowooybuqbl6ntboz3.jpg?h=250&')
124
- },
125
- {
126
- id: 'whiskers',
127
- title: 'Normann Whisk Beaters',
128
- file: create_image('whiskers', 'https://images.contentful.com/liicpxzmg1q0/10TkaLheGeQG6qQGqWYqUI/d510dde5e575d40288cf75b42383aa53/ryugj83mqwa1asojwtwb.jpg?h=250&')
129
- }
130
- ]
131
- end
132
-
133
- def entries
134
- {
135
- 'brand' => [
136
- {
137
- id: 'playsam',
138
- name: 'Playsam, Inc',
139
- website: 'http://www.playsam.com',
140
- logo: Links::Asset.new('playsam_image')
141
- },
142
- {
143
- id: 'normann',
144
- name: "Normann Copenhagen, Inc",
145
- website: 'http://www.normann-copenhagen.com/',
146
- logo: Links::Asset.new('normann_image')
147
- }
148
- ],
149
- 'category' => [
150
- {
151
- id: 'toys',
152
- title: 'Toys',
153
- description: 'Toys for children',
154
- icon: Links::Asset.new('toy_image')
155
- },
156
- {
157
- id: 'kitchen',
158
- title: 'House and Kitchen',
159
- description: 'House and Kitchen accessories',
160
- icon: Links::Asset.new('kitchen_image')
161
- }
162
- ],
163
- 'product' => [
164
- {
165
- id: 'playsam_car',
166
- name: 'Playsam Streamliner Classic Car, Espresso',
167
- 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!",
168
- image: Links::Asset.new('toy_car'),
169
- brand: Links::Entry.new('playsam'),
170
- category: Links::Entry.new('toys'),
171
- url: 'http://www.amazon.com/dp/B001R6JUZ2/'
172
- },
173
- {
174
- id: 'whisk_beater',
175
- name: 'Whisk Beater',
176
- description: "A creative little whisk that comes in 8 different colors. Handy and easy to clean after use. A great gift idea.",
177
- image: Links::Asset.new('whiskers'),
178
- brand: Links::Entry.new('normann'),
179
- category: Links::Entry.new('kitchen'),
180
- url: 'http://www.amazon.com/dp/B0081F2CCK/'
181
- }
182
- ]
183
- }
184
- end
185
- end
186
- end
187
- end
@@ -1,117 +0,0 @@
1
- require "contentful_bootstrap/templates/base"
2
- require "contentful_bootstrap/templates/links"
3
-
4
- module ContentfulBootstrap
5
- module Templates
6
- class Gallery < Base
7
- def content_types
8
- [
9
- {
10
- id: 'author',
11
- name: "Author",
12
- display_field: "name",
13
- fields: [
14
- {
15
- name: "Name",
16
- id: "name",
17
- type: "Symbol"
18
- }
19
- ]
20
- },
21
- {
22
- id: 'image',
23
- name: 'Image',
24
- display_field: 'title',
25
- fields: [
26
- {
27
- id: 'title',
28
- name: 'Title',
29
- type: 'Symbol'
30
- },
31
- {
32
- id: 'photo',
33
- name: 'Photo',
34
- type: 'Link',
35
- link_type: 'Asset'
36
- }
37
- ]
38
- },
39
- {
40
- id: 'gallery',
41
- name: 'Gallery',
42
- display_field: 'title',
43
- fields: [
44
- {
45
- id: 'title',
46
- name: 'Title',
47
- type: 'Symbol'
48
- },
49
- {
50
- id: 'author',
51
- name: 'Author',
52
- type: 'Link',
53
- link_type: 'Entry'
54
- },
55
- {
56
- id: 'images',
57
- name: 'Images',
58
- type: 'Array',
59
- items: {
60
- type: 'Link',
61
- link_type: 'Entry'
62
- }
63
- }
64
- ]
65
- }
66
- ]
67
- end
68
-
69
- def assets
70
- [
71
- {
72
- id: 'pie',
73
- title: 'Pie in the Sky',
74
- file: create_image('pie', 'https://c2.staticflickr.com/6/5245/5335909339_d307a7cbcf_b.jpg')
75
- },
76
- {
77
- id: 'flower',
78
- title: 'The Flower',
79
- file: create_image('flower', 'http://c2.staticflickr.com/4/3922/15045568809_b24591e318_b.jpg')
80
- }
81
- ]
82
- end
83
-
84
- def entries
85
- {
86
- 'author' => [
87
- {
88
- id: 'dave',
89
- name: 'Dave'
90
- }
91
- ],
92
- 'image' => [
93
- {
94
- id: 'pie_entry',
95
- title: 'A Pie in the Sky',
96
- photo: Links::Asset.new('pie')
97
- },
98
- {
99
- id: 'flower_entry',
100
- title: 'The Flower',
101
- photo: Links::Asset.new('flower')
102
- }
103
- ],
104
- 'gallery' => [
105
- {
106
- id: 'gallery',
107
- title: 'Photo Gallery',
108
- author: Links::Entry.new('dave'),
109
- images: [Links::Entry.new('pie_entry'), Links::Entry.new('flower_entry')]
110
- }
111
- ]
112
- }
113
- end
114
- end
115
- end
116
- end
117
-