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.
- checksums.yaml +4 -4
- data/Gemfile +4 -3
- data/app/api/locomotive/api.rb +1 -0
- data/app/api/locomotive/api/entities/page_entity.rb +1 -1
- data/app/api/locomotive/api/entities/site_entity.rb +9 -1
- data/app/api/locomotive/api/exception_rescuers.rb +3 -5
- data/app/api/locomotive/api/forms/page_form.rb +1 -1
- data/app/api/locomotive/api/forms/site_form.rb +1 -2
- data/app/api/locomotive/api/helpers/authentication_helper.rb +6 -1
- data/app/api/locomotive/api/helpers/locales_helper.rb +15 -0
- data/app/api/locomotive/api/helpers/params_helper.rb +13 -0
- data/app/api/locomotive/api/middlewares/locale_middleware.rb +6 -1
- data/app/api/locomotive/api/resources/content_entry_resource.rb +2 -0
- data/app/api/locomotive/api/resources/content_type_resource.rb +2 -2
- data/app/api/locomotive/api/resources/current_site_resource.rb +2 -1
- data/app/api/locomotive/api/resources/membership_resource.rb +0 -4
- data/app/api/locomotive/api/resources/page_resource.rb +6 -1
- data/app/api/locomotive/api/resources/site_resource.rb +4 -2
- data/app/assets/javascripts/locomotive.js +1 -0
- data/app/assets/javascripts/locomotive/utils/nprogress.js.coffee +3 -1
- data/app/assets/javascripts/locomotive/views/editable_elements/index_view.js.coffee +10 -3
- data/app/assets/javascripts/locomotive/views/inputs/markdown_view.js.coffee +82 -0
- data/app/assets/javascripts/locomotive/views/inputs/rte/file_view.js.coffee +1 -1
- data/app/assets/javascripts/locomotive/views/inputs/rte/link_view.js.coffee +1 -1
- data/app/assets/javascripts/locomotive/views/inputs/rte_view.js.coffee.erb +1 -1
- data/app/assets/javascripts/locomotive/views/inputs/text_view.js.coffee +4 -1
- data/app/assets/javascripts/locomotive/views/pages/list_view.js.coffee +3 -0
- data/app/assets/javascripts/locomotive/views/shared/form_view.js.coffee +22 -1
- data/app/assets/javascripts/locomotive/views/shared/header_view.js.coffee +2 -2
- data/app/assets/stylesheets/locomotive/application.scss +2 -0
- data/app/assets/stylesheets/locomotive/base/_form.scss +2 -0
- data/app/assets/stylesheets/locomotive/base/form/_api_key.scss +0 -1
- data/app/assets/stylesheets/locomotive/base/form/_array_input.scss +2 -0
- data/app/assets/stylesheets/locomotive/base/form/_base.scss +13 -2
- data/app/assets/stylesheets/locomotive/base/form/_color_input.scss +12 -0
- data/app/assets/stylesheets/locomotive/base/form/_markdown.scss +292 -0
- data/app/assets/stylesheets/locomotive/base/form/_popover.scss +22 -0
- data/app/assets/stylesheets/locomotive/base/form/_rte.scss +2 -1
- data/app/assets/stylesheets/locomotive/components/_activity_feed.scss +1 -0
- data/app/assets/stylesheets/locomotive/components/_dashboard.scss +29 -0
- data/app/assets/stylesheets/locomotive/components/_live_editing.scss +13 -1
- data/app/assets/stylesheets/locomotive/components/_main.scss +1 -1
- data/app/assets/stylesheets/locomotive/components/_transitions.scss +24 -3
- data/app/assets/stylesheets/locomotive/components/sidebar/_base.scss +1 -0
- data/app/assets/stylesheets/locomotive/globals/_bootstrap.scss +2 -2
- data/app/assets/stylesheets/locomotive/globals/_variables.scss +4 -3
- data/app/assets/stylesheets/locomotive/layouts/_live_editing.scss +4 -0
- data/app/controllers/locomotive/concerns/locale_helpers_controller.rb +1 -0
- data/app/controllers/locomotive/content_entries_controller.rb +10 -2
- data/app/controllers/locomotive/pages_controller.rb +2 -1
- data/app/controllers/locomotive/passwords_controller.rb +17 -1
- data/app/helpers/locomotive/base_helper.rb +19 -0
- data/app/helpers/locomotive/content_types_helper.rb +2 -1
- data/app/helpers/locomotive/custom_fields_helper.rb +14 -1
- data/app/helpers/locomotive/dashboard_helper.rb +12 -0
- data/app/helpers/locomotive/editable_elements_helper.rb +9 -4
- data/app/helpers/locomotive/pages_helper.rb +1 -14
- data/app/helpers/locomotive/shared/pages_helper.rb +17 -0
- data/app/helpers/locomotive/translations_helper.rb +0 -14
- data/app/inputs/locomotive/color_input.rb +18 -0
- data/app/inputs/locomotive/markdown_input.rb +19 -0
- data/app/models/locomotive/account.rb +2 -1
- data/app/models/locomotive/concerns/content_entry/file_size.rb +27 -0
- data/app/models/locomotive/concerns/content_type/group_by.rb +3 -1
- data/app/models/locomotive/concerns/page/layout.rb +63 -19
- data/app/models/locomotive/concerns/shared/site_scope.rb +37 -0
- data/app/models/locomotive/concerns/site/cache.rb +32 -0
- data/app/models/locomotive/concerns/theme_asset/plain_text.rb +85 -0
- data/app/models/locomotive/content_entry.rb +7 -7
- data/app/models/locomotive/content_type.rb +12 -6
- data/app/models/locomotive/page.rb +12 -14
- data/app/models/locomotive/site.rb +9 -3
- data/app/models/locomotive/snippet.rb +6 -4
- data/app/models/locomotive/theme_asset.rb +8 -73
- data/app/models/locomotive/translation.rb +6 -5
- data/app/policies/locomotive/site_policy.rb +2 -2
- data/app/services/locomotive/content_entry_service.rb +7 -6
- data/app/services/locomotive/site_service.rb +1 -0
- data/app/views/locomotive/content_entries/_entry.html.slim +1 -0
- data/app/views/locomotive/content_entries/edit.html.slim +1 -1
- data/app/views/locomotive/content_entries/new.html.slim +1 -1
- data/app/views/locomotive/current_site/_membership.html.slim +1 -0
- data/app/views/locomotive/current_site/edit.html.slim +1 -1
- data/app/views/locomotive/current_site/form/_access_points.html.slim +1 -1
- data/app/views/locomotive/current_site/form/_advanced.html.slim +2 -0
- data/app/views/locomotive/dashboard/_activity.html.slim +26 -0
- data/app/views/locomotive/dashboard/_url.html.slim +9 -0
- data/app/views/locomotive/dashboard/show.html.slim +3 -21
- data/app/views/locomotive/devise_mailer/reset_password_instructions.html.slim +1 -1
- data/app/views/locomotive/editable_elements/_edit.html.slim +8 -1
- data/app/views/locomotive/editable_elements/_form.html.slim +1 -1
- data/app/views/locomotive/editable_elements/index_without_preview.html.slim +24 -17
- data/app/views/locomotive/layouts/application.html.slim +6 -4
- data/app/views/locomotive/layouts/live_editing.html.slim +9 -0
- data/app/views/locomotive/layouts/not_logged_in.html.slim +1 -1
- data/app/views/locomotive/layouts/without_site.html.slim +2 -0
- data/app/views/locomotive/memberships/edit.html.slim +1 -1
- data/app/views/locomotive/memberships/new.html.slim +1 -1
- data/app/views/locomotive/my_account/edit.html.slim +7 -5
- data/app/views/locomotive/pages/_header.html.slim +7 -0
- data/app/views/locomotive/pages/edit.html.slim +2 -4
- data/app/views/locomotive/pages/form/_main.html.slim +4 -1
- data/app/views/locomotive/pages/form/_tabs.html.slim +4 -3
- data/app/views/locomotive/public_submission_accounts/_account.html.slim +1 -1
- data/app/views/locomotive/public_submission_accounts/edit.html.slim +1 -1
- data/app/views/locomotive/shared/_header.html.slim +25 -22
- data/app/views/locomotive/shared/_locale_picker_link.html.slim +3 -0
- data/app/views/locomotive/shared/_main_app_header.html.slim +1 -1
- data/app/views/locomotive/shared/_sidebar.html.slim +15 -11
- data/app/views/locomotive/shared/rte/_markdown_toolbar.html.slim +42 -0
- data/config/locales/admin_ui.en.yml +9 -4
- data/config/locales/default.en.yml +4 -0
- data/config/locales/devise.en.yml +1 -0
- data/config/locales/simple_form.en.yml +6 -2
- data/lib/locomotive/action_controller/responder.rb +5 -0
- data/lib/locomotive/engine.rb +5 -0
- data/lib/locomotive/middlewares/site.rb +39 -21
- data/lib/locomotive/simple_form.rb +3 -31
- data/lib/locomotive/steam/middlewares/cache.rb +62 -0
- data/lib/locomotive/steam/middlewares/page_editing.rb +9 -3
- data/lib/locomotive/steam/services/api_entry_submission_service.rb +6 -3
- data/lib/locomotive/steam/services/liquid_parser_with_cache_service.rb +74 -0
- data/lib/locomotive/steam_adaptor.rb +7 -1
- data/lib/locomotive/version.rb +1 -1
- data/lib/tasks/development.rake +4 -0
- data/lib/tasks/locomotive.rake +14 -0
- data/spec/lib/locomotive/steam/services/api_entry_submission_service_spec.rb +10 -1
- data/spec/lib/locomotive/steam/services/liquid_parser_with_cache_service_spec.rb +53 -0
- data/spec/models/locomotive/concerns/content_entry/file_size_spec.rb +40 -0
- data/spec/models/locomotive/concerns/page/layout_spec.rb +122 -17
- data/spec/models/locomotive/concerns/site/cache_spec.rb +60 -0
- data/spec/models/locomotive/content_entry_spec.rb +7 -0
- data/spec/models/locomotive/content_type_spec.rb +18 -11
- data/spec/models/locomotive/page_spec.rb +32 -8
- data/spec/models/locomotive/snippet_spec.rb +13 -4
- data/spec/models/locomotive/theme_asset_spec.rb +10 -3
- data/spec/models/locomotive/translation_spec.rb +28 -0
- data/spec/requests/locomotive/steam/cache_spec.rb +83 -0
- data/spec/requests/site_spec.rb +24 -0
- data/spec/support/capybara.rb +5 -13
- data/spec/support/factories.rb +9 -0
- data/spec/support/features/session_helpers.rb +19 -3
- data/spec/support/features/site_helpers.rb +27 -0
- data/spec/support/shared_examples/site_scope_examples.rb +27 -0
- data/vendor/assets/images/locomotive/bootstrap-colorpicker/alpha-horizontal.png +0 -0
- data/vendor/assets/images/locomotive/bootstrap-colorpicker/alpha.png +0 -0
- data/vendor/assets/images/locomotive/bootstrap-colorpicker/hue-horizontal.png +0 -0
- data/vendor/assets/images/locomotive/bootstrap-colorpicker/hue.png +0 -0
- data/vendor/assets/images/locomotive/bootstrap-colorpicker/saturation.png +0 -0
- data/vendor/assets/javascripts/locomotive/bootstrap-colorpicker.js +1 -0
- data/vendor/assets/javascripts/locomotive/datepicker_i18n.js.erb +6 -6
- data/vendor/assets/javascripts/locomotive/kramed.min.js +11 -0
- data/vendor/assets/stylesheets/locomotive/bootstrap-colorpicker.scss +9 -0
- metadata +59 -44
- data/app/controllers/locomotive/api/accounts_controller.rb +0 -60
- data/app/controllers/locomotive/api/base_controller.rb +0 -35
- data/app/controllers/locomotive/api/content_assets_controller.rb +0 -51
- data/app/controllers/locomotive/api/content_entries_controller.rb +0 -71
- data/app/controllers/locomotive/api/content_types_controller.rb +0 -52
- data/app/controllers/locomotive/api/current_site_controller.rb +0 -34
- data/app/controllers/locomotive/api/memberships_controller.rb +0 -52
- data/app/controllers/locomotive/api/my_account_controller.rb +0 -46
- data/app/controllers/locomotive/api/pages_controller.rb +0 -53
- data/app/controllers/locomotive/api/sites_controller.rb +0 -58
- data/app/controllers/locomotive/api/snippets_controller.rb +0 -52
- data/app/controllers/locomotive/api/theme_assets_controller.rb +0 -51
- data/app/controllers/locomotive/api/tokens_controller.rb +0 -36
- data/app/controllers/locomotive/api/translations_controller.rb +0 -51
- data/app/controllers/locomotive/api/version_controller.rb +0 -11
- data/spec/models/locomotive/editable_control_spec.rb +0 -79
- data/spec/models/locomotive/editable_file_spec.rb +0 -94
- data/spec/models/locomotive/editable_text_spec.rb +0 -219
- data/vendor/assets/images/select2-spinner.gif +0 -0
- data/vendor/assets/images/select2.png +0 -0
- 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,
|
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
|
-
|
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 :
|
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 :
|
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
|
77
|
+
def to_steam
|
76
78
|
repository = Locomotive::Steam::Services.build_instance.repositories.site
|
77
|
-
repository.build(self.attributes)
|
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 :
|
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
|
-
|
21
|
-
|
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 :
|
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
|
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
|