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.
Files changed (146) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +661 -863
  3. data/README.md +5 -63
  4. data/app/assets/javascripts/alchemy/alchemy.base.js.coffee +11 -10
  5. data/app/assets/javascripts/alchemy/alchemy.initializer.js.coffee +6 -0
  6. data/app/assets/stylesheets/alchemy/_extends.scss +0 -6
  7. data/app/assets/stylesheets/alchemy/_mixins.scss +6 -0
  8. data/app/assets/stylesheets/alchemy/buttons.scss +1 -1
  9. data/app/assets/stylesheets/alchemy/elements.scss +1 -1
  10. data/app/assets/stylesheets/alchemy/menubar.scss +1 -1
  11. data/app/assets/stylesheets/alchemy/selects.scss +5 -1
  12. data/app/assets/stylesheets/alchemy/upload.scss +1 -1
  13. data/app/controllers/alchemy/admin/pages_controller.rb +1 -1
  14. data/app/controllers/alchemy/base_controller.rb +4 -57
  15. data/app/controllers/alchemy/messages_controller.rb +2 -2
  16. data/app/controllers/alchemy/pages_controller.rb +22 -31
  17. data/app/controllers/alchemy/pictures_controller.rb +2 -2
  18. data/app/helpers/alchemy/admin/base_helper.rb +7 -0
  19. data/app/helpers/alchemy/admin/elements_helper.rb +31 -15
  20. data/app/helpers/alchemy/admin/pages_helper.rb +17 -0
  21. data/app/helpers/alchemy/base_helper.rb +0 -28
  22. data/app/helpers/alchemy/pages_helper.rb +18 -12
  23. data/app/helpers/alchemy/url_helper.rb +2 -2
  24. data/app/models/alchemy/cell.rb +1 -1
  25. data/app/models/alchemy/content/factory.rb +12 -6
  26. data/app/models/alchemy/element.rb +3 -3
  27. data/app/models/alchemy/element/definitions.rb +1 -1
  28. data/app/models/alchemy/element_to_page.rb +7 -0
  29. data/app/models/alchemy/language.rb +1 -1
  30. data/app/models/alchemy/page.rb +8 -1
  31. data/app/models/alchemy/page/page_cells.rb +2 -2
  32. data/app/models/alchemy/page/page_elements.rb +23 -5
  33. data/app/models/alchemy/page/page_natures.rb +3 -3
  34. data/app/models/alchemy/page/page_scopes.rb +1 -1
  35. data/app/models/alchemy/picture.rb +1 -1
  36. data/app/views/alchemy/admin/pages/_create_language_form.html.erb +1 -1
  37. data/app/views/alchemy/admin/pages/_form.html.erb +1 -1
  38. data/app/views/alchemy/admin/pictures/_picture_to_assign.html.erb +1 -1
  39. data/app/views/alchemy/breadcrumb/_page.html.erb +3 -2
  40. data/app/views/alchemy/breadcrumb/_separator.html.erb +1 -0
  41. data/app/views/alchemy/breadcrumb/_wrapper.html.erb +13 -0
  42. data/app/views/alchemy/language_links/_language.html.erb +1 -1
  43. data/app/views/alchemy/navigation/_link.html.erb +1 -1
  44. data/app/views/alchemy/pages/show.rss.builder +5 -7
  45. data/app/views/layouts/alchemy/admin.html.erb +5 -0
  46. data/config/routes.rb +13 -10
  47. data/lib/alchemy/configuration_methods.rb +29 -0
  48. data/lib/alchemy/controller_actions.rb +12 -4
  49. data/lib/alchemy/engine.rb +3 -0
  50. data/lib/alchemy/errors.rb +1 -1
  51. data/lib/alchemy/essence.rb +14 -12
  52. data/lib/alchemy/on_page_layout.rb +58 -0
  53. data/lib/alchemy/page_layout.rb +1 -1
  54. data/lib/alchemy/permissions.rb +21 -16
  55. data/lib/alchemy/routing_constraints.rb +49 -0
  56. data/lib/alchemy/seeder.rb +4 -2
  57. data/lib/alchemy/ssl_protection.rb +30 -0
  58. data/lib/alchemy/test_support/essence_shared_examples.rb +118 -25
  59. data/lib/alchemy/test_support/factories.rb +5 -8
  60. data/lib/alchemy/test_support/integration_helpers.rb +16 -10
  61. data/lib/alchemy/upgrader/three_point_two.rb +34 -4
  62. data/lib/alchemy/version.rb +1 -1
  63. data/lib/rails/generators/alchemy/{scaffold → install}/files/_article_editor.html.erb +0 -0
  64. data/lib/rails/generators/alchemy/{scaffold → install}/files/_article_view.html.erb +0 -0
  65. data/lib/rails/generators/alchemy/{scaffold → install}/files/_standard.html.erb +0 -0
  66. data/lib/rails/generators/alchemy/{scaffold → install}/files/alchemy.de.yml +0 -0
  67. data/lib/rails/generators/alchemy/{scaffold → install}/files/alchemy.elements.css.scss +0 -0
  68. data/lib/rails/generators/alchemy/{scaffold → install}/files/alchemy.en.yml +0 -0
  69. data/lib/rails/generators/alchemy/{scaffold → install}/files/alchemy.es.yml +0 -0
  70. data/lib/rails/generators/alchemy/{scaffold → install}/files/application.html.erb +0 -0
  71. data/lib/rails/generators/alchemy/install/install_generator.rb +69 -0
  72. data/lib/rails/generators/alchemy/{scaffold/files/elements.yml → install/templates/elements.yml.tt} +2 -0
  73. data/lib/rails/generators/alchemy/{scaffold → install}/templates/page_layouts.yml.tt +2 -0
  74. data/lib/rails/generators/alchemy/views/views_generator.rb +41 -0
  75. data/lib/rails/templates/alchemy.rb +2 -2
  76. data/lib/tasks/alchemy/db.rake +0 -5
  77. data/lib/tasks/alchemy/install.rake +10 -5
  78. data/lib/tasks/alchemy/tidy.rake +2 -0
  79. data/spec/controllers/admin/attachments_controller_spec.rb +1 -1
  80. data/spec/controllers/admin/clipboard_controller_spec.rb +1 -1
  81. data/spec/controllers/admin/contents_controller_spec.rb +1 -1
  82. data/spec/controllers/admin/dashboard_controller_spec.rb +2 -2
  83. data/spec/controllers/admin/elements_controller_spec.rb +1 -1
  84. data/spec/controllers/admin/essence_files_controller_spec.rb +1 -1
  85. data/spec/controllers/admin/essence_pictures_controller_spec.rb +1 -1
  86. data/spec/controllers/admin/languages_controller_spec.rb +1 -1
  87. data/spec/controllers/admin/layoutpages_controller_spec.rb +1 -1
  88. data/spec/controllers/admin/pages_controller_spec.rb +4 -4
  89. data/spec/controllers/admin/pictures_controller_spec.rb +1 -1
  90. data/spec/controllers/admin/resources_controller_spec.rb +1 -1
  91. data/spec/controllers/admin/trash_controller_spec.rb +1 -1
  92. data/spec/controllers/alchemy/admin/tags_controller_spec.rb +1 -1
  93. data/spec/controllers/attachments_controller_spec.rb +1 -1
  94. data/spec/controllers/base_controller_spec.rb +22 -0
  95. data/spec/controllers/elements_controller_spec.rb +1 -1
  96. data/spec/controllers/pages_controller_spec.rb +15 -16
  97. data/spec/controllers/pictures_controller_spec.rb +212 -162
  98. data/spec/dummy/app/controllers/login_controller.rb +5 -0
  99. data/spec/dummy/app/models/dummy_model.rb +3 -0
  100. data/spec/dummy/config/alchemy/cells.yml +4 -1
  101. data/spec/dummy/config/alchemy/elements.yml +8 -0
  102. data/spec/dummy/config/alchemy/page_layouts.yml +5 -1
  103. data/spec/dummy/config/routes.rb +1 -2
  104. data/spec/dummy/db/migrate/20150412103152_create_dummy_model.rb +7 -0
  105. data/spec/dummy/db/schema.rb +30 -26
  106. data/spec/features/admin/dashboard_spec.rb +11 -9
  107. data/spec/features/admin/language_tree_feature_spec.rb +5 -6
  108. data/spec/features/admin/legacy_page_url_management_spec.rb +1 -1
  109. data/spec/features/admin/link_overlay_spec.rb +1 -1
  110. data/spec/features/admin/locale_select_feature_spec.rb +1 -1
  111. data/spec/features/admin/modules_integration_spec.rb +1 -1
  112. data/spec/features/admin/navigation_feature_spec.rb +1 -1
  113. data/spec/features/admin/page_creation_feature_spec.rb +1 -1
  114. data/spec/features/admin/page_editing_feature_spec.rb +3 -3
  115. data/spec/features/admin/picture_library_integration_spec.rb +1 -1
  116. data/spec/features/admin/resources_integration_spec.rb +1 -1
  117. data/spec/features/admin/site_select_feature_spec.rb +32 -0
  118. data/spec/features/admin/tinymce_feature_spec.rb +1 -3
  119. data/spec/features/page_feature_spec.rb +36 -27
  120. data/spec/features/security_spec.rb +1 -1
  121. data/spec/features/translation_integration_spec.rb +3 -3
  122. data/spec/helpers/admin/elements_helper_spec.rb +103 -26
  123. data/spec/helpers/admin/pages_helper_spec.rb +32 -1
  124. data/spec/helpers/base_helper_spec.rb +0 -45
  125. data/spec/helpers/pages_helper_spec.rb +18 -17
  126. data/spec/helpers/url_helper_spec.rb +8 -5
  127. data/spec/libraries/controller_actions_spec.rb +2 -2
  128. data/spec/libraries/on_page_layout_spec.rb +112 -0
  129. data/spec/libraries/page_layout_spec.rb +5 -1
  130. data/spec/libraries/permissions_spec.rb +13 -15
  131. data/spec/models/cell_spec.rb +4 -0
  132. data/spec/models/content_spec.rb +6 -0
  133. data/spec/models/dummy_model_spec.rb +11 -0
  134. data/spec/models/element_spec.rb +6 -1
  135. data/spec/models/element_to_page_spec.rb +14 -0
  136. data/spec/models/page_spec.rb +111 -19
  137. data/spec/routing/routing_spec.rb +120 -101
  138. data/spec/spec_helper.rb +3 -3
  139. metadata +36 -21
  140. data/app/views/alchemy/breadcrumb/_spacer.html.erb +0 -1
  141. data/lib/alchemy/capistrano.rb +0 -230
  142. data/lib/alchemy/test_support/auth_helpers.rb +0 -35
  143. data/lib/rails/generators/alchemy/deploy_script/deploy_script_generator.rb +0 -90
  144. data/lib/rails/generators/alchemy/deploy_script/templates/deploy.rb.tt +0 -113
  145. data/lib/rails/generators/alchemy/scaffold/scaffold_generator.rb +0 -63
  146. 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
- image_file = @picture.image_file
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 could be placed on that page because of the pages layout.
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 "" if elements.blank?
66
+ return [] if elements.blank?
61
67
  cells_definition = @page.cell_definitions
62
- return "" if cells_definition.blank?
68
+ return [] if cells_definition.blank?
63
69
  options = {}
64
- celled_elements = []
65
70
  cells_definition.each do |cell|
66
- cell_elements = elements.select { |e| cell['elements'].include?(e.class.name == 'Element' ? e.name : e['name']) }
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
- other_elements = elements - celled_elements
74
- unless other_elements.blank?
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
- # We don't want to show empty cells
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("alchemy_contents.element_id != #{element.id}")
109
- .where("alchemy_contents.essence_type" => "Alchemy::EssenceSelect")
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('&nbsp;').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
- @breadcrumb ||= breadcrumb(@page)
211
- @breadcrumb.include?(page)
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: %(<span class="separator">&gt;</span>),
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
- pages = breadcrumb(options[:page]).accessible_by(current_ability, :see)
239
- pages = pages.restricted if options.delete(:restricted_only)
240
- pages.to_a.reverse! if options[:reverse]
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
- render(
249
- partial: 'alchemy/breadcrumb/page',
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 = {:urlname => page.urlname}.update(optional_params)
57
- multi_language? ? url_params.update(:lang => page.language_code) : url_params
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
@@ -56,7 +56,7 @@ module Alchemy
56
56
  private
57
57
 
58
58
  def read_yml_file
59
- ::YAML.load_file(yml_file_path) || []
59
+ ::YAML.load(ERB.new(File.read(yml_file_path)).result) || []
60
60
  end
61
61
 
62
62
  def yml_file_path
@@ -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.match(/\AAlchemy::/)
132
- essence_type
133
- else
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: 'alchemy_elements_alchemy_pages'
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(alchemy_languages: {site_id: Site.current || Site.default}).joins(page: 'language') }
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('alchemy_contents.id')
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.load_file(definitions_file_path) || []
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
@@ -0,0 +1,7 @@
1
+ module Alchemy
2
+ class ElementToPage
3
+ def self.table_name
4
+ [Element.table_name, Page.table_name].join('_')
5
+ end
6
+ end
7
+ 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(alchemy_pages: {language_root: true}) }
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
 
@@ -199,7 +199,14 @@ module Alchemy
199
199
  options
200
200
  end
201
201
 
202
- private
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's page_layout defintion.
39
+ # Returns the cell definitions from page definition.
40
40
  def cell_definitions
41
- cell_names = self.layout_description['cells']
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 }, class_name: 'Alchemy::Element', join_table: 'alchemy_elements_alchemy_pages'
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 page's page_layout definition.
90
+ # All names of elements that are defined in the corresponding
91
+ # page and cell definition.
89
92
  #
90
- # Define elements in +config/alchemy/page_layout.yml+ file
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('alchemy_contents.id')
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 description from config/alchemy/page_layouts.yml file.
66
- def layout_description
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 :definition, :layout_description
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.