locomotivecms_steam 1.0.0.pre.alpha → 1.0.0.pre.alpha.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +1 -1
- data/Gemfile.lock +49 -34
- data/bin/steam.rb +1 -1
- data/lib/locomotive/steam.rb +8 -6
- data/lib/locomotive/steam/adapters/filesystem/simple_cache_store.rb +4 -0
- data/lib/locomotive/steam/adapters/filesystem/yaml_loaders/content_type.rb +1 -1
- data/lib/locomotive/steam/adapters/filesystem/yaml_loaders/page.rb +32 -10
- data/lib/locomotive/steam/adapters/filesystem/yaml_loaders/theme_asset.rb +31 -1
- data/lib/locomotive/steam/decorators/i18n_decorator.rb +1 -1
- data/lib/locomotive/steam/decorators/template_decorator.rb +1 -0
- data/lib/locomotive/steam/entities/content_entry.rb +9 -1
- data/lib/locomotive/steam/entities/content_type_field.rb +4 -0
- data/lib/locomotive/steam/entities/theme_asset.rb +8 -0
- data/lib/locomotive/steam/initializers/sprockets.rb +49 -0
- data/lib/locomotive/steam/liquid/filters/base.rb +5 -6
- data/lib/locomotive/steam/liquid/tags/editable/base.rb +4 -5
- data/lib/locomotive/steam/liquid/tags/extends.rb +1 -36
- data/lib/locomotive/steam/liquid/tags/inherited_block.rb +10 -4
- data/lib/locomotive/steam/liquid/tags/snippet.rb +8 -9
- data/lib/locomotive/steam/middlewares/dynamic_assets.rb +6 -36
- data/lib/locomotive/steam/middlewares/helpers.rb +9 -2
- data/lib/locomotive/steam/middlewares/site.rb +10 -2
- data/lib/locomotive/steam/models/associations/embedded.rb +1 -1
- data/lib/locomotive/steam/models/mapper.rb +2 -1
- data/lib/locomotive/steam/repositories.rb +1 -1
- data/lib/locomotive/steam/repositories/content_type_field_repository.rb +8 -0
- data/lib/locomotive/steam/repositories/theme_asset_repository.rb +1 -1
- data/lib/locomotive/steam/server.rb +0 -1
- data/lib/locomotive/steam/services.rb +7 -3
- data/lib/locomotive/steam/services/asset_host_service.rb +1 -3
- data/lib/locomotive/steam/services/image_resizer_service.rb +1 -3
- data/lib/locomotive/steam/services/liquid_parser_service.rb +1 -2
- data/lib/locomotive/steam/services/url_builder_service.rb +18 -1
- data/lib/locomotive/steam/version.rb +1 -1
- data/locomotivecms_steam.gemspec +9 -11
- data/spec/integration/repositories/theme_asset_repository_spec.rb +10 -0
- data/spec/support/helpers.rb +1 -0
- data/spec/support/liquid.rb +5 -0
- data/spec/unit/adapters/filesystem/simple_cache_store_spec.rb +27 -0
- data/spec/unit/adapters/filesystem/yaml_loaders/page_spec.rb +2 -0
- data/spec/unit/decorators/i18n_decorator_spec.rb +10 -0
- data/spec/unit/entities/content_entry_spec.rb +2 -2
- data/spec/unit/entities/content_type_field_spec.rb +15 -5
- data/spec/unit/entities/snippet_spec.rb +17 -0
- data/spec/unit/initializers/sprockets_spec.rb +25 -0
- data/spec/unit/liquid/drops/content_entry_collection_spec.rb +2 -0
- data/spec/unit/liquid/filters/html_spec.rb +28 -37
- data/spec/unit/liquid/tags/editable/control_spec.rb +4 -3
- data/spec/unit/liquid/tags/editable/file_spec.rb +7 -4
- data/spec/unit/liquid/tags/editable/text_spec.rb +4 -6
- data/spec/unit/liquid/tags/extends_spec.rb +3 -3
- data/spec/unit/liquid/tags/inherited_block_spec.rb +2 -2
- data/spec/unit/liquid/tags/nav_spec.rb +2 -2
- data/spec/unit/liquid/tags/snippet_spec.rb +3 -3
- data/spec/unit/middlewares/dynamic_assets_spec.rb +18 -9
- data/spec/unit/repositories/content_type_field_repository_spec.rb +51 -0
- data/spec/unit/services/url_builder_service_spec.rb +20 -3
- metadata +39 -56
- data/lib/locomotive/steam/core_ext.rb +0 -6
- data/lib/locomotive/steam/core_ext/array.rb +0 -3
- data/lib/locomotive/steam/core_ext/boolean/false.rb +0 -3
- data/lib/locomotive/steam/core_ext/boolean/true.rb +0 -3
- data/lib/locomotive/steam/core_ext/hash.rb +0 -39
- data/lib/locomotive/steam/core_ext/kernel.rb +0 -14
- data/lib/locomotive/steam/core_ext/string.rb +0 -37
- data/spec/fixtures/default/app/views/pages/songs.liquid +0 -6
- data/spec/unit/core_ext/string_spec.rb +0 -44
@@ -1,4 +1,53 @@
|
|
1
1
|
require 'sprockets'
|
2
2
|
require 'sprockets-sass'
|
3
|
+
require 'sprockets-less'
|
4
|
+
require 'coffee_script'
|
5
|
+
require 'compass'
|
3
6
|
|
4
7
|
Sprockets::Sass.add_sass_functions = false
|
8
|
+
|
9
|
+
module Locomotive::Steam
|
10
|
+
|
11
|
+
class SprocketsEnvironment < ::Sprockets::Environment
|
12
|
+
|
13
|
+
def initialize(root, options = {})
|
14
|
+
super(root)
|
15
|
+
|
16
|
+
@steam_path = root
|
17
|
+
|
18
|
+
append_steam_paths
|
19
|
+
|
20
|
+
install_yui_compressor(options)
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
def append_steam_paths
|
26
|
+
%w(fonts stylesheets javascripts).each do |name|
|
27
|
+
append_path File.join(@steam_path, name)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def install_yui_compressor(options)
|
32
|
+
return unless options[:minify]
|
33
|
+
|
34
|
+
require 'yui/compressor'
|
35
|
+
|
36
|
+
if is_java_installed?
|
37
|
+
# minify javascripts and stylesheets
|
38
|
+
self.js_compressor = YUI::JavaScriptCompressor.new
|
39
|
+
self.css_compressor = YUI::CssCompressor.new
|
40
|
+
else
|
41
|
+
message = "[Important] YUICompressor requires java to be installed. The JAVA_HOME variable should also be set.\n"
|
42
|
+
Locomotive::Common::Logger.warn message.red
|
43
|
+
false
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def is_java_installed?
|
48
|
+
`which java` != '' && (!ENV['JAVA_HOME'].blank? && File.exists?(ENV['JAVA_HOME']))
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
@@ -34,14 +34,13 @@ module Locomotive
|
|
34
34
|
def css_js_asset_url(input, extension, folder)
|
35
35
|
return '' if input.nil?
|
36
36
|
|
37
|
-
if input =~ /^
|
38
|
-
|
37
|
+
if input =~ /^https?:/
|
38
|
+
input
|
39
39
|
else
|
40
|
-
uri = URI(asset_url("#{folder}/#{input}"))
|
40
|
+
uri = input.starts_with?('/') ? URI(input) : URI(asset_url("#{folder}/#{input}"))
|
41
|
+
uri.path = "#{uri.path}#{extension}" unless uri.path.ends_with?(extension)
|
42
|
+
uri.to_s
|
41
43
|
end
|
42
|
-
|
43
|
-
uri.path = "#{uri.path}#{extension}" unless uri.path.ends_with?(extension)
|
44
|
-
uri.to_s
|
45
44
|
end
|
46
45
|
|
47
46
|
def asset_url(path)
|
@@ -22,10 +22,8 @@ module Locomotive
|
|
22
22
|
end
|
23
23
|
|
24
24
|
def parse(tokens)
|
25
|
-
super
|
26
|
-
|
27
|
-
if listener = options[:events_listener]
|
28
|
-
listener.emit(@tag_name.to_sym, page: options[:page], attributes: default_element_attributes)
|
25
|
+
super.tap do
|
26
|
+
ActiveSupport::Notifications.instrument("steam.parse.editable.#{@tag_name}", page: options[:page], attributes: default_element_attributes)
|
29
27
|
end
|
30
28
|
end
|
31
29
|
|
@@ -53,7 +51,8 @@ module Locomotive
|
|
53
51
|
fixed: !!@element_options[:fixed],
|
54
52
|
disabled: false,
|
55
53
|
inline_editing: true,
|
56
|
-
from_parent: false
|
54
|
+
from_parent: false,
|
55
|
+
type: @tag_name.to_sym
|
57
56
|
}
|
58
57
|
end
|
59
58
|
|
@@ -12,13 +12,10 @@ module Locomotive
|
|
12
12
|
# no need to go further if the parent does not exist
|
13
13
|
raise PageNotFound.new("Page with fullpath '#{@template_name}' was not found") if parent.nil?
|
14
14
|
|
15
|
-
|
16
|
-
listener.emit(:extends, page: options[:page], parent: parent)
|
17
|
-
end
|
15
|
+
ActiveSupport::Notifications.instrument("steam.parse.extends", page: options[:page], parent: parent)
|
18
16
|
|
19
17
|
# the source has already been parsed before
|
20
18
|
options[:parser]._parse(parent, options.merge(page: parent))
|
21
|
-
# parent.template || ::Liquid::Template.parse(parent.source, options.merge(page: parent))
|
22
19
|
end
|
23
20
|
|
24
21
|
end
|
@@ -28,35 +25,3 @@ module Locomotive
|
|
28
25
|
end
|
29
26
|
end
|
30
27
|
end
|
31
|
-
|
32
|
-
# def prepare_parsing
|
33
|
-
# super
|
34
|
-
|
35
|
-
# parent_page = @context[:parent_page]
|
36
|
-
|
37
|
-
# @context[:page].merge_editable_elements_from_page(parent_page)
|
38
|
-
|
39
|
-
# @context[:snippets] = parent_page.snippet_dependencies
|
40
|
-
# @context[:templates] = ([*parent_page.template_dependencies] + [parent_page.id]).compact
|
41
|
-
# end
|
42
|
-
|
43
|
-
# if @template_name == 'parent'
|
44
|
-
# @context[:parent_page] = @context[:cached_parent] || @context[:page].parent
|
45
|
-
# else
|
46
|
-
# locale = ::Mongoid::Fields::I18n.locale
|
47
|
-
|
48
|
-
# @context[:parent_page] = @context[:cached_pages].try(:[], @template_name) ||
|
49
|
-
# @context[:site].pages.where("fullpath.#{locale}" => @template_name).first
|
50
|
-
# end
|
51
|
-
|
52
|
-
# raise PageNotFound.new("Page with fullpath '#{@template_name}' was not found") if @context[:parent_page].nil?
|
53
|
-
|
54
|
-
# # be sure to work with a copy of the parent template otherwise there will be conflicts
|
55
|
-
# parent_template = @context[:parent_page].template.try(:clone)
|
56
|
-
|
57
|
-
# raise PageNotTranslated.new("Page with fullpath '#{@template_name}' was not translated") if parent_template.nil?
|
58
|
-
|
59
|
-
# # force the page to restore the original version of its template (from the serialized version)
|
60
|
-
# @context[:parent_page].instance_variable_set(:@template, nil)
|
61
|
-
|
62
|
-
# parent_template
|
@@ -6,9 +6,7 @@ module Locomotive
|
|
6
6
|
|
7
7
|
def parse(tokens)
|
8
8
|
super.tap do
|
9
|
-
|
10
|
-
listener.emit(:inherited_block, page: options[:page], name: @name, found_super: self.contains_super?(nodelist))
|
11
|
-
end
|
9
|
+
ActiveSupport::Notifications.instrument("steam.parse.inherited_block", page: options[:page], name: @name, found_super: self.contains_super?(nodelist))
|
12
10
|
end
|
13
11
|
end
|
14
12
|
|
@@ -18,7 +16,7 @@ module Locomotive
|
|
18
16
|
nodes.any? do |node|
|
19
17
|
if is_node_block_super?(node)
|
20
18
|
true
|
21
|
-
elsif
|
19
|
+
elsif is_node_with_nodelist?(node)
|
22
20
|
contains_super?(node.nodelist)
|
23
21
|
end
|
24
22
|
end
|
@@ -30,6 +28,14 @@ module Locomotive
|
|
30
28
|
node.raw.strip == 'block.super'
|
31
29
|
end
|
32
30
|
|
31
|
+
def is_node_with_nodelist?(node)
|
32
|
+
if node.respond_to?(:nodelist) && !node.is_a?(Locomotive::Steam::Liquid::Tags::InheritedBlock)
|
33
|
+
# some blocks does not have a body like the link_to tag
|
34
|
+
_nodelist = node.nodelist rescue nil
|
35
|
+
!_nodelist.nil?
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
33
39
|
end
|
34
40
|
|
35
41
|
::Liquid::Template.register_tag('block'.freeze, InheritedBlock)
|
@@ -6,14 +6,12 @@ module Locomotive
|
|
6
6
|
class Snippet < ::Liquid::Include
|
7
7
|
|
8
8
|
def parse(tokens)
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
options[:parser]._parse(snippet, options.merge(snippet: name))
|
16
|
-
end
|
9
|
+
ActiveSupport::Notifications.instrument("steam.parse.include", page: options[:page], name: @template_name)
|
10
|
+
|
11
|
+
# look for editable elements
|
12
|
+
name = evaluate_snippet_name
|
13
|
+
if options[:snippet_finder] && snippet = options[:snippet_finder].find(name)
|
14
|
+
options[:parser]._parse(snippet, options.merge(snippet: name))
|
17
15
|
end
|
18
16
|
end
|
19
17
|
|
@@ -35,7 +33,8 @@ module Locomotive
|
|
35
33
|
|
36
34
|
def evaluate_snippet_name(context = nil)
|
37
35
|
context.try(:evaluate, @template_name) ||
|
38
|
-
@template_name.send(:state).first
|
36
|
+
(!@template_name.is_a?(String) && @template_name.send(:state).first) ||
|
37
|
+
@template_name
|
39
38
|
end
|
40
39
|
|
41
40
|
end
|
@@ -1,56 +1,26 @@
|
|
1
|
-
require 'coffee_script'
|
2
|
-
|
3
1
|
module Locomotive::Steam
|
4
2
|
module Middlewares
|
5
3
|
|
6
4
|
class DynamicAssets
|
7
5
|
|
8
|
-
|
6
|
+
REGEXP = /^\/(javascripts|stylesheets)\/(.*)$/o
|
7
|
+
|
8
|
+
attr_reader :app, :assets
|
9
9
|
|
10
10
|
def initialize(app, options)
|
11
11
|
@app = app
|
12
|
-
@
|
13
|
-
|
14
|
-
@assets = ::Sprockets::Environment.new(options[:root]).tap do |env|
|
15
|
-
install_yui_compressor(env, options)
|
16
|
-
|
17
|
-
%w(fonts stylesheets javascripts).each do |name|
|
18
|
-
env.append_path File.join(options[:root], name)
|
19
|
-
end
|
20
|
-
end
|
12
|
+
@assets = Locomotive::Steam::SprocketsEnvironment.new(options[:root], options)
|
21
13
|
end
|
22
14
|
|
23
15
|
def call(env)
|
24
|
-
if env['PATH_INFO'] =~
|
16
|
+
if env['PATH_INFO'] =~ REGEXP
|
25
17
|
env['PATH_INFO'] = $2
|
26
|
-
|
18
|
+
assets.call(env)
|
27
19
|
else
|
28
20
|
app.call(env)
|
29
21
|
end
|
30
22
|
end
|
31
23
|
|
32
|
-
private
|
33
|
-
|
34
|
-
def install_yui_compressor(sprockets, options)
|
35
|
-
return unless options[:minify]
|
36
|
-
|
37
|
-
require 'yui/compressor'
|
38
|
-
|
39
|
-
if is_java_installed?
|
40
|
-
# minify javascripts and stylesheets
|
41
|
-
sprockets.js_compressor = YUI::JavaScriptCompressor.new
|
42
|
-
sprockets.css_compressor = YUI::CssCompressor.new
|
43
|
-
else
|
44
|
-
message = "[Important] YUICompressor requires java to be installed. The JAVA_HOME variable should also be set.\n"
|
45
|
-
Locomotive::Common::Logger.warn message.red
|
46
|
-
false
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
def is_java_installed?
|
51
|
-
`which java` != '' && (!ENV['JAVA_HOME'].blank? && File.exists?(ENV['JAVA_HOME']))
|
52
|
-
end
|
53
|
-
|
54
24
|
end
|
55
25
|
|
56
26
|
end
|
@@ -18,8 +18,11 @@ module Locomotive::Steam
|
|
18
18
|
end
|
19
19
|
|
20
20
|
def redirect_to(location, type = 301)
|
21
|
-
|
22
|
-
|
21
|
+
_location = mounted_on && (location =~ Steam::IsHTTP).nil? ? "#{mounted_on}#{location}" : location
|
22
|
+
|
23
|
+
self.log "Redirected to #{_location}".blue
|
24
|
+
|
25
|
+
@next_response = [type, { 'Content-Type' => 'text/html', 'Location' => _location }, []]
|
23
26
|
end
|
24
27
|
|
25
28
|
def modify_path(path = nil, &block)
|
@@ -34,6 +37,10 @@ module Locomotive::Steam
|
|
34
37
|
path
|
35
38
|
end
|
36
39
|
|
40
|
+
def mounted_on
|
41
|
+
request.env['steam.mounted_on']
|
42
|
+
end
|
43
|
+
|
37
44
|
def log(msg, offset = 2)
|
38
45
|
Locomotive::Common::Logger.info (' ' * offset) + msg
|
39
46
|
end
|
@@ -9,8 +9,7 @@ module Locomotive::Steam
|
|
9
9
|
include Helpers
|
10
10
|
|
11
11
|
def _call
|
12
|
-
|
13
|
-
services.repositories.current_site = site = env['steam.site']
|
12
|
+
site = find_site
|
14
13
|
|
15
14
|
# render a simple message if the service was not able to find a site
|
16
15
|
# based on the request.
|
@@ -22,6 +21,15 @@ module Locomotive::Steam
|
|
22
21
|
|
23
22
|
private
|
24
23
|
|
24
|
+
def find_site
|
25
|
+
if env['steam.site']
|
26
|
+
# happens if Steam is running within the Engine
|
27
|
+
services.set_site(env['steam.site'])
|
28
|
+
else
|
29
|
+
env['steam.site'] = services.current_site
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
25
33
|
def render_no_site
|
26
34
|
render_response('Hi, we are sorry but no site was found.', 404, 'text/html')
|
27
35
|
end
|
@@ -18,7 +18,7 @@ module Locomotive::Steam
|
|
18
18
|
# of the parent repository, that will change the local repository
|
19
19
|
# as well.
|
20
20
|
def initialize(repository_klass, collection, scope, options = {})
|
21
|
-
adapter.collection = collection
|
21
|
+
adapter.collection = collection || []
|
22
22
|
|
23
23
|
@repository = repository_klass.new(adapter)
|
24
24
|
@repository.scope = scope
|
@@ -78,7 +78,8 @@ module Locomotive::Steam
|
|
78
78
|
# create a proxy class for each localized attribute
|
79
79
|
def build_localized_attributes(attributes)
|
80
80
|
@localized_attributes.each do |name|
|
81
|
-
|
81
|
+
_name = name.to_sym
|
82
|
+
attributes[_name] = I18nField.new(_name, attributes[name.to_s] || attributes[_name])
|
82
83
|
end
|
83
84
|
end
|
84
85
|
|
@@ -41,7 +41,7 @@ module Locomotive
|
|
41
41
|
|
42
42
|
def build_adapter(options)
|
43
43
|
name = ((options || {})[:name] || :filesystem).to_s
|
44
|
-
require_relative "adapters/#{name}"
|
44
|
+
require_relative "adapters/#{name.downcase}"
|
45
45
|
klass = "Locomotive::Steam::#{name.camelize}Adapter".constantize
|
46
46
|
klass.new(options)
|
47
47
|
end
|
@@ -14,6 +14,10 @@ module Locomotive
|
|
14
14
|
embedded_association :select_options, ContentTypeFieldSelectOptionRepository
|
15
15
|
end
|
16
16
|
|
17
|
+
def by_name(name)
|
18
|
+
first { where(name: name) }
|
19
|
+
end
|
20
|
+
|
17
21
|
def selects
|
18
22
|
query { where(type: :select) }.all
|
19
23
|
end
|
@@ -22,6 +26,10 @@ module Locomotive
|
|
22
26
|
query { where(k(:type, :in) => %i(belongs_to has_many many_to_many)) }.all
|
23
27
|
end
|
24
28
|
|
29
|
+
def no_associations
|
30
|
+
query { where(k(:type, :nin) => %i(belongs_to has_many many_to_many)) }.all
|
31
|
+
end
|
32
|
+
|
25
33
|
def unique
|
26
34
|
query { where(unique: true) }.all.inject({}) do |memo, field|
|
27
35
|
memo[field.name] = field
|
@@ -19,6 +19,10 @@ module Locomotive
|
|
19
19
|
|
20
20
|
include Morphine
|
21
21
|
|
22
|
+
register :current_site do
|
23
|
+
repositories.current_site = site_finder.find
|
24
|
+
end
|
25
|
+
|
22
26
|
register :repositories do
|
23
27
|
Steam::Repositories.new(nil, nil, configuration)
|
24
28
|
end
|
@@ -52,7 +56,7 @@ module Locomotive
|
|
52
56
|
end
|
53
57
|
|
54
58
|
register :url_builder do
|
55
|
-
Steam::UrlBuilderService.new(current_site, locale)
|
59
|
+
Steam::UrlBuilderService.new(current_site, locale, request)
|
56
60
|
end
|
57
61
|
|
58
62
|
register :theme_asset_url do
|
@@ -108,8 +112,8 @@ module Locomotive
|
|
108
112
|
@locale = repositories.locale = locale
|
109
113
|
end
|
110
114
|
|
111
|
-
def
|
112
|
-
repositories.current_site
|
115
|
+
def set_site(site)
|
116
|
+
self.current_site = repositories.current_site = site
|
113
117
|
end
|
114
118
|
|
115
119
|
end
|