locomotive_cms 2.1.4 → 2.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (143) hide show
  1. data/Gemfile +1 -5
  2. data/app/assets/images/locomotive/icons/flags/zh-CN.png +0 -0
  3. data/app/assets/javascripts/aloha/plugins/custom/inputcontrol/css/inputcontrol.css +3 -0
  4. data/app/assets/javascripts/aloha/plugins/custom/inputcontrol/lib/inputcontrol-plugin.js +94 -0
  5. data/app/assets/javascripts/aloha/plugins/custom/inputcontrol/package.json +1 -0
  6. data/app/assets/javascripts/locomotive.js +2 -1
  7. data/app/assets/javascripts/locomotive/models/content_type.js.coffee +6 -2
  8. data/app/assets/javascripts/locomotive/models/page.js.coffee +1 -1
  9. data/app/assets/javascripts/locomotive/models/site.js.coffee +1 -1
  10. data/app/assets/javascripts/locomotive/utils/aloha_settings.js.coffee +17 -7
  11. data/app/assets/javascripts/locomotive/utils/tinymce_settings.js.coffee +6 -0
  12. data/app/assets/javascripts/locomotive/views/application_view.js.coffee +13 -2
  13. data/app/assets/javascripts/locomotive/views/content_entries/_form_view.js.coffee +19 -2
  14. data/app/assets/javascripts/locomotive/views/content_entries/_popup_form_view.js.coffee +1 -1
  15. data/app/assets/javascripts/locomotive/views/content_entries/index_view.js.coffee +2 -2
  16. data/app/assets/javascripts/locomotive/views/content_types/_form_view.js.coffee +2 -1
  17. data/app/assets/javascripts/locomotive/views/content_types/custom_field_entry_view.js.coffee +3 -0
  18. data/app/assets/javascripts/locomotive/views/current_site/edit_view.js.coffee +2 -1
  19. data/app/assets/javascripts/locomotive/views/editable_elements/edit_all_view.js.coffee +3 -6
  20. data/app/assets/javascripts/locomotive/views/editable_elements/text_view.js.coffee +47 -0
  21. data/app/assets/javascripts/locomotive/views/inline_editor/toolbar_view.js.coffee +1 -1
  22. data/app/assets/javascripts/locomotive/views/pages/_form_view.js.coffee +2 -1
  23. data/app/assets/javascripts/locomotive/views/pages/list_view.js.coffee +2 -2
  24. data/app/assets/javascripts/locomotive/views/shared/fields/belongs_to_view.js.coffee +32 -0
  25. data/app/assets/javascripts/locomotive/views/shared/fields/has_many_view.js.coffee +2 -2
  26. data/app/assets/javascripts/locomotive/views/shared/fields/many_to_many_view.js.coffee +2 -2
  27. data/app/assets/javascripts/locomotive/views/shared/form_view.js.coffee +2 -0
  28. data/app/assets/javascripts/locomotive/views/snippets/_form_view.js.coffee +2 -1
  29. data/app/assets/javascripts/locomotive/views/theme_assets/_form_view.js.coffee +2 -1
  30. data/app/assets/javascripts/locomotive/views/theme_assets/index_view.js.coffee +0 -1
  31. data/app/assets/javascripts/tinymce/plugins/locomotive_media/langs/es.js +1 -0
  32. data/app/assets/javascripts/tinymce/plugins/locomotive_media/langs/et.js +1 -0
  33. data/app/assets/javascripts/tinymce/plugins/locomotive_media/langs/it.js +1 -0
  34. data/app/assets/javascripts/tinymce/plugins/locomotive_media/langs/ja.js +1 -0
  35. data/app/assets/javascripts/tinymce/plugins/locomotive_media/langs/nb.js +1 -0
  36. data/app/assets/javascripts/tinymce/plugins/locomotive_media/langs/nl.js +1 -0
  37. data/app/assets/javascripts/tinymce/plugins/locomotive_media/langs/no.js +1 -0
  38. data/app/assets/javascripts/tinymce/plugins/locomotive_media/langs/pl.js +1 -0
  39. data/app/assets/javascripts/tinymce/plugins/locomotive_media/langs/pt.js +1 -0
  40. data/app/assets/javascripts/tinymce/plugins/locomotive_media/langs/zh-cn.js +1 -0
  41. data/app/assets/stylesheets/locomotive.css +1 -0
  42. data/app/assets/stylesheets/locomotive/backoffice/codemirror_changes.css.scss +2 -0
  43. data/app/assets/stylesheets/locomotive/backoffice/formtastic_changes.css.scss +17 -3
  44. data/app/controllers/locomotive/content_entries_controller.rb +6 -2
  45. data/app/controllers/locomotive/public/content_entries_controller.rb +6 -0
  46. data/app/helpers/locomotive/base_helper.rb +8 -0
  47. data/app/helpers/locomotive/sites_helper.rb +6 -0
  48. data/app/models/locomotive/content_entry.rb +35 -5
  49. data/app/models/locomotive/content_type.rb +26 -8
  50. data/app/models/locomotive/editable_element.rb +15 -1
  51. data/app/models/locomotive/editable_file.rb +0 -2
  52. data/app/models/locomotive/editable_long_text.rb +3 -3
  53. data/app/models/locomotive/editable_short_text.rb +3 -64
  54. data/app/models/locomotive/editable_text.rb +84 -0
  55. data/app/models/locomotive/extensions/content_entry/csv.rb +7 -3
  56. data/app/models/locomotive/extensions/page/editable_elements.rb +3 -5
  57. data/app/models/locomotive/extensions/site/locales.rb +20 -0
  58. data/app/models/locomotive/extensions/site/timezone.rb +35 -0
  59. data/app/models/locomotive/site.rb +20 -16
  60. data/app/models/locomotive/theme_asset.rb +1 -1
  61. data/app/presenters/locomotive/content_entry_presenter.rb +1 -1
  62. data/app/presenters/locomotive/{editable_short_text_presenter.rb → editable_text_presenter.rb} +14 -2
  63. data/app/views/locomotive/current_site/_form.html.haml +1 -0
  64. data/app/views/locomotive/custom_fields/types/_belongs_to.html.haml +6 -5
  65. data/app/views/locomotive/pages/_editable_elements.html.haml +1 -1
  66. data/app/views/locomotive/shared/_head.html.haml +2 -0
  67. data/app/views/locomotive/shared/_main_app_head_before_backbone.html.haml +1 -0
  68. data/config/locales/admin_ui.de.yml +1 -0
  69. data/config/locales/admin_ui.en.yml +1 -0
  70. data/config/locales/admin_ui.et.yml +1 -0
  71. data/config/locales/admin_ui.fr.yml +1 -0
  72. data/config/locales/admin_ui.ja.yml +1 -0
  73. data/config/locales/admin_ui.nb.yml +2 -0
  74. data/config/locales/admin_ui.pl.yml +1 -0
  75. data/config/locales/admin_ui.pt-BR.yml +2 -1
  76. data/config/locales/admin_ui.ru.yml +24 -4
  77. data/config/locales/admin_ui.zh-CN.yml +347 -0
  78. data/config/locales/carrierwave.zh-CN.yml +4 -0
  79. data/config/locales/default.zh-CN.yml +116 -0
  80. data/config/locales/devise.nb.yml +1 -0
  81. data/config/locales/devise.zh-CN.yml +64 -0
  82. data/config/locales/flash.zh-CN.yml +115 -0
  83. data/config/locales/formtastic.en.yml +1 -0
  84. data/config/locales/formtastic.ru.yml +4 -1
  85. data/config/locales/formtastic.zh-CN.yml +112 -0
  86. data/features/backoffice/content_types/localized.feature +63 -0
  87. data/features/backoffice/pages.feature +3 -1
  88. data/features/backoffice/site.feature +7 -0
  89. data/features/public/contact_form.feature +11 -0
  90. data/features/public/content_entries.feature +13 -0
  91. data/features/public/pages.feature +24 -0
  92. data/features/step_definitions/page_steps.rb +6 -0
  93. data/features/step_definitions/web_steps.rb +24 -7
  94. data/lib/generators/locomotive/install/templates/locomotive.rb +2 -2
  95. data/lib/generators/locomotive/install/templates/mongoid.yml +23 -29
  96. data/lib/locomotive.rb +1 -4
  97. data/lib/locomotive/configuration.rb +3 -3
  98. data/lib/locomotive/dependencies.rb +1 -0
  99. data/lib/locomotive/engine.rb +2 -1
  100. data/lib/locomotive/liquid/drops/page.rb +1 -1
  101. data/lib/locomotive/liquid/filters/date.rb +3 -1
  102. data/lib/locomotive/liquid/filters/misc.rb +4 -0
  103. data/lib/locomotive/liquid/filters/text.rb +4 -0
  104. data/lib/locomotive/liquid/tags/editable.rb +1 -2
  105. data/lib/locomotive/liquid/tags/editable/text.rb +79 -0
  106. data/lib/locomotive/liquid/tags/inline_editor.rb +1 -1
  107. data/lib/locomotive/liquid/tags/link_to.rb +72 -13
  108. data/lib/locomotive/liquid/tags/with_scope.rb +3 -3
  109. data/lib/locomotive/middlewares.rb +0 -1
  110. data/lib/locomotive/mongoid/patches.rb +0 -16
  111. data/lib/locomotive/render.rb +1 -1
  112. data/lib/locomotive/version.rb +1 -1
  113. data/lib/tasks/locomotive.rake +15 -9
  114. data/mongodb/migrate/20130326201349_rename_entry_to_content_entry.rb +1 -1
  115. data/mongodb/migrate/20130621135025_create_editable_texts.rb +42 -0
  116. data/mongodb/migrate/20130627101548_localize_slugs_of_content_entries.rb +43 -0
  117. data/spec/dummy/config/initializers/locomotive.rb +1 -1
  118. data/spec/dummy/config/initializers/session_store.rb +1 -1
  119. data/spec/lib/locomotive/liquid/drops/page_spec.rb +1 -1
  120. data/spec/lib/locomotive/liquid/filters/misc_spec.rb +26 -0
  121. data/spec/lib/locomotive/liquid/tags/editable/text_spec.rb +85 -0
  122. data/spec/lib/locomotive/liquid/tags/link_to_spec.rb +111 -0
  123. data/spec/lib/locomotive/liquid/tags/with_scope_spec.rb +6 -0
  124. data/spec/models/locomotive/content_entry_spec.rb +27 -7
  125. data/spec/models/locomotive/{editable_short_text_spec.rb → editable_text_spec.rb} +53 -8
  126. data/spec/models/locomotive/extensions/page/editable_elements_spec.rb +6 -6
  127. data/spec/models/locomotive/site_spec.rb +52 -32
  128. data/vendor/assets/images/select2-spinner.gif +0 -0
  129. data/vendor/assets/images/select2.png +0 -0
  130. data/vendor/assets/images/select2x2.png +0 -0
  131. data/vendor/assets/javascripts/locomotive/liquid_mode.js +1 -1
  132. data/vendor/assets/javascripts/select2/select2.js +3054 -0
  133. data/vendor/assets/stylesheets/select2/select2.css.scss +652 -0
  134. metadata +77 -33
  135. data/app/assets/javascripts/locomotive/views/editable_elements/long_text_view.js.coffee +0 -36
  136. data/app/assets/javascripts/locomotive/views/editable_elements/short_text_view.js.coffee +0 -22
  137. data/app/presenters/locomotive/editable_long_text_presenter.rb +0 -5
  138. data/lib/locomotive/liquid/tags/editable/long_text.rb +0 -33
  139. data/lib/locomotive/liquid/tags/editable/short_text.rb +0 -41
  140. data/lib/locomotive/middlewares/fonts.rb +0 -42
  141. data/lib/locomotive/session_store.rb +0 -64
  142. data/spec/lib/locomotive/liquid/tags/editable/short_text_spec.rb +0 -46
  143. data/spec/models/locomotive/editable_long_text_spec.rb +0 -50
@@ -0,0 +1,79 @@
1
+ module Locomotive
2
+ module Liquid
3
+ module Tags
4
+ module Editable
5
+ class Text < Base
6
+
7
+ protected
8
+
9
+ def render_element(context, element)
10
+ content = element.default_content? ? render_default_content(context) : element.content
11
+
12
+ if self.editable?(context, element)
13
+ self.render_editable_element(element, content)
14
+ else
15
+ content
16
+ end
17
+ end
18
+
19
+ def render_editable_element(element, content)
20
+ tag_name = 'div'
21
+ css = 'editable-text'
22
+
23
+ unless element.line_break?
24
+ tag_name = 'span'
25
+ css += ' editable-single-text'
26
+ end
27
+
28
+ %{
29
+ <#{tag_name} class='#{css}' data-element-id='#{element.id}' data-element-index='#{element._index}'>
30
+ #{content}
31
+ </#{tag_name}>
32
+ }
33
+ end
34
+
35
+ def document_type
36
+ EditableText
37
+ end
38
+
39
+ def editable?(context, element)
40
+ context.registers[:inline_editor] &&
41
+ %(raw html).include?(element.format) &&
42
+ (!element.fixed? || (element.fixed? && !element.from_parent?))
43
+ end
44
+
45
+ def default_element_attributes
46
+ super.merge(
47
+ content_from_default: self.render_default_content(nil),
48
+ format: @options[:format] || 'html',
49
+ rows: @options[:rows] || 10,
50
+ line_break: @options[:line_break].blank? ? true : @options[:line_break]
51
+ )
52
+ end
53
+
54
+ end
55
+
56
+ ::Liquid::Template.register_tag('editable_text', Text)
57
+
58
+ class ShortText < Text
59
+ def initialize(tag_name, markup, tokens, context)
60
+ Rails.logger.warn %(The "editable_<short|long>_text" liquid tags are deprecated. Use "editable_text" instead.)
61
+ super
62
+ end
63
+ def default_element_attributes
64
+ super.merge(format: 'raw', rows: 2, line_break: false)
65
+ end
66
+ end
67
+ ::Liquid::Template.register_tag('editable_short_text', ShortText)
68
+
69
+ class LongText < ShortText
70
+ def default_element_attributes
71
+ super.merge(format: 'html', rows: 15, line_break: true)
72
+ end
73
+ end
74
+ ::Liquid::Template.register_tag('editable_long_text', LongText)
75
+
76
+ end
77
+ end
78
+ end
79
+ end
@@ -6,7 +6,7 @@ module Liquid
6
6
  def render(context)
7
7
  if context.registers[:current_locomotive_account] && context.registers[:inline_editor]
8
8
 
9
- plugins = 'common/ui,common/format,common/table,common/list,common/link,common/highlighteditables,common/block,common/undo,common/contenthandler,common/paste,common/commands,common/abbr,common/align,common/horizontalruler,common/image,custom/locomotive_media'
9
+ plugins = 'common/ui,common/format,common/table,common/list,common/link,common/highlighteditables,common/block,common/undo,common/contenthandler,common/paste,common/commands,common/abbr,common/align,common/horizontalruler,common/image,custom/locomotive_media,custom/inputcontrol'
10
10
 
11
11
  controller = context.registers[:controller]
12
12
  controller.instance_variable_set(:@plugins, plugins)
@@ -2,10 +2,11 @@ module Locomotive
2
2
  module Liquid
3
3
  module Tags
4
4
  class LinkTo < Hybrid
5
+
5
6
  Syntax = /(#{::Liquid::Expression}+)(#{::Liquid::TagAttributes}?)/
6
-
7
+
7
8
  include ActionView::Helpers::UrlHelper
8
-
9
+
9
10
  def initialize(tag_name, markup, tokens, context)
10
11
  if markup =~ Syntax
11
12
  @handle = $1
@@ -16,24 +17,82 @@ module Locomotive
16
17
  else
17
18
  raise SyntaxError.new("Syntax Error in 'link_to' - Valid syntax: link_to page_handle, locale es (locale is optional)")
18
19
  end
19
-
20
+
20
21
  super
21
22
  end
22
-
23
+
23
24
  def render(context)
24
- site = context.registers[:site]
25
- if page = site.pages.where(handle: @handle).first
26
- path = "/#{site.localized_page_fullpath(page, @options['locale'])}"
27
- ::Mongoid::Fields::I18n.with_locale(@options['locale']) do
28
- if @render_as_block
29
- context.scopes.last['target'] = page
30
- link_to super.html_safe, path
31
- else
32
- link_to page.title, path
25
+ site = context.registers[:site]
26
+
27
+ if page = self.retrieve_page_from_handle(site, context)
28
+ label = self.label_from_page(page)
29
+ path = self.public_page_url(site, page)
30
+
31
+ if @render_as_block
32
+ context.scopes.last['target'] = page
33
+ label = super.html_safe
34
+ end
35
+
36
+ link_to label, path
37
+ else
38
+ '' # no page found
39
+ end
40
+ end
41
+
42
+ protected
43
+
44
+ def retrieve_page_from_handle(site, context)
45
+ context.scopes.reverse_each do |scope|
46
+ handle = scope[@handle] || @handle
47
+
48
+ page = case handle
49
+ when Locomotive::Page then handle
50
+ when String then fetch_page(site, handle)
51
+ when Locomotive::ContentEntry then fetch_page(site, handle, true)
52
+ else
53
+ nil
54
+ end
55
+
56
+ return page unless page.nil?
57
+ end
58
+
59
+ nil
60
+ end
61
+
62
+ def fetch_page(site, handle, templatized = false)
63
+ ::Mongoid::Fields::I18n.with_locale(@options['locale']) do
64
+ if templatized
65
+ criteria = site.pages.where(target_klass_name: handle.class.to_s, templatized: true)
66
+ criteria = criteria.where(handle: @options['with']) if @options['with']
67
+ criteria.first.tap do |page|
68
+ page.content_entry = handle if page
33
69
  end
70
+ else
71
+ site.pages.where(handle: handle).first
34
72
  end
35
73
  end
36
74
  end
75
+
76
+ def label_from_page(page)
77
+ ::Mongoid::Fields::I18n.with_locale(@options['locale']) do
78
+ if page.templatized?
79
+ page.content_entry._label
80
+ else
81
+ page.title
82
+ end
83
+ end
84
+ end
85
+
86
+ def public_page_url(site, page)
87
+ fullpath = site.localized_page_fullpath(page, @options['locale'])
88
+
89
+ if page.templatized?
90
+ fullpath.gsub!('content_type_template', page.content_entry._slug)
91
+ end
92
+
93
+ File.join('/', fullpath)
94
+ end
95
+
37
96
  end
38
97
 
39
98
  ::Liquid::Template.register_tag('link_to', LinkTo)
@@ -14,8 +14,8 @@ module Locomotive
14
14
  #
15
15
 
16
16
  class WithScope < ::Liquid::Block
17
-
18
- TagAttributes = /(\w+|\w+\.\w+)\s*\:\s*(#{::Liquid::QuotedFragment})/
17
+ SlashedString = /\/[^\/]*\//
18
+ TagAttributes = /(\w+|\w+\.\w+)\s*\:\s*(#{SlashedString}|#{::Liquid::QuotedFragment})/
19
19
 
20
20
  def initialize(tag_name, markup, tokens, context)
21
21
  @attributes = HashWithIndifferentAccess.new
@@ -37,7 +37,7 @@ module Locomotive
37
37
 
38
38
  def decode(attributes, context)
39
39
  attributes.each_pair do |key, value|
40
- attributes[key] = context[value]
40
+ attributes[key] = value.match(SlashedString) ? Regexp.new(value[1..-2]) : context[value]
41
41
  end
42
42
  end
43
43
 
@@ -1,4 +1,3 @@
1
- require 'locomotive/middlewares/fonts'
2
1
  require 'locomotive/middlewares/seo_trailing_slash'
3
2
  require 'locomotive/middlewares/cache'
4
3
  require 'locomotive/middlewares/inline_editor'
@@ -9,7 +9,6 @@ end
9
9
  # FIXME: we have serialiez templates which have references to the old BSON::ObjectId class.
10
10
  module BSON
11
11
  class ObjectId < Moped::BSON::ObjectId; end
12
- # class Binary < Moped::BSON::Binary; end
13
12
  end
14
13
 
15
14
  module Mongoid#:nodoc:
@@ -53,21 +52,6 @@ module Mongoid#:nodoc:
53
52
  include Localizable
54
53
  end
55
54
 
56
- # class UniquenessValidator < ActiveModel::EachValidator
57
-
58
- # def to_validate_with_localization(document, attribute, value)
59
- # field = document.fields[attribute.to_s]
60
- # if field.try(:localized?)
61
- # # no need of the translations, just the current value
62
- # value = document.send(attribute.to_sym)
63
- # end
64
- # to_validate_without_localization(document, attribute, value)
65
- # end
66
-
67
- # alias_method_chain :to_validate, :localization
68
-
69
- # end
70
-
71
55
  module ClassMethods
72
56
  def validates_exclusion_of(*args)
73
57
  validates_with(ExclusionValidator, _merge_attributes(args))
@@ -189,7 +189,7 @@ module Locomotive
189
189
  'fullpath' => request.fullpath,
190
190
  'url' => request.url,
191
191
  'ip_address' => request.remote_ip,
192
- 'now' => Time.now.utc,
192
+ 'now' => Time.now.in_time_zone(current_site.timezone),
193
193
  'today' => Date.today,
194
194
  'locale' => I18n.locale.to_s,
195
195
  'default_locale' => current_site.default_locale.to_s,
@@ -1,3 +1,3 @@
1
1
  module Locomotive #:nodoc
2
- VERSION = '2.1.4'
2
+ VERSION = '2.2.0'
3
3
  end
@@ -12,15 +12,21 @@ namespace :locomotive do
12
12
  desc 'Rebuild the serialized template of all the site pages'
13
13
  task rebuild_serialized_page_templates: :environment do
14
14
  Locomotive::Site.all.each do |site|
15
- pages = site.pages.to_a
16
- while !pages.empty? do
17
- page = pages.pop
18
- begin
19
- page.send :_parse_and_serialize_template
20
- page.save
21
- puts "[#{site.name}] processing...#{page.title}"
22
- rescue TypeError => e
23
- pages.insert(0, page)
15
+ default_locale = site.default_locale
16
+
17
+ ([default_locale] + (site.locales - [default_locale])). each do |locale|
18
+ Mongoid::Fields::I18n.with_locale(locale) do
19
+ pages = site.pages.to_a
20
+ while !pages.empty? do
21
+ page = pages.pop
22
+ begin
23
+ page.send :_parse_and_serialize_template
24
+ page.save
25
+ puts "[#{site.name}][#{locale}] processing...#{page.title}"
26
+ rescue TypeError => e
27
+ pages.insert(0, page)
28
+ end
29
+ end
24
30
  end
25
31
  end
26
32
  end
@@ -74,7 +74,7 @@ class RenameEntryToContentEntry < MongoidMigration::Migration
74
74
 
75
75
  def self.fetch_rows(klass, &block)
76
76
  per_page = 100
77
- collection = klass.collection #.driver
77
+ collection = klass.collection
78
78
  count = collection.find.count
79
79
  num_pages = (count.to_f / per_page).floor
80
80
 
@@ -0,0 +1,42 @@
1
+ class CreateEditableTexts < MongoidMigration::Migration
2
+ def self.up
3
+ self.pages.each do |page|
4
+ attributes = {}
5
+
6
+ page['editable_elements'].each_with_index do |element, index|
7
+ next unless element['_type'] =~ /Text$/
8
+ attributes.merge!(new_attributes_for(element['_type'], index))
9
+ end
10
+
11
+ self.update_page(page['_id'], attributes)
12
+ end
13
+ end
14
+
15
+ def self.down
16
+
17
+ end
18
+
19
+ protected
20
+
21
+ def self.new_attributes_for(type, index)
22
+ {
23
+ "editable_elements.#{index}._type" => 'Locomotive::EditableText',
24
+ "editable_elements.#{index}.format" => type.ends_with?('LongText') ? 'html' : 'raw',
25
+ "editable_elements.#{index}.rows" => type.ends_with?('LongText') ? 15 : 2,
26
+ "editable_elements.#{index}.line_break" => type.ends_with?('LongText') ? true : false
27
+ }
28
+ end
29
+
30
+ def self.pages
31
+ Locomotive::Page.collection.find('editable_elements._type' => {
32
+ '$in' => ['Locomotive::EditableShortText', 'Locomotive::EditableLongText']
33
+ })
34
+ end
35
+
36
+ def self.update_page(id, attributes)
37
+ selector = { '_id' => id }
38
+ modifications = { '$set' => attributes }
39
+ Locomotive::Page.collection.find(selector).update(modifications)
40
+ end
41
+
42
+ end
@@ -0,0 +1,43 @@
1
+ class LocalizeSlugsOfContentEntries < 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.content_entries.each do |entry|
7
+ next if entry.attributes['_slug'].is_a?(Hash) # already translated
8
+
9
+ puts "\t#{entry._label} is not translated"
10
+
11
+ self.update_entry(site, entry)
12
+ end
13
+ end
14
+ end
15
+
16
+ def self.down
17
+ Locomotive::ContentEntry.all.each do |entry|
18
+ selector = { '_id' => entry._id }
19
+ modifications = entry.attributes['_slug'].values.first
20
+
21
+ Locomotive::ContentEntry.collection.find(selector).update({ '$set' => { '_slug' => modifications } })
22
+ end
23
+ end
24
+
25
+ # 2 cases:
26
+ # - not translated, set the slug for all the locales of the site
27
+ # - already translated copy the SAME slug for all the locales of the entry
28
+ #
29
+ def self.update_entry(site, entry)
30
+ selector = { '_id' => entry._id }
31
+ modifications = {}
32
+ slug = Mongoid::Fields::I18n.with_locale(site.default_locale) { entry._slug }
33
+
34
+ locales = entry.localized? ? entry.translated_in : site.locales
35
+
36
+ locales.each do |locale|
37
+ modifications[locale.to_s] = slug
38
+ end
39
+
40
+ Locomotive::ContentEntry.collection.find(selector).update({ '$set' => { '_slug' => modifications } })
41
+ end
42
+
43
+ end
@@ -38,7 +38,7 @@ Locomotive.configure do |config|
38
38
  config.default_locale = :en
39
39
 
40
40
  # available locales suggested to "localize" a site. You will have to pick up at least one among that list.
41
- config.site_locales = %w{en de fr pl pt-BR it nl nb es ru ja}
41
+ # config.site_locales = %w{en de fr pl pt-BR it nl nb es ru ja}
42
42
 
43
43
  # tell if logs are enabled. Useful for debug purpose.
44
44
  config.enable_logs = true
@@ -1,6 +1,6 @@
1
1
  # Be sure to restart your server when you modify this file.
2
2
 
3
- Dummy::Application.config.session_store :cookie_store, key: '_dummy_session', :domain => :all
3
+ # Dummy::Application.config.session_store :mongoid_store, key: '_dummy_session', :domain => :all
4
4
 
5
5
  # Use the database for sessions instead of the cookie-based default,
6
6
  # which shouldn't be used to store highly confidential information
@@ -186,7 +186,7 @@ describe Locomotive::Liquid::Drops::Page do
186
186
  'home' => @home
187
187
  }.merge(assigns)
188
188
 
189
- Liquid::Template.parse(template).render assigns
189
+ Liquid::Template.parse(template).render!(assigns)
190
190
  end
191
191
 
192
192
  end
@@ -20,6 +20,32 @@ describe Locomotive::Liquid::Filters::Misc do
20
20
  default(nil, 42).should == 42
21
21
  end
22
22
 
23
+ describe 'random' do
24
+
25
+ context 'from an integer' do
26
+
27
+ subject { random(4) }
28
+ it { should be_a_kind_of(Fixnum) }
29
+ it { should satisfy { |n| n >=0 && n < 4 } }
30
+
31
+ end
32
+
33
+ context 'from a string' do
34
+
35
+ subject { random('4') }
36
+ it { should be_a_kind_of(Fixnum) }
37
+ it { should satisfy { |n| n >=0 && n < 4 } }
38
+
39
+ end
40
+
41
+ end
42
+
43
+ it 'returns a random number' do
44
+ random_number = random(4)
45
+ random_number.class.should == Fixnum
46
+
47
+ end
48
+
23
49
  it 'should return a navigation block for the pagination' do
24
50
  pagination = {
25
51
  "previous" => nil,