locomotive_cms 2.2.3 → 2.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/Gemfile +1 -0
- data/README.textile +2 -1
- data/app/assets/images/locomotive/icons/flags/bg.png +0 -0
- data/app/assets/images/locomotive/icons/flags/cs.png +0 -0
- data/app/assets/javascripts/locomotive/models/page.js.coffee +1 -1
- data/app/assets/javascripts/locomotive/utils/aloha_settings.js.coffee +2 -2
- data/app/assets/javascripts/locomotive/views/application_view.js.coffee +2 -2
- data/app/assets/javascripts/locomotive/views/content_assets/picker_view.js.coffee +2 -0
- data/app/assets/javascripts/locomotive/views/content_entries/_form_view.js.coffee +8 -0
- data/app/assets/javascripts/locomotive/views/editable_elements/text_view.js.coffee +2 -2
- data/app/assets/javascripts/locomotive/views/pages/edit_view.js.coffee +2 -0
- data/app/assets/javascripts/locomotive/views/shared/fields/belongs_to_view.js.coffee +2 -0
- data/app/assets/javascripts/locomotive/views/shared/form_view.js.coffee +7 -5
- data/app/assets/javascripts/tinymce/plugins/locomotive_media/editor_plugin.js +7 -3
- data/app/assets/javascripts/tinymce/plugins/locomotive_media/langs/cs.js +1 -0
- data/app/assets/stylesheets/locomotive/backoffice/datepicker.css.scss +66 -0
- data/app/assets/stylesheets/locomotive/backoffice/dialog_changes.css.scss +8 -2
- data/app/assets/stylesheets/locomotive/backoffice/formtastic_changes.css.scss +8 -0
- data/app/assets/stylesheets/locomotive/backoffice/menu/_colors.css.scss +1 -1
- data/app/controllers/locomotive/api/base_controller.rb +3 -0
- data/app/controllers/locomotive/api/content_entries_controller.rb +4 -4
- data/app/controllers/locomotive/api/tokens_controller.rb +4 -0
- data/app/controllers/locomotive/base_controller.rb +6 -3
- data/app/controllers/locomotive/public/base_controller.rb +3 -0
- data/app/controllers/locomotive/public/content_entries_controller.rb +2 -1
- data/app/helpers/locomotive/custom_fields_helper.rb +2 -2
- data/app/models/locomotive/content_type.rb +7 -0
- data/app/models/locomotive/editable_file.rb +1 -0
- data/app/models/locomotive/editable_text.rb +4 -1
- data/app/models/locomotive/extensions/page/editable_elements.rb +21 -0
- data/app/models/locomotive/extensions/page/templatized.rb +2 -2
- data/app/models/locomotive/extensions/page/tree.rb +5 -0
- data/app/models/locomotive/extensions/site/timezone.rb +7 -10
- data/app/models/locomotive/theme_asset.rb +2 -2
- data/app/presenters/locomotive/membership_presenter.rb +2 -1
- data/app/presenters/locomotive/site_presenter.rb +10 -1
- data/app/uploaders/locomotive/theme_asset_uploader.rb +7 -0
- data/app/views/locomotive/custom_fields/types/_date_time.html.haml +5 -0
- data/app/views/locomotive/notifications/new_content_entry.html.haml +1 -1
- data/app/views/locomotive/pages/_page.html.haml +2 -2
- data/config/locales/admin_ui.bg.yml +349 -0
- data/config/locales/admin_ui.cs.yml +359 -0
- data/config/locales/admin_ui.de.yml +25 -9
- data/config/locales/admin_ui.en.yml +3 -1
- data/config/locales/admin_ui.es.yml +2 -0
- data/config/locales/admin_ui.et.yml +3 -1
- data/config/locales/admin_ui.fr.yml +2 -0
- data/config/locales/admin_ui.it.yml +2 -0
- data/config/locales/admin_ui.ja.yml +2 -0
- data/config/locales/admin_ui.nb.yml +2 -0
- data/config/locales/admin_ui.nl.yml +2 -0
- data/config/locales/admin_ui.pl.yml +2 -0
- data/config/locales/admin_ui.pt-BR.yml +3 -1
- data/config/locales/admin_ui.ru.yml +2 -0
- data/config/locales/admin_ui.zh-CN.yml +2 -0
- data/config/locales/carrierwave.bg.yml +4 -0
- data/config/locales/carrierwave.cs.yml +4 -0
- data/config/locales/default.bg.yml +231 -0
- data/config/locales/default.cs.yml +249 -0
- data/config/locales/default.de.yml +24 -16
- data/config/locales/default.en.yml +4 -0
- data/config/locales/default.es.yml +1 -1
- data/config/locales/default.et.yml +1 -1
- data/config/locales/default.fr.yml +1 -1
- data/config/locales/default.it.yml +1 -1
- data/config/locales/default.ja.yml +4 -0
- data/config/locales/default.nb.yml +1 -1
- data/config/locales/default.nl.yml +1 -1
- data/config/locales/default.pl.yml +1 -1
- data/config/locales/default.pt-BR.yml +1 -1
- data/config/locales/default.ru.yml +1 -1
- data/config/locales/default.zh-CN.yml +1 -1
- data/config/locales/devise.bg.yml +64 -0
- data/config/locales/devise.cs.yml +64 -0
- data/config/locales/flash.bg.yml +115 -0
- data/config/locales/flash.cs.yml +115 -0
- data/config/locales/formtastic.bg.yml +113 -0
- data/config/locales/formtastic.cs.yml +125 -0
- data/config/locales/formtastic.de.yml +9 -0
- data/features/api/content_entries.feature +2 -0
- data/features/api/memberships.feature +26 -0
- data/features/backoffice/content_types/many_to_many.feature +3 -3
- data/features/backoffice/pages.feature +16 -0
- data/features/backoffice/regressions.feature +19 -0
- data/features/public/contact_form.feature +9 -0
- data/features/step_definitions/api_steps.rb +4 -1
- data/features/step_definitions/content_types_steps.rb +5 -0
- data/features/step_definitions/more_web_steps.rb +4 -0
- data/features/step_definitions/web_steps.rb +4 -0
- data/lib/generators/locomotive/install/templates/locomotive.rb +2 -2
- data/lib/locomotive.rb +1 -8
- data/lib/locomotive/action_controller.rb +1 -0
- data/lib/locomotive/action_controller/ssl.rb +11 -2
- data/lib/locomotive/action_controller/timezone.rb +13 -0
- data/lib/locomotive/configuration.rb +2 -2
- data/lib/locomotive/custom_fields.rb +1 -1
- data/lib/locomotive/dependencies.rb +2 -0
- data/lib/locomotive/engine.rb +10 -0
- data/lib/locomotive/httparty/webservice.rb +6 -5
- data/lib/locomotive/liquid/drops/base.rb +0 -2
- data/lib/locomotive/liquid/drops/content_entry.rb +11 -7
- data/lib/locomotive/liquid/drops/content_types.rb +46 -30
- data/lib/locomotive/liquid/drops/current_user.rb +3 -3
- data/lib/locomotive/liquid/drops/page.rb +15 -15
- data/lib/locomotive/liquid/drops/proxy_collection.rb +5 -1
- data/lib/locomotive/liquid/drops/site.rb +10 -6
- data/lib/locomotive/liquid/drops/uploader.rb +2 -2
- data/lib/locomotive/liquid/filters/date.rb +29 -3
- data/lib/locomotive/liquid/filters/resize.rb +3 -1
- data/lib/locomotive/liquid/filters/text.rb +4 -0
- data/lib/locomotive/liquid/tags/editable/control.rb +11 -1
- data/lib/locomotive/liquid/tags/link_to.rb +5 -3
- data/lib/locomotive/liquid/tags/nav.rb +19 -10
- data/lib/locomotive/liquid/tags/with_scope.rb +29 -31
- data/lib/locomotive/markdown.rb +23 -0
- data/lib/locomotive/render.rb +6 -2
- data/lib/locomotive/version.rb +1 -1
- data/lib/tasks/locomotive.rake +5 -2
- data/mongodb/migrate/20130511121956_generate_checksum_for_theme_assets.rb +5 -1
- data/mongodb/migrate/20130903145451_localize_redirect_urls_of_pages.rb +42 -0
- data/spec/dummy/config/initializers/locomotive.rb +2 -2
- data/spec/dummy/config/mongoid.yml +1 -0
- data/spec/lib/locomotive/httparty/webservice_spec.rb +1 -1
- data/spec/lib/locomotive/liquid/filters/date_spec.rb +61 -2
- data/spec/lib/locomotive/liquid/filters/text_spec.rb +4 -0
- data/spec/lib/locomotive/liquid/tags/consume_spec.rb +6 -2
- data/spec/lib/locomotive/liquid/tags/nav_spec.rb +1 -1
- data/spec/lib/locomotive/liquid/tags/with_scope_spec.rb +33 -27
- data/spec/lib/locomotive/render_spec.rb +2 -2
- data/spec/lib/locomotive/routing/site_dispatcher_spec.rb +1 -1
- data/spec/models/locomotive/content_entry_spec.rb +1 -1
- data/spec/models/locomotive/editable_control_spec.rb +9 -0
- data/spec/models/locomotive/extensions/page/editable_elements_spec.rb +6 -0
- data/spec/models/locomotive/page_spec.rb +13 -0
- data/spec/requests/admin_ssl_spec.rb +29 -7
- data/spec/support/factories.rb +6 -0
- data/vendor/assets/javascripts/locomotive/jquery-ui-timepicker-addon.js +2134 -0
- data/vendor/assets/stylesheets/select2/select2.css.scss +3 -3
- metadata +54 -94
@@ -27,7 +27,7 @@ module Locomotive
|
|
27
27
|
def count
|
28
28
|
@count ||= self.collection.count
|
29
29
|
end
|
30
|
-
|
30
|
+
|
31
31
|
def all
|
32
32
|
self.collection
|
33
33
|
end
|
@@ -43,6 +43,10 @@ module Locomotive
|
|
43
43
|
self.collection.any?
|
44
44
|
end
|
45
45
|
|
46
|
+
def content_type
|
47
|
+
|
48
|
+
end
|
49
|
+
|
46
50
|
protected
|
47
51
|
|
48
52
|
def paginate(options = {})
|
@@ -3,23 +3,27 @@ module Locomotive
|
|
3
3
|
module Drops
|
4
4
|
class Site < Base
|
5
5
|
|
6
|
-
delegate :name, :seo_title, :meta_keywords, :meta_description, to:
|
6
|
+
delegate :name, :seo_title, :meta_keywords, :meta_description, to: :@_source
|
7
7
|
|
8
8
|
def index
|
9
|
-
@index ||=
|
9
|
+
@index ||= @_source.pages.root.first
|
10
10
|
end
|
11
11
|
|
12
12
|
def pages
|
13
|
-
|
13
|
+
liquify(*self.scoped_pages)
|
14
|
+
end
|
15
|
+
|
16
|
+
def domains
|
17
|
+
@_source.domains
|
14
18
|
end
|
15
19
|
|
16
20
|
protected
|
17
21
|
|
18
22
|
def scoped_pages
|
19
|
-
if @context[
|
20
|
-
|
23
|
+
if @context['with_scope']
|
24
|
+
@_source.pages.where(@context['with_scope'])
|
21
25
|
else
|
22
|
-
|
26
|
+
@_source.pages
|
23
27
|
end
|
24
28
|
end
|
25
29
|
|
@@ -3,12 +3,38 @@ module Locomotive
|
|
3
3
|
module Filters
|
4
4
|
module Date
|
5
5
|
|
6
|
-
def
|
6
|
+
def parse_date_time(input, format = nil)
|
7
|
+
return '' if input.blank?
|
8
|
+
|
9
|
+
format ||= I18n.t('time.formats.default')
|
10
|
+
date_time = ::DateTime._strptime(input, format)
|
11
|
+
|
12
|
+
if date_time
|
13
|
+
::Time.zone.local(date_time[:year], date_time[:mon], date_time[:mday], date_time[:hour], date_time[:min], date_time[:sec] || 0)
|
14
|
+
else
|
15
|
+
::Time.zone.parse(input) rescue ''
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def parse_date(input, format)
|
20
|
+
return '' if input.blank?
|
21
|
+
|
22
|
+
format ||= I18n.t('date.formats.default')
|
23
|
+
date = ::Date._strptime(input, format)
|
24
|
+
|
25
|
+
if date
|
26
|
+
::Date.new(date[:year], date[:mon], date[:mday])
|
27
|
+
else
|
28
|
+
::Date.parse(value) rescue ''
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def distance_of_time_in_words(input, from_time = Time.zone.now, include_seconds = false)
|
7
33
|
# make sure we deals with instances of Time
|
8
34
|
input = to_time(input)
|
9
35
|
from_time = to_time(from_time)
|
10
36
|
|
11
|
-
::ActionController::Base.helpers.distance_of_time_in_words(input, from_time)
|
37
|
+
::ActionController::Base.helpers.distance_of_time_in_words(input, from_time, { include_seconds: include_seconds })
|
12
38
|
end
|
13
39
|
|
14
40
|
def localized_date(input, *args)
|
@@ -42,7 +68,7 @@ module Locomotive
|
|
42
68
|
def to_time(input)
|
43
69
|
case input
|
44
70
|
when Date then input.to_time
|
45
|
-
when String then Time.parse(input)
|
71
|
+
when String then Time.zone.parse(input)
|
46
72
|
else
|
47
73
|
input
|
48
74
|
end
|
@@ -4,7 +4,9 @@ module Locomotive
|
|
4
4
|
module Resize
|
5
5
|
|
6
6
|
def resize(input, resize_string)
|
7
|
-
|
7
|
+
source = input.instance_variable_get(:@_source) || input
|
8
|
+
|
9
|
+
Locomotive::Dragonfly.resize_url(source, resize_string)
|
8
10
|
end
|
9
11
|
|
10
12
|
end
|
@@ -8,7 +8,9 @@ module Locomotive
|
|
8
8
|
|
9
9
|
def default_element_attributes
|
10
10
|
if @nodelist.first.is_a?(String)
|
11
|
-
|
11
|
+
content = self.render_default_content(@nodelist.first)
|
12
|
+
|
13
|
+
super.merge(content: content, options: @options[:options])
|
12
14
|
else
|
13
15
|
super
|
14
16
|
end
|
@@ -22,6 +24,14 @@ module Locomotive
|
|
22
24
|
EditableControl
|
23
25
|
end
|
24
26
|
|
27
|
+
def render_default_content(node)
|
28
|
+
if node
|
29
|
+
node.to_s.strip
|
30
|
+
else
|
31
|
+
nil
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
25
35
|
end
|
26
36
|
|
27
37
|
::Liquid::Template.register_tag('editable_control', Control)
|
@@ -46,9 +46,11 @@ module Locomotive
|
|
46
46
|
handle = scope[@handle] || @handle
|
47
47
|
|
48
48
|
page = case handle
|
49
|
-
when Locomotive::Page
|
50
|
-
when
|
51
|
-
when
|
49
|
+
when Locomotive::Page then handle
|
50
|
+
when Locomotive::Liquid::Drops::Page then handle.instance_variable_get(:@_source)
|
51
|
+
when String then fetch_page(site, handle)
|
52
|
+
when Locomotive::ContentEntry then fetch_page(site, handle, true)
|
53
|
+
when Locomotive::Liquid::Drops::ContentEntry then fetch_page(site, handle.instance_variable_get(:@_source), true)
|
52
54
|
else
|
53
55
|
nil
|
54
56
|
end
|
@@ -50,7 +50,7 @@ module Locomotive
|
|
50
50
|
css << 'first' if index == 0
|
51
51
|
css << 'last' if index == entries.size - 1
|
52
52
|
|
53
|
-
children_output << render_entry_link(p, css.join(' '), 1)
|
53
|
+
children_output << render_entry_link(context, p, css.join(' '), 1)
|
54
54
|
end
|
55
55
|
|
56
56
|
output = children_output.join("\n")
|
@@ -81,13 +81,11 @@ module Locomotive
|
|
81
81
|
end
|
82
82
|
|
83
83
|
# Returns a list element, a link to the page and its children
|
84
|
-
def render_entry_link(page, css, depth)
|
85
|
-
selected = @page.fullpath =~ /^#{page.fullpath}
|
86
|
-
|
87
|
-
icon = @options[:icon] ? '<span></span>' : ''
|
88
|
-
|
89
|
-
title = @options[:liquid_render] ? @options[:liquid_render].render('page' => page) : page.title
|
84
|
+
def render_entry_link(context, page, css, depth)
|
85
|
+
selected = @page.fullpath =~ /^#{page.fullpath}(\/.*)?$/ ? " #{@options[:active_class]}" : ''
|
90
86
|
|
87
|
+
icon = @options[:icon] ? '<span></span>' : ''
|
88
|
+
title = render_title(context, page)
|
91
89
|
label = %{#{icon if @options[:icon] != 'after' }#{title}#{icon if @options[:icon] == 'after' }}
|
92
90
|
|
93
91
|
link_options = caret = ''
|
@@ -102,7 +100,7 @@ module Locomotive
|
|
102
100
|
|
103
101
|
output = %{<li id="#{page.slug.to_s.dasherize}-link" class="link#{selected} #{css}">}
|
104
102
|
output << %{<a href="#{href}"#{link_options}>#{label}#{caret}</a>}
|
105
|
-
output << render_entry_children(page, depth.succ) if (depth.succ <= @options[:depth].to_i)
|
103
|
+
output << render_entry_children(context, page, depth.succ) if (depth.succ <= @options[:depth].to_i)
|
106
104
|
output << %{</li>}
|
107
105
|
|
108
106
|
output.strip
|
@@ -113,7 +111,7 @@ module Locomotive
|
|
113
111
|
end
|
114
112
|
|
115
113
|
# Recursively creates a nested unordered list for the depth specified
|
116
|
-
def render_entry_children(page, depth)
|
114
|
+
def render_entry_children(context, page, depth)
|
117
115
|
output = %{}
|
118
116
|
|
119
117
|
children = page.children_with_minimal_attributes(@options[:add_attributes]).reject { |c| !include_page?(c) }
|
@@ -124,7 +122,7 @@ module Locomotive
|
|
124
122
|
css << 'first' if children.first == c
|
125
123
|
css << 'last' if children.last == c
|
126
124
|
|
127
|
-
output << render_entry_link(c, css.join(' '), depth)
|
125
|
+
output << render_entry_link(context, c, css.join(' '), depth)
|
128
126
|
end
|
129
127
|
output << %{</ul>}
|
130
128
|
end
|
@@ -132,6 +130,17 @@ module Locomotive
|
|
132
130
|
output
|
133
131
|
end
|
134
132
|
|
133
|
+
def render_title(context, page)
|
134
|
+
if @options[:liquid_render]
|
135
|
+
context.stack do
|
136
|
+
context['page'] = page
|
137
|
+
@options[:liquid_render].render(context)
|
138
|
+
end
|
139
|
+
else
|
140
|
+
page.title
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
135
144
|
# Determines whether or not a page should be a part of the menu
|
136
145
|
def include_page?(page)
|
137
146
|
if !page.listed? || page.templatized? || !page.published?
|
@@ -6,57 +6,55 @@ module Locomotive
|
|
6
6
|
#
|
7
7
|
# Usage:
|
8
8
|
#
|
9
|
-
# {% with_scope main_developer: 'John Doe', active: true %}
|
9
|
+
# {% with_scope main_developer: 'John Doe', providers.in: ['acme'], started_at.le: today, active: true %}
|
10
10
|
# {% for project in contents.projects %}
|
11
11
|
# {{ project.name }}
|
12
12
|
# {% endfor %}
|
13
13
|
# {% endwith_scope %}
|
14
14
|
#
|
15
15
|
|
16
|
-
class WithScope < ::
|
17
|
-
SlashedString = /\/[^\/]*\//
|
18
|
-
TagAttributes = /(\w+|\w+\.\w+)\s*\:\s*(#{SlashedString}|#{::Liquid::QuotedFragment})/
|
16
|
+
class WithScope < Solid::Block
|
19
17
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
18
|
+
OPERATORS = %w(all exists gt gte in lt lte ne nin size near within)
|
19
|
+
|
20
|
+
SYMBOL_OPERATORS_REGEXP = /(\w+\.(#{OPERATORS.join('|')})){1}\s*\:/
|
21
|
+
|
22
|
+
# register the tag
|
23
|
+
tag_name :with_scope
|
24
|
+
|
25
|
+
def initialize(tag_name, arguments_string, tokens, context = {})
|
26
|
+
# convert symbol operators into valid ruby code
|
27
|
+
arguments_string.gsub!(SYMBOL_OPERATORS_REGEXP, ':"\1" =>')
|
28
|
+
|
29
|
+
super(tag_name, arguments_string, tokens, context)
|
27
30
|
end
|
28
31
|
|
29
|
-
def
|
30
|
-
|
31
|
-
|
32
|
-
|
32
|
+
def display(options = {}, &block)
|
33
|
+
current_context.stack do
|
34
|
+
current_context['with_scope'] = self.decode(options)
|
35
|
+
yield
|
33
36
|
end
|
34
37
|
end
|
35
38
|
|
36
|
-
|
39
|
+
protected
|
37
40
|
|
38
|
-
def decode(
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
end
|
41
|
+
def decode(options)
|
42
|
+
HashWithIndifferentAccess.new.tap do |hash|
|
43
|
+
options.each do |key, value|
|
44
|
+
_key, _operator = key.to_s.split('.')
|
43
45
|
|
44
|
-
|
45
|
-
|
46
|
+
# _slug instead of _permalink
|
47
|
+
_key = '_slug' if _key == '_permalink'
|
46
48
|
|
47
|
-
|
48
|
-
|
49
|
+
# key to h4s symbol
|
50
|
+
_key = _key.to_s.to_sym.send(_operator.to_sym) if _operator
|
49
51
|
|
50
|
-
|
51
|
-
|
52
|
-
_key.to_s.to_sym.send(_operator.to_sym)
|
53
|
-
else
|
54
|
-
_key
|
52
|
+
hash[_key] = value
|
53
|
+
end
|
55
54
|
end
|
56
55
|
end
|
57
56
|
end
|
58
57
|
|
59
|
-
::Liquid::Template.register_tag('with_scope', WithScope)
|
60
58
|
end
|
61
59
|
end
|
62
60
|
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Locomotive
|
2
|
+
module Markdown
|
3
|
+
|
4
|
+
def self.render(text)
|
5
|
+
self.parser.render(text)
|
6
|
+
end
|
7
|
+
|
8
|
+
def self.parser
|
9
|
+
@@markdown ||= Redcarpet::Markdown.new Redcarpet::Render::HTML, {
|
10
|
+
autolink: true,
|
11
|
+
fenced_code: true,
|
12
|
+
generate_toc: true,
|
13
|
+
gh_blockcode: true,
|
14
|
+
hard_wrap: true,
|
15
|
+
no_intraemphasis: true,
|
16
|
+
strikethrough: true,
|
17
|
+
tables: true,
|
18
|
+
xhtml: true
|
19
|
+
}
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
end
|
data/lib/locomotive/render.rb
CHANGED
@@ -150,7 +150,7 @@ module Locomotive
|
|
150
150
|
end
|
151
151
|
|
152
152
|
# Tip: switch from false to true to enable the re-thrown exception flag
|
153
|
-
::Liquid::Context.new({}, assigns, self.locomotive_default_registers,
|
153
|
+
::Liquid::Context.new({}, assigns, self.locomotive_default_registers, true)
|
154
154
|
end
|
155
155
|
|
156
156
|
# Get the assigns from the flash object (session). For instance, once
|
@@ -189,13 +189,16 @@ module Locomotive
|
|
189
189
|
'fullpath' => request.fullpath,
|
190
190
|
'url' => request.url,
|
191
191
|
'ip_address' => request.remote_ip,
|
192
|
+
'post?' => request.post?,
|
193
|
+
'host' => request.host_with_port,
|
192
194
|
'now' => Time.now.in_time_zone(current_site.timezone),
|
193
195
|
'today' => Date.today,
|
194
196
|
'locale' => I18n.locale.to_s,
|
195
197
|
'default_locale' => current_site.default_locale.to_s,
|
196
198
|
'locales' => current_site.locales,
|
197
199
|
'current_user' => Locomotive::Liquid::Drops::CurrentUser.new(current_locomotive_account),
|
198
|
-
'session' => Locomotive::Liquid::Drops::SessionProxy.new
|
200
|
+
'session' => Locomotive::Liquid::Drops::SessionProxy.new,
|
201
|
+
'wagon' => false
|
199
202
|
}
|
200
203
|
end
|
201
204
|
|
@@ -209,6 +212,7 @@ module Locomotive
|
|
209
212
|
site: current_site,
|
210
213
|
page: @page,
|
211
214
|
inline_editor: self.editing_page?,
|
215
|
+
logger: Rails.logger,
|
212
216
|
current_locomotive_account: current_locomotive_account
|
213
217
|
}
|
214
218
|
end
|
data/lib/locomotive/version.rb
CHANGED
data/lib/tasks/locomotive.rake
CHANGED
@@ -14,19 +14,22 @@ namespace :locomotive do
|
|
14
14
|
Locomotive::Site.all.each do |site|
|
15
15
|
default_locale = site.default_locale
|
16
16
|
|
17
|
-
([default_locale] + (site.locales - [default_locale])).
|
17
|
+
([default_locale] + (site.locales - [default_locale])).each do |locale|
|
18
18
|
Mongoid::Fields::I18n.with_locale(locale) do
|
19
19
|
pages = site.pages.to_a
|
20
20
|
while !pages.empty? do
|
21
21
|
page = pages.pop
|
22
22
|
begin
|
23
23
|
page.send :_parse_and_serialize_template
|
24
|
+
page.instance_variable_set :@template_changed, true
|
24
25
|
page.save
|
25
|
-
puts "[#{site.name}][#{locale}] processing...#{page.title}"
|
26
|
+
puts "[#{site.name}][#{locale}] processing...#{page.title} [saved]"
|
26
27
|
rescue TypeError
|
27
28
|
pages.insert(0, page)
|
28
29
|
rescue ::Liquid::Error => e
|
29
30
|
puts "\tLiquid error: #{e.message} (#{page._id})"
|
31
|
+
rescue Exception => e
|
32
|
+
puts "\tUnknown error: #{e.message} (#{page._id})"
|
30
33
|
end
|
31
34
|
end
|
32
35
|
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
class LocalizeRedirectUrlsOfPages < MongoidMigration::Migration
|
2
|
+
def self.up
|
3
|
+
Locomotive::Site.all.each do |site|
|
4
|
+
puts "[#{site.name}] - #{site.default_locale} / #{site.locales}"
|
5
|
+
|
6
|
+
site.pages.each do |page|
|
7
|
+
next if page.attributes['redirect_url'].is_a?(Hash) # already translated
|
8
|
+
|
9
|
+
puts "\tPage #{page.id} is not translated"
|
10
|
+
|
11
|
+
self.update_page(site, page)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.down
|
17
|
+
Locomotive::Page.all.each do |page|
|
18
|
+
selector = { '_id' => page._id }
|
19
|
+
modifications = page.attributes['redirect_url'].values.first
|
20
|
+
|
21
|
+
Locomotive::Page.collection.find(selector).update({ '$set' => { 'redirect_url' => modifications } })
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
# 2 cases:
|
26
|
+
# - not translated, set the redirect_url for all the locales of the site
|
27
|
+
# - already translated copy the SAME redirect_url for all the locales of the page
|
28
|
+
#
|
29
|
+
def self.update_page(site, page)
|
30
|
+
selector = { '_id' => page._id }
|
31
|
+
modifications = {}
|
32
|
+
redirect_url = Mongoid::Fields::I18n.with_locale(site.default_locale) { page.redirect_url }
|
33
|
+
|
34
|
+
locales = page.translated? ? page.translated_in : site.locales
|
35
|
+
|
36
|
+
locales.each do |locale|
|
37
|
+
modifications[locale.to_s] = redirect_url
|
38
|
+
end
|
39
|
+
|
40
|
+
Locomotive::Page.collection.find(selector).update({ '$set' => { 'redirect_url' => modifications } })
|
41
|
+
end
|
42
|
+
end
|