locomotivecms_mounter 1.4.4 → 1.5.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: 79663d1b58f4a46ada47776d7e14c92462900fab
4
- data.tar.gz: 10e9dd0d045ff02bf5340a3b2717927adcc622ee
3
+ metadata.gz: 8f209dbffa2e246e39048d073252752052349057
4
+ data.tar.gz: 5d567b2a2e79a3bda8247283ff1833f1c4b4eed6
5
5
  SHA512:
6
- metadata.gz: 3a7cefcb901b7a5bce7d9ab72936d2a9f2590b6244548f177c24e8c20a56a484a7737f2fa5894be40e8b87cba99d42f840aedb82429abf217f96bf18e11e16cf
7
- data.tar.gz: 20bc67d5480e46fc5ba0e91f89c4b8825d2074062939455368e1cba92fb15143410e67e082365e0c80a5bc0abb6e10439deb488dffc7a89dbd76bd13535ca0f1
6
+ metadata.gz: 74e99e2982545980ce4bb993a7332ad3124bed53d47e16cc6e85502b4a0e2316318295895670a102bc3cb72eddc176ab23e962cf3ec1bcbc84050cdd118b9457
7
+ data.tar.gz: aa9fa4a15dbb7c030c69bdfa7be922830795dd0025b76a4eaaa05e2ba02dc2b168b5fae324a63691c3a805353ca8d7069d51fa395fbe8043f5d480c3cbf8781a
data/Gemfile.lock CHANGED
@@ -1,9 +1,9 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- locomotivecms_mounter (1.4.4)
4
+ locomotivecms_mounter (1.5.0)
5
5
  RedCloth (~> 4.2.3)
6
- activesupport (~> 3.2.18)
6
+ activesupport (~> 3.2.21)
7
7
  chronic (~> 0.10.2)
8
8
  coffee-script (~> 2.2.0)
9
9
  colorize (~> 0.5.8)
@@ -28,12 +28,12 @@ GEM
28
28
  remote: http://rubygems.org/
29
29
  specs:
30
30
  RedCloth (4.2.9)
31
- activesupport (3.2.19)
31
+ activesupport (3.2.21)
32
32
  i18n (~> 0.6, >= 0.6.4)
33
33
  multi_json (~> 1.0)
34
34
  addressable (2.3.6)
35
35
  chronic (0.10.2)
36
- chunky_png (1.3.1)
36
+ chunky_png (1.3.3)
37
37
  coffee-script (2.2.0)
38
38
  coffee-script-source
39
39
  execjs
@@ -55,22 +55,22 @@ GEM
55
55
  crack (0.4.2)
56
56
  safe_yaml (~> 1.0.0)
57
57
  diff-lcs (1.2.5)
58
- execjs (2.2.1)
59
- ffi (1.9.3)
58
+ execjs (2.2.2)
59
+ ffi (1.9.6)
60
60
  haml (4.0.5)
61
61
  tilt
62
62
  hike (1.2.3)
63
63
  httmultiparty (0.3.10)
64
64
  httparty (>= 0.7.3)
65
65
  multipart-post
66
- httparty (0.13.1)
66
+ httparty (0.13.3)
67
67
  json (~> 1.8)
68
68
  multi_xml (>= 0.5.2)
69
69
  i18n (0.6.11)
70
70
  json (1.8.1)
71
71
  less (2.2.2)
72
72
  commonjs (~> 0.2.6)
73
- libv8 (3.11.8.17)
73
+ libv8 (3.16.14.3)
74
74
  logger (1.2.8)
75
75
  mime-types (1.25.1)
76
76
  multi_json (1.8.4)
@@ -93,9 +93,9 @@ GEM
93
93
  diff-lcs (>= 1.1.3, < 2.0)
94
94
  rspec-mocks (2.14.6)
95
95
  ruby-debug-wrapper (0.0.1)
96
- safe_yaml (1.0.3)
97
- sass (3.4.5)
98
- sprockets (2.12.2)
96
+ safe_yaml (1.0.4)
97
+ sass (3.4.7)
98
+ sprockets (2.12.3)
99
99
  hike (~> 1.2)
100
100
  multi_json (~> 1.0)
101
101
  rack (~> 1.0)
@@ -104,11 +104,11 @@ GEM
104
104
  sprockets (~> 2.0)
105
105
  tilt (~> 1.1)
106
106
  stringex (2.0.11)
107
- therubyracer (0.11.4)
108
- libv8 (~> 3.11.8.12)
107
+ therubyracer (0.12.1)
108
+ libv8 (~> 3.16.14.0)
109
109
  ref
110
110
  tilt (1.4.1)
111
- tzinfo (0.3.41)
111
+ tzinfo (0.3.42)
112
112
  vcr (2.4.0)
113
113
  webmock (1.9.3)
114
114
  addressable (>= 2.2.7)
@@ -120,11 +120,12 @@ PLATFORMS
120
120
  ruby
121
121
 
122
122
  DEPENDENCIES
123
+ libv8 (= 3.16.14.3)
123
124
  locomotivecms_mounter!
124
125
  rack-test (~> 0.6.1)
125
126
  rake (= 0.9.2)
126
127
  rspec (~> 2.14.1)
127
128
  ruby-debug-wrapper (~> 0.0.1)
128
- therubyracer (~> 0.11.4)
129
+ therubyracer (~> 0.12.1)
129
130
  vcr (= 2.4.0)
130
131
  webmock (= 1.9.3)
@@ -36,6 +36,84 @@ module Locomotive
36
36
  end
37
37
  end
38
38
 
39
+ # Read a resource or a list of resources from the API
40
+ # Raise an exception if something went wrong.
41
+ #
42
+ # @param [ String ] resource_name The path to the resource (usually, the resource name)
43
+ # @param [ Hash ] query If we want to filter the results
44
+ # @param [ String ] locale The locale for the request
45
+ # @param [ Array ] attribute_names The attributes we want to keep in the response
46
+ #
47
+ def self.fetch(resource_name, query = {}, locale = nil, attribute_names = nil)
48
+ params = { query: query || {} }
49
+ params[:query][:locale] = locale if locale
50
+
51
+ url = "/#{resource_name}.json"
52
+ response = self.get(url, params)
53
+ data = response.parsed_response
54
+
55
+ if response.success?
56
+ object_or_list = self.keep_attributes(data, attribute_names)
57
+
58
+ if response.headers['x-total-pages']
59
+ PaginatedCollection.new(url, params, attribute_names).tap do |collection|
60
+ collection.list = object_or_list
61
+ collection.total_pages = response.headers['x-total-pages'].to_i
62
+ collection.total_entries = response.headers['x-total-entries'].to_i
63
+ end
64
+ else
65
+ object_or_list
66
+ end
67
+ else
68
+ raise ApiReadException.new(data['error'])
69
+ end
70
+ end
71
+
72
+ # Create a resource from the API.
73
+ # Raise an exception if something went wrong.
74
+ #
75
+ # @param [ String ] resource_name The path to the resource (usually, the resource name)
76
+ # @param [ Hash ] attributes The attributes of the resource
77
+ # @param [ String ] locale The locale for the request
78
+ # @param [ Array ] attribute_names The attributes we want to keep in the response
79
+ #
80
+ # @return [ Object] The response of the API
81
+ #
82
+ def self.create(resource_name, attributes, locale = nil, attribute_names = nil)
83
+ params = self.build_create_or_params(resource_name, attributes, locale)
84
+ response = self.post("/#{resource_name}.json", params)
85
+ data = response.parsed_response
86
+
87
+ if response.success?
88
+ self.keep_attributes(data, attribute_names)
89
+ else
90
+ raise ApiWriteException.new(data)
91
+ end
92
+ end
93
+
94
+ # Update a resource from the API.
95
+ # Raise an exception if something went wrong.
96
+ #
97
+ # @param [ String ] resource_name The path to the resource (usually, the resource name)
98
+ # @param [ String ] id The unique identifier of the resource
99
+ # @param [ Hash ] attributes The attributes of the resource
100
+ # @param [ String ] locale The locale for the request
101
+ # @param [ Array ] attribute_names The attributes we want to keep in the response
102
+ #
103
+ # @return [ Object] The response of the API
104
+ #
105
+ def self.update(resource_name, id, attributes, locale = nil, attribute_names = nil)
106
+ params = self.build_create_or_params(resource_name, attributes, locale)
107
+ response = self.put("/#{resource_name}/#{id}.json", params)
108
+ data = response.parsed_response
109
+
110
+ if response.success?
111
+ self.keep_attributes(data, attribute_names)
112
+ else
113
+ raise ApiWriteException.new(data)
114
+ end
115
+ end
116
+
39
117
  def self.teardown
40
118
  Locomotive::Mounter::EngineApi.default_options[:base_uri] = nil
41
119
  Locomotive::Mounter::EngineApi.default_options[:base_auth] = nil
@@ -58,7 +136,70 @@ module Locomotive
58
136
  end
59
137
  end
60
138
 
139
+ def self.build_create_or_params(resource_name, attributes, locale)
140
+ name = resource_name.to_s.split('/').last.singularize
141
+
142
+ params = { query: { name => attributes } }
143
+ params[:query][:locale] = locale if locale
144
+
145
+ params
146
+ end
147
+
148
+ def self.keep_attributes(data, attribute_names)
149
+ return data if attribute_names.blank?
150
+
151
+ case data
152
+ when Hash then data.to_hash.delete_if { |k, _| !attribute_names.include?(k) }
153
+ when Array
154
+ data.map do |row|
155
+ row.delete_if { |k, _| !attribute_names.include?(k) }
156
+ end
157
+ else
158
+ data
159
+ end
160
+ end
161
+
162
+ end
163
+
164
+ class PaginatedCollection < Struct.new(:url, :params, :attribute_names)
165
+
166
+ attr_accessor :list, :total_pages, :total_entries
167
+
168
+ alias :size :total_entries
169
+
170
+ def each(&block)
171
+ if self.total_pages == 1 && self.list
172
+ self.list.each(&block)
173
+ else
174
+ self.paginated_each(&block)
175
+ end
176
+ end
177
+
178
+ def paginated_each(&block)
179
+ loop do
180
+ self.params[:query][:page] = self.page
181
+
182
+ response = Locomotive::Mounter::EngineApi.get(self.url, self.params)
183
+ data = response.parsed_response
184
+
185
+ if response.success?
186
+ self.list = Locomotive::Mounter::EngineApi.send(:keep_attributes, data, self.attribute_names)
187
+ self.list.each(&block)
188
+ else
189
+ raise ApiReadException.new(data['error'])
190
+ end
191
+
192
+ break if self.page >= self.total_pages
193
+
194
+ @page += 1
195
+ end
196
+ end
197
+
198
+ def page
199
+ @page ||= 1
200
+ end
201
+
61
202
  end
62
203
 
63
204
  end
64
- end
205
+ end
@@ -34,5 +34,11 @@ module Locomotive
34
34
  class WrongCredentials < DefaultException
35
35
  end
36
36
 
37
+ class ApiReadException < DefaultException
38
+ end
39
+
40
+ class ApiWriteException < DefaultException
41
+ end
42
+
37
43
  end
38
44
  end
@@ -13,15 +13,21 @@ module Locomotive
13
13
  # unless the site_path changed.
14
14
  #
15
15
  # @param [ String ] site_path The root directory of the site
16
+ # @param [ Boolean ] minify Minify the js and css assets (default: false)
16
17
  #
17
- def self.environment(site_path)
18
+ def self.environment(site_path, minify = false)
18
19
  return @@env if @@env && @@path == site_path
19
20
 
20
21
  @@path = site_path
21
22
  @@env = ::Sprockets::Environment.new.tap do |env|
22
- # minify javascripts and stylesheets
23
- env.js_compressor = YUI::JavaScriptCompressor.new
24
- env.css_compressor = YUI::CssCompressor.new
23
+ if minify && is_java_installed?
24
+ # minify javascripts and stylesheets
25
+ env.js_compressor = YUI::JavaScriptCompressor.new
26
+ env.css_compressor = YUI::CssCompressor.new
27
+ else
28
+ message = "[Important] YUICompressor requires java to be installed. The JAVA_HOME variable should also be set.\n"
29
+ Locomotive::Mounter.logger.warn message.colorize(color: :red)
30
+ end
25
31
 
26
32
  %w(fonts stylesheets javascripts).each do |name|
27
33
  env.append_path File.join(site_path, 'public', name)
@@ -29,8 +35,12 @@ module Locomotive
29
35
  end
30
36
  end
31
37
 
38
+ def self.is_java_installed?
39
+ `which java` != '' && (!ENV['JAVA_HOME'].blank? && File.exists?(ENV['JAVA_HOME']))
40
+ end
41
+
32
42
  end
33
43
 
34
44
  end
35
45
  end
36
- end
46
+ end
@@ -10,6 +10,8 @@ module Locomotive
10
10
  field :title, localized: true
11
11
  field :slug, localized: true
12
12
  field :fullpath, localized: true
13
+ field :is_layout, default: false
14
+ field :allow_layout, default: false
13
15
  field :redirect_url, localized: true
14
16
  field :redirect_type, default: 301
15
17
  field :template, localized: true
@@ -40,6 +42,7 @@ module Locomotive
40
42
  alias :published? :published
41
43
  alias :templatized? :templatized
42
44
  alias :searchable? :searchable
45
+ alias :is_layout? :is_layout
43
46
 
44
47
  ## methods ##
45
48
 
@@ -62,15 +65,17 @@ module Locomotive
62
65
  # Return the fullpath dasherized and with the "*" character
63
66
  # for the slug of templatized page.
64
67
  #
68
+ # @param [ Boolean ] wildcard If true, replace the slug of a templatized page by the "*" character (default: true)
69
+ #
65
70
  # @return [ String ] The safe full path or nil if the page is not translated in the current locale
66
71
  #
67
- def safe_fullpath
72
+ def safe_fullpath(wildcard = true)
68
73
  if self.index_or_404?
69
74
  self.slug
70
75
  else
71
- base = self.parent.safe_fullpath
76
+ base = self.parent.safe_fullpath(wildcard)
72
77
  _slug = if self.templatized? && !self.templatized_from_parent
73
- '*'
78
+ wildcard ? '*' : self.slug
74
79
  elsif !self.translated_in?(Locomotive::Mounter.locale)
75
80
  self.slug_translations[self.mounting_point.default_locale]
76
81
  else
@@ -155,23 +160,23 @@ module Locomotive
155
160
  self.depth * 1000 + (self.position || 199)
156
161
  end
157
162
 
158
- # A layout is a page whose the template does
159
- # not include the extend keyword.
160
- # If the template is blank then, it is not considered as a layout
163
+ # Tell if the page extends the template of another page.
164
+ # Basically, we check if the template of the page includes
165
+ # the "extends" liquid tag.
161
166
  #
162
167
  # @return [ Boolean ] True if the template can be a layout.
163
168
  #
164
- def is_layout?
165
- self.layout.nil?
169
+ def extends_template?
170
+ !self.template_fullpath.nil?
166
171
  end
167
172
 
168
- # Return the fullpath of the page which is used
169
- # as a layout for the current page.
173
+ # Return the fullpath of the page whose template is extended
174
+ # in the current template.
170
175
  #
171
- # @return [ String ] The fullpath to the layout
176
+ # @return [ String ] The fullpath of the "extended" page or nil if no extends tag
172
177
  #
173
- def layout
174
- return false if self.source.nil? || self.source.strip.blank?
178
+ def template_fullpath
179
+ return nil if self.source.nil? || self.source.strip.blank?
175
180
 
176
181
  self.source =~ /\{%\s*extends\s+\'?([[\w|\-|\_]|\/]+)\'?\s*%\}/
177
182
  $1
@@ -333,7 +338,7 @@ module Locomotive
333
338
  # @return [ String ] The YAML version of the page
334
339
  #
335
340
  def to_yaml
336
- fields = %w(title slug redirect_url redirect_type handle published listed searchable cache_strategy response_type position seo_title meta_description meta_keywords)
341
+ fields = %w(title slug redirect_url redirect_type handle published listed is_layout searchable cache_strategy response_type position seo_title meta_description meta_keywords)
337
342
 
338
343
  _attributes = self.attributes.delete_if do |k, v|
339
344
  !fields.include?(k.to_s) || (!v.is_a?(FalseClass) && v.blank?)
@@ -363,7 +368,8 @@ module Locomotive
363
368
  # @return [ Hash ] The params
364
369
  #
365
370
  def to_params
366
- params = self.filter_attributes %w(title parent_id slug redirect_url redirect_type handle listed published searchable cache_strategy
371
+ params = self.filter_attributes %w(title parent_id slug redirect_url redirect_type handle listed is_layout
372
+ allow_layout published searchable cache_strategy
367
373
  response_type position templatized seo_title meta_description meta_keywords)
368
374
 
369
375
  # slug
@@ -394,7 +400,7 @@ module Locomotive
394
400
  # @return [ Hash ] The safe params
395
401
  #
396
402
  def to_safe_params
397
- fields = %w(title slug listed published searchable handle cache_strategy
403
+ fields = %w(title slug listed is_layout allow_layout published searchable handle cache_strategy
398
404
  redirect_url response_type templatized content_type_id position
399
405
  seo_title meta_description meta_keywords)
400
406
 
@@ -433,4 +439,4 @@ module Locomotive
433
439
 
434
440
  end
435
441
  end
436
- end
442
+ end
@@ -25,23 +25,13 @@ module Locomotive
25
25
  self.output_title(:pulling)
26
26
  end
27
27
 
28
- def get(resource_name, locale = nil, raw = false)
29
- params = { query: {} }
28
+ def get(resource_name, locale = nil, dont_filter_attributes = false)
29
+ attribute_names = dont_filter_attributes ? nil : self.safe_attributes
30
30
 
31
- params[:query][:locale] = locale if locale
32
-
33
- response = Locomotive::Mounter::EngineApi.get("/#{resource_name}.json", params).parsed_response
34
-
35
- return response if raw
36
-
37
- case response
38
- when Hash then response.to_hash.delete_if { |k, _| !self.safe_attributes.include?(k) }
39
- when Array
40
- response.map do |row|
41
- row.delete_if { |k, _| !self.safe_attributes.include?(k) }
42
- end
43
- else
44
- response
31
+ begin
32
+ Locomotive::Mounter::EngineApi.fetch(resource_name, {}, locale, attribute_names)
33
+ rescue ApiReadException => e
34
+ raise ReaderException.new(e.message)
45
35
  end
46
36
  end
47
37
 
@@ -74,4 +64,4 @@ module Locomotive
74
64
  end
75
65
  end
76
66
  end
77
- end
67
+ end
@@ -139,4 +139,4 @@ module Locomotive
139
139
  end
140
140
  end
141
141
  end
142
- end
142
+ end
@@ -2,7 +2,7 @@
2
2
  module Locomotive
3
3
  module Mounter #:nodoc
4
4
 
5
- VERSION = '1.4.4'
5
+ VERSION = '1.5.0'
6
6
 
7
7
  end
8
8
  end
@@ -37,101 +37,71 @@ module Locomotive
37
37
  self.runner.parameters[:data] || false
38
38
  end
39
39
 
40
- # Get remote resource(s) by the API
40
+ # Get remote resource(s) from the API
41
41
  #
42
42
  # @param [ String ] resource_name The path to the resource (usually, the resource name)
43
43
  # @param [ String ] locale The locale for the request
44
- # @param [ Boolean ] raw True if the result has to be converted into object.
44
+ # @param [ Boolean ] dont_filter_attributes False if the we want to only keep the attributes defined by the safe_attributes method
45
45
  #
46
46
  # @return [ Object] The object or a collection of objects.
47
47
  #
48
- def get(resource_name, locale = nil, raw = false)
49
- params = { query: {} }
48
+ def get(resource_name, locale = nil, dont_filter_attributes = false)
49
+ attribute_names = dont_filter_attributes ? nil : self.safe_attributes
50
50
 
51
- params[:query][:locale] = locale if locale
52
-
53
- response = Locomotive::Mounter::EngineApi.get("/#{resource_name}.json", params)
54
- data = response.parsed_response
55
-
56
- if response.success?
57
- return data if raw
58
- self.raw_data_to_object(data)
59
- else
60
- raise WriterException.new(data['error'])
51
+ begin
52
+ Locomotive::Mounter::EngineApi.fetch(resource_name, {}, locale, attribute_names)
53
+ rescue ApiReadException => e
54
+ raise WriterException.new(e.message)
61
55
  end
62
56
  end
63
57
 
64
- # Create a resource by the API.
58
+ # Create a resource from the API.
65
59
  #
66
60
  # @param [ String ] resource_name The path to the resource (usually, the resource name)
67
- # @param [ Hash ] params The attributes of the resource
61
+ # @param [ Hash ] attributes The attributes of the resource
68
62
  # @param [ String ] locale The locale for the request
69
- # @param [ Boolean ] raw True if the result has to be converted into object.
63
+ # @param [ Boolean ] raw True if the result has to be filtered in order to keep only the attributes defined by the safe_attributes method
70
64
  #
71
65
  # @return [ Object] The response of the API or nil if an error occurs
72
66
  #
73
- def post(resource_name, params, locale = nil, raw = false)
74
- params_name = resource_name.to_s.split('/').last.singularize
75
-
76
- query = { query: { params_name => params } }
67
+ def post(resource_name, attributes, locale = nil, dont_filter_attributes = false)
68
+ attribute_names = dont_filter_attributes ? nil : self.safe_attributes
77
69
 
78
- query[:query][:locale] = locale if locale
79
-
80
- response = Locomotive::Mounter::EngineApi.post("/#{resource_name}.json", query)
81
- data = response.parsed_response
82
-
83
- if response.success?
84
- return data if raw
85
- self.raw_data_to_object(data)
86
- else
87
- message = data
88
-
89
- message = data.map do |attribute, errors|
70
+ begin
71
+ Locomotive::Mounter::EngineApi.create(resource_name, attributes, locale, attribute_names)
72
+ rescue ApiWriteException => e
73
+ message = e.message
74
+ message = message.map do |attribute, errors|
90
75
  " #{attribute} => #{[*errors].join(', ')}\n".colorize(color: :red)
91
- end.join("\n") if data.respond_to?(:keys)
76
+ end.join("\n") if message.respond_to?(:keys)
92
77
 
93
78
  raise WriterException.new(message)
94
-
95
- # self.log "\n"
96
- # data.each do |attribute, errors|
97
- # self.log " #{attribute} => #{[*errors].join(', ')}\n".colorize(color: :red)
98
- # end if data.respond_to?(:keys)
99
- # nil # DEBUG
100
79
  end
101
80
  end
102
81
 
103
- # Update a resource by the API.
82
+ # Update a resource from the API.
104
83
  #
105
84
  # @param [ String ] resource_name The path to the resource (usually, the resource name)
106
- # @param [ String ] id The unique identifier of the resource
85
+ # @param [ Hash ] attributes The attributes of the resource
107
86
  # @param [ Hash ] params The attributes of the resource
108
87
  # @param [ String ] locale The locale for the request
109
88
  #
110
- # @return [ Object] The response of the API or nil if an error occurs
89
+ # @return [ Object] The response of the API
111
90
  #
112
- def put(resource_name, id, params, locale = nil)
113
- params_name = resource_name.to_s.split('/').last.singularize
114
-
115
- query = { query: { params_name => params } }
116
-
117
- query[:query][:locale] = locale if locale
118
-
119
- response = Locomotive::Mounter::EngineApi.put("/#{resource_name}/#{id}.json", query)
120
- data = response.parsed_response
121
-
122
- if response.success?
123
- self.raw_data_to_object(data)
124
- else
125
- message = data
126
-
127
- message = data.map do |attribute, errors|
128
- " #{attribute} => #{[*errors].join(', ')}" #.colorize(color: :red)
129
- end.join("\n") if data.respond_to?(:keys)
91
+ def put(resource_name, id, attributes, locale = nil)
92
+ begin
93
+ Locomotive::Mounter::EngineApi.update(resource_name, id, attributes, locale, self.safe_attributes)
94
+ rescue ApiWriteException => e
95
+ message = e.message
96
+ message = message.map do |attribute, errors|
97
+ " #{attribute} => #{[*errors].join(', ')}\n".colorize(color: :red)
98
+ end.join("\n") if message.respond_to?(:keys)
130
99
 
131
100
  raise WriterException.new(message)
132
101
 
102
+ # self.log "\n"
133
103
  # data.each do |attribute, errors|
134
- # self.log "\t\t #{attribute} => #{[*errors].join(', ')}".colorize(color: :red)
104
+ # self.log " #{attribute} => #{[*errors].join(', ')}\n".colorize(color: :red)
135
105
  # end if data.respond_to?(:keys)
136
106
  # nil # DEBUG
137
107
  end
@@ -194,28 +164,9 @@ module Locomotive
194
164
  response ? :success : :error
195
165
  end
196
166
 
197
- # Convert raw data into the corresponding object (Page, Site, ...etc)
198
- #
199
- # @param [ Hash ] data The attributes of the object
200
- #
201
- # @return [ Object ] A new instance of the object
202
- #
203
- def raw_data_to_object(data)
204
- case data
205
- when Hash then data.to_hash.delete_if { |k, _| !self.safe_attributes.include?(k) }
206
- when Array
207
- data.map do |row|
208
- # puts "#{row.inspect}\n---" # DEBUG
209
- row.delete_if { |k, _| !self.safe_attributes.include?(k) }
210
- end
211
- else
212
- data
213
- end
214
- end
215
-
216
167
  end
217
168
 
218
169
  end
219
170
  end
220
171
  end
221
- end
172
+ end
@@ -22,7 +22,9 @@ module Locomotive
22
22
 
23
23
  # assign an _id to a local content entry if possible
24
24
  self.content_types.each do |slug, content_type|
25
- self.get("content_types/#{slug}/entries", nil, true).each do |attributes|
25
+ entries = self.get("content_types/#{slug}/entries", nil, true)
26
+
27
+ entries.each do |attributes|
26
28
  content_entry = content_type.find_entry(attributes['_slug'])
27
29
 
28
30
  if content_entry
@@ -222,4 +224,4 @@ module Locomotive
222
224
  end
223
225
  end
224
226
  end
225
- end
227
+ end
@@ -25,7 +25,9 @@ module Locomotive
25
25
 
26
26
  # set the unique identifier to each local page
27
27
  self.get(:pages, nil, true).each do |attributes|
28
- page = self.pages[attributes['fullpath'].dasherize]
28
+ page = self.pages.values.find do |_page|
29
+ _page.safe_fullpath(false) == attributes['fullpath'].dasherize
30
+ end
29
31
 
30
32
  self.remote_translations[attributes['fullpath']] = attributes['translated_in']
31
33
 
@@ -46,8 +48,12 @@ module Locomotive
46
48
  self.output_locale
47
49
 
48
50
  done, attempts = {}, 0
51
+
52
+ # begin by the layouts (pages inside the layouts folder)
53
+ _write_layouts(pages, done)
54
+
49
55
  while done.size < pages.length - 1 && attempts < MAX_ATTEMPTS
50
- _write(pages['index'], done, done.size > 0)
56
+ _write(pages['index'], done, attempts > 0)
51
57
 
52
58
  # keep track of the attempts because we don't want to get an infinite loop.
53
59
  attempts += 1
@@ -63,7 +69,22 @@ module Locomotive
63
69
 
64
70
  protected
65
71
 
66
- def _write(page, done, already_done = false)
72
+ def _write_layouts(pages, done)
73
+ if pages['layouts']
74
+ _write(pages['layouts'], done, false, false)
75
+
76
+ layouts = pages.values.find_all { |page| page.fullpath =~ /^layouts\// }
77
+
78
+ # make sure the templates without the extends tag are first in the list
79
+ layouts.sort! { |a, b| (a.extends_template? ? 1 : 0) <=> (b.extends_template? ? 1 : 0) }
80
+
81
+ layouts.each do |page|
82
+ _write(page, done, false, false)
83
+ end
84
+ end
85
+ end
86
+
87
+ def _write(page, done, already_done = false, with_children = true)
67
88
  if self.safely_translated?(page)
68
89
  write_page(page) unless already_done
69
90
  else
@@ -75,12 +96,14 @@ module Locomotive
75
96
  done[page.fullpath] = true
76
97
 
77
98
  # loop over its children
78
- (page.children || []).sort_by(&:depth_and_position).each do |child|
79
- layout = child.layout
80
- layout = page.fullpath if layout && layout == 'parent'
99
+ if with_children
100
+ (page.children || []).sort_by(&:depth_and_position).each do |child|
101
+ template_fullpath = child.template_fullpath
102
+ template_fullpath = page.fullpath if template_fullpath && template_fullpath == 'parent'
81
103
 
82
- if done[child.fullpath].nil? && (!layout || done[layout])
83
- _write(child, done)
104
+ if done[child.fullpath].nil? && (!template_fullpath || done[template_fullpath])
105
+ _write(child, done)
106
+ end
84
107
  end
85
108
  end
86
109
  end
@@ -153,40 +176,6 @@ module Locomotive
153
176
  self.mounting_point.pages
154
177
  end
155
178
 
156
- # # Return the pages which are layouts for others.
157
- # # They are sorted by the depth.
158
- # #
159
- # # @return [ Array ] The list of layouts
160
- # #
161
- # def layouts
162
- # self.pages.values.find_all do |page|
163
- # self.safely_translated?(page) && self.is_layout?(page)
164
- # end.sort { |a, b| a.depth <=> b.depth }
165
- # end
166
-
167
- # # Return the pages wich are not layouts for others.
168
- # # They are sorted by both the depth and the position.
169
- # #
170
- # # @return [ Array ] The list of non-layout pages
171
- # #
172
- # def other_than_layouts
173
- # list = (self.pages.values - self.layouts)
174
-
175
- # # get only the translated ones in the current locale
176
- # list.delete_if do |page|
177
- # # if (!page.parent.nil? && !page.translated_in?(self.mounting_point.default_locale)) ||
178
- # # !page.translated_in?(Locomotive::Mounter.locale)
179
- # if !self.safely_translated?(page)
180
- # self.output_resource_op page
181
- # self.output_resource_op_status page, :not_translated
182
- # true
183
- # end
184
- # end
185
-
186
- # # sort them
187
- # list.sort { |a, b| a.depth_and_position <=> b.depth_and_position }
188
- # end
189
-
190
179
  # Tell if the page passed in parameter has already been
191
180
  # translated on the remote engine for the locale passed
192
181
  # as the second parameter.
@@ -218,27 +207,6 @@ module Locomotive
218
207
  end
219
208
  end
220
209
 
221
- # # Tell if the page is a real layout, which means no extends tag inside
222
- # # and that at least one of the other pages reference it as a parent template.
223
- # #
224
- # # @param [ Object ] page The page
225
- # #
226
- # # @return [ Boolean] True if it is a real layout.
227
- # #
228
- # def is_layout?(page)
229
- # if page.is_layout?
230
- # # has child(ren) extending the page itself ?
231
- # return true if (page.children || []).any? { |child| child.layout == 'parent' }
232
-
233
- # fullpath = page.fullpath_in_default_locale
234
-
235
- # # among all the pages, is there a page extending the page itself ?
236
- # self.pages.values.any? { |_page| _page.fullpath_in_default_locale != fullpath && _page.layout == fullpath }
237
- # else
238
- # false # extends not present
239
- # end
240
- # end
241
-
242
210
  # Return the parameters of a page sent by the API.
243
211
  # It includes the editable_elements if the data option is enabled or
244
212
  # if the page is a new one.
@@ -263,7 +231,7 @@ module Locomotive
263
231
  (params[:editable_elements] || []).each do |element|
264
232
  if element[:content] =~ /^\/samples\//
265
233
  element[:source] = self.path_to_file(element.delete(:content))
266
- elsif element[:content] =~ %r($http://)
234
+ elsif element[:content] =~ %r(^http://)
267
235
  element[:source_url] = element.delete(:content)
268
236
  else
269
237
  # string / text elements
@@ -278,4 +246,4 @@ module Locomotive
278
246
  end
279
247
  end
280
248
  end
281
- end
249
+ end
@@ -84,7 +84,7 @@ module Locomotive
84
84
  self.site._id = _site['id']
85
85
  end
86
86
  end
87
- rescue WriterException => e
87
+ rescue WriterException, ApiReadException => e
88
88
  nil
89
89
  end
90
90
  end
@@ -122,4 +122,4 @@ module Locomotive
122
122
  end
123
123
  end
124
124
  end
125
- end
125
+ end
@@ -191,11 +191,11 @@ module Locomotive
191
191
  end
192
192
 
193
193
  def sprockets
194
- Locomotive::Mounter::Extensions::Sprockets.environment(self.mounting_point.path)
194
+ Locomotive::Mounter::Extensions::Sprockets.environment(self.mounting_point.path, true)
195
195
  end
196
196
 
197
197
  end
198
198
  end
199
199
  end
200
200
  end
201
- end
201
+ end
@@ -34,7 +34,7 @@ Gem::Specification.new do |s|
34
34
  s.add_dependency 'tzinfo', '~> 0.3.29'
35
35
  s.add_dependency 'chronic', '~> 0.10.2'
36
36
 
37
- s.add_dependency 'activesupport', '~> 3.2.18'
37
+ s.add_dependency 'activesupport', '~> 3.2.21'
38
38
  s.add_dependency 'i18n', '~> 0.6.11'
39
39
  s.add_dependency 'stringex', '~> 2.0.3'
40
40
 
@@ -52,9 +52,10 @@ Gem::Specification.new do |s|
52
52
  s.add_development_dependency 'rack-test', '~> 0.6.1'
53
53
  s.add_development_dependency 'ruby-debug-wrapper', '~> 0.0.1'
54
54
  s.add_development_dependency 'vcr', '2.4.0'
55
- s.add_development_dependency 'therubyracer', '~> 0.11.4'
55
+ s.add_development_dependency 'therubyracer', '~> 0.12.1'
56
56
  # s.add_development_dependency 'fakeweb'
57
57
  s.add_development_dependency 'webmock', '1.9.3'
58
+ s.add_development_dependency 'libv8', '3.16.14.3'
58
59
  # s.add_development_dependency 'bson'
59
60
  # s.add_development_dependency 'bson_ext'
60
61
  # s.add_development_dependency 'typhoeus', '0.5.0'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: locomotivecms_mounter
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.4
4
+ version: 1.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Didier Lafforgue
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-09-22 00:00:00.000000000 Z
11
+ date: 2014-11-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: tilt
@@ -176,14 +176,14 @@ dependencies:
176
176
  requirements:
177
177
  - - "~>"
178
178
  - !ruby/object:Gem::Version
179
- version: 3.2.18
179
+ version: 3.2.21
180
180
  type: :runtime
181
181
  prerelease: false
182
182
  version_requirements: !ruby/object:Gem::Requirement
183
183
  requirements:
184
184
  - - "~>"
185
185
  - !ruby/object:Gem::Version
186
- version: 3.2.18
186
+ version: 3.2.21
187
187
  - !ruby/object:Gem::Dependency
188
188
  name: i18n
189
189
  requirement: !ruby/object:Gem::Requirement
@@ -386,14 +386,14 @@ dependencies:
386
386
  requirements:
387
387
  - - "~>"
388
388
  - !ruby/object:Gem::Version
389
- version: 0.11.4
389
+ version: 0.12.1
390
390
  type: :development
391
391
  prerelease: false
392
392
  version_requirements: !ruby/object:Gem::Requirement
393
393
  requirements:
394
394
  - - "~>"
395
395
  - !ruby/object:Gem::Version
396
- version: 0.11.4
396
+ version: 0.12.1
397
397
  - !ruby/object:Gem::Dependency
398
398
  name: webmock
399
399
  requirement: !ruby/object:Gem::Requirement
@@ -408,6 +408,20 @@ dependencies:
408
408
  - - '='
409
409
  - !ruby/object:Gem::Version
410
410
  version: 1.9.3
411
+ - !ruby/object:Gem::Dependency
412
+ name: libv8
413
+ requirement: !ruby/object:Gem::Requirement
414
+ requirements:
415
+ - - '='
416
+ - !ruby/object:Gem::Version
417
+ version: 3.16.14.3
418
+ type: :development
419
+ prerelease: false
420
+ version_requirements: !ruby/object:Gem::Requirement
421
+ requirements:
422
+ - - '='
423
+ - !ruby/object:Gem::Version
424
+ version: 3.16.14.3
411
425
  description: Mount any LocomotiveCMS site, from a template on the filesystem, a zip
412
426
  file or even an online engine
413
427
  email: