alchemy_cms 3.2.0.beta → 3.2.0.rc1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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
|
@@ -83,7 +83,7 @@ module Alchemy
|
|
|
83
83
|
# All pages from +Alchemy::Site.current+
|
|
84
84
|
#
|
|
85
85
|
scope :from_current_site, -> {
|
|
86
|
-
where(
|
|
86
|
+
where(Language.table_name => {site_id: Site.current || Site.default}).joins(:language)
|
|
87
87
|
}
|
|
88
88
|
|
|
89
89
|
# All pages for xml sitemap
|
|
@@ -71,7 +71,7 @@ module Alchemy
|
|
|
71
71
|
}
|
|
72
72
|
|
|
73
73
|
scope :deletable, -> {
|
|
74
|
-
where("#{
|
|
74
|
+
where("#{table_name}.id NOT IN (SELECT picture_id FROM #{EssencePicture.table_name})")
|
|
75
75
|
}
|
|
76
76
|
|
|
77
77
|
scope :without_tag, -> {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
<%= alchemy_form_for [:admin, @page], class: 'edit_page' do |f| %>
|
|
2
2
|
<%= f.input :page_layout,
|
|
3
3
|
collection: @page_layouts,
|
|
4
|
-
label: @page
|
|
4
|
+
label: page_layout_label(@page),
|
|
5
5
|
include_blank: false,
|
|
6
6
|
input_html: {class: 'alchemy_selectbox'} %>
|
|
7
7
|
<div class="input check_boxes">
|
|
@@ -4,12 +4,13 @@
|
|
|
4
4
|
<% elsif page == pages.last %>
|
|
5
5
|
<% css_classes << "last" %>
|
|
6
6
|
<% end %>
|
|
7
|
+
|
|
7
8
|
<%= link_to_unless(
|
|
8
9
|
!options[:link_active_page] && options[:page] == page,
|
|
9
10
|
h(page.name),
|
|
10
11
|
show_alchemy_page_path(page),
|
|
11
12
|
class: css_classes.compact.join(" "),
|
|
12
13
|
title: page.title
|
|
13
|
-
) do |name,
|
|
14
|
+
) do |name, _url, html_options| %>
|
|
14
15
|
<%= content_tag :span, name, html_options %>
|
|
15
|
-
<% end %>
|
|
16
|
+
<% end %>
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<span class="separator"><%= sanitize options[:separator] %></span>
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
<% if pages.any? %>
|
|
2
|
+
<div class="breadcrumb">
|
|
3
|
+
<%= render({
|
|
4
|
+
collection: pages,
|
|
5
|
+
partial: 'alchemy/breadcrumb/page',
|
|
6
|
+
spacer_template: 'alchemy/breadcrumb/separator',
|
|
7
|
+
locals: {
|
|
8
|
+
pages: pages,
|
|
9
|
+
options: options
|
|
10
|
+
}
|
|
11
|
+
}.delete_if { |k, _v| k == :spacer_template && options[:separator].blank? }) %>
|
|
12
|
+
</div>
|
|
13
|
+
<% end %>
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
|
|
7
7
|
<%= link_to(
|
|
8
8
|
content_tag(:span, language.label(options[:linkname])).html_safe,
|
|
9
|
-
show_alchemy_page_path(language.pages.language_roots.first,
|
|
9
|
+
show_alchemy_page_path(language.pages.language_roots.first, locale: language.code),
|
|
10
10
|
class: css_classes.join(" "),
|
|
11
11
|
title: link_title
|
|
12
12
|
) %>
|
|
@@ -1,22 +1,20 @@
|
|
|
1
|
-
xml.instruct! :xml, :
|
|
2
|
-
xml.rss :
|
|
1
|
+
xml.instruct! :xml, version: "1.0"
|
|
2
|
+
xml.rss version: "2.0" do
|
|
3
3
|
|
|
4
4
|
xml.channel do
|
|
5
5
|
|
|
6
6
|
xml.title @page.title
|
|
7
7
|
xml.description @page.meta_description
|
|
8
|
-
xml.link show_page_url(:
|
|
8
|
+
xml.link show_page_url(urlname: @page.urlname, locale: multi_language? ? @page.language_code : nil)
|
|
9
9
|
|
|
10
10
|
@page.feed_elements.each do |element|
|
|
11
11
|
xml.item do
|
|
12
12
|
xml.title element.content_for_rss_title.try(:ingredient)
|
|
13
13
|
xml.description element.content_for_rss_description.try(:ingredient)
|
|
14
14
|
xml.pubDate element.ingredient('date').to_s(:rfc822) if element.has_ingredient?('date')
|
|
15
|
-
xml.link show_page_url(:
|
|
16
|
-
xml.guid show_page_url(:
|
|
15
|
+
xml.link show_page_url(urlname: @page.urlname, anchor: element_dom_id(element), locale: multi_language? ? @page.language_code : nil)
|
|
16
|
+
xml.guid show_page_url(urlname: @page.urlname, anchor: element_dom_id(element), locale: multi_language? ? @page.language_code : nil)
|
|
17
17
|
end
|
|
18
18
|
end
|
|
19
|
-
|
|
20
19
|
end
|
|
21
|
-
|
|
22
20
|
end
|
|
@@ -86,6 +86,11 @@
|
|
|
86
86
|
<%= select_tag 'change_locale',
|
|
87
87
|
options_for_select(translations_for_select, ::I18n.locale),
|
|
88
88
|
class: 'alchemy_selectbox tiny' %>
|
|
89
|
+
<%- if multi_site? -%>
|
|
90
|
+
<%= select_tag 'change_site',
|
|
91
|
+
options_for_select(sites_for_select, Alchemy::Site.current.id),
|
|
92
|
+
class: 'alchemy_selectbox tiny' %>
|
|
93
|
+
<%- end -%>
|
|
89
94
|
</div>
|
|
90
95
|
</div>
|
|
91
96
|
<% end %>
|
data/config/routes.rb
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
require 'alchemy/routing_constraints'
|
|
2
2
|
|
|
3
|
+
Alchemy::Engine.routes.draw do
|
|
3
4
|
root :to => 'pages#show'
|
|
4
5
|
|
|
5
6
|
get '/sitemap.xml' => 'pages#sitemap', format: 'xml'
|
|
@@ -34,20 +35,22 @@ Alchemy::Engine.routes.draw do
|
|
|
34
35
|
|
|
35
36
|
namespace :api, defaults: {format: 'json'} do
|
|
36
37
|
resources :contents, only: [:index, :show]
|
|
38
|
+
|
|
37
39
|
resources :elements, only: [:index, :show] do
|
|
38
40
|
get '/contents' => 'contents#index', as: 'contents'
|
|
39
41
|
get '/contents/:name' => 'contents#show', as: 'content'
|
|
40
42
|
end
|
|
43
|
+
|
|
41
44
|
resources :pages, only: [:index] do
|
|
42
45
|
get 'elements' => 'elements#index', as: 'elements'
|
|
43
46
|
get 'elements/:named' => 'elements#index', as: 'named_elements'
|
|
44
47
|
end
|
|
48
|
+
|
|
45
49
|
get '/pages/*urlname(.:format)' => 'pages#show', as: 'page'
|
|
46
50
|
get '/admin/pages/:id(.:format)' => 'pages#show', as: 'preview_page'
|
|
47
51
|
end
|
|
48
52
|
|
|
49
53
|
namespace :admin do
|
|
50
|
-
|
|
51
54
|
resources :contents do
|
|
52
55
|
collection do
|
|
53
56
|
post :order
|
|
@@ -149,16 +152,16 @@ Alchemy::Engine.routes.draw do
|
|
|
149
152
|
end
|
|
150
153
|
|
|
151
154
|
resources :sites
|
|
152
|
-
|
|
153
155
|
end
|
|
154
156
|
|
|
155
|
-
get '/:
|
|
156
|
-
|
|
157
|
-
|
|
157
|
+
get '/:locale' => 'pages#show',
|
|
158
|
+
constraints: {locale: Alchemy::RoutingConstraints::LOCALE_REGEXP},
|
|
159
|
+
as: :show_language_root
|
|
158
160
|
|
|
159
161
|
# The page show action has to be last route
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
:
|
|
163
|
-
|
|
162
|
+
constraints(locale: Alchemy::RoutingConstraints::LOCALE_REGEXP) do
|
|
163
|
+
get '(/:locale)/*urlname(.:format)' => 'pages#show',
|
|
164
|
+
constraints: Alchemy::RoutingConstraints.new,
|
|
165
|
+
as: :show_page
|
|
166
|
+
end
|
|
164
167
|
end
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
module Alchemy
|
|
2
|
+
module ConfigurationMethods
|
|
3
|
+
extend ActiveSupport::Concern
|
|
4
|
+
|
|
5
|
+
included do
|
|
6
|
+
helper_method :configuration, :multi_language?, :multi_site?
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
# Returns the configuration value of given key.
|
|
10
|
+
#
|
|
11
|
+
# Config file is in +config/alchemy/config.yml+
|
|
12
|
+
#
|
|
13
|
+
def configuration(name)
|
|
14
|
+
Config.get(name)
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
# Returns true if more than one language is published.
|
|
18
|
+
#
|
|
19
|
+
def multi_language?
|
|
20
|
+
Language.published.count > 1
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
# Returns true if more than one site exists.
|
|
24
|
+
#
|
|
25
|
+
def multi_site?
|
|
26
|
+
Site.count > 1
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
@@ -46,7 +46,16 @@ module Alchemy
|
|
|
46
46
|
# Returns the current site.
|
|
47
47
|
#
|
|
48
48
|
def current_alchemy_site
|
|
49
|
-
@current_alchemy_site ||=
|
|
49
|
+
@current_alchemy_site ||= begin
|
|
50
|
+
site_id = params[:site_id] || session[:site_id]
|
|
51
|
+
if site_id.nil?
|
|
52
|
+
session.delete :site_id
|
|
53
|
+
Site.find_for_host(request.host)
|
|
54
|
+
else
|
|
55
|
+
session[:site_id] = site_id
|
|
56
|
+
Site.find(site_id)
|
|
57
|
+
end
|
|
58
|
+
end
|
|
50
59
|
end
|
|
51
60
|
|
|
52
61
|
# Ensures usage of Alchemy's permissions class.
|
|
@@ -95,8 +104,8 @@ module Alchemy
|
|
|
95
104
|
end
|
|
96
105
|
|
|
97
106
|
def load_alchemy_language_from_params
|
|
98
|
-
if params[:
|
|
99
|
-
Language.find_by_code(params[:
|
|
107
|
+
if params[:locale].present?
|
|
108
|
+
Language.find_by_code(params[:locale])
|
|
100
109
|
end
|
|
101
110
|
end
|
|
102
111
|
|
|
@@ -125,6 +134,5 @@ module Alchemy
|
|
|
125
134
|
Language.current = language
|
|
126
135
|
end
|
|
127
136
|
end
|
|
128
|
-
|
|
129
137
|
end
|
|
130
138
|
end
|
data/lib/alchemy/engine.rb
CHANGED
|
@@ -25,6 +25,7 @@ require 'userstamp'
|
|
|
25
25
|
require_relative './auth_accessors'
|
|
26
26
|
require_relative './cache_digests/template_tracker'
|
|
27
27
|
require_relative './config'
|
|
28
|
+
require_relative './configuration_methods'
|
|
28
29
|
require_relative './controller_actions'
|
|
29
30
|
require_relative './errors'
|
|
30
31
|
require_relative './essence'
|
|
@@ -37,9 +38,11 @@ require_relative './logger'
|
|
|
37
38
|
require_relative './modules'
|
|
38
39
|
require_relative './mount_point'
|
|
39
40
|
require_relative './name_conversions'
|
|
41
|
+
require_relative './on_page_layout'
|
|
40
42
|
require_relative './page_layout'
|
|
41
43
|
require_relative './permissions'
|
|
42
44
|
require_relative './picture_attributes'
|
|
45
|
+
require_relative './ssl_protection'
|
|
43
46
|
require_relative './resource'
|
|
44
47
|
require_relative './tinymce'
|
|
45
48
|
require_relative './touching'
|
data/lib/alchemy/errors.rb
CHANGED
|
@@ -13,7 +13,7 @@ module Alchemy
|
|
|
13
13
|
class DefaultLanguageNotFoundError < StandardError
|
|
14
14
|
# Raised if no default language can be found.
|
|
15
15
|
def message
|
|
16
|
-
"No default language found
|
|
16
|
+
"No default language found! Please run the `bin/rake db:seed` task."
|
|
17
17
|
end
|
|
18
18
|
end
|
|
19
19
|
|
data/lib/alchemy/essence.rb
CHANGED
|
@@ -36,12 +36,12 @@ module Alchemy #:nodoc:
|
|
|
36
36
|
stampable stamper_class_name: Alchemy.user_class_name
|
|
37
37
|
validate :validate_ingredient, :on => :update, :if => 'validations.any?'
|
|
38
38
|
|
|
39
|
-
has_one :content, :as => :essence
|
|
40
|
-
has_one :element, :through => :content
|
|
41
|
-
has_one :page, :through => :element
|
|
39
|
+
has_one :content, :as => :essence, class_name: "Alchemy::Content"
|
|
40
|
+
has_one :element, :through => :content, class_name: "Alchemy::Element"
|
|
41
|
+
has_one :page, :through => :element, class_name: "Alchemy::Page"
|
|
42
42
|
|
|
43
|
-
scope :available, -> { joins(:element).merge(Element.available) }
|
|
44
|
-
scope :from_element, ->(name) { joins(:element).where(
|
|
43
|
+
scope :available, -> { joins(:element).merge(Alchemy::Element.available) }
|
|
44
|
+
scope :from_element, ->(name) { joins(:element).where(Element.table_name => { name: name }) }
|
|
45
45
|
|
|
46
46
|
delegate :restricted?, to: :page, allow_nil: true
|
|
47
47
|
delegate :trashed?, to: :element, allow_nil: true
|
|
@@ -124,7 +124,9 @@ module Alchemy #:nodoc:
|
|
|
124
124
|
def validate_ingredient
|
|
125
125
|
validations.each do |validation|
|
|
126
126
|
if validation.respond_to?(:keys)
|
|
127
|
-
validation.map
|
|
127
|
+
validation.map do |key, value|
|
|
128
|
+
self.send("validate_#{key}", value)
|
|
129
|
+
end
|
|
128
130
|
else
|
|
129
131
|
self.send("validate_#{validation}")
|
|
130
132
|
end
|
|
@@ -139,23 +141,23 @@ module Alchemy #:nodoc:
|
|
|
139
141
|
@validation_errors ||= []
|
|
140
142
|
end
|
|
141
143
|
|
|
142
|
-
def validate_presence
|
|
143
|
-
if ingredient.blank?
|
|
144
|
+
def validate_presence(validate = true)
|
|
145
|
+
if validate && ingredient.blank?
|
|
144
146
|
errors.add(ingredient_column, :blank)
|
|
145
147
|
validation_errors << :blank
|
|
146
148
|
end
|
|
147
149
|
end
|
|
148
150
|
|
|
149
|
-
def validate_uniqueness
|
|
150
|
-
return if !public?
|
|
151
|
+
def validate_uniqueness(validate = true)
|
|
152
|
+
return if !validate || !public?
|
|
151
153
|
if duplicates.any?
|
|
152
154
|
errors.add(ingredient_column, :taken)
|
|
153
155
|
validation_errors << :taken
|
|
154
156
|
end
|
|
155
157
|
end
|
|
156
158
|
|
|
157
|
-
def validate_format(
|
|
158
|
-
matcher = Config.get('format_matchers')[
|
|
159
|
+
def validate_format(format)
|
|
160
|
+
matcher = Config.get('format_matchers')[format] || format
|
|
159
161
|
if ingredient.to_s.match(Regexp.new(matcher)).nil?
|
|
160
162
|
errors.add(ingredient_column, :invalid)
|
|
161
163
|
validation_errors << :invalid
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
module Alchemy
|
|
2
|
+
|
|
3
|
+
# = Adds before filter to pages show action
|
|
4
|
+
#
|
|
5
|
+
# Use this mixin to add the +on_page_layout+ class method
|
|
6
|
+
# into your +ApplicationController+.
|
|
7
|
+
#
|
|
8
|
+
# Pass a block or method name in which you have the +@page+ object and can do
|
|
9
|
+
# everything as if you where in a normal controller action.
|
|
10
|
+
#
|
|
11
|
+
# Pass a +Alchemy::PageLayout+ name or +:all+ to
|
|
12
|
+
# call this callback only on specific pages or all pages.
|
|
13
|
+
#
|
|
14
|
+
# == Example:
|
|
15
|
+
#
|
|
16
|
+
# class ApplicationController < ActionController::Base
|
|
17
|
+
# extend Alchemy::OnPageLayout
|
|
18
|
+
#
|
|
19
|
+
# on_page_layout :all do
|
|
20
|
+
# @my_stuff = Stuff.all
|
|
21
|
+
# end
|
|
22
|
+
#
|
|
23
|
+
# on_page_layout :contact, :do_something
|
|
24
|
+
#
|
|
25
|
+
# private
|
|
26
|
+
#
|
|
27
|
+
# def do_something
|
|
28
|
+
# @contacts = Contact.all
|
|
29
|
+
# if @page.tag_list.include?('something')
|
|
30
|
+
# do_something
|
|
31
|
+
# end
|
|
32
|
+
# end
|
|
33
|
+
# end
|
|
34
|
+
#
|
|
35
|
+
module OnPageLayout
|
|
36
|
+
|
|
37
|
+
def on_page_layout(page_layout, callback = nil)
|
|
38
|
+
Alchemy::PagesController.class_eval do
|
|
39
|
+
|
|
40
|
+
append_before_action only: :show, if: -> { call_page_layout_callback_for?(page_layout) } do
|
|
41
|
+
if block_given?
|
|
42
|
+
instance_eval(&Proc.new)
|
|
43
|
+
elsif callback
|
|
44
|
+
self.send(callback)
|
|
45
|
+
else
|
|
46
|
+
raise "You need to either pass a block or method name as callback for `on_page_layout`"
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
private
|
|
51
|
+
|
|
52
|
+
def call_page_layout_callback_for?(page_layout)
|
|
53
|
+
page_layout.to_sym == :all || @page.page_layout.to_sym == page_layout.to_sym
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
end
|
data/lib/alchemy/page_layout.rb
CHANGED
|
@@ -157,7 +157,7 @@ module Alchemy
|
|
|
157
157
|
#
|
|
158
158
|
def read_layouts_file
|
|
159
159
|
if File.exists?(layouts_file_path)
|
|
160
|
-
YAML.
|
|
160
|
+
YAML.load(ERB.new(File.read(layouts_file_path)).result) || []
|
|
161
161
|
else
|
|
162
162
|
raise LoadError, "Could not find page_layouts.yml file! Please run `rails generate alchemy:scaffold`"
|
|
163
163
|
end
|
data/lib/alchemy/permissions.rb
CHANGED
|
@@ -46,7 +46,7 @@ module Alchemy
|
|
|
46
46
|
p.public? && !p.restricted?
|
|
47
47
|
end
|
|
48
48
|
can :see, Alchemy::Page, restricted: false, visible: true
|
|
49
|
-
can(
|
|
49
|
+
can(:display, Alchemy::Picture) { |p| !p.restricted? }
|
|
50
50
|
end
|
|
51
51
|
end
|
|
52
52
|
|
|
@@ -72,7 +72,7 @@ module Alchemy
|
|
|
72
72
|
p.public?
|
|
73
73
|
end
|
|
74
74
|
can :see, Alchemy::Page, restricted: true, visible: true
|
|
75
|
-
can
|
|
75
|
+
can :display, Alchemy::Picture
|
|
76
76
|
can [:read, :update], Alchemy.user_class, id: @user.id
|
|
77
77
|
end
|
|
78
78
|
end
|
|
@@ -99,22 +99,22 @@ module Alchemy
|
|
|
99
99
|
]
|
|
100
100
|
|
|
101
101
|
# Controller actions
|
|
102
|
-
can :leave,
|
|
103
|
-
can [:info, :help],
|
|
104
|
-
can :manage,
|
|
105
|
-
can :index,
|
|
106
|
-
can :edit,
|
|
102
|
+
can :leave, :alchemy_admin
|
|
103
|
+
can [:info, :help], :alchemy_admin_dashboard
|
|
104
|
+
can :manage, :alchemy_admin_clipboard
|
|
105
|
+
can :index, :trash
|
|
106
|
+
can :edit, :alchemy_admin_layoutpages
|
|
107
107
|
|
|
108
108
|
# Resources
|
|
109
|
-
can [:read, :download],
|
|
110
|
-
can :manage,
|
|
111
|
-
can :manage,
|
|
112
|
-
can :manage,
|
|
113
|
-
can :manage,
|
|
114
|
-
can :manage,
|
|
115
|
-
can :edit_content,
|
|
116
|
-
can [:read, :
|
|
117
|
-
can [:read, :autocomplete],
|
|
109
|
+
can [:read, :download], Alchemy::Attachment
|
|
110
|
+
can :manage, Alchemy::Content
|
|
111
|
+
can :manage, Alchemy::Element
|
|
112
|
+
can :manage, Alchemy::EssenceFile
|
|
113
|
+
can :manage, Alchemy::EssencePicture
|
|
114
|
+
can :manage, Alchemy::LegacyPageUrl
|
|
115
|
+
can :edit_content, Alchemy::Page
|
|
116
|
+
can [:read, :info], Alchemy::Picture
|
|
117
|
+
can [:read, :autocomplete], Alchemy::Tag
|
|
118
118
|
end
|
|
119
119
|
end
|
|
120
120
|
|
|
@@ -203,6 +203,11 @@ module Alchemy
|
|
|
203
203
|
:unlock,
|
|
204
204
|
:visit,
|
|
205
205
|
to: :edit_content
|
|
206
|
+
|
|
207
|
+
alias_action :show,
|
|
208
|
+
:thumbnail,
|
|
209
|
+
:zoom,
|
|
210
|
+
to: :display
|
|
206
211
|
end
|
|
207
212
|
|
|
208
213
|
# Include the role specific permissions.
|