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
@@ -0,0 +1,14 @@
1
+ require "stringio"
2
+
3
+ module Contentful
4
+ module Bootstrap
5
+ module Support
6
+ def silence_stderr
7
+ old_stderr, $stderr = $stderr, StringIO.new
8
+ yield
9
+ ensure
10
+ $stderr = old_stderr
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,3 @@
1
+ require "contentful/bootstrap/templates/blog"
2
+ require "contentful/bootstrap/templates/catalogue"
3
+ require "contentful/bootstrap/templates/gallery"
@@ -0,0 +1,118 @@
1
+ require "contentful/management"
2
+
3
+ module Contentful
4
+ module Bootstrap
5
+ module Templates
6
+ class Base
7
+ attr_reader :space
8
+
9
+ def initialize(space)
10
+ @space = space
11
+ end
12
+
13
+ def run
14
+ create_content_types
15
+ create_assets
16
+ create_entries
17
+ end
18
+
19
+ def content_types
20
+ []
21
+ end
22
+
23
+ def entries
24
+ {}
25
+ end
26
+
27
+ def assets
28
+ []
29
+ end
30
+
31
+ protected
32
+ def create_image(name, url)
33
+ image = Contentful::Management::File.new
34
+ image.properties[:contentType] = 'image/jpeg'
35
+ image.properties[:fileName] = "#{name}.jpg"
36
+ image.properties[:upload] = url
37
+ image
38
+ end
39
+
40
+ private
41
+ def create_content_types
42
+ content_types.each do |ct|
43
+ puts "Creating Content Type '#{ct[:name]}'"
44
+
45
+ fields = []
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]
50
+
51
+ ct[:fields].each do |f|
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)
57
+
58
+ if is_array?(f)
59
+ array_field = Contentful::Management::Field.new
60
+ array_field.type = f[:items][:type]
61
+ array_field.link_type = f[:items][:link_type]
62
+ field.items = array_field
63
+ end
64
+
65
+ fields << field
66
+ end
67
+
68
+ content_type.fields = fields
69
+ content_type.save
70
+ content_type.activate
71
+ end
72
+ end
73
+
74
+ def is_link?(field)
75
+ field.has_key?(:link_type)
76
+ end
77
+
78
+ def is_array?(field)
79
+ field.has_key?(:items)
80
+ end
81
+
82
+ def create_assets
83
+ assets.each do |asset|
84
+ puts "Creating Asset '#{asset[:title]}'"
85
+ asset = space.assets.create(asset)
86
+ asset.process_file
87
+ sleep(1) # Wait for Process
88
+ asset.publish
89
+ end
90
+ end
91
+
92
+ def create_entries
93
+ entries.each do |content_type_id, entry_list|
94
+ content_type = space.content_types.find(content_type_id)
95
+ entry_list.each_with_index do |e, index|
96
+ puts "Creating Entry #{index} for #{content_type_id.capitalize}"
97
+
98
+ array_fields = []
99
+ e.each_pair do |field_name, value|
100
+ array_fields << field_name if value.is_a? Array
101
+ end
102
+
103
+ array_fields.each do |af|
104
+ e[af].map! do |f|
105
+ space.send(f.kind).find(f.id)
106
+ end
107
+ end
108
+
109
+ entry = content_type.entries.create(e)
110
+ entry.save
111
+ entry.publish
112
+ end
113
+ end
114
+ end
115
+ end
116
+ end
117
+ end
118
+ end
@@ -0,0 +1,77 @@
1
+ require "contentful/bootstrap/templates/base"
2
+ require "contentful/bootstrap/templates/links"
3
+
4
+ module Contentful
5
+ module Bootstrap
6
+ module Templates
7
+ class Blog < Base
8
+ def content_types
9
+ [
10
+ {
11
+ id: 'author',
12
+ name: 'Author',
13
+ display_field: 'name',
14
+ fields: [
15
+ {
16
+ id: 'name',
17
+ name: "Author Name",
18
+ type: "Symbol"
19
+ }
20
+ ]
21
+ },
22
+ {
23
+ id: 'post',
24
+ name: 'Post',
25
+ display_field: 'title',
26
+ fields: [
27
+ {
28
+ id: 'title',
29
+ name: "Post Title",
30
+ type: "Symbol"
31
+ },
32
+ {
33
+ id: 'content',
34
+ name: "Content",
35
+ type: "Text"
36
+ },
37
+ {
38
+ id: 'author',
39
+ name: "Author",
40
+ type: "Link",
41
+ link_type: "Entry"
42
+ }
43
+ ]
44
+ }
45
+ ]
46
+ end
47
+
48
+ def entries
49
+ {
50
+ 'author' => [
51
+ {
52
+ id: "dan_brown",
53
+ name: "Dan Brown"
54
+ },
55
+ {
56
+ id: "pablo_neruda",
57
+ name: "Pablo Neruda"
58
+ }
59
+ ],
60
+ 'post' => [
61
+ {
62
+ title: "Inferno",
63
+ content: "Inferno is the last book in Dan Brown's collection...",
64
+ author: Links::Entry.new("dan_brown")
65
+ },
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")
70
+ }
71
+ ]
72
+ }
73
+ end
74
+ end
75
+ end
76
+ end
77
+ end
@@ -0,0 +1,189 @@
1
+ require "contentful/bootstrap/templates/base"
2
+ require "contentful/bootstrap/templates/links"
3
+
4
+ module Contentful
5
+ module Bootstrap
6
+ module Templates
7
+ class Catalogue < Base
8
+ def content_types
9
+ [
10
+ {
11
+ id: 'brand',
12
+ name: 'Brand',
13
+ display_field: 'name',
14
+ fields: [
15
+ {
16
+ id: 'name',
17
+ name: "Company Name",
18
+ type: "Symbol"
19
+ },
20
+ {
21
+ id: 'website',
22
+ name: "Website",
23
+ type: "Symbol"
24
+ },
25
+ {
26
+ id: 'logo',
27
+ name: "Logo",
28
+ type: "Link",
29
+ link_type: "Asset"
30
+ }
31
+ ]
32
+ },
33
+ {
34
+ id: 'category',
35
+ name: 'Category',
36
+ display_field: 'title',
37
+ fields: [
38
+ {
39
+ id: 'title',
40
+ name: "Title",
41
+ type: "Symbol"
42
+ },
43
+ {
44
+ id: 'description',
45
+ name: "Description",
46
+ type: "Text"
47
+ },
48
+ {
49
+ id: 'icon',
50
+ name: "Icon",
51
+ type: "Link",
52
+ link_type: "Asset"
53
+ }
54
+ ]
55
+ },
56
+ {
57
+ id: 'product',
58
+ name: 'Product',
59
+ display_field: 'name',
60
+ fields: [
61
+ {
62
+ id: 'name',
63
+ name: "name",
64
+ type: "Symbol"
65
+ },
66
+ {
67
+ id: 'description',
68
+ name: "Description",
69
+ type: "Text"
70
+ },
71
+ {
72
+ id: 'image',
73
+ name: "Image",
74
+ type: "Link",
75
+ link_type: "Asset"
76
+ },
77
+ {
78
+ id: 'brand',
79
+ name: "Brand",
80
+ type: "Link",
81
+ link_type: "Entry"
82
+ },
83
+ {
84
+ id: 'category',
85
+ name: "Category",
86
+ type: "Link",
87
+ link_type: "Entry"
88
+ },
89
+ {
90
+ id: 'url',
91
+ name: "Available at",
92
+ type: "Symbol"
93
+ }
94
+ ]
95
+ }
96
+ ]
97
+ end
98
+
99
+ def assets
100
+ [
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&')
105
+ },
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&')
110
+ },
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&')
115
+ },
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&')
120
+ },
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&')
125
+ },
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&')
130
+ }
131
+ ]
132
+ end
133
+
134
+ def entries
135
+ {
136
+ 'brand' => [
137
+ {
138
+ id: 'playsam',
139
+ name: 'Playsam, Inc',
140
+ website: 'http://www.playsam.com',
141
+ logo: Links::Asset.new('playsam_image')
142
+ },
143
+ {
144
+ id: 'normann',
145
+ name: "Normann Copenhagen, Inc",
146
+ website: 'http://www.normann-copenhagen.com/',
147
+ logo: Links::Asset.new('normann_image')
148
+ }
149
+ ],
150
+ 'category' => [
151
+ {
152
+ id: 'toys',
153
+ title: 'Toys',
154
+ description: 'Toys for children',
155
+ icon: Links::Asset.new('toy_image')
156
+ },
157
+ {
158
+ id: 'kitchen',
159
+ title: 'House and Kitchen',
160
+ description: 'House and Kitchen accessories',
161
+ icon: Links::Asset.new('kitchen_image')
162
+ }
163
+ ],
164
+ 'product' => [
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/'
173
+ },
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/'
182
+ }
183
+ ]
184
+ }
185
+ end
186
+ end
187
+ end
188
+ end
189
+ end
@@ -0,0 +1,119 @@
1
+ require "contentful/bootstrap/templates/base"
2
+ require "contentful/bootstrap/templates/links"
3
+
4
+ module Contentful
5
+ module Bootstrap
6
+ module Templates
7
+ class Gallery < Base
8
+ def content_types
9
+ [
10
+ {
11
+ id: 'author',
12
+ name: "Author",
13
+ display_field: "name",
14
+ fields: [
15
+ {
16
+ name: "Name",
17
+ id: "name",
18
+ type: "Symbol"
19
+ }
20
+ ]
21
+ },
22
+ {
23
+ id: 'image',
24
+ name: 'Image',
25
+ display_field: 'title',
26
+ fields: [
27
+ {
28
+ id: 'title',
29
+ name: 'Title',
30
+ type: 'Symbol'
31
+ },
32
+ {
33
+ id: 'photo',
34
+ name: 'Photo',
35
+ type: 'Link',
36
+ link_type: 'Asset'
37
+ }
38
+ ]
39
+ },
40
+ {
41
+ id: 'gallery',
42
+ name: 'Gallery',
43
+ display_field: 'title',
44
+ fields: [
45
+ {
46
+ id: 'title',
47
+ name: 'Title',
48
+ type: 'Symbol'
49
+ },
50
+ {
51
+ id: 'author',
52
+ name: 'Author',
53
+ type: 'Link',
54
+ link_type: 'Entry'
55
+ },
56
+ {
57
+ id: 'images',
58
+ name: 'Images',
59
+ type: 'Array',
60
+ items: {
61
+ type: 'Link',
62
+ link_type: 'Entry'
63
+ }
64
+ }
65
+ ]
66
+ }
67
+ ]
68
+ end
69
+
70
+ def assets
71
+ [
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')
76
+ },
77
+ {
78
+ id: 'flower',
79
+ title: 'The Flower',
80
+ file: create_image('flower', 'http://c2.staticflickr.com/4/3922/15045568809_b24591e318_b.jpg')
81
+ }
82
+ ]
83
+ end
84
+
85
+ def entries
86
+ {
87
+ 'author' => [
88
+ {
89
+ id: 'dave',
90
+ name: 'Dave'
91
+ }
92
+ ],
93
+ 'image' => [
94
+ {
95
+ id: 'pie_entry',
96
+ title: 'A Pie in the Sky',
97
+ photo: Links::Asset.new('pie')
98
+ },
99
+ {
100
+ id: 'flower_entry',
101
+ title: 'The Flower',
102
+ photo: Links::Asset.new('flower')
103
+ }
104
+ ],
105
+ 'gallery' => [
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')]
111
+ }
112
+ ]
113
+ }
114
+ end
115
+ end
116
+ end
117
+ end
118
+ end
119
+