locomotivecms 3.0.0.pre.beta.1 → 3.0.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (175) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +4 -3
  3. data/app/api/locomotive/api.rb +1 -0
  4. data/app/api/locomotive/api/entities/page_entity.rb +1 -1
  5. data/app/api/locomotive/api/entities/site_entity.rb +9 -1
  6. data/app/api/locomotive/api/exception_rescuers.rb +3 -5
  7. data/app/api/locomotive/api/forms/page_form.rb +1 -1
  8. data/app/api/locomotive/api/forms/site_form.rb +1 -2
  9. data/app/api/locomotive/api/helpers/authentication_helper.rb +6 -1
  10. data/app/api/locomotive/api/helpers/locales_helper.rb +15 -0
  11. data/app/api/locomotive/api/helpers/params_helper.rb +13 -0
  12. data/app/api/locomotive/api/middlewares/locale_middleware.rb +6 -1
  13. data/app/api/locomotive/api/resources/content_entry_resource.rb +2 -0
  14. data/app/api/locomotive/api/resources/content_type_resource.rb +2 -2
  15. data/app/api/locomotive/api/resources/current_site_resource.rb +2 -1
  16. data/app/api/locomotive/api/resources/membership_resource.rb +0 -4
  17. data/app/api/locomotive/api/resources/page_resource.rb +6 -1
  18. data/app/api/locomotive/api/resources/site_resource.rb +4 -2
  19. data/app/assets/javascripts/locomotive.js +1 -0
  20. data/app/assets/javascripts/locomotive/utils/nprogress.js.coffee +3 -1
  21. data/app/assets/javascripts/locomotive/views/editable_elements/index_view.js.coffee +10 -3
  22. data/app/assets/javascripts/locomotive/views/inputs/markdown_view.js.coffee +82 -0
  23. data/app/assets/javascripts/locomotive/views/inputs/rte/file_view.js.coffee +1 -1
  24. data/app/assets/javascripts/locomotive/views/inputs/rte/link_view.js.coffee +1 -1
  25. data/app/assets/javascripts/locomotive/views/inputs/rte_view.js.coffee.erb +1 -1
  26. data/app/assets/javascripts/locomotive/views/inputs/text_view.js.coffee +4 -1
  27. data/app/assets/javascripts/locomotive/views/pages/list_view.js.coffee +3 -0
  28. data/app/assets/javascripts/locomotive/views/shared/form_view.js.coffee +22 -1
  29. data/app/assets/javascripts/locomotive/views/shared/header_view.js.coffee +2 -2
  30. data/app/assets/stylesheets/locomotive/application.scss +2 -0
  31. data/app/assets/stylesheets/locomotive/base/_form.scss +2 -0
  32. data/app/assets/stylesheets/locomotive/base/form/_api_key.scss +0 -1
  33. data/app/assets/stylesheets/locomotive/base/form/_array_input.scss +2 -0
  34. data/app/assets/stylesheets/locomotive/base/form/_base.scss +13 -2
  35. data/app/assets/stylesheets/locomotive/base/form/_color_input.scss +12 -0
  36. data/app/assets/stylesheets/locomotive/base/form/_markdown.scss +292 -0
  37. data/app/assets/stylesheets/locomotive/base/form/_popover.scss +22 -0
  38. data/app/assets/stylesheets/locomotive/base/form/_rte.scss +2 -1
  39. data/app/assets/stylesheets/locomotive/components/_activity_feed.scss +1 -0
  40. data/app/assets/stylesheets/locomotive/components/_dashboard.scss +29 -0
  41. data/app/assets/stylesheets/locomotive/components/_live_editing.scss +13 -1
  42. data/app/assets/stylesheets/locomotive/components/_main.scss +1 -1
  43. data/app/assets/stylesheets/locomotive/components/_transitions.scss +24 -3
  44. data/app/assets/stylesheets/locomotive/components/sidebar/_base.scss +1 -0
  45. data/app/assets/stylesheets/locomotive/globals/_bootstrap.scss +2 -2
  46. data/app/assets/stylesheets/locomotive/globals/_variables.scss +4 -3
  47. data/app/assets/stylesheets/locomotive/layouts/_live_editing.scss +4 -0
  48. data/app/controllers/locomotive/concerns/locale_helpers_controller.rb +1 -0
  49. data/app/controllers/locomotive/content_entries_controller.rb +10 -2
  50. data/app/controllers/locomotive/pages_controller.rb +2 -1
  51. data/app/controllers/locomotive/passwords_controller.rb +17 -1
  52. data/app/helpers/locomotive/base_helper.rb +19 -0
  53. data/app/helpers/locomotive/content_types_helper.rb +2 -1
  54. data/app/helpers/locomotive/custom_fields_helper.rb +14 -1
  55. data/app/helpers/locomotive/dashboard_helper.rb +12 -0
  56. data/app/helpers/locomotive/editable_elements_helper.rb +9 -4
  57. data/app/helpers/locomotive/pages_helper.rb +1 -14
  58. data/app/helpers/locomotive/shared/pages_helper.rb +17 -0
  59. data/app/helpers/locomotive/translations_helper.rb +0 -14
  60. data/app/inputs/locomotive/color_input.rb +18 -0
  61. data/app/inputs/locomotive/markdown_input.rb +19 -0
  62. data/app/models/locomotive/account.rb +2 -1
  63. data/app/models/locomotive/concerns/content_entry/file_size.rb +27 -0
  64. data/app/models/locomotive/concerns/content_type/group_by.rb +3 -1
  65. data/app/models/locomotive/concerns/page/layout.rb +63 -19
  66. data/app/models/locomotive/concerns/shared/site_scope.rb +37 -0
  67. data/app/models/locomotive/concerns/site/cache.rb +32 -0
  68. data/app/models/locomotive/concerns/theme_asset/plain_text.rb +85 -0
  69. data/app/models/locomotive/content_entry.rb +7 -7
  70. data/app/models/locomotive/content_type.rb +12 -6
  71. data/app/models/locomotive/page.rb +12 -14
  72. data/app/models/locomotive/site.rb +9 -3
  73. data/app/models/locomotive/snippet.rb +6 -4
  74. data/app/models/locomotive/theme_asset.rb +8 -73
  75. data/app/models/locomotive/translation.rb +6 -5
  76. data/app/policies/locomotive/site_policy.rb +2 -2
  77. data/app/services/locomotive/content_entry_service.rb +7 -6
  78. data/app/services/locomotive/site_service.rb +1 -0
  79. data/app/views/locomotive/content_entries/_entry.html.slim +1 -0
  80. data/app/views/locomotive/content_entries/edit.html.slim +1 -1
  81. data/app/views/locomotive/content_entries/new.html.slim +1 -1
  82. data/app/views/locomotive/current_site/_membership.html.slim +1 -0
  83. data/app/views/locomotive/current_site/edit.html.slim +1 -1
  84. data/app/views/locomotive/current_site/form/_access_points.html.slim +1 -1
  85. data/app/views/locomotive/current_site/form/_advanced.html.slim +2 -0
  86. data/app/views/locomotive/dashboard/_activity.html.slim +26 -0
  87. data/app/views/locomotive/dashboard/_url.html.slim +9 -0
  88. data/app/views/locomotive/dashboard/show.html.slim +3 -21
  89. data/app/views/locomotive/devise_mailer/reset_password_instructions.html.slim +1 -1
  90. data/app/views/locomotive/editable_elements/_edit.html.slim +8 -1
  91. data/app/views/locomotive/editable_elements/_form.html.slim +1 -1
  92. data/app/views/locomotive/editable_elements/index_without_preview.html.slim +24 -17
  93. data/app/views/locomotive/layouts/application.html.slim +6 -4
  94. data/app/views/locomotive/layouts/live_editing.html.slim +9 -0
  95. data/app/views/locomotive/layouts/not_logged_in.html.slim +1 -1
  96. data/app/views/locomotive/layouts/without_site.html.slim +2 -0
  97. data/app/views/locomotive/memberships/edit.html.slim +1 -1
  98. data/app/views/locomotive/memberships/new.html.slim +1 -1
  99. data/app/views/locomotive/my_account/edit.html.slim +7 -5
  100. data/app/views/locomotive/pages/_header.html.slim +7 -0
  101. data/app/views/locomotive/pages/edit.html.slim +2 -4
  102. data/app/views/locomotive/pages/form/_main.html.slim +4 -1
  103. data/app/views/locomotive/pages/form/_tabs.html.slim +4 -3
  104. data/app/views/locomotive/public_submission_accounts/_account.html.slim +1 -1
  105. data/app/views/locomotive/public_submission_accounts/edit.html.slim +1 -1
  106. data/app/views/locomotive/shared/_header.html.slim +25 -22
  107. data/app/views/locomotive/shared/_locale_picker_link.html.slim +3 -0
  108. data/app/views/locomotive/shared/_main_app_header.html.slim +1 -1
  109. data/app/views/locomotive/shared/_sidebar.html.slim +15 -11
  110. data/app/views/locomotive/shared/rte/_markdown_toolbar.html.slim +42 -0
  111. data/config/locales/admin_ui.en.yml +9 -4
  112. data/config/locales/default.en.yml +4 -0
  113. data/config/locales/devise.en.yml +1 -0
  114. data/config/locales/simple_form.en.yml +6 -2
  115. data/lib/locomotive/action_controller/responder.rb +5 -0
  116. data/lib/locomotive/engine.rb +5 -0
  117. data/lib/locomotive/middlewares/site.rb +39 -21
  118. data/lib/locomotive/simple_form.rb +3 -31
  119. data/lib/locomotive/steam/middlewares/cache.rb +62 -0
  120. data/lib/locomotive/steam/middlewares/page_editing.rb +9 -3
  121. data/lib/locomotive/steam/services/api_entry_submission_service.rb +6 -3
  122. data/lib/locomotive/steam/services/liquid_parser_with_cache_service.rb +74 -0
  123. data/lib/locomotive/steam_adaptor.rb +7 -1
  124. data/lib/locomotive/version.rb +1 -1
  125. data/lib/tasks/development.rake +4 -0
  126. data/lib/tasks/locomotive.rake +14 -0
  127. data/spec/lib/locomotive/steam/services/api_entry_submission_service_spec.rb +10 -1
  128. data/spec/lib/locomotive/steam/services/liquid_parser_with_cache_service_spec.rb +53 -0
  129. data/spec/models/locomotive/concerns/content_entry/file_size_spec.rb +40 -0
  130. data/spec/models/locomotive/concerns/page/layout_spec.rb +122 -17
  131. data/spec/models/locomotive/concerns/site/cache_spec.rb +60 -0
  132. data/spec/models/locomotive/content_entry_spec.rb +7 -0
  133. data/spec/models/locomotive/content_type_spec.rb +18 -11
  134. data/spec/models/locomotive/page_spec.rb +32 -8
  135. data/spec/models/locomotive/snippet_spec.rb +13 -4
  136. data/spec/models/locomotive/theme_asset_spec.rb +10 -3
  137. data/spec/models/locomotive/translation_spec.rb +28 -0
  138. data/spec/requests/locomotive/steam/cache_spec.rb +83 -0
  139. data/spec/requests/site_spec.rb +24 -0
  140. data/spec/support/capybara.rb +5 -13
  141. data/spec/support/factories.rb +9 -0
  142. data/spec/support/features/session_helpers.rb +19 -3
  143. data/spec/support/features/site_helpers.rb +27 -0
  144. data/spec/support/shared_examples/site_scope_examples.rb +27 -0
  145. data/vendor/assets/images/locomotive/bootstrap-colorpicker/alpha-horizontal.png +0 -0
  146. data/vendor/assets/images/locomotive/bootstrap-colorpicker/alpha.png +0 -0
  147. data/vendor/assets/images/locomotive/bootstrap-colorpicker/hue-horizontal.png +0 -0
  148. data/vendor/assets/images/locomotive/bootstrap-colorpicker/hue.png +0 -0
  149. data/vendor/assets/images/locomotive/bootstrap-colorpicker/saturation.png +0 -0
  150. data/vendor/assets/javascripts/locomotive/bootstrap-colorpicker.js +1 -0
  151. data/vendor/assets/javascripts/locomotive/datepicker_i18n.js.erb +6 -6
  152. data/vendor/assets/javascripts/locomotive/kramed.min.js +11 -0
  153. data/vendor/assets/stylesheets/locomotive/bootstrap-colorpicker.scss +9 -0
  154. metadata +59 -44
  155. data/app/controllers/locomotive/api/accounts_controller.rb +0 -60
  156. data/app/controllers/locomotive/api/base_controller.rb +0 -35
  157. data/app/controllers/locomotive/api/content_assets_controller.rb +0 -51
  158. data/app/controllers/locomotive/api/content_entries_controller.rb +0 -71
  159. data/app/controllers/locomotive/api/content_types_controller.rb +0 -52
  160. data/app/controllers/locomotive/api/current_site_controller.rb +0 -34
  161. data/app/controllers/locomotive/api/memberships_controller.rb +0 -52
  162. data/app/controllers/locomotive/api/my_account_controller.rb +0 -46
  163. data/app/controllers/locomotive/api/pages_controller.rb +0 -53
  164. data/app/controllers/locomotive/api/sites_controller.rb +0 -58
  165. data/app/controllers/locomotive/api/snippets_controller.rb +0 -52
  166. data/app/controllers/locomotive/api/theme_assets_controller.rb +0 -51
  167. data/app/controllers/locomotive/api/tokens_controller.rb +0 -36
  168. data/app/controllers/locomotive/api/translations_controller.rb +0 -51
  169. data/app/controllers/locomotive/api/version_controller.rb +0 -11
  170. data/spec/models/locomotive/editable_control_spec.rb +0 -79
  171. data/spec/models/locomotive/editable_file_spec.rb +0 -94
  172. data/spec/models/locomotive/editable_text_spec.rb +0 -219
  173. data/vendor/assets/images/select2-spinner.gif +0 -0
  174. data/vendor/assets/images/select2.png +0 -0
  175. data/vendor/assets/images/select2x2.png +0 -0
@@ -5,6 +5,7 @@ module Locomotive
5
5
 
6
6
  ## extensions ##
7
7
  include ::CustomFields::Source
8
+ include Concerns::Shared::SiteScope
8
9
  include Concerns::ContentType::Label
9
10
  include Concerns::ContentType::DefaultValues
10
11
  include Concerns::ContentType::EntryTemplate
@@ -22,14 +23,14 @@ module Locomotive
22
23
  field :group_by_field_id, type: BSON::ObjectId
23
24
  field :order_by # either a BSON::ObjectId (field id) or a String (:_position, ...etc)
24
25
  field :order_direction, default: 'asc'
25
- field :public_submission_enabled, type: Boolean, default: false
26
- field :public_submission_accounts, type: Array
26
+ field :public_submission_enabled, type: Boolean, default: false
27
+ field :public_submission_accounts, type: Array, default: []
27
28
  field :filter_fields, type: Array
28
29
  field :number_of_entries
29
30
  field :display_settings, type: Hash
30
31
 
31
32
  ## associations ##
32
- belongs_to :site, class_name: 'Locomotive::Site', validate: false
33
+ # belongs_to :site, class_name: 'Locomotive::Site', validate: false
33
34
  has_many :entries, class_name: 'Locomotive::ContentEntry', dependent: :destroy
34
35
 
35
36
  ## named scopes ##
@@ -40,7 +41,7 @@ module Locomotive
40
41
  scope :localized, -> { elem_match(entries_custom_fields: { localized: true }) }
41
42
 
42
43
  ## indexes ##
43
- index site_id: 1, slug: 1
44
+ # index site_id: 1, slug: 1
44
45
 
45
46
  ## callbacks ##
46
47
  before_validation :normalize_slug
@@ -49,7 +50,8 @@ module Locomotive
49
50
  after_validation :bubble_fields_errors_up
50
51
 
51
52
  ## validations ##
52
- validates_presence_of :site, :name, :slug
53
+ # validates_presence_of :site, :name, :slug
54
+ validates_presence_of :name, :slug
53
55
  validates_uniqueness_of :slug, scope: :site_id
54
56
  validates_size_of :entries_custom_fields, minimum: 1, message: :too_few_custom_fields
55
57
 
@@ -78,7 +80,7 @@ module Locomotive
78
80
  _entries = self.entries.order_by([_order_by_definition]).where(options[:where] || {})
79
81
 
80
82
  # pagination or full list
81
- !self.order_manually? && page ? _entries.page(page).per(per_page) : _entries
83
+ page ? _entries.page(page).per(per_page) : _entries
82
84
  end
83
85
 
84
86
  # Find a custom field describing an entry based on its id
@@ -104,6 +106,10 @@ module Locomotive
104
106
  (self.display_settings || {})['hidden']
105
107
  end
106
108
 
109
+ def touch_site_attribute
110
+ :content_version
111
+ end
112
+
107
113
  protected
108
114
 
109
115
  def normalize_slug
@@ -6,15 +6,16 @@ module Locomotive
6
6
  MINIMAL_ATTRIBUTES = %w(_id title slug fullpath position depth published templatized target_klass_name redirect listed response_type parent_id parent_ids site_id created_at updated_at raw_template is_layout)
7
7
 
8
8
  ## concerns ##
9
+ include Concerns::Shared::SiteScope
10
+ include Concerns::Shared::Userstamp
11
+ include Concerns::Shared::Slug
12
+ include Concerns::Shared::Seo
9
13
  include Concerns::Page::Tree
10
14
  include Concerns::Page::EditableElements
11
15
  include Concerns::Page::Layout
12
16
  include Concerns::Page::Templatized
13
17
  include Concerns::Page::Redirect
14
18
  include Concerns::Page::Listed
15
- include Concerns::Shared::Slug
16
- include Concerns::Shared::Seo
17
- include Concerns::Shared::Userstamp
18
19
 
19
20
  ## fields ##
20
21
  field :title, localize: true
@@ -24,17 +25,14 @@ module Locomotive
24
25
  field :raw_template, localize: true
25
26
  field :locales, type: Array
26
27
  field :published, type: Boolean, default: false
27
- field :cache_strategy, default: 'none'
28
+ field :cache_enabled, type: Boolean, default: true
28
29
  field :response_type, default: 'text/html'
29
30
 
30
- ## associations ##
31
- belongs_to :site, class_name: 'Locomotive::Site', validate: false, autosave: false
32
-
33
31
  ## indexes ##
34
- index site_id: 1
35
- index site_id: 1, handle: 1
36
32
  index parent_id: 1
33
+ index site_id: 1, handle: 1
37
34
  index site_id: 1, fullpath: 1
35
+ index site_id: 1, updated_at: 1
38
36
 
39
37
  ## behaviours ##
40
38
  slugify_from :title
@@ -48,7 +46,7 @@ module Locomotive
48
46
  after_save :update_children, unless: :skip_callbacks_on_update
49
47
 
50
48
  ## validations ##
51
- validates_presence_of :site, :title, :slug
49
+ validates_presence_of :title, :slug
52
50
  validates_uniqueness_of :slug, scope: [:site_id, :parent_id], allow_blank: true
53
51
  validates_uniqueness_of :handle, scope: :site_id, allow_blank: true
54
52
  validates_exclusion_of :slug, in: Locomotive.config.reserved_slugs, if: Proc.new { |p| p.depth <= 1 }
@@ -86,10 +84,6 @@ module Locomotive
86
84
  self.index? || self.not_found?
87
85
  end
88
86
 
89
- def with_cache?
90
- self.cache_strategy != 'none'
91
- end
92
-
93
87
  def default_response_type?
94
88
  self.response_type == 'text/html'
95
89
  end
@@ -108,6 +102,10 @@ module Locomotive
108
102
  self.updating_descendants = false
109
103
  end
110
104
 
105
+ def touch_site_attribute
106
+ self.raw_template_changed? ? :template_version : :content_version
107
+ end
108
+
111
109
  protected
112
110
 
113
111
  def do_not_remove_index_and_404_pages
@@ -8,6 +8,7 @@ module Locomotive
8
8
  include Concerns::Site::AccessPoints
9
9
  include Concerns::Site::Locales
10
10
  include Concerns::Site::Timezone
11
+ include Concerns::Site::Cache
11
12
 
12
13
  ## fields ##
13
14
  field :name
@@ -16,6 +17,8 @@ module Locomotive
16
17
  mount_uploader :picture, PictureUploader, validate_integrity: true
17
18
 
18
19
  ## associations ##
20
+ belongs_to :created_by, class_name: 'Locomotive::Account'
21
+ embeds_many :memberships, class_name: 'Locomotive::Membership'
19
22
  has_many :pages, class_name: 'Locomotive::Page', validate: false, autosave: false
20
23
  has_many :snippets, class_name: 'Locomotive::Snippet', dependent: :destroy, validate: false, autosave: false
21
24
  has_many :theme_assets, class_name: 'Locomotive::ThemeAsset', dependent: :destroy, validate: false, autosave: false
@@ -24,7 +27,6 @@ module Locomotive
24
27
  has_many :content_entries, class_name: 'Locomotive::ContentEntry', dependent: :destroy, validate: false, autosave: false
25
28
  has_many :translations, class_name: 'Locomotive::Translation', dependent: :destroy, validate: false, autosave: false
26
29
  has_many :activities, class_name: 'Locomotive::Activity', dependent: :destroy, validate: false, autosave: false
27
- embeds_many :memberships, class_name: 'Locomotive::Membership'
28
30
 
29
31
  ## validations ##
30
32
  validates_presence_of :name
@@ -72,9 +74,13 @@ module Locomotive
72
74
  self.memberships.detect { |m| m.admin? && m.account_id == account._id }
73
75
  end
74
76
 
75
- def to_liquid
77
+ def to_steam
76
78
  repository = Locomotive::Steam::Services.build_instance.repositories.site
77
- repository.build(self.attributes).to_liquid
79
+ repository.build(self.attributes.dup)
80
+ end
81
+
82
+ def to_liquid
83
+ to_steam.to_liquid
78
84
  end
79
85
 
80
86
  protected
@@ -2,6 +2,7 @@ module Locomotive
2
2
  class Snippet
3
3
 
4
4
  include Locomotive::Mongoid::Document
5
+ include Concerns::Shared::SiteScope
5
6
  include Concerns::Shared::Slug
6
7
 
7
8
  ## fields ##
@@ -9,11 +10,8 @@ module Locomotive
9
10
  field :slug
10
11
  field :template, localize: true
11
12
 
12
- ## associations ##
13
- belongs_to :site, class_name: 'Locomotive::Site', validate: false, autosave: false
14
-
15
13
  ## validations ##
16
- validates_presence_of :site, :name, :slug, :template
14
+ validates_presence_of :name, :slug, :template
17
15
  validates_uniqueness_of :slug, scope: :site_id
18
16
 
19
17
  ## named scopes ##
@@ -24,5 +22,9 @@ module Locomotive
24
22
 
25
23
  ## methods ##
26
24
 
25
+ def touch_site_attribute
26
+ :template_version
27
+ end
28
+
27
29
  end
28
30
  end
@@ -4,8 +4,10 @@ module Locomotive
4
4
  include Locomotive::Mongoid::Document
5
5
 
6
6
  ## extensions ##
7
+ include Concerns::Shared::SiteScope
7
8
  include Concerns::Asset::Types
8
9
  include Concerns::Asset::Checksum
10
+ include Concerns::ThemeAsset::PlainText
9
11
 
10
12
  ## fields ##
11
13
  field :local_path
@@ -17,34 +19,27 @@ module Locomotive
17
19
 
18
20
  mount_uploader :source, ThemeAssetUploader, mount_on: :source_filename, validate_integrity: true
19
21
 
20
- ## associations ##
21
- belongs_to :site, class_name: 'Locomotive::Site', validate: false, autosave: false
22
-
23
- ## indexes ##
24
- index site_id: 1
25
- index site_id: 1, local_path: 1
22
+ # indexes
23
+ index site_id: 1, local_path: 1
26
24
 
27
25
  ## callbacks ##
28
26
  before_validation :check_for_folder_changes
29
- before_validation :store_plain_text
30
27
  before_validation :sanitize_folder
31
28
  before_validation :build_local_path
32
29
 
33
30
  ## validations ##
34
- validates_presence_of :site
35
31
  validates_presence_of :source, on: :create
36
- validates_presence_of :plain_text_name, if: Proc.new { |a| a.performing_plain_text? }
37
32
  validates_uniqueness_of :local_path, scope: :site_id
38
33
  validate :content_type_can_not_change
39
34
 
40
35
  ## named scopes ##
41
36
 
42
- ## accessors ##
43
- attr_accessor :plain_text_name, :plain_text, :plain_text_type, :performing_plain_text
44
- # attr_accessible :folder, :source, :plain_text_type, :performing_plain_text, :plain_text_name, :plain_text
45
-
46
37
  ## methods ##
47
38
 
39
+ def touch_site_attribute
40
+ :template_version
41
+ end
42
+
48
43
  def stylesheet_or_javascript?
49
44
  self.stylesheet? || self.javascript?
50
45
  end
@@ -58,50 +53,6 @@ module Locomotive
58
53
  end
59
54
  end
60
55
 
61
- def plain_text_name
62
- if not @plain_text_name_changed
63
- @plain_text_name ||= self.safe_source_filename
64
- end
65
- @plain_text_name.gsub(/(\.[a-z0-9A-Z]+)$/, '') rescue nil
66
- end
67
-
68
- def plain_text_name=(name)
69
- @plain_text_name_changed = true
70
- @plain_text_name = name
71
- end
72
-
73
- def plain_text
74
- # only for ruby >= 1.9.x. Forget about ruby 1.8
75
- @plain_text ||= (self.source.read.force_encoding('UTF-8') rescue nil)
76
- end
77
-
78
- def plain_text_type
79
- @plain_text_type || (stylesheet_or_javascript? ? self.content_type : nil)
80
- end
81
-
82
- def performing_plain_text?
83
- Boolean.set(self.performing_plain_text) || false
84
- end
85
-
86
- def store_plain_text
87
- return if self.persisted? && !self.stylesheet_or_javascript?
88
-
89
- self.content_type ||= @plain_text_type if self.performing_plain_text?
90
-
91
- data = self.performing_plain_text? ? self.plain_text : self.source.read
92
-
93
- return if !self.stylesheet_or_javascript? || self.plain_text_name.blank? || data.blank?
94
-
95
- sanitized_source = self.escape_shortcut_urls(data)
96
-
97
- self.source = ::CarrierWave::SanitizedFile.new({
98
- tempfile: StringIO.new(sanitized_source),
99
- filename: "#{self.plain_text_name}.#{self.stylesheet? ? 'css' : 'js'}"
100
- })
101
-
102
- @plain_text = sanitized_source # no need to reset the plain_text instance variable to have the last version
103
- end
104
-
105
56
  def self.all_grouped_by_folder(site)
106
57
  assets = site.theme_assets.order_by(:slug.asc)
107
58
  assets.group_by { |a| a.folder.split('/').first.to_sym }
@@ -141,22 +92,6 @@ module Locomotive
141
92
  end
142
93
  end
143
94
 
144
- def escape_shortcut_urls(text)
145
- return if text.blank?
146
-
147
- text.gsub(/[("'](\/(stylesheets|javascripts|images|media|fonts|pdfs|others)\/(([^;.]+)\/)*([a-zA-Z_\-0-9]+)\.[a-z]{2,4})(\?[0-9]+)?[)"']/) do |path|
148
-
149
- sanitized_path = path.gsub(/[("')]/, '').gsub(/^\//, '').gsub(/\?[0-9]+$/, '')
150
-
151
- if asset = self.site.theme_assets.where(local_path: sanitized_path).first
152
- timestamp = self.updated_at.to_i
153
- "#{path.first}#{asset.source.url}?#{timestamp}#{path.last}"
154
- else
155
- path
156
- end
157
- end
158
- end
159
-
160
95
  def check_for_folder_changes
161
96
  # https://github.com/jnicklas/carrierwave/issues/330
162
97
  # https://github.com/jnicklas/carrierwave-mongoid/issues/23
@@ -2,6 +2,7 @@ module Locomotive
2
2
  class Translation
3
3
 
4
4
  include Locomotive::Mongoid::Document
5
+ include Concerns::Shared::SiteScope
5
6
  include Concerns::Shared::Userstamp
6
7
 
7
8
  ## fields ##
@@ -9,12 +10,9 @@ module Locomotive
9
10
  field :values, type: Hash, default: {}
10
11
  field :completion, type: Integer, default: 0
11
12
 
12
- ## associations ##
13
- belongs_to :site, class_name: 'Locomotive::Site', validate: false, autosave: false
14
-
15
13
  ## validations ##
16
14
  validates_uniqueness_of :key, scope: :site_id
17
- validates_presence_of :site, :key
15
+ validates_presence_of :key
18
16
 
19
17
  ## named scopes ##
20
18
  scope :ordered, -> { order_by(key: :asc) }
@@ -26,13 +24,16 @@ module Locomotive
26
24
  before_validation :remove_blanks
27
25
 
28
26
  ## indexes ##
29
- index site_id: 1
30
27
  index site_id: 1, key: 1
31
28
  index site_id: 1, completion: 1
32
29
  index site_id: 1, key: 1, completion: 1
33
30
 
34
31
  ## methods ##
35
32
 
33
+ def touch_site_attribute
34
+ :content_version
35
+ end
36
+
36
37
  protected
37
38
 
38
39
  # Make sure the translation key is underscored
@@ -46,11 +46,11 @@ module Locomotive
46
46
  end
47
47
 
48
48
  def permitted_attributes
49
- plain = [:name, :handle, :picture, :remove_picture, :seo_title, :meta_keywords, :meta_description, :timezone_name, :robots_txt]
49
+ plain = [:name, :handle, :picture, :remove_picture, :seo_title, :meta_keywords, :meta_description, :timezone_name, :robots_txt, :cache_enabled]
50
50
  hash = { domains: [], locales: [] }
51
51
 
52
52
  unless update_advanced?
53
- plain -= [:timezone_name, :robots_txt]
53
+ plain -= [:timezone_name, :robots_txt, :cache_enabled]
54
54
  hash.delete(:locales)
55
55
  end
56
56
 
@@ -13,6 +13,8 @@ module Locomotive
13
13
  #
14
14
  # For a more powerful search, you can use the "where" key which accepts a JSON string or a Hash.
15
15
  #
16
+ # The no_pagination option is used to skip the pagination of the content entries
17
+ #
16
18
  # @param [ Hash ] options The options for the pagination and the filtering
17
19
  #
18
20
  # @return [ Object ] a paginated list of content entries
@@ -191,13 +193,12 @@ module Locomotive
191
193
  end
192
194
 
193
195
  def prepare_options_for_all(options)
194
- where = prepare_where_statement(options)
196
+ { where: prepare_where_statement(options) }.tap do |_options|
197
+ unless options[:no_pagination]
198
+ _options[:page] = options[:page] || 1
199
+ _options[:per_page] = options[:per_page] || Locomotive.config.ui[:per_page]
200
+ end
195
201
 
196
- {
197
- page: options[:page] || 1,
198
- per_page: options[:per_page] || Locomotive.config.ui[:per_page],
199
- where: where
200
- }.tap do |_options|
201
202
  _options[:order_by] = options[:order_by] if options[:order_by]
202
203
  end
203
204
  end
@@ -30,6 +30,7 @@ module Locomotive
30
30
  end
31
31
 
32
32
  Site.new(attributes).tap do |site|
33
+ site.created_by = account
33
34
  site.memberships.build account: account, role: 'admin'
34
35
 
35
36
  success = raise_if_not_valid ? site.save! : site.save
@@ -18,5 +18,6 @@
18
18
 
19
19
  .buttons
20
20
  = link_to t(:edit, scope: 'locomotive.shared.form.array_input'), edit_content_entry_path(current_site, slug, item, _location: false), class: 'choose btn btn-primary btn-sm'
21
+ | &nbsp;
21
22
  = link_to '#', class: 'delete' do
22
23
  i.fa.fa-trash-o
@@ -12,7 +12,7 @@
12
12
  = hidden_field_tag :active_tab, ''
13
13
  = hidden_field_tag :_location, params[:_location]
14
14
 
15
- = f.action 'hide'
15
+ = f.action class: 'hide'
16
16
 
17
17
  = render 'locomotive/content_entries/form/tabs', f: f
18
18
 
@@ -7,7 +7,7 @@
7
7
  = hidden_field_tag :active_tab, ''
8
8
  = hidden_field_tag :_location, params[:_location]
9
9
 
10
- = f.action 'hide'
10
+ = f.action class: 'hide'
11
11
 
12
12
  = render 'locomotive/content_entries/form/tabs', f: f
13
13