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.
Files changed (140) hide show
  1. checksums.yaml +7 -0
  2. data/Gemfile +1 -0
  3. data/README.textile +2 -1
  4. data/app/assets/images/locomotive/icons/flags/bg.png +0 -0
  5. data/app/assets/images/locomotive/icons/flags/cs.png +0 -0
  6. data/app/assets/javascripts/locomotive/models/page.js.coffee +1 -1
  7. data/app/assets/javascripts/locomotive/utils/aloha_settings.js.coffee +2 -2
  8. data/app/assets/javascripts/locomotive/views/application_view.js.coffee +2 -2
  9. data/app/assets/javascripts/locomotive/views/content_assets/picker_view.js.coffee +2 -0
  10. data/app/assets/javascripts/locomotive/views/content_entries/_form_view.js.coffee +8 -0
  11. data/app/assets/javascripts/locomotive/views/editable_elements/text_view.js.coffee +2 -2
  12. data/app/assets/javascripts/locomotive/views/pages/edit_view.js.coffee +2 -0
  13. data/app/assets/javascripts/locomotive/views/shared/fields/belongs_to_view.js.coffee +2 -0
  14. data/app/assets/javascripts/locomotive/views/shared/form_view.js.coffee +7 -5
  15. data/app/assets/javascripts/tinymce/plugins/locomotive_media/editor_plugin.js +7 -3
  16. data/app/assets/javascripts/tinymce/plugins/locomotive_media/langs/cs.js +1 -0
  17. data/app/assets/stylesheets/locomotive/backoffice/datepicker.css.scss +66 -0
  18. data/app/assets/stylesheets/locomotive/backoffice/dialog_changes.css.scss +8 -2
  19. data/app/assets/stylesheets/locomotive/backoffice/formtastic_changes.css.scss +8 -0
  20. data/app/assets/stylesheets/locomotive/backoffice/menu/_colors.css.scss +1 -1
  21. data/app/controllers/locomotive/api/base_controller.rb +3 -0
  22. data/app/controllers/locomotive/api/content_entries_controller.rb +4 -4
  23. data/app/controllers/locomotive/api/tokens_controller.rb +4 -0
  24. data/app/controllers/locomotive/base_controller.rb +6 -3
  25. data/app/controllers/locomotive/public/base_controller.rb +3 -0
  26. data/app/controllers/locomotive/public/content_entries_controller.rb +2 -1
  27. data/app/helpers/locomotive/custom_fields_helper.rb +2 -2
  28. data/app/models/locomotive/content_type.rb +7 -0
  29. data/app/models/locomotive/editable_file.rb +1 -0
  30. data/app/models/locomotive/editable_text.rb +4 -1
  31. data/app/models/locomotive/extensions/page/editable_elements.rb +21 -0
  32. data/app/models/locomotive/extensions/page/templatized.rb +2 -2
  33. data/app/models/locomotive/extensions/page/tree.rb +5 -0
  34. data/app/models/locomotive/extensions/site/timezone.rb +7 -10
  35. data/app/models/locomotive/theme_asset.rb +2 -2
  36. data/app/presenters/locomotive/membership_presenter.rb +2 -1
  37. data/app/presenters/locomotive/site_presenter.rb +10 -1
  38. data/app/uploaders/locomotive/theme_asset_uploader.rb +7 -0
  39. data/app/views/locomotive/custom_fields/types/_date_time.html.haml +5 -0
  40. data/app/views/locomotive/notifications/new_content_entry.html.haml +1 -1
  41. data/app/views/locomotive/pages/_page.html.haml +2 -2
  42. data/config/locales/admin_ui.bg.yml +349 -0
  43. data/config/locales/admin_ui.cs.yml +359 -0
  44. data/config/locales/admin_ui.de.yml +25 -9
  45. data/config/locales/admin_ui.en.yml +3 -1
  46. data/config/locales/admin_ui.es.yml +2 -0
  47. data/config/locales/admin_ui.et.yml +3 -1
  48. data/config/locales/admin_ui.fr.yml +2 -0
  49. data/config/locales/admin_ui.it.yml +2 -0
  50. data/config/locales/admin_ui.ja.yml +2 -0
  51. data/config/locales/admin_ui.nb.yml +2 -0
  52. data/config/locales/admin_ui.nl.yml +2 -0
  53. data/config/locales/admin_ui.pl.yml +2 -0
  54. data/config/locales/admin_ui.pt-BR.yml +3 -1
  55. data/config/locales/admin_ui.ru.yml +2 -0
  56. data/config/locales/admin_ui.zh-CN.yml +2 -0
  57. data/config/locales/carrierwave.bg.yml +4 -0
  58. data/config/locales/carrierwave.cs.yml +4 -0
  59. data/config/locales/default.bg.yml +231 -0
  60. data/config/locales/default.cs.yml +249 -0
  61. data/config/locales/default.de.yml +24 -16
  62. data/config/locales/default.en.yml +4 -0
  63. data/config/locales/default.es.yml +1 -1
  64. data/config/locales/default.et.yml +1 -1
  65. data/config/locales/default.fr.yml +1 -1
  66. data/config/locales/default.it.yml +1 -1
  67. data/config/locales/default.ja.yml +4 -0
  68. data/config/locales/default.nb.yml +1 -1
  69. data/config/locales/default.nl.yml +1 -1
  70. data/config/locales/default.pl.yml +1 -1
  71. data/config/locales/default.pt-BR.yml +1 -1
  72. data/config/locales/default.ru.yml +1 -1
  73. data/config/locales/default.zh-CN.yml +1 -1
  74. data/config/locales/devise.bg.yml +64 -0
  75. data/config/locales/devise.cs.yml +64 -0
  76. data/config/locales/flash.bg.yml +115 -0
  77. data/config/locales/flash.cs.yml +115 -0
  78. data/config/locales/formtastic.bg.yml +113 -0
  79. data/config/locales/formtastic.cs.yml +125 -0
  80. data/config/locales/formtastic.de.yml +9 -0
  81. data/features/api/content_entries.feature +2 -0
  82. data/features/api/memberships.feature +26 -0
  83. data/features/backoffice/content_types/many_to_many.feature +3 -3
  84. data/features/backoffice/pages.feature +16 -0
  85. data/features/backoffice/regressions.feature +19 -0
  86. data/features/public/contact_form.feature +9 -0
  87. data/features/step_definitions/api_steps.rb +4 -1
  88. data/features/step_definitions/content_types_steps.rb +5 -0
  89. data/features/step_definitions/more_web_steps.rb +4 -0
  90. data/features/step_definitions/web_steps.rb +4 -0
  91. data/lib/generators/locomotive/install/templates/locomotive.rb +2 -2
  92. data/lib/locomotive.rb +1 -8
  93. data/lib/locomotive/action_controller.rb +1 -0
  94. data/lib/locomotive/action_controller/ssl.rb +11 -2
  95. data/lib/locomotive/action_controller/timezone.rb +13 -0
  96. data/lib/locomotive/configuration.rb +2 -2
  97. data/lib/locomotive/custom_fields.rb +1 -1
  98. data/lib/locomotive/dependencies.rb +2 -0
  99. data/lib/locomotive/engine.rb +10 -0
  100. data/lib/locomotive/httparty/webservice.rb +6 -5
  101. data/lib/locomotive/liquid/drops/base.rb +0 -2
  102. data/lib/locomotive/liquid/drops/content_entry.rb +11 -7
  103. data/lib/locomotive/liquid/drops/content_types.rb +46 -30
  104. data/lib/locomotive/liquid/drops/current_user.rb +3 -3
  105. data/lib/locomotive/liquid/drops/page.rb +15 -15
  106. data/lib/locomotive/liquid/drops/proxy_collection.rb +5 -1
  107. data/lib/locomotive/liquid/drops/site.rb +10 -6
  108. data/lib/locomotive/liquid/drops/uploader.rb +2 -2
  109. data/lib/locomotive/liquid/filters/date.rb +29 -3
  110. data/lib/locomotive/liquid/filters/resize.rb +3 -1
  111. data/lib/locomotive/liquid/filters/text.rb +4 -0
  112. data/lib/locomotive/liquid/tags/editable/control.rb +11 -1
  113. data/lib/locomotive/liquid/tags/link_to.rb +5 -3
  114. data/lib/locomotive/liquid/tags/nav.rb +19 -10
  115. data/lib/locomotive/liquid/tags/with_scope.rb +29 -31
  116. data/lib/locomotive/markdown.rb +23 -0
  117. data/lib/locomotive/render.rb +6 -2
  118. data/lib/locomotive/version.rb +1 -1
  119. data/lib/tasks/locomotive.rake +5 -2
  120. data/mongodb/migrate/20130511121956_generate_checksum_for_theme_assets.rb +5 -1
  121. data/mongodb/migrate/20130903145451_localize_redirect_urls_of_pages.rb +42 -0
  122. data/spec/dummy/config/initializers/locomotive.rb +2 -2
  123. data/spec/dummy/config/mongoid.yml +1 -0
  124. data/spec/lib/locomotive/httparty/webservice_spec.rb +1 -1
  125. data/spec/lib/locomotive/liquid/filters/date_spec.rb +61 -2
  126. data/spec/lib/locomotive/liquid/filters/text_spec.rb +4 -0
  127. data/spec/lib/locomotive/liquid/tags/consume_spec.rb +6 -2
  128. data/spec/lib/locomotive/liquid/tags/nav_spec.rb +1 -1
  129. data/spec/lib/locomotive/liquid/tags/with_scope_spec.rb +33 -27
  130. data/spec/lib/locomotive/render_spec.rb +2 -2
  131. data/spec/lib/locomotive/routing/site_dispatcher_spec.rb +1 -1
  132. data/spec/models/locomotive/content_entry_spec.rb +1 -1
  133. data/spec/models/locomotive/editable_control_spec.rb +9 -0
  134. data/spec/models/locomotive/extensions/page/editable_elements_spec.rb +6 -0
  135. data/spec/models/locomotive/page_spec.rb +13 -0
  136. data/spec/requests/admin_ssl_spec.rb +29 -7
  137. data/spec/support/factories.rb +6 -0
  138. data/vendor/assets/javascripts/locomotive/jquery-ui-timepicker-addon.js +2134 -0
  139. data/vendor/assets/stylesheets/select2/select2.css.scss +3 -3
  140. metadata +54 -94
@@ -12,6 +12,22 @@ Scenario: Pages list is not accessible for non authenticated accounts
12
12
  When I go to pages
13
13
  Then I should see "You need to sign in or sign up before continuing"
14
14
 
15
+ Scenario: Templatized pages are avaiable to authors
16
+ Given I am not authenticated
17
+ And I am an authenticated "author"
18
+ And I have a custom model named "Articles" with
19
+ | label | type | required |
20
+ | Title | string | true |
21
+ And I have entries for "Articles" with
22
+ | title |
23
+ | Hello world |
24
+ And a templatized page for the "Articles" model and with the template:
25
+ """
26
+ Here is the title: "{{ article.title }}"
27
+ """
28
+ When I go to pages
29
+ Then I should see "Template for Articles"
30
+
15
31
  @javascript
16
32
  Scenario: Creating a valid page
17
33
  When I go to pages
@@ -0,0 +1,19 @@
1
+ Feature: Specific tests to avoid bug regressions
2
+
3
+ @javascript
4
+ Scenario: Changing a field requiredness when the first field is a file (WTF)
5
+ Given I have the site: "test site" set up
6
+ And I have a custom model named "Projects" with
7
+ | label | type | required | target |
8
+ | Image | file | true | |
9
+ | Description | string | true | |
10
+ And I am an authenticated user
11
+ Given I go to the list of "Projects"
12
+ And I follow "new entry" within the main content
13
+ Then I should see "Description*"
14
+ Given I go to the "Projects" model edition page
15
+ And I click on the 2nd required flag
16
+ And I press "Save"
17
+ And I wait 100ms
18
+ When I follow "new entry" within the main content
19
+ Then I should not see "Description*"
@@ -87,3 +87,12 @@ Feature: Contact form
87
87
  And I fill in "Message" with "LocomotiveCMS rocks"
88
88
  And I press "Submit"
89
89
  Then I should see "Email is required"
90
+
91
+ Scenario: Make sure to use the right locale
92
+ When I view the rendered page at "/contact"
93
+ And the locale of the current ruby thread changes to "fr"
94
+ And I fill in "E-Mail Address" with "did@locomotivecms.com"
95
+ And I fill in "Message" with "LocomotiveCMS rocks"
96
+ And I select "Code" from "Category"
97
+ And I press "Submit"
98
+ Then I should see "Thanks did@locomotivecms.com"
@@ -1,4 +1,3 @@
1
-
2
1
  def api_base_url
3
2
  "http://#{Locomotive::Site.first.domains.first}/locomotive/api/"
4
3
  end
@@ -159,6 +158,10 @@ Then /^the JSON at "([^"]*)" should match \/(.+)\/$/ do |path, regex|
159
158
  parse_json(last_json, path).should =~ /#{regex}/
160
159
  end
161
160
 
161
+ Then /^the response content type should match \/(.+)\/$/ do |regex|
162
+ @json_response.header['Content-Type'].should =~ /#{regex}/
163
+ end
164
+
162
165
  Then /^the JSON at "([^"]*)" should be the time "(.+)"$/ do |path, time_str|
163
166
  format = '%Y-%m-%dT%H:%M:%S%Z'
164
167
  json_time_str = parse_json(last_json, path)
@@ -122,3 +122,8 @@ Then %r{^there should not be any notified accounts on the "([^"]*)" model$} do |
122
122
  content_type = Locomotive::ContentType.where(name: name).first
123
123
  content_type.reload.public_submission_accounts.should eq([])
124
124
  end
125
+
126
+ Given(/^I click on the (\d+)[a-z]+ required flag$/) do |nth|
127
+ find(".custom-field:nth-child(#{nth}) .required-input .switchHandle").click
128
+ sleep(0.1)
129
+ end
@@ -1,3 +1,7 @@
1
+ When(/^the locale of the current ruby thread changes to "(.*?)"$/) do |locale|
2
+ ::I18n.locale = ::Mongoid::Fields::I18n.locale = 'fr'
3
+ end
4
+
1
5
  When /^I follow image link "([^"]*)"$/ do |img_alt|
2
6
  find(:xpath, "//img[@alt = '#{img_alt}']/parent::a").click()
3
7
  end
@@ -212,3 +212,7 @@ end
212
212
  Then /^show me the page$/ do
213
213
  save_and_open_page
214
214
  end
215
+
216
+ Then(/^I click on "(.*?)"$/) do |selector|
217
+ find(selector).click
218
+ end
@@ -23,11 +23,11 @@ Locomotive.configure do |config|
23
23
  # per_page: 10
24
24
  # }
25
25
 
26
- # default locale (for now, only en, de, fr, pl, pt-BR, it, nb, ja and zh-CN are supported)
26
+ # default locale (for now, only en, de, fr, pl, pt-BR, it, nb, ja, zh-CN, cs and bg are supported)
27
27
  config.default_locale = :en
28
28
 
29
29
  # available locales suggested to "localize" a site. You will have to pick up at least one among that list.
30
- # config.site_locales = %w{en de fr pl pt-BR it nl nb es ru ja zh-CN}
30
+ # config.site_locales = %w{en de fr pl pt-BR it nl nb es ru ja zh-CN cs bg}
31
31
 
32
32
  # tell if logs are enabled. Useful for debug purpose.
33
33
  config.enable_logs = true
@@ -7,6 +7,7 @@ require 'locomotive/haml'
7
7
  require 'locomotive/formtastic'
8
8
  require 'locomotive/dragonfly'
9
9
  require 'locomotive/kaminari'
10
+ require 'locomotive/markdown'
10
11
  require 'locomotive/liquid'
11
12
  require 'locomotive/presentable'
12
13
  require 'locomotive/mongoid'
@@ -61,14 +62,6 @@ module Locomotive
61
62
  # add middlewares (dragonfly, font, seo, ...etc)
62
63
  self.add_middlewares
63
64
 
64
- # Load all the dynamic classes (custom fields)
65
- begin
66
- ContentType.all.collect { |content_type| content_type.klass_with_custom_fields(:entries) }
67
- rescue Exception => e
68
- # let assume it's because of the first install (meaning no config.yml file)
69
- Locomotive.log :warn, "WARNING: unable to load the content types, #{e.message}"
70
- end
71
-
72
65
  # enable the hosting solution if both we are not in test or dev and that the config.hosting option has been filled up
73
66
  self.enable_hosting
74
67
 
@@ -2,5 +2,6 @@ require 'locomotive/action_controller/locale_helpers'
2
2
  require 'locomotive/action_controller/section_helpers'
3
3
  require 'locomotive/action_controller/url_helpers'
4
4
  require 'locomotive/action_controller/ssl'
5
+ require 'locomotive/action_controller/timezone'
5
6
  require 'locomotive/action_controller/responder'
6
7
  require 'locomotive/action_controller/public_responder'
@@ -3,9 +3,18 @@ module Locomotive
3
3
  module Ssl
4
4
 
5
5
  def require_ssl
6
- redirect_to protocol: 'https://' if Locomotive.config.enable_admin_ssl && !request.ssl?
6
+ # already a ssl request or ssl disabled ?
7
+ return if !Locomotive.config.enable_admin_ssl || request.ssl?
8
+
9
+ # only require ssl for requests for the main domain
10
+ if !Locomotive.config.multi_sites? || Locomotive.config.multi_sites.domain == request.domain
11
+ redirect_to protocol: 'https://'
12
+ end
13
+
14
+ true
7
15
  end
8
16
 
9
17
  end
10
18
  end
11
- end
19
+ end
20
+
@@ -0,0 +1,13 @@
1
+ module Locomotive
2
+ module ActionController
3
+ module Timezone
4
+
5
+ protected
6
+
7
+ def set_timezone(&block)
8
+ Time.use_zone(current_site.try(:timezone) || 'UTC', &block)
9
+ end
10
+
11
+ end
12
+ end
13
+ end
@@ -7,8 +7,8 @@ module Locomotive
7
7
  reserved_subdomains: %w{www admin email blog webmail mail support help site sites},
8
8
  # forbidden_paths: %w{layouts snippets stylesheets javascripts assets admin system api},
9
9
  reserved_slugs: %w{stylesheets javascripts assets admin locomotive images api pages edit},
10
- locales: %w{en de fr pl pt-BR it nl nb es ru et ja zh-CN},
11
- site_locales: %w{en de fr pl pt-BR it nl nb es ru et ja zh-CN},
10
+ locales: %w{en de fr pl pt-BR it nl nb es ru et ja zh-CN cs bg},
11
+ site_locales: %w{en de fr pl pt-BR it nl nb es ru et ja zh-CN cs bg},
12
12
  cookie_key: '_locomotive_session',
13
13
  enable_logs: false,
14
14
  enable_admin_ssl: false,
@@ -1,6 +1,6 @@
1
1
  # Custom options for CustomFields
2
2
  CustomFields.options = {
3
- reserved_names: Mongoid.destructive_fields + %w(created_at updated_at)
3
+ reserved_names: Mongoid.destructive_fields + %w(id _id send created_at updated_at)
4
4
  }
5
5
 
6
6
  module CustomFields
@@ -9,6 +9,7 @@ require 'devise-encryptable'
9
9
  require 'kaminari'
10
10
  require 'haml'
11
11
  require 'liquid'
12
+ require 'solid'
12
13
  require 'formtastic'
13
14
  require 'responders'
14
15
  require 'carrierwave'
@@ -17,6 +18,7 @@ require 'mimetype_fu'
17
18
  require 'actionmailer_with_request'
18
19
  require 'httparty'
19
20
  require 'redcloth'
21
+ require 'redcarpet'
20
22
  require 'dragonfly'
21
23
  require 'cancan'
22
24
  require 'cells'
@@ -11,6 +11,16 @@ module Locomotive
11
11
  paths['mongodb/migrate'] = 'mongodb/migrate'
12
12
  # config.autoload_once_paths += %W( #{config.root}/app/controllers #{config.root}/app/models #{config.root}/app/helpers #{config.root}/app/uploaders)
13
13
 
14
+ initializer 'locomotive.content_types' do |app|
15
+ # Load all the dynamic classes (custom fields)
16
+ begin
17
+ ContentType.all.collect { |content_type| content_type.klass_with_custom_fields(:entries) }
18
+ rescue Exception => e
19
+ # let assume it's because of the first install (meaning no config.yml file)
20
+ Locomotive.log :warn, "WARNING: unable to load the content types, #{e.message}"
21
+ end
22
+ end
23
+
14
24
  initializer 'locomotive.cells' do |app|
15
25
  Cell::Base.prepend_view_path("#{config.root}/app/cells")
16
26
  end
@@ -23,13 +23,14 @@ module Locomotive
23
23
 
24
24
  # puts "[WebService] consuming #{path}, #{options.inspect}"
25
25
 
26
- response = self.get(path, options)
26
+ response = self.get(path, options)
27
+ parsed_response = response.parsed_response
27
28
 
28
29
  if response.code == 200
29
- if response.respond_to?(:underscore_keys)
30
- response.underscore_keys
30
+ if parsed_response.respond_to?(:underscore_keys)
31
+ parsed_response.underscore_keys
31
32
  else
32
- response.collect(&:underscore_keys)
33
+ parsed_response.collect(&:underscore_keys)
33
34
  end
34
35
  else
35
36
  nil
@@ -39,4 +40,4 @@ module Locomotive
39
40
 
40
41
  end
41
42
  end
42
- end
43
+ end
@@ -6,8 +6,6 @@ module Locomotive
6
6
 
7
7
  @@forbidden_attributes = %w{_id _version _index}
8
8
 
9
- attr_reader :_source
10
-
11
9
  def initialize(source)
12
10
  @_source = source
13
11
  end
@@ -3,14 +3,14 @@ module Locomotive
3
3
  module Drops
4
4
  class ContentEntry < Base
5
5
 
6
- delegate :_slug, :_permalink, :seo_title, :meta_keywords, :meta_description, to: '_source'
6
+ delegate :_slug, :_permalink, :seo_title, :meta_keywords, :meta_description, to: :@_source
7
7
 
8
8
  def _id
9
- self._source._id.to_s
9
+ @_source._id.to_s
10
10
  end
11
11
 
12
12
  def _label
13
- @_label ||= self._source._label
13
+ @_label ||= @_source._label
14
14
  end
15
15
 
16
16
  # Returns the next content for the parent content type.
@@ -23,7 +23,7 @@ module Locomotive
23
23
  # {% endif %}
24
24
  #
25
25
  def next
26
- @next ||= self._source.next.to_liquid
26
+ @next ||= @_source.next.to_liquid
27
27
  end
28
28
 
29
29
  # Returns the previous content for the parent content type.
@@ -36,14 +36,18 @@ module Locomotive
36
36
  # {% endif %}
37
37
  #
38
38
  def previous
39
- @previous ||= self._source.previous.to_liquid
39
+ @previous ||= @_source.previous.to_liquid
40
+ end
41
+
42
+ def errors
43
+ @_source.errors.messages.to_hash.stringify_keys
40
44
  end
41
45
 
42
46
  def before_method(meth)
43
- return '' if self._source.nil?
47
+ return '' if @_source.nil?
44
48
 
45
49
  if not @@forbidden_attributes.include?(meth.to_s)
46
- value = self._source.send(meth)
50
+ value = @_source.send(meth)
47
51
 
48
52
  if value.respond_to?(:all) # check for an association
49
53
  filter_and_order_list(value)
@@ -48,45 +48,61 @@ module Locomotive
48
48
  @collection ||= @content_type.ordered_entries(@context['with_scope']).visible
49
49
  end
50
50
 
51
+ # Modify the attributes of the with_scope tag so that
52
+ # they can be resolved by MongoDB.
53
+ #
51
54
  def modify_with_scope
52
- fields = @content_type.ordered_custom_fields(:entries)
53
-
54
55
  @context['with_scope'].dup.each do |key, value|
55
- if relation = self.relation_with(key)
56
- # belongs_to, has_many, many_to_many relationships: use the _id
57
- self.modify_with_scope_with_relation(key, value, relation)
58
- elsif field = fields.detect { |f| f.name == key && f.type == 'select' }
59
- # use the id of the option instead of the name
60
- self.modify_with_scope_with_select(key, value, field)
56
+ field = @content_type.find_entries_custom_field(key.to_s)
57
+
58
+ next if field.nil?
59
+
60
+ case field.type.to_sym
61
+ when :belongs_to
62
+ self.modify_with_scope_key(key, "#{key.to_s}_id", self.object_to_id(field, value))
63
+ when :many_to_many
64
+ self.modify_with_scope_key(key, "#{key.to_s.singularize}_ids", self.object_to_id(field, value))
65
+ when :select
66
+ option = field.select_options.detect { |option| [option.name, option._id.to_s].include?(value) }
67
+ self.modify_with_scope_key(key, "#{key.to_s}_id", option.try(:_id))
61
68
  end
62
69
  end
63
70
  end
64
71
 
65
- def modify_with_scope_with_relation(key, value, relation)
66
- model = Locomotive::ContentType.class_name_to_content_type(relation.class_name, @context.registers[:site])
67
- entry = model.entries.where(model.label_field_name => value).first
68
-
69
- # modify the scope
70
- @context['with_scope'].delete(key)
71
- @context['with_scope'][relation.key] = entry
72
- end
73
-
74
- def relation_with(name)
75
- @relations ||= @content_type.klass_with_custom_fields(:entries).relations
76
-
77
- if @relations.keys.include?(name.to_s)
78
- @relations[name]
79
- elsif @relations.keys.include?(name.to_s.pluralize)
80
- @relations[name.to_s.pluralize]
72
+ # Change the value of a key of the with_scope depending of its type.
73
+ # If the key is a Origin::Key, we only change the name.
74
+ # If the key is a String, we replace it.
75
+ #
76
+ # @param [ Object ] key Either a String or a Origin::Key
77
+ # @param [ String ] name The new name of the key
78
+ # @param [ String ] value The new value associated to the key
79
+ #
80
+ def modify_with_scope_key(key, name, value)
81
+ if key.respond_to?(:operator)
82
+ key.instance_variable_set :@name, name
83
+ @context['with_scope'][key] = value
84
+ else
85
+ @context['with_scope'].delete(key)
86
+ @context['with_scope'][name] = value
81
87
  end
82
88
  end
83
89
 
84
- def modify_with_scope_with_select(key, value, field)
85
- option = field.select_options.detect { |option| [option.name, option._id.to_s].include?(value) }
86
-
87
- # modify the scope
88
- @context['with_scope'].delete(key)
89
- @context['with_scope']["#{key}_id"] = option.try(:_id)
90
+ # Get the _id attribute of a object or a list of objects which
91
+ # can include String (needed to retrieve a model
92
+ # based on its permalink or its label field) or ContentEntry instances.
93
+ #
94
+ # @param [ Object ] field The custom field
95
+ # @param [ Object ] value An object (content entry or label) or a list of objects
96
+ #
97
+ def object_to_id(field, value)
98
+ if value.respond_to?(:map)
99
+ value.map { |el| self.object_to_id(field, el) }
100
+ elsif value.respond_to?(:_id)
101
+ value._id
102
+ else
103
+ model = Locomotive::ContentType.class_name_to_content_type(field.class_name, @content_type.site)
104
+ model.entries.or({ _slug: value }, { model.label_field_name => value }).first.try(:_id)
105
+ end
90
106
  end
91
107
 
92
108
  end
@@ -4,15 +4,15 @@ module Locomotive
4
4
  class CurrentUser < Base
5
5
 
6
6
  def logged_in?
7
- _source.present?
7
+ @_source.present?
8
8
  end
9
9
 
10
10
  def name
11
- _source.name if logged_in?
11
+ @_source.name if logged_in?
12
12
  end
13
13
 
14
14
  def email
15
- _source.email if logged_in?
15
+ @_source.email if logged_in?
16
16
  end
17
17
 
18
18
  end
@@ -3,62 +3,62 @@ module Locomotive
3
3
  module Drops
4
4
  class Page < Base
5
5
 
6
- delegate :seo_title, :meta_keywords, :meta_description, :redirect_url, :handle, to: '_source'
6
+ delegate :seo_title, :meta_keywords, :meta_description, :redirect_url, :handle, to: :@_source
7
7
 
8
8
  def title
9
- self._source.templatized? ? @context['entry']._label : self._source.title
9
+ @_source.templatized? ? @context['entry']._label : @_source.title
10
10
  end
11
11
 
12
12
  def slug
13
- self._source.templatized? ? @context['entry']._slug.singularize : self._source.slug
13
+ @_source.templatized? ? @context['entry']._slug.singularize : @_source.slug
14
14
  end
15
15
 
16
16
  def parent
17
- @parent ||= self._source.parent.to_liquid
17
+ @parent ||= @_source.parent.to_liquid
18
18
  end
19
19
 
20
20
  def breadcrumbs
21
- @breadcrumbs ||= liquify(*self._source.ancestors_and_self)
21
+ @breadcrumbs ||= liquify(*@_source.ancestors_and_self)
22
22
  end
23
23
 
24
24
  def children
25
- @children ||= liquify(*self._source.children)
25
+ @children ||= liquify(*@_source.children)
26
26
  end
27
27
 
28
28
  def fullpath
29
- @fullpath ||= self._source.fullpath
29
+ @fullpath ||= @_source.fullpath
30
30
  end
31
31
 
32
32
  def depth
33
- self._source.depth
33
+ @_source.depth
34
34
  end
35
35
 
36
36
  def listed?
37
- self._source.listed?
37
+ @_source.listed?
38
38
  end
39
39
 
40
40
  def published?
41
- self._source.published?
41
+ @_source.published?
42
42
  end
43
43
 
44
44
  def redirect?
45
- self._source.redirect?
45
+ @_source.redirect?
46
46
  end
47
47
 
48
48
  def templatized?
49
- self._source.templatized?
49
+ @_source.templatized?
50
50
  end
51
51
 
52
52
  def content_type
53
- if self._source.content_type
54
- ContentTypeProxyCollection.new(self._source.content_type)
53
+ if @_source.content_type
54
+ ContentTypeProxyCollection.new(@_source.content_type)
55
55
  else
56
56
  nil
57
57
  end
58
58
  end
59
59
 
60
60
  def before_method(meth)
61
- self._source.editable_elements.where(slug: meth).try(:first).try(:content)
61
+ @_source.editable_elements.where(slug: meth).try(:first).try(:content)
62
62
  end
63
63
 
64
64
  end