locomotivecms_wagon 2.1.0.rc4 → 2.1.0.rc5

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: c992663746d4414b01ab474e5e4169863dbf246e
4
- data.tar.gz: 64dcd654ebf23562683183c5313decd1417b0b34
3
+ metadata.gz: fbfa30794e5fef44d286be75267b65d52ed3bcaf
4
+ data.tar.gz: 25dd384d0decd405edc613af02956ee6d6065494
5
5
  SHA512:
6
- metadata.gz: f1c80340c057ba5867d1313553bf9e1c05c1181d57a2e2c3fc31988c5e941c3b64ec0791133df2618798c89a4891676243d1f2b9c984adccc332395112828a2c
7
- data.tar.gz: 63dc747d936d59492842b1cf34d0418e8878fbbfa68f2c486c9763d1f3bb1dd7ade520e4a041041eebd105d3455ae08f619630733abf173959b57babd2e5701a
6
+ metadata.gz: d4b3d642b06e9b59c7a469baf8d55dc76a2699504975d605425a310b6843a7b9da590518998b93e92136c3efd64e2f75bad42e79f87efe2407f774a133a3f1d3
7
+ data.tar.gz: 7e3399257bdf768c364bb85387c65efd92de04d5c8705f11f46a7eb52fa2e2378a099e737d6d53bad1c408472b72de62569f59d030a5d9fa348e0ce45f5b1975
data/Gemfile CHANGED
@@ -8,7 +8,7 @@ gem 'rb-fsevent', '~> 0.9.1'
8
8
  # Development
9
9
  # gem 'locomotivecms_common', github: 'locomotivecms/common', ref: '257047b', require: false
10
10
  # gem 'locomotivecms_coal', github: 'locomotivecms/coal', ref: 'f4ff435', require: false
11
- # gem 'locomotivecms_steam', github: 'locomotivecms/steam', ref: 'c44f003', require: false
11
+ # gem 'locomotivecms_steam', github: 'locomotivecms/steam', ref: 'a3054f1', require: false
12
12
 
13
13
  # Local development
14
14
  # gem 'locomotivecms_coal', path: '../gems/coal', require: false
@@ -2,7 +2,7 @@
2
2
  #
3
3
  # Syntax:
4
4
  #
5
- # - <namespace_1>: # no empty spaces, only digits and underscores
5
+ # <namespace_1>: # no empty spaces, only digits and underscores
6
6
  # label: <my label> # used as the label of a tab in the back-office
7
7
  # # label: # if you want to provide the label in another language (back-office)
8
8
  # # en: <your label in English if the local of the current user is English>
@@ -22,7 +22,7 @@
22
22
  # # <name_2>:
23
23
  # # ...
24
24
  #
25
- # - <namespace_2>:
25
+ # <namespace_2>:
26
26
  # # ...
27
27
  #
28
28
  #
@@ -2,7 +2,7 @@
2
2
  #
3
3
  # Syntax:
4
4
  #
5
- # - <namespace_1>: # no empty spaces, only digits and underscores
5
+ # <namespace_1>: # no empty spaces, only digits and underscores
6
6
  # label: <my label> # used as the label of a tab in the back-office
7
7
  # # label: # if you want to provide the label in another language (back-office)
8
8
  # # en: <your label in English if the local of the current user is English>
@@ -22,7 +22,7 @@
22
22
  # # <name_2>:
23
23
  # # ...
24
24
  #
25
- # - <namespace_2>:
25
+ # <namespace_2>:
26
26
  # # ...
27
27
  #
28
28
  #
@@ -2,7 +2,7 @@
2
2
  #
3
3
  # Syntax:
4
4
  #
5
- # - <namespace_1>: # no empty spaces, only digits and underscores
5
+ # <namespace_1>: # no empty spaces, only digits and underscores
6
6
  # label: <my label> # used as the label of a tab in the back-office
7
7
  # # label: # if you want to provide the label in another language (back-office)
8
8
  # # en: <your label in English if the local of the current user is English>
@@ -22,7 +22,7 @@
22
22
  # # <name_2>:
23
23
  # # ...
24
24
  #
25
- # - <namespace_2>:
25
+ # <namespace_2>:
26
26
  # # ...
27
27
  #
28
28
  #
@@ -2,7 +2,7 @@
2
2
  #
3
3
  # Syntax:
4
4
  #
5
- # - <namespace_1>: # no empty spaces, only digits and underscores
5
+ # <namespace_1>: # no empty spaces, only digits and underscores
6
6
  # label: <my label> # used as the label of a tab in the back-office
7
7
  # # label: # if you want to provide the label in another language (back-office)
8
8
  # # en: <your label in English if the local of the current user is English>
@@ -22,7 +22,7 @@
22
22
  # # <name_2>:
23
23
  # # ...
24
24
  #
25
- # - <namespace_2>:
25
+ # <namespace_2>:
26
26
  # # ...
27
27
  #
28
28
  #
@@ -39,11 +39,23 @@ module Locomotive::Wagon
39
39
  end
40
40
  end
41
41
 
42
- def write_metafields_schema(schema)
43
- return if schema.blank?
42
+ def decode_metafields_schema(schema)
43
+ if schema.is_a?(Array)
44
+ schema = array_of_hash_to_hash(schema, 'name') do |namespace|
45
+ namespace['fields'] = array_of_hash_to_hash(namespace.delete('fields'), 'name')
46
+ end
47
+ end
48
+
49
+ schema
50
+ end
51
+
52
+ def write_metafields_schema(json)
53
+ return if json.blank?
54
+
55
+ schema = decode_metafields_schema(JSON.parse(json))
44
56
 
45
57
  File.open(File.join(path, 'config', 'metafields_schema.yml'), 'wb') do |file|
46
- file.write JSON.parse(schema).to_yaml
58
+ file.write schema.to_yaml
47
59
  end
48
60
  end
49
61
 
@@ -58,6 +70,16 @@ module Locomotive::Wagon
58
70
  attributes['metafields'] = replace_asset_urls_in_hash(metafields)
59
71
  end
60
72
 
73
+ def array_of_hash_to_hash(array, name, &block)
74
+ {}.tap do |hash|
75
+ (array || []).each do |element|
76
+ key = element.delete(name)
77
+ hash[key] = element
78
+ yield element if block_given?
79
+ end
80
+ end
81
+ end
82
+
61
83
  def localized_attributes(&block)
62
84
  %w(seo_title meta_keywords meta_description).each do |name|
63
85
  yield(name)
@@ -18,13 +18,15 @@ module Locomotive::Wagon
18
18
  end
19
19
 
20
20
  def persist(decorated_entity)
21
- decorated_entity._id = remote_id = remote_entity_id(decorated_entity.fullpath)
21
+ decorated_entity._id = remote_id = remote_entity_id(decorated_entity)
22
22
 
23
23
  translated_in(decorated_entity) do |locale|
24
24
  if remote_id.nil?
25
25
  remote_id = api_client.pages.create(decorated_entity.to_hash)._id
26
- else
26
+ elsif can_update?(decorated_entity)
27
27
  api_client.pages.update(remote_id, decorated_entity.to_hash, locale)
28
+ else
29
+ raise "The local and the remote (#{remote_entity_fullpath_from_handle(decorated_entity)}) versions of that page have the same handle but they are not in the same folder."
28
30
  end
29
31
  end
30
32
  end
@@ -46,20 +48,62 @@ module Locomotive::Wagon
46
48
  PageDecorator.new(entity, default_locale, content_assets_pusher, persist_content)
47
49
  end
48
50
 
49
- def remote_entity_id(fullpath)
51
+ def can_update?(local_entity)
52
+ if local_entity.handle && id = remote_entity_id_from_handle(local_entity)
53
+ remote_entity_folder_path(id) == local_entity.folder_path
54
+ else
55
+ true
56
+ end
57
+ end
58
+
59
+ def remote_entity_id(local_entity)
60
+ remote_entity_id_from_fullpath(local_entity) || remote_entity_id_from_handle(local_entity)
61
+ end
62
+
63
+ def remote_entity_id_from_fullpath(local_entity)
64
+ fullpath = local_entity.fullpath
50
65
  remote_entities[fullpath] || remote_entities[fullpath.dasherize]
51
66
  end
52
67
 
68
+ def remote_entity_id_from_handle(local_entity)
69
+ remote_entities[local_entity.handle.try(:to_sym)]
70
+ end
71
+
72
+ def remote_entity_fullpath_from_handle(local_entity)
73
+ id = remote_entity_id_from_handle(local_entity)
74
+ remote_entities_by_id[id]
75
+ end
76
+
53
77
  def remote_entities
54
78
  return @remote_entities if @remote_entities
55
79
 
56
80
  @remote_entities = {}.tap do |hash|
57
81
  api_client.pages.fullpaths(default_locale).each do |entity|
58
- hash[entity.fullpath] = entity._id
82
+ hash[entity.fullpath] = entity._id
83
+
84
+ if entity.respond_to?(:handle) && entity.handle.present?
85
+ # to_sym: trick to not have conflicts with fullpaths
86
+ hash[entity.handle.to_sym] = entity._id
87
+ end
59
88
  end
60
89
  end
61
90
  end
62
91
 
92
+ def remote_entity_folder_path(id)
93
+ if path = remote_entities_by_id[id]
94
+ *segments, slug = path.split('/')
95
+ segments.join('/')
96
+ else
97
+ nil
98
+ end
99
+ end
100
+
101
+ def remote_entities_by_id
102
+ @remote_entities_by_id ||= remote_entities.each_with_object({}) do |(key, value), out|
103
+ out[value] = key if key.is_a?(String)
104
+ end
105
+ end
106
+
63
107
  def translated_in(decorated_entity, &block)
64
108
  locales.find_all do |locale|
65
109
  decorated_entity.__with_locale__(locale) do
@@ -151,7 +151,11 @@ module Locomotive::Wagon
151
151
 
152
152
  filepath = File.join(File.expand_path(path), 'app', 'views', 'pages', fullpath + (locale != default_locale ? ".#{locale}" : '') + '.liquid')
153
153
 
154
- message = "[Tip]".light_white + " add a new page in your Wagon site at this location: " + filepath.light_white
154
+ message = if File.exists?(filepath)
155
+ "[Warning]".red + ' by default and unless you overide the slug in the YAML header of your page, Wagon will replace underscores by dashes in your page slug. Try this instead: ' + fullpath.dasherize.light_white
156
+ else
157
+ "[Tip]".light_white + " add a new page in your Wagon site at this location: " + filepath.light_white
158
+ end
155
159
 
156
160
  Locomotive::Common::Logger.info (' ' * 2) + message
157
161
  end
@@ -30,6 +30,11 @@ module Locomotive
30
30
  _attributes -= %i(title published listed position seo_title meta_keywords meta_description editable_elements)
31
31
  end
32
32
 
33
+ # no need to update the slug if this is for an update
34
+ # in case of a localized site, if this is a new page, the _id will remain empty
35
+ # for the other locales.
36
+ _attributes -= %i(slug) if persisted?
37
+
33
38
  _attributes
34
39
  end
35
40
 
@@ -77,6 +82,11 @@ module Locomotive
77
82
  replace_with_content_assets!(self.liquid_source)
78
83
  end
79
84
 
85
+ def folder_path
86
+ *segments, slug = fullpath.split('/')
87
+ segments.join('/')
88
+ end
89
+
80
90
  private
81
91
 
82
92
  def persisted?
@@ -1,5 +1,5 @@
1
1
  module Locomotive
2
2
  module Wagon
3
- VERSION = '2.1.0.rc4'
3
+ VERSION = '2.1.0.rc5'
4
4
  end
5
5
  end
@@ -28,7 +28,7 @@ Gem::Specification.new do |gem|
28
28
 
29
29
  gem.add_dependency 'locomotivecms_common', '~> 0.1.0'
30
30
  gem.add_dependency 'locomotivecms_coal', '~> 1.1.0'
31
- gem.add_dependency 'locomotivecms_steam', '~> 1.1.0.rc2'
31
+ gem.add_dependency 'locomotivecms_steam', '~> 1.1.0.rc3'
32
32
 
33
33
  gem.add_dependency 'listen', '~> 3.0.4'
34
34
  gem.add_dependency 'rack-livereload', '~> 0.3.16'
@@ -7,14 +7,16 @@ http_interactions:
7
7
  encoding: UTF-8
8
8
  string: email=john%40doe.net&password=asimplepassword
9
9
  headers:
10
+ User-Agent:
11
+ - HTTPClient/1.0 (2.7.1, ruby 2.2.3 (2015-08-18))
10
12
  Accept:
11
13
  - application/json
14
+ Accept-Encoding:
15
+ - gzip,deflate
16
+ Date:
17
+ - Mon, 21 Mar 2016 17:36:40 GMT
12
18
  Content-Type:
13
19
  - application/x-www-form-urlencoded
14
- Accept-Encoding:
15
- - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
16
- User-Agent:
17
- - Ruby
18
20
  response:
19
21
  status:
20
22
  code: 401
@@ -27,16 +29,16 @@ http_interactions:
27
29
  Cache-Control:
28
30
  - no-cache
29
31
  X-Request-Id:
30
- - 4c1dde74-5ab5-47e1-878b-6bafaa3ae31d
32
+ - f97c50d2-f8ae-4fd8-bce0-3b623afae5f3
31
33
  X-Runtime:
32
- - '0.491453'
34
+ - '0.448075'
33
35
  Content-Length:
34
36
  - '40'
35
37
  body:
36
38
  encoding: UTF-8
37
39
  string: '{"message":"Invalid email or password."}'
38
40
  http_version:
39
- recorded_at: Wed, 17 Feb 2016 20:59:45 GMT
41
+ recorded_at: Mon, 21 Mar 2016 17:36:41 GMT
40
42
  - request:
41
43
  method: post
42
44
  uri: http://localhost:3000/locomotive/api/v3/my_account.json
@@ -44,14 +46,16 @@ http_interactions:
44
46
  encoding: UTF-8
45
47
  string: account%5Bemail%5D=john%40doe.net&account%5Bname%5D=John&account%5Bpassword%5D=asimplepassword
46
48
  headers:
49
+ User-Agent:
50
+ - HTTPClient/1.0 (2.7.1, ruby 2.2.3 (2015-08-18))
47
51
  Accept:
48
52
  - application/json
53
+ Accept-Encoding:
54
+ - gzip,deflate
55
+ Date:
56
+ - Mon, 21 Mar 2016 17:36:41 GMT
49
57
  Content-Type:
50
58
  - application/x-www-form-urlencoded
51
- Accept-Encoding:
52
- - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
53
- User-Agent:
54
- - Ruby
55
59
  response:
56
60
  status:
57
61
  code: 201
@@ -60,20 +64,20 @@ http_interactions:
60
64
  Content-Type:
61
65
  - application/json
62
66
  Etag:
63
- - W/"ecd8bcbc56ad219c12f928c0c7642228"
67
+ - W/"13d961357bc8b2ce65f4f13ee8adba85"
64
68
  Cache-Control:
65
69
  - max-age=0, private, must-revalidate
66
70
  X-Request-Id:
67
- - 163cedb0-c315-4318-905a-2ca2184c2865
71
+ - a3c557e9-41e9-44dc-ae1d-91af5ddd3b96
68
72
  X-Runtime:
69
- - '0.086436'
73
+ - '0.098826'
70
74
  Content-Length:
71
75
  - '250'
72
76
  body:
73
77
  encoding: UTF-8
74
- string: '{"_id":"56c4df41c3651180309c60d3","created_at":"2016-02-17T20:59:45Z","updated_at":"2016-02-17T20:59:45Z","name":"John","email":"john@doe.net","locale":"en","api_key":"3f7bb7a02a1ad6c3e285beda89e6e8a3f75d9154","super_admin":false,"local_admin":false}'
78
+ string: '{"_id":"56f03129c36511207342cbcb","created_at":"2016-03-21T17:36:41Z","updated_at":"2016-03-21T17:36:41Z","name":"John","email":"john@doe.net","locale":"en","api_key":"901baf472a28a8e3a6a871255c90b232de964686","super_admin":false,"local_admin":false}'
75
79
  http_version:
76
- recorded_at: Wed, 17 Feb 2016 20:59:45 GMT
80
+ recorded_at: Mon, 21 Mar 2016 17:36:41 GMT
77
81
  - request:
78
82
  method: post
79
83
  uri: http://localhost:3000/locomotive/api/v3/tokens.json
@@ -81,14 +85,16 @@ http_interactions:
81
85
  encoding: UTF-8
82
86
  string: email=admin%40locomotivecms.com&password=locomotive
83
87
  headers:
88
+ User-Agent:
89
+ - HTTPClient/1.0 (2.7.1, ruby 2.2.3 (2015-08-18))
84
90
  Accept:
85
91
  - application/json
92
+ Accept-Encoding:
93
+ - gzip,deflate
94
+ Date:
95
+ - Mon, 21 Mar 2016 17:36:41 GMT
86
96
  Content-Type:
87
97
  - application/x-www-form-urlencoded
88
- Accept-Encoding:
89
- - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
90
- User-Agent:
91
- - Ruby
92
98
  response:
93
99
  status:
94
100
  code: 201
@@ -97,37 +103,39 @@ http_interactions:
97
103
  Content-Type:
98
104
  - application/json
99
105
  Etag:
100
- - W/"9f0203483ba848323bbda0b85ed7725e"
106
+ - W/"3cfd61d41b23cdfb3d8833133c136131"
101
107
  Cache-Control:
102
108
  - max-age=0, private, must-revalidate
103
109
  X-Request-Id:
104
- - 4aed7a00-f72d-4367-890b-d827b3cff156
110
+ - 805ec3c4-ce19-4edb-bd06-6b499447f2a1
105
111
  X-Runtime:
106
- - '0.015710'
112
+ - '0.016118'
107
113
  Content-Length:
108
114
  - '32'
109
115
  body:
110
116
  encoding: UTF-8
111
- string: '{"token":"e1QSfNaw8zQM7rWX5CPf"}'
117
+ string: '{"token":"V8VMCfCsp7XzQLvAd1AY"}'
112
118
  http_version:
113
- recorded_at: Wed, 17 Feb 2016 20:59:45 GMT
119
+ recorded_at: Mon, 21 Mar 2016 17:36:41 GMT
114
120
  - request:
115
121
  method: get
116
- uri: http://localhost:3000/locomotive/api/v3/my_account.json?auth_token=e1QSfNaw8zQM7rWX5CPf
122
+ uri: http://localhost:3000/locomotive/api/v3/my_account.json?auth_token=V8VMCfCsp7XzQLvAd1AY
117
123
  body:
118
- encoding: US-ASCII
124
+ encoding: UTF-8
119
125
  string: ''
120
126
  headers:
127
+ User-Agent:
128
+ - HTTPClient/1.0 (2.7.1, ruby 2.2.3 (2015-08-18))
121
129
  Accept:
122
130
  - application/json
131
+ Accept-Encoding:
132
+ - gzip,deflate
133
+ Date:
134
+ - Mon, 21 Mar 2016 17:36:41 GMT
123
135
  X-Locomotive-Account-Email:
124
136
  - admin@locomotivecms.com
125
137
  X-Locomotive-Account-Token:
126
- - e1QSfNaw8zQM7rWX5CPf
127
- Accept-Encoding:
128
- - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
129
- User-Agent:
130
- - Ruby
138
+ - V8VMCfCsp7XzQLvAd1AY
131
139
  response:
132
140
  status:
133
141
  code: 200
@@ -136,37 +144,39 @@ http_interactions:
136
144
  Content-Type:
137
145
  - application/json
138
146
  Etag:
139
- - W/"7d8f03d047be776ab17daf20e33dc4ad"
147
+ - W/"2ce6a3f4e073d2d83a53613d0139477e"
140
148
  Cache-Control:
141
149
  - max-age=0, private, must-revalidate
142
150
  X-Request-Id:
143
- - 18bee298-4a65-4938-9e2f-f80f0c82f53e
151
+ - e4ca46c9-4c89-42db-9bdb-ca21e8adb1a9
144
152
  X-Runtime:
145
- - '0.027460'
153
+ - '0.029466'
146
154
  Content-Length:
147
155
  - '261'
148
156
  body:
149
157
  encoding: UTF-8
150
- string: '{"_id":"56c4df17c36511800c8b9037","created_at":"2016-02-17T20:59:03Z","updated_at":"2016-02-17T20:59:03Z","name":"Admin","email":"admin@locomotivecms.com","locale":"en","api_key":"d49cd50f6f0d2b163f48fc73cb249f0244c37074","super_admin":false,"local_admin":true}'
158
+ string: '{"_id":"56f03072c365112052cab389","created_at":"2016-03-21T17:33:38Z","updated_at":"2016-03-21T17:33:38Z","name":"Admin","email":"admin@locomotivecms.com","locale":"en","api_key":"d49cd50f6f0d2b163f48fc73cb249f0244c37074","super_admin":false,"local_admin":true}'
151
159
  http_version:
152
- recorded_at: Wed, 17 Feb 2016 20:59:45 GMT
160
+ recorded_at: Mon, 21 Mar 2016 17:36:41 GMT
153
161
  - request:
154
162
  method: get
155
- uri: http://localhost:3000/locomotive/api/v3/my_account.json?auth_token=e1QSfNaw8zQM7rWX5CPf
163
+ uri: http://localhost:3000/locomotive/api/v3/my_account.json?auth_token=V8VMCfCsp7XzQLvAd1AY
156
164
  body:
157
- encoding: US-ASCII
165
+ encoding: UTF-8
158
166
  string: ''
159
167
  headers:
168
+ User-Agent:
169
+ - HTTPClient/1.0 (2.7.1, ruby 2.2.3 (2015-08-18))
160
170
  Accept:
161
171
  - application/json
172
+ Accept-Encoding:
173
+ - gzip,deflate
174
+ Date:
175
+ - Mon, 21 Mar 2016 17:36:41 GMT
162
176
  X-Locomotive-Account-Email:
163
177
  - admin@locomotivecms.com
164
178
  X-Locomotive-Account-Token:
165
- - e1QSfNaw8zQM7rWX5CPf
166
- Accept-Encoding:
167
- - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
168
- User-Agent:
169
- - Ruby
179
+ - V8VMCfCsp7XzQLvAd1AY
170
180
  response:
171
181
  status:
172
182
  code: 200
@@ -175,18 +185,18 @@ http_interactions:
175
185
  Content-Type:
176
186
  - application/json
177
187
  Etag:
178
- - W/"7d8f03d047be776ab17daf20e33dc4ad"
188
+ - W/"2ce6a3f4e073d2d83a53613d0139477e"
179
189
  Cache-Control:
180
190
  - max-age=0, private, must-revalidate
181
191
  X-Request-Id:
182
- - 58ee0cc3-0a25-43f6-ab83-ec81d9ed63ff
192
+ - 059e56ad-ec66-4fa7-98a4-85f7eb38746c
183
193
  X-Runtime:
184
- - '0.015876'
194
+ - '0.019939'
185
195
  Content-Length:
186
196
  - '261'
187
197
  body:
188
198
  encoding: UTF-8
189
- string: '{"_id":"56c4df17c36511800c8b9037","created_at":"2016-02-17T20:59:03Z","updated_at":"2016-02-17T20:59:03Z","name":"Admin","email":"admin@locomotivecms.com","locale":"en","api_key":"d49cd50f6f0d2b163f48fc73cb249f0244c37074","super_admin":false,"local_admin":true}'
199
+ string: '{"_id":"56f03072c365112052cab389","created_at":"2016-03-21T17:33:38Z","updated_at":"2016-03-21T17:33:38Z","name":"Admin","email":"admin@locomotivecms.com","locale":"en","api_key":"d49cd50f6f0d2b163f48fc73cb249f0244c37074","super_admin":false,"local_admin":true}'
190
200
  http_version:
191
- recorded_at: Wed, 17 Feb 2016 20:59:45 GMT
201
+ recorded_at: Mon, 21 Mar 2016 17:36:41 GMT
192
202
  recorded_with: VCR 3.0.0