alchemy_cms 3.2.0.beta → 3.2.0.rc1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +661 -863
- data/README.md +5 -63
- data/app/assets/javascripts/alchemy/alchemy.base.js.coffee +11 -10
- data/app/assets/javascripts/alchemy/alchemy.initializer.js.coffee +6 -0
- data/app/assets/stylesheets/alchemy/_extends.scss +0 -6
- data/app/assets/stylesheets/alchemy/_mixins.scss +6 -0
- data/app/assets/stylesheets/alchemy/buttons.scss +1 -1
- data/app/assets/stylesheets/alchemy/elements.scss +1 -1
- data/app/assets/stylesheets/alchemy/menubar.scss +1 -1
- data/app/assets/stylesheets/alchemy/selects.scss +5 -1
- data/app/assets/stylesheets/alchemy/upload.scss +1 -1
- data/app/controllers/alchemy/admin/pages_controller.rb +1 -1
- data/app/controllers/alchemy/base_controller.rb +4 -57
- data/app/controllers/alchemy/messages_controller.rb +2 -2
- data/app/controllers/alchemy/pages_controller.rb +22 -31
- data/app/controllers/alchemy/pictures_controller.rb +2 -2
- data/app/helpers/alchemy/admin/base_helper.rb +7 -0
- data/app/helpers/alchemy/admin/elements_helper.rb +31 -15
- data/app/helpers/alchemy/admin/pages_helper.rb +17 -0
- data/app/helpers/alchemy/base_helper.rb +0 -28
- data/app/helpers/alchemy/pages_helper.rb +18 -12
- data/app/helpers/alchemy/url_helper.rb +2 -2
- data/app/models/alchemy/cell.rb +1 -1
- data/app/models/alchemy/content/factory.rb +12 -6
- data/app/models/alchemy/element.rb +3 -3
- data/app/models/alchemy/element/definitions.rb +1 -1
- data/app/models/alchemy/element_to_page.rb +7 -0
- data/app/models/alchemy/language.rb +1 -1
- data/app/models/alchemy/page.rb +8 -1
- data/app/models/alchemy/page/page_cells.rb +2 -2
- data/app/models/alchemy/page/page_elements.rb +23 -5
- data/app/models/alchemy/page/page_natures.rb +3 -3
- data/app/models/alchemy/page/page_scopes.rb +1 -1
- data/app/models/alchemy/picture.rb +1 -1
- data/app/views/alchemy/admin/pages/_create_language_form.html.erb +1 -1
- data/app/views/alchemy/admin/pages/_form.html.erb +1 -1
- data/app/views/alchemy/admin/pictures/_picture_to_assign.html.erb +1 -1
- data/app/views/alchemy/breadcrumb/_page.html.erb +3 -2
- data/app/views/alchemy/breadcrumb/_separator.html.erb +1 -0
- data/app/views/alchemy/breadcrumb/_wrapper.html.erb +13 -0
- data/app/views/alchemy/language_links/_language.html.erb +1 -1
- data/app/views/alchemy/navigation/_link.html.erb +1 -1
- data/app/views/alchemy/pages/show.rss.builder +5 -7
- data/app/views/layouts/alchemy/admin.html.erb +5 -0
- data/config/routes.rb +13 -10
- data/lib/alchemy/configuration_methods.rb +29 -0
- data/lib/alchemy/controller_actions.rb +12 -4
- data/lib/alchemy/engine.rb +3 -0
- data/lib/alchemy/errors.rb +1 -1
- data/lib/alchemy/essence.rb +14 -12
- data/lib/alchemy/on_page_layout.rb +58 -0
- data/lib/alchemy/page_layout.rb +1 -1
- data/lib/alchemy/permissions.rb +21 -16
- data/lib/alchemy/routing_constraints.rb +49 -0
- data/lib/alchemy/seeder.rb +4 -2
- data/lib/alchemy/ssl_protection.rb +30 -0
- data/lib/alchemy/test_support/essence_shared_examples.rb +118 -25
- data/lib/alchemy/test_support/factories.rb +5 -8
- data/lib/alchemy/test_support/integration_helpers.rb +16 -10
- data/lib/alchemy/upgrader/three_point_two.rb +34 -4
- data/lib/alchemy/version.rb +1 -1
- data/lib/rails/generators/alchemy/{scaffold → install}/files/_article_editor.html.erb +0 -0
- data/lib/rails/generators/alchemy/{scaffold → install}/files/_article_view.html.erb +0 -0
- data/lib/rails/generators/alchemy/{scaffold → install}/files/_standard.html.erb +0 -0
- data/lib/rails/generators/alchemy/{scaffold → install}/files/alchemy.de.yml +0 -0
- data/lib/rails/generators/alchemy/{scaffold → install}/files/alchemy.elements.css.scss +0 -0
- data/lib/rails/generators/alchemy/{scaffold → install}/files/alchemy.en.yml +0 -0
- data/lib/rails/generators/alchemy/{scaffold → install}/files/alchemy.es.yml +0 -0
- data/lib/rails/generators/alchemy/{scaffold → install}/files/application.html.erb +0 -0
- data/lib/rails/generators/alchemy/install/install_generator.rb +69 -0
- data/lib/rails/generators/alchemy/{scaffold/files/elements.yml → install/templates/elements.yml.tt} +2 -0
- data/lib/rails/generators/alchemy/{scaffold → install}/templates/page_layouts.yml.tt +2 -0
- data/lib/rails/generators/alchemy/views/views_generator.rb +41 -0
- data/lib/rails/templates/alchemy.rb +2 -2
- data/lib/tasks/alchemy/db.rake +0 -5
- data/lib/tasks/alchemy/install.rake +10 -5
- data/lib/tasks/alchemy/tidy.rake +2 -0
- data/spec/controllers/admin/attachments_controller_spec.rb +1 -1
- data/spec/controllers/admin/clipboard_controller_spec.rb +1 -1
- data/spec/controllers/admin/contents_controller_spec.rb +1 -1
- data/spec/controllers/admin/dashboard_controller_spec.rb +2 -2
- data/spec/controllers/admin/elements_controller_spec.rb +1 -1
- data/spec/controllers/admin/essence_files_controller_spec.rb +1 -1
- data/spec/controllers/admin/essence_pictures_controller_spec.rb +1 -1
- data/spec/controllers/admin/languages_controller_spec.rb +1 -1
- data/spec/controllers/admin/layoutpages_controller_spec.rb +1 -1
- data/spec/controllers/admin/pages_controller_spec.rb +4 -4
- data/spec/controllers/admin/pictures_controller_spec.rb +1 -1
- data/spec/controllers/admin/resources_controller_spec.rb +1 -1
- data/spec/controllers/admin/trash_controller_spec.rb +1 -1
- data/spec/controllers/alchemy/admin/tags_controller_spec.rb +1 -1
- data/spec/controllers/attachments_controller_spec.rb +1 -1
- data/spec/controllers/base_controller_spec.rb +22 -0
- data/spec/controllers/elements_controller_spec.rb +1 -1
- data/spec/controllers/pages_controller_spec.rb +15 -16
- data/spec/controllers/pictures_controller_spec.rb +212 -162
- data/spec/dummy/app/controllers/login_controller.rb +5 -0
- data/spec/dummy/app/models/dummy_model.rb +3 -0
- data/spec/dummy/config/alchemy/cells.yml +4 -1
- data/spec/dummy/config/alchemy/elements.yml +8 -0
- data/spec/dummy/config/alchemy/page_layouts.yml +5 -1
- data/spec/dummy/config/routes.rb +1 -2
- data/spec/dummy/db/migrate/20150412103152_create_dummy_model.rb +7 -0
- data/spec/dummy/db/schema.rb +30 -26
- data/spec/features/admin/dashboard_spec.rb +11 -9
- data/spec/features/admin/language_tree_feature_spec.rb +5 -6
- data/spec/features/admin/legacy_page_url_management_spec.rb +1 -1
- data/spec/features/admin/link_overlay_spec.rb +1 -1
- data/spec/features/admin/locale_select_feature_spec.rb +1 -1
- data/spec/features/admin/modules_integration_spec.rb +1 -1
- data/spec/features/admin/navigation_feature_spec.rb +1 -1
- data/spec/features/admin/page_creation_feature_spec.rb +1 -1
- data/spec/features/admin/page_editing_feature_spec.rb +3 -3
- data/spec/features/admin/picture_library_integration_spec.rb +1 -1
- data/spec/features/admin/resources_integration_spec.rb +1 -1
- data/spec/features/admin/site_select_feature_spec.rb +32 -0
- data/spec/features/admin/tinymce_feature_spec.rb +1 -3
- data/spec/features/page_feature_spec.rb +36 -27
- data/spec/features/security_spec.rb +1 -1
- data/spec/features/translation_integration_spec.rb +3 -3
- data/spec/helpers/admin/elements_helper_spec.rb +103 -26
- data/spec/helpers/admin/pages_helper_spec.rb +32 -1
- data/spec/helpers/base_helper_spec.rb +0 -45
- data/spec/helpers/pages_helper_spec.rb +18 -17
- data/spec/helpers/url_helper_spec.rb +8 -5
- data/spec/libraries/controller_actions_spec.rb +2 -2
- data/spec/libraries/on_page_layout_spec.rb +112 -0
- data/spec/libraries/page_layout_spec.rb +5 -1
- data/spec/libraries/permissions_spec.rb +13 -15
- data/spec/models/cell_spec.rb +4 -0
- data/spec/models/content_spec.rb +6 -0
- data/spec/models/dummy_model_spec.rb +11 -0
- data/spec/models/element_spec.rb +6 -1
- data/spec/models/element_to_page_spec.rb +14 -0
- data/spec/models/page_spec.rb +111 -19
- data/spec/routing/routing_spec.rb +120 -101
- data/spec/spec_helper.rb +3 -3
- metadata +36 -21
- data/app/views/alchemy/breadcrumb/_spacer.html.erb +0 -1
- data/lib/alchemy/capistrano.rb +0 -230
- data/lib/alchemy/test_support/auth_helpers.rb +0 -35
- data/lib/rails/generators/alchemy/deploy_script/deploy_script_generator.rb +0 -90
- data/lib/rails/generators/alchemy/deploy_script/templates/deploy.rb.tt +0 -113
- data/lib/rails/generators/alchemy/scaffold/scaffold_generator.rb +0 -63
- data/spec/dummy/app/controllers/errors_controller.rb +0 -5
@@ -11,6 +11,7 @@ module Alchemy
|
|
11
11
|
def show
|
12
12
|
@size = params[:size]
|
13
13
|
expires_in 1.month, public: !@picture.restricted?
|
14
|
+
|
14
15
|
respond_to { |format| send_image(processed_image, format) }
|
15
16
|
end
|
16
17
|
|
@@ -28,8 +29,7 @@ module Alchemy
|
|
28
29
|
end
|
29
30
|
|
30
31
|
def zoom
|
31
|
-
|
32
|
-
respond_to { |format| send_image(image_file, format) }
|
32
|
+
respond_to { |format| send_image(@picture.image_file, format) }
|
33
33
|
end
|
34
34
|
|
35
35
|
private
|
@@ -64,6 +64,13 @@ module Alchemy
|
|
64
64
|
end
|
65
65
|
end
|
66
66
|
|
67
|
+
# Used for site selector in Alchemy cockpit.
|
68
|
+
def sites_for_select
|
69
|
+
Alchemy::Site.all.map do |site|
|
70
|
+
[site.name, site.id]
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
67
74
|
# Returns a javascript driven live filter for lists.
|
68
75
|
#
|
69
76
|
# The items must have a html +name+ attribute that holds the filterable value.
|
@@ -54,30 +54,30 @@ module Alchemy
|
|
54
54
|
end
|
55
55
|
end
|
56
56
|
|
57
|
-
# Returns all elements that
|
57
|
+
# Returns all elements that can be placed on the current page.
|
58
58
|
# The elements will be grouped by cell.
|
59
|
+
#
|
60
|
+
# @param [Array] elements
|
61
|
+
# collection of element objects
|
62
|
+
# @param [String] object_method
|
63
|
+
# method that is called on the element objects used for the select option value
|
64
|
+
#
|
59
65
|
def grouped_elements_for_select(elements, object_method = 'name')
|
60
|
-
return
|
66
|
+
return [] if elements.blank?
|
61
67
|
cells_definition = @page.cell_definitions
|
62
|
-
return
|
68
|
+
return [] if cells_definition.blank?
|
63
69
|
options = {}
|
64
|
-
celled_elements = []
|
65
70
|
cells_definition.each do |cell|
|
66
|
-
cell_elements = elements
|
67
|
-
celled_elements += cell_elements
|
71
|
+
cell_elements = elements_for_cell(elements, cell)
|
68
72
|
optgroup_label = Cell.translated_label_for(cell['name'])
|
69
73
|
options[optgroup_label] = cell_elements.map do |e|
|
70
74
|
element_array_for_options(e, object_method, cell)
|
71
75
|
end
|
72
76
|
end
|
73
|
-
|
74
|
-
|
75
|
-
options[_t(:main_content)] = other_elements.map do |e|
|
76
|
-
element_array_for_options(e, object_method)
|
77
|
-
end
|
77
|
+
options[_t(:main_content)] = elements_for_main_content(elements).map do |e|
|
78
|
+
element_array_for_options(e, object_method)
|
78
79
|
end
|
79
|
-
|
80
|
-
options.delete_if { |cell, elements| elements.blank? }
|
80
|
+
options.delete_if { |_cell, elements| elements.blank? } # Throw out empty cells
|
81
81
|
end
|
82
82
|
|
83
83
|
def element_array_for_options(e, object_method, cell = nil)
|
@@ -105,14 +105,30 @@ module Alchemy
|
|
105
105
|
#
|
106
106
|
def update_essence_select_elements(page, element)
|
107
107
|
elements = page.elements.not_trashed.joins(:contents)
|
108
|
-
.where("
|
109
|
-
.where(
|
108
|
+
.where(["#{Content.table_name}.element_id != ?", element.id])
|
109
|
+
.where(Content.table_name => {essence_type: "Alchemy::EssenceSelect"})
|
110
110
|
return if elements.blank?
|
111
111
|
elements.collect do |element|
|
112
112
|
render 'alchemy/admin/elements/refresh_editor', element: element
|
113
113
|
end.join.html_safe
|
114
114
|
end
|
115
115
|
|
116
|
+
private
|
117
|
+
|
118
|
+
def elements_for_main_content(elements)
|
119
|
+
page_definition = @page.definition['elements']
|
120
|
+
elements.select do |e|
|
121
|
+
page_definition.include?(e.class.name == 'Element' ? e.name : e['name'])
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
def elements_for_cell(elements, cell)
|
126
|
+
cell_elements = cell['elements']
|
127
|
+
elements.select do |e|
|
128
|
+
cell_elements.include?(e.class.name == 'Element' ? e.name : e['name'])
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
116
132
|
end
|
117
133
|
end
|
118
134
|
end
|
@@ -48,6 +48,23 @@ module Alchemy
|
|
48
48
|
end.delete_if(&:blank?).join("<br>").html_safe
|
49
49
|
end
|
50
50
|
|
51
|
+
# Renders a label for page's page layout
|
52
|
+
#
|
53
|
+
# If the page layout description of the page is missing, it displays a warning.
|
54
|
+
#
|
55
|
+
def page_layout_label(page)
|
56
|
+
if page.persisted? && page.layout_description.blank?
|
57
|
+
[
|
58
|
+
content_tag(:span, '',
|
59
|
+
class: 'inline warning icon',
|
60
|
+
title: _t(:page_layout_description_missing)
|
61
|
+
),
|
62
|
+
_t(:page_type)
|
63
|
+
].join(' ').html_safe
|
64
|
+
else
|
65
|
+
_t(:page_type)
|
66
|
+
end
|
67
|
+
end
|
51
68
|
end
|
52
69
|
end
|
53
70
|
end
|
@@ -54,33 +54,6 @@ module Alchemy
|
|
54
54
|
end
|
55
55
|
end
|
56
56
|
|
57
|
-
# Returns an array of all pages in the same branch from current.
|
58
|
-
# I.e. used to find the active page in navigation.
|
59
|
-
def breadcrumb(current)
|
60
|
-
return [] if current.nil?
|
61
|
-
current.self_and_ancestors.where("parent_id IS NOT NULL")
|
62
|
-
end
|
63
|
-
|
64
|
-
# Returns the Alchemy configuration.
|
65
|
-
#
|
66
|
-
# *DO NOT REMOVE THIS HERE.*
|
67
|
-
#
|
68
|
-
# We need this, if an external engine or app includes this module into actionview.
|
69
|
-
#
|
70
|
-
def configuration(name)
|
71
|
-
Alchemy::Config.get(name)
|
72
|
-
end
|
73
|
-
|
74
|
-
# Returns true if Alchemy is in multi language mode
|
75
|
-
#
|
76
|
-
# *DO NOT REMOVE THIS HERE.*
|
77
|
-
#
|
78
|
-
# We need this, if an external engine or app includes this module into actionview.
|
79
|
-
#
|
80
|
-
def multi_language?
|
81
|
-
Alchemy::Language.published.count > 1
|
82
|
-
end
|
83
|
-
|
84
57
|
# Renders the flash partial (+alchemy/admin/partials/flash+)
|
85
58
|
#
|
86
59
|
# @param [String] notice The notice you want to display
|
@@ -104,6 +77,5 @@ module Alchemy
|
|
104
77
|
page
|
105
78
|
end
|
106
79
|
end
|
107
|
-
|
108
80
|
end
|
109
81
|
end
|
@@ -207,8 +207,8 @@ module Alchemy
|
|
207
207
|
|
208
208
|
# Returns true if page is in the active branch
|
209
209
|
def page_active?(page)
|
210
|
-
@
|
211
|
-
@
|
210
|
+
@_page_ancestors ||= Page.ancestors_for(@page)
|
211
|
+
@_page_ancestors.include?(page)
|
212
212
|
end
|
213
213
|
|
214
214
|
# Returns +'active'+ if the given external page is in the current url path or +nil+.
|
@@ -229,15 +229,25 @@ module Alchemy
|
|
229
229
|
#
|
230
230
|
def render_breadcrumb(options={})
|
231
231
|
options = {
|
232
|
-
separator:
|
232
|
+
separator: ">",
|
233
233
|
page: @page,
|
234
234
|
restricted_only: false,
|
235
235
|
reverse: false,
|
236
236
|
link_active_page: false
|
237
237
|
}.merge(options)
|
238
|
-
|
239
|
-
pages =
|
240
|
-
|
238
|
+
|
239
|
+
pages = Page.
|
240
|
+
ancestors_for(options[:page]).
|
241
|
+
accessible_by(current_ability, :see)
|
242
|
+
|
243
|
+
if options.delete(:restricted_only)
|
244
|
+
pages = pages.restricted
|
245
|
+
end
|
246
|
+
|
247
|
+
if options.delete(:reverse)
|
248
|
+
pages.to_a.reverse!
|
249
|
+
end
|
250
|
+
|
241
251
|
if options[:without].present?
|
242
252
|
if options[:without].class == Array
|
243
253
|
pages = pages.to_a - options[:without]
|
@@ -245,12 +255,8 @@ module Alchemy
|
|
245
255
|
pages.to_a.delete(options[:without])
|
246
256
|
end
|
247
257
|
end
|
248
|
-
|
249
|
-
|
250
|
-
collection: pages,
|
251
|
-
spacer_template: 'alchemy/breadcrumb/spacer',
|
252
|
-
locals: {pages: pages, options: options}
|
253
|
-
)
|
258
|
+
|
259
|
+
render 'alchemy/breadcrumb/wrapper', pages: pages, options: options
|
254
260
|
end
|
255
261
|
|
256
262
|
# Returns current page title
|
@@ -53,8 +53,8 @@ module Alchemy
|
|
53
53
|
# Returns the correct params-hash for passing to show_page_path
|
54
54
|
def show_page_path_params(page, optional_params={})
|
55
55
|
raise ArgumentError, 'Page is nil' if page.nil?
|
56
|
-
url_params = {:
|
57
|
-
multi_language? ? url_params.update(:
|
56
|
+
url_params = {urlname: page.urlname}.update(optional_params)
|
57
|
+
multi_language? ? url_params.update(locale: page.language_code) : url_params
|
58
58
|
end
|
59
59
|
|
60
60
|
# Returns the path for downloading an alchemy attachment
|
data/app/models/alchemy/cell.rb
CHANGED
@@ -122,19 +122,26 @@ module Alchemy
|
|
122
122
|
# Returns a normalized Essence type
|
123
123
|
#
|
124
124
|
# Adds Alchemy module name in front of given essence type
|
125
|
+
# unless there is a Class with the specified name that is an essence.
|
125
126
|
#
|
126
127
|
# @param [String]
|
127
128
|
# the essence type to normalize
|
128
129
|
#
|
129
130
|
def normalize_essence_type(essence_type)
|
130
131
|
essence_type = essence_type.classify
|
131
|
-
if essence_type
|
132
|
-
|
133
|
-
|
134
|
-
essence_type.gsub!(/\AEssence/, 'Alchemy::Essence')
|
135
|
-
end
|
132
|
+
return essence_type if is_an_essence?(essence_type)
|
133
|
+
|
134
|
+
"Alchemy::#{essence_type}"
|
136
135
|
end
|
137
136
|
|
137
|
+
private
|
138
|
+
|
139
|
+
def is_an_essence?(essence_type)
|
140
|
+
klass = Module.const_get(essence_type)
|
141
|
+
klass.is_a?(Class) && klass.new.acts_as_essence?
|
142
|
+
rescue NameError
|
143
|
+
false
|
144
|
+
end
|
138
145
|
end # end class methods
|
139
146
|
|
140
147
|
# Instance Methods
|
@@ -179,6 +186,5 @@ module Alchemy
|
|
179
186
|
}
|
180
187
|
attributes
|
181
188
|
end
|
182
|
-
|
183
189
|
end
|
184
190
|
end
|
@@ -37,7 +37,7 @@ module Alchemy
|
|
37
37
|
belongs_to :page
|
38
38
|
has_and_belongs_to_many :touchable_pages, -> { uniq },
|
39
39
|
class_name: 'Alchemy::Page',
|
40
|
-
join_table:
|
40
|
+
join_table: ElementToPage.table_name
|
41
41
|
|
42
42
|
validates_presence_of :name, :on => :create
|
43
43
|
validates_format_of :name, :on => :create, :with => /\A[a-z0-9_-]+\z/
|
@@ -57,7 +57,7 @@ module Alchemy
|
|
57
57
|
scope :excluded, ->(names) { where(arel_table[:name].not_in(names)) }
|
58
58
|
scope :not_in_cell, -> { where(cell_id: nil) }
|
59
59
|
scope :in_cell, -> { where("#{self.table_name}.cell_id IS NOT NULL") }
|
60
|
-
scope :from_current_site, -> { where(
|
60
|
+
scope :from_current_site, -> { where(Language.table_name => {site_id: Site.current || Site.default}).joins(page: 'language') }
|
61
61
|
|
62
62
|
delegate :restricted?, to: :page, allow_nil: true
|
63
63
|
|
@@ -402,7 +402,7 @@ module Alchemy
|
|
402
402
|
# Returns an array of all EssenceRichtext contents ids
|
403
403
|
#
|
404
404
|
def richtext_contents_ids
|
405
|
-
contents.essence_richtexts.pluck(
|
405
|
+
contents.essence_richtexts.pluck("#{Content.table_name}.id")
|
406
406
|
end
|
407
407
|
|
408
408
|
# The names of all cells from given page this element could be placed in.
|
@@ -23,7 +23,7 @@ module Alchemy
|
|
23
23
|
#
|
24
24
|
def read_definitions_file
|
25
25
|
if ::File.exists?(definitions_file_path)
|
26
|
-
::YAML.
|
26
|
+
::YAML.load(ERB.new(File.read(definitions_file_path)).result) || []
|
27
27
|
else
|
28
28
|
raise LoadError, "Could not find elements.yml file! Please run `rails generate alchemy:scaffold`"
|
29
29
|
end
|
@@ -37,7 +37,7 @@ module Alchemy
|
|
37
37
|
before_save :remove_old_default, if: proc { |m| m.default_changed? && m != Language.default }
|
38
38
|
|
39
39
|
scope :published, -> { where(public: true) }
|
40
|
-
scope :with_root_page, -> { joins(:pages).where(
|
40
|
+
scope :with_root_page, -> { joins(:pages).where(Page.table_name => {language_root: true}) }
|
41
41
|
scope :on_site, ->(s) { s.present? ? where(site_id: s) : all }
|
42
42
|
default_scope { on_site(Site.current) }
|
43
43
|
|
data/app/models/alchemy/page.rb
CHANGED
@@ -199,7 +199,14 @@ module Alchemy
|
|
199
199
|
options
|
200
200
|
end
|
201
201
|
|
202
|
-
|
202
|
+
# Returns an array of all pages in the same branch from current.
|
203
|
+
# I.e. used to find the active page in navigation.
|
204
|
+
def ancestors_for(current)
|
205
|
+
return [] if current.nil?
|
206
|
+
current.self_and_ancestors.contentpages
|
207
|
+
end
|
208
|
+
|
209
|
+
private
|
203
210
|
|
204
211
|
# Aggregates the attributes from given source for copy of page.
|
205
212
|
#
|
@@ -36,9 +36,9 @@ module Alchemy
|
|
36
36
|
cells.any?
|
37
37
|
end
|
38
38
|
|
39
|
-
# Returns the cell definitions from page
|
39
|
+
# Returns the cell definitions from page definition.
|
40
40
|
def cell_definitions
|
41
|
-
cell_names =
|
41
|
+
cell_names = definition['cells']
|
42
42
|
return [] if cell_names.blank?
|
43
43
|
Cell.all_definitions_for(cell_names)
|
44
44
|
end
|
@@ -8,7 +8,9 @@ module Alchemy
|
|
8
8
|
|
9
9
|
has_many :elements, -> { order(:position) }
|
10
10
|
has_many :contents, :through => :elements
|
11
|
-
has_and_belongs_to_many :to_be_sweeped_elements, -> { uniq },
|
11
|
+
has_and_belongs_to_many :to_be_sweeped_elements, -> { uniq },
|
12
|
+
class_name: 'Alchemy::Element',
|
13
|
+
join_table: ElementToPage.table_name
|
12
14
|
|
13
15
|
after_create :autogenerate_elements, :unless => proc { systempage? || do_not_autogenerate }
|
14
16
|
after_update :trash_not_allowed_elements, :if => :page_layout_changed?
|
@@ -85,19 +87,35 @@ module Alchemy
|
|
85
87
|
element_definitions_by_name(element_definition_names)
|
86
88
|
end
|
87
89
|
|
88
|
-
# All names of elements that are defined in the
|
90
|
+
# All names of elements that are defined in the corresponding
|
91
|
+
# page and cell definition.
|
89
92
|
#
|
90
|
-
#
|
93
|
+
# Assign elements to a page in +config/alchemy/page_layouts.yml+ and/or
|
94
|
+
# +config/alchemy/cells.yml+ file.
|
91
95
|
#
|
92
|
-
# == Example:
|
96
|
+
# == Example of page_layouts.yml:
|
93
97
|
#
|
94
98
|
# - name: contact
|
99
|
+
# cells: [right_column]
|
95
100
|
# elements: [headline, contactform]
|
96
101
|
#
|
102
|
+
# == Example of cells.yml:
|
103
|
+
#
|
104
|
+
# - name: right_column
|
105
|
+
# elements: [teaser]
|
106
|
+
#
|
97
107
|
def element_definition_names
|
108
|
+
element_names_from_page_definition | element_names_from_cell_definition
|
109
|
+
end
|
110
|
+
|
111
|
+
def element_names_from_page_definition
|
98
112
|
definition['elements'] || []
|
99
113
|
end
|
100
114
|
|
115
|
+
def element_names_from_cell_definition
|
116
|
+
cell_definitions.map { |d| d['elements'] }.flatten
|
117
|
+
end
|
118
|
+
|
101
119
|
# Returns Element definitions with given name(s)
|
102
120
|
#
|
103
121
|
# @param [Array || String]
|
@@ -169,7 +187,7 @@ module Alchemy
|
|
169
187
|
# Returns an array of all EssenceRichtext contents ids
|
170
188
|
#
|
171
189
|
def richtext_contents_ids
|
172
|
-
contents.essence_richtexts.pluck(
|
190
|
+
contents.essence_richtexts.pluck("#{Content.table_name}.id")
|
173
191
|
end
|
174
192
|
|
175
193
|
private
|
@@ -62,8 +62,8 @@ module Alchemy
|
|
62
62
|
I18n.t(self.status[status_type].to_s, scope: "page_states.#{status_type}")
|
63
63
|
end
|
64
64
|
|
65
|
-
# Returns the self#page_layout
|
66
|
-
def
|
65
|
+
# Returns the self#page_layout definition from config/alchemy/page_layouts.yml file.
|
66
|
+
def definition
|
67
67
|
return {} if self.systempage?
|
68
68
|
description = PageLayout.get(self.page_layout)
|
69
69
|
if description.nil?
|
@@ -72,7 +72,7 @@ module Alchemy
|
|
72
72
|
end
|
73
73
|
description
|
74
74
|
end
|
75
|
-
alias_method :
|
75
|
+
alias_method :layout_description, :definition
|
76
76
|
|
77
77
|
# Returns translated name of the pages page_layout value.
|
78
78
|
# Page layout names are defined inside the config/alchemy/page_layouts.yml file.
|