locomotivecms_mounter 1.2.5 → 1.2.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/locomotive/mounter/extensions/compass.rb +2 -1
- data/lib/locomotive/mounter/extensions/sprockets.rb +30 -0
- data/lib/locomotive/mounter/models/content_entry.rb +23 -2
- data/lib/locomotive/mounter/models/page.rb +14 -4
- data/lib/locomotive/mounter/models/theme_asset.rb +19 -6
- data/lib/locomotive/mounter/mounting_point.rb +12 -0
- data/lib/locomotive/mounter/reader/file_system/theme_assets_reader.rb +1 -1
- data/lib/locomotive/mounter/version.rb +1 -1
- data/lib/locomotive/mounter/writer/api/base.rb +1 -1
- data/lib/locomotive/mounter/writer/api/theme_assets_writer.rb +32 -4
- data/lib/locomotive/mounter.rb +3 -0
- metadata +32 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 301a98697d9128b4ec05baa581691f173f0e081b
|
4
|
+
data.tar.gz: d969e10e742d09b6e9b8d14a9d2e6131b6651ddd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 95d709f4fdb958ca747c0a8fbeb96111f555acb534e9ddf240a72b9ac0cde7b5f6776ebdd63ccf021e347c8eb246c9fed4ec3be47f109922ca533ad90748c46e
|
7
|
+
data.tar.gz: 1832c1335bea29613ebefc00b188b843b823bd50912599e39981b6b54a7e080a8b713fff2364b049f765bafe58e14621f73c672fe4e59ae0343b4621e3ae82e7
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module Locomotive
|
2
|
+
module Mounter
|
3
|
+
module Extensions
|
4
|
+
|
5
|
+
module Sprockets
|
6
|
+
|
7
|
+
@@env = @@path = nil
|
8
|
+
|
9
|
+
# Build a Sprocket environment for the current site.
|
10
|
+
# This method returns an unique environment for each call
|
11
|
+
# unless the site_path changed.
|
12
|
+
#
|
13
|
+
# @param [ String ] site_path The root directory of the site
|
14
|
+
#
|
15
|
+
def self.environment(site_path)
|
16
|
+
return @@env if @@env && @@path == site_path
|
17
|
+
|
18
|
+
@@path = site_path
|
19
|
+
@@env = ::Sprockets::Environment.new.tap do |env|
|
20
|
+
%w(fonts stylesheets javascripts).each do |name|
|
21
|
+
env.append_path File.join(site_path, 'public', name)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -102,7 +102,7 @@ module Locomotive
|
|
102
102
|
#
|
103
103
|
def is_dynamic_field?(name)
|
104
104
|
name = name.to_s.gsub(/\=$/, '').to_sym
|
105
|
-
!self.content_type.find_field
|
105
|
+
!self.content_type.try(:find_field, name).nil?
|
106
106
|
end
|
107
107
|
|
108
108
|
# Return the value of a dynamic field and cast it depending
|
@@ -117,7 +117,7 @@ module Locomotive
|
|
117
117
|
value = self.localized_dynamic_attribute_value(field)
|
118
118
|
|
119
119
|
case field.type
|
120
|
-
when :date
|
120
|
+
when :date, :date_time
|
121
121
|
value.is_a?(String) ? Chronic.parse(value) : value
|
122
122
|
when :file
|
123
123
|
value.present? ? { 'url' => value } : nil
|
@@ -158,6 +158,27 @@ module Locomotive
|
|
158
158
|
end
|
159
159
|
end
|
160
160
|
|
161
|
+
# We also have to deal with dynamic attributes so that
|
162
|
+
# it does not raise an exception when calling the attributes=
|
163
|
+
# method.
|
164
|
+
#
|
165
|
+
# @param [ Hash ] attributes The new attributes
|
166
|
+
#
|
167
|
+
def write_attributes(attributes)
|
168
|
+
_attributes = attributes.select do |name, value|
|
169
|
+
if self.is_dynamic_field?(name)
|
170
|
+
self.dynamic_setter(name, value)
|
171
|
+
false
|
172
|
+
else
|
173
|
+
true
|
174
|
+
end
|
175
|
+
end
|
176
|
+
|
177
|
+
super(_attributes)
|
178
|
+
end
|
179
|
+
|
180
|
+
alias :attributes= :write_attributes
|
181
|
+
|
161
182
|
# The magic of dynamic fields happens within this method.
|
162
183
|
# It calls the getter/setter of a dynamic field if it is one of them.
|
163
184
|
def method_missing(name, *args, &block)
|
@@ -29,7 +29,7 @@ module Locomotive
|
|
29
29
|
field :editable_elements, type: :array, class_name: 'Locomotive::Mounter::Models::EditableElement'
|
30
30
|
|
31
31
|
## other accessors ##
|
32
|
-
attr_accessor :content_type_id, :content_entry, :parent_id, :children
|
32
|
+
attr_accessor :content_type_id, :content_entry, :parent_id, :children, :templatized_from_parent
|
33
33
|
|
34
34
|
## aliases ##
|
35
35
|
alias :listed? :listed
|
@@ -64,7 +64,7 @@ module Locomotive
|
|
64
64
|
self.slug
|
65
65
|
else
|
66
66
|
base = self.parent.safe_fullpath
|
67
|
-
_slug = if self.templatized?
|
67
|
+
_slug = if self.templatized? && !self.templatized_from_parent
|
68
68
|
'*'
|
69
69
|
elsif !self.translated_in?(Locomotive::Mounter.locale)
|
70
70
|
self.slug_translations[self.mounting_point.default_locale]
|
@@ -180,7 +180,8 @@ module Locomotive
|
|
180
180
|
!self.redirect_url.blank?
|
181
181
|
end
|
182
182
|
|
183
|
-
# Add a child to the page. It also sets the parent of the child
|
183
|
+
# Add a child to the page. It also sets the parent of the child.
|
184
|
+
# If the parent page is a templatized one, give the same properties to the child.
|
184
185
|
#
|
185
186
|
# @param [ Object ] page The child page
|
186
187
|
#
|
@@ -189,6 +190,15 @@ module Locomotive
|
|
189
190
|
def add_child(page)
|
190
191
|
page.parent = self
|
191
192
|
|
193
|
+
if self.templatized?
|
194
|
+
page.templatized_from_parent = true
|
195
|
+
|
196
|
+
# copy properties from the parent
|
197
|
+
%w(templatized content_type content_type_id).each do |name|
|
198
|
+
page.send(:"#{name}=", self.send(name.to_sym))
|
199
|
+
end
|
200
|
+
end
|
201
|
+
|
192
202
|
(self.children ||= []) << page
|
193
203
|
|
194
204
|
self.children.sort! { |a, b| (a.position || 999) <=> (b.position || 999) }
|
@@ -333,7 +343,7 @@ module Locomotive
|
|
333
343
|
_attributes.delete('redirect_type') if self.redirect_url.blank?
|
334
344
|
|
335
345
|
# templatized page
|
336
|
-
_attributes['content_type'] = self.content_type.slug if self.templatized?
|
346
|
+
_attributes['content_type'] = self.content_type.slug if self.templatized? && !self.templatized_from_parent
|
337
347
|
|
338
348
|
# editable elements
|
339
349
|
_attributes['editable_elements'] = {}
|
@@ -4,11 +4,13 @@ module Locomotive
|
|
4
4
|
|
5
5
|
class ThemeAsset < Base
|
6
6
|
|
7
|
-
PRECOMPILED_CSS_TYPES
|
7
|
+
PRECOMPILED_CSS_TYPES = %w(sass scss less)
|
8
8
|
|
9
|
-
PRECOMPILED_JS_TYPES
|
9
|
+
PRECOMPILED_JS_TYPES = %w(coffee)
|
10
10
|
|
11
|
-
PRECOMPILED_FILE_TYPES
|
11
|
+
PRECOMPILED_FILE_TYPES = PRECOMPILED_CSS_TYPES + PRECOMPILED_JS_TYPES
|
12
|
+
|
13
|
+
CSS_JS_SHORT_PATH_REGEXP = /^(javascripts|stylesheets|fonts)\/(.*)$/
|
12
14
|
|
13
15
|
## fields ##
|
14
16
|
field :folder
|
@@ -42,6 +44,17 @@ module Locomotive
|
|
42
44
|
File.join(self.folder, self.filename)
|
43
45
|
end
|
44
46
|
|
47
|
+
# Return the path without the leading javascripts, stylesheets, fonts
|
48
|
+
# font. This is needed by Sprockets.
|
49
|
+
# Only relevant for javascripts / stylesshets files.
|
50
|
+
#
|
51
|
+
# @return [ String ] The path of the asset without the first folder
|
52
|
+
#
|
53
|
+
def short_path
|
54
|
+
self.path =~ /^(javascripts|stylesheets|fonts)\/(.*)$/
|
55
|
+
$2
|
56
|
+
end
|
57
|
+
|
45
58
|
# Return the mime type of the file based on the Mime::Types lib.
|
46
59
|
#
|
47
60
|
# @return [ String ] The mime type of the file or nil if unknown.
|
@@ -99,9 +112,9 @@ module Locomotive
|
|
99
112
|
|
100
113
|
if self.uri
|
101
114
|
@raw = HTTParty.get(self.uri.to_s).body
|
102
|
-
elsif self.precompiled?
|
103
|
-
template = Tilt.new(self.filepath)
|
104
|
-
@raw = template.render
|
115
|
+
# elsif self.precompiled?
|
116
|
+
# template = Tilt.new(self.filepath)
|
117
|
+
# @raw = template.render
|
105
118
|
else
|
106
119
|
@raw = File.read(self.filepath)
|
107
120
|
end
|
@@ -5,6 +5,18 @@ module Locomotive
|
|
5
5
|
|
6
6
|
attr_accessor :resources, :root_page, :path
|
7
7
|
|
8
|
+
# attr_reader :sprockets
|
9
|
+
|
10
|
+
# Initializes Sprockets once the path is set
|
11
|
+
def path= dir
|
12
|
+
@path = dir
|
13
|
+
|
14
|
+
# @sprockets = Locomotive::Mounter::Extensions::Sprockets.environment
|
15
|
+
# %w(fonts stylesheets javascripts).each do |name|
|
16
|
+
# @sprockets.append_path File.join(dir, 'public', name)
|
17
|
+
# end
|
18
|
+
end
|
19
|
+
|
8
20
|
# Return all the locales defined by the site related to that mounting point.
|
9
21
|
#
|
10
22
|
# @return [ Array ] The list of the locales
|
@@ -43,7 +43,7 @@ module Locomotive
|
|
43
43
|
Dir.glob(File.join(self.root_dir, '**/*')).each do |file|
|
44
44
|
next if self.exclude?(file)
|
45
45
|
|
46
|
-
folder = File.dirname(file.gsub(self.root_dir, ''))
|
46
|
+
folder = File.dirname(file.gsub("#{self.root_dir}/", ''))
|
47
47
|
|
48
48
|
asset = Locomotive::Mounter::Models::ThemeAsset.new(folder: folder, filepath: file)
|
49
49
|
|
@@ -20,17 +20,22 @@ module Locomotive
|
|
20
20
|
# the assets stored in the engine have the same base url
|
21
21
|
attr_accessor :remote_base_url
|
22
22
|
|
23
|
+
# cache the compiled theme assets to avoid to perform compilation more than once
|
24
|
+
attr_accessor :cached_compiled_assets
|
25
|
+
|
23
26
|
def prepare
|
24
27
|
super
|
25
28
|
|
26
29
|
self.checksums = {}
|
27
30
|
|
31
|
+
self.cached_compiled_assets = {}
|
32
|
+
|
28
33
|
# prepare the place where the assets will be stored temporarily.
|
29
34
|
self.create_tmp_folder
|
30
35
|
|
31
36
|
# assign an _id to a local content type if possible
|
32
37
|
self.get(:theme_assets, nil, true).each do |attributes|
|
33
|
-
remote_path = File.join(
|
38
|
+
remote_path = File.join(attributes['folder'], File.basename(attributes['local_path']))
|
34
39
|
|
35
40
|
if theme_asset = self.theme_assets[remote_path]
|
36
41
|
theme_asset._id = attributes['id']
|
@@ -114,7 +119,7 @@ module Locomotive
|
|
114
119
|
FileUtils.mkdir_p(File.dirname(path))
|
115
120
|
|
116
121
|
File.open(path, 'w') do |file|
|
117
|
-
file.write(theme_asset
|
122
|
+
file.write(self.content_of(theme_asset))
|
118
123
|
end
|
119
124
|
|
120
125
|
File.new(path)
|
@@ -150,11 +155,11 @@ module Locomotive
|
|
150
155
|
# @return [ Boolean ] True if the checksums of the local and remote files are different.
|
151
156
|
#
|
152
157
|
def theme_asset_changed?(theme_asset)
|
153
|
-
content = theme_asset
|
158
|
+
content = self.content_of(theme_asset)
|
154
159
|
|
155
160
|
if theme_asset.stylesheet_or_javascript?
|
156
161
|
# we need to compare compiled contents (sass, coffeescript) with the right urls inside
|
157
|
-
content = content.gsub(/[("'](\/(stylesheets|javascripts|images|media|others)\/(([^;.]+)\/)*([a-zA-Z_\-0-9]+)\.[a-z]{2,3})[)"']/) do |path|
|
162
|
+
content = content.gsub(/[("'](\/(stylesheets|javascripts|fonts|images|media|others)\/(([^;.]+)\/)*([a-zA-Z_\-0-9]+)\.[a-z]{2,3})[)"']/) do |path|
|
158
163
|
sanitized_path = path.gsub(/[("')]/, '').gsub(/^\//, '')
|
159
164
|
sanitized_path = File.join(self.remote_base_url, sanitized_path)
|
160
165
|
|
@@ -166,6 +171,29 @@ module Locomotive
|
|
166
171
|
Digest::MD5.hexdigest(content) != self.checksums[theme_asset._id]
|
167
172
|
end
|
168
173
|
|
174
|
+
# Return the content of a theme asset.
|
175
|
+
# If the theme asset is either a stylesheet or javascript file,
|
176
|
+
# it uses Sprockets to compile it.
|
177
|
+
# Otherwise, it returns the raw content of the asset.
|
178
|
+
#
|
179
|
+
# @return [ String ] The content of the theme asset
|
180
|
+
#
|
181
|
+
def content_of(theme_asset)
|
182
|
+
if theme_asset.stylesheet_or_javascript?
|
183
|
+
if self.cached_compiled_assets[theme_asset.path].nil?
|
184
|
+
self.cached_compiled_assets[theme_asset.path] = self.sprockets[theme_asset.short_path].to_s
|
185
|
+
end
|
186
|
+
|
187
|
+
self.cached_compiled_assets[theme_asset.path]
|
188
|
+
else
|
189
|
+
theme_asset.content
|
190
|
+
end
|
191
|
+
end
|
192
|
+
|
193
|
+
def sprockets
|
194
|
+
Locomotive::Mounter::Extensions::Sprockets.environment(self.mounting_point.path)
|
195
|
+
end
|
196
|
+
|
169
197
|
end
|
170
198
|
end
|
171
199
|
end
|
data/lib/locomotive/mounter.rb
CHANGED
@@ -14,6 +14,8 @@ require 'digest/sha1'
|
|
14
14
|
require 'chronic'
|
15
15
|
|
16
16
|
require 'tilt'
|
17
|
+
require 'sprockets'
|
18
|
+
require 'sprockets-sass'
|
17
19
|
require 'haml'
|
18
20
|
require 'compass'
|
19
21
|
|
@@ -36,6 +38,7 @@ require 'locomotive/mounter/engine_api'
|
|
36
38
|
|
37
39
|
# Extensions
|
38
40
|
require 'locomotive/mounter/extensions/httmultiparty'
|
41
|
+
require 'locomotive/mounter/extensions/sprockets'
|
39
42
|
require 'locomotive/mounter/extensions/compass'
|
40
43
|
require 'locomotive/mounter/extensions/tilt/template'
|
41
44
|
require 'locomotive/mounter/extensions/tilt/css'
|
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.2.
|
4
|
+
version: 1.2.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Didier Lafforgue
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-
|
11
|
+
date: 2013-09-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: tilt
|
@@ -24,6 +24,34 @@ dependencies:
|
|
24
24
|
- - '='
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: 1.3.3
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: sprockets
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '2.0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '2.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: sprockets-sass
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
27
55
|
- !ruby/object:Gem::Dependency
|
28
56
|
name: haml
|
29
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -387,6 +415,7 @@ files:
|
|
387
415
|
- lib/locomotive/mounter/exceptions.rb
|
388
416
|
- lib/locomotive/mounter/extensions/compass.rb
|
389
417
|
- lib/locomotive/mounter/extensions/httmultiparty.rb
|
418
|
+
- lib/locomotive/mounter/extensions/sprockets.rb
|
390
419
|
- lib/locomotive/mounter/extensions/tilt/css.rb
|
391
420
|
- lib/locomotive/mounter/extensions/tilt/haml.rb
|
392
421
|
- lib/locomotive/mounter/extensions/tilt/liquid.rb
|
@@ -472,7 +501,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
472
501
|
version: 1.3.6
|
473
502
|
requirements: []
|
474
503
|
rubyforge_project: locomotivecms_mounter
|
475
|
-
rubygems_version: 2.0.
|
504
|
+
rubygems_version: 2.0.7
|
476
505
|
signing_key:
|
477
506
|
specification_version: 4
|
478
507
|
summary: LocomotiveCMS Mounter
|