alchemy_cms 3.1.3 → 3.2.0.beta

Sign up to get free protection for your applications and to get access to all the features.
Files changed (110) hide show
  1. checksums.yaml +4 -4
  2. data/.editorconfig +2 -2
  3. data/.hound.yml +2 -0
  4. data/.rubocop.yml +1063 -0
  5. data/.travis.yml +14 -10
  6. data/Gemfile +4 -7
  7. data/README.md +16 -8
  8. data/alchemy_cms.gemspec +8 -7
  9. data/app/assets/javascripts/alchemy/alchemy.base.js.coffee +10 -11
  10. data/app/assets/javascripts/alchemy/alchemy.js +1 -1
  11. data/app/assets/stylesheets/alchemy/{admin.css.scss → admin.scss} +1 -0
  12. data/app/assets/stylesheets/alchemy/{icon-font.css.scss → icon-font.scss} +0 -0
  13. data/app/assets/stylesheets/alchemy/{menubar.css.scss → menubar.scss} +0 -0
  14. data/app/assets/stylesheets/alchemy/{print.css.scss → print.scss} +0 -0
  15. data/app/assets/stylesheets/alchemy/selects.scss +0 -6
  16. data/app/controllers/alchemy/admin/contents_controller.rb +3 -4
  17. data/app/controllers/alchemy/admin/pictures_controller.rb +0 -2
  18. data/app/controllers/alchemy/api/contents_controller.rb +1 -1
  19. data/app/controllers/alchemy/api/elements_controller.rb +2 -2
  20. data/app/controllers/alchemy/api/pages_controller.rb +1 -1
  21. data/app/controllers/alchemy/elements_controller.rb +0 -6
  22. data/app/controllers/alchemy/pages_controller.rb +17 -13
  23. data/app/controllers/alchemy/pictures_controller.rb +1 -0
  24. data/app/helpers/alchemy/admin/navigation_helper.rb +1 -1
  25. data/app/models/alchemy/element.rb +41 -17
  26. data/app/models/alchemy/page/page_naming.rb +16 -29
  27. data/bin/alchemy +1 -1
  28. data/config/routes.rb +1 -2
  29. data/db/migrate/20130827094554_alchemy_two_point_six.rb +0 -17
  30. data/lib/alchemy/capistrano.rb +3 -4
  31. data/lib/alchemy/controller_actions.rb +2 -1
  32. data/lib/alchemy/engine.rb +1 -0
  33. data/lib/alchemy/errors.rb +7 -0
  34. data/lib/alchemy/essence.rb +4 -4
  35. data/lib/alchemy/permissions.rb +1 -1
  36. data/lib/alchemy/shell.rb +26 -11
  37. data/lib/alchemy/test_support/controller_requests.rb +48 -12
  38. data/lib/alchemy/upgrader.rb +1 -0
  39. data/lib/alchemy/upgrader/three_point_one.rb +0 -1
  40. data/lib/alchemy/upgrader/three_point_two.rb +39 -0
  41. data/lib/alchemy/version.rb +1 -1
  42. data/lib/rails/templates/alchemy.rb +2 -2
  43. data/lib/tasks/alchemy/install.rake +2 -1
  44. data/spec/controllers/admin/attachments_controller_spec.rb +14 -14
  45. data/spec/controllers/admin/clipboard_controller_spec.rb +5 -5
  46. data/spec/controllers/admin/contents_controller_spec.rb +8 -14
  47. data/spec/controllers/admin/dashboard_controller_spec.rb +12 -12
  48. data/spec/controllers/admin/elements_controller_spec.rb +30 -31
  49. data/spec/controllers/admin/essence_files_controller_spec.rb +6 -6
  50. data/spec/controllers/admin/essence_pictures_controller_spec.rb +17 -17
  51. data/spec/controllers/admin/languages_controller_spec.rb +3 -3
  52. data/spec/controllers/admin/layoutpages_controller_spec.rb +3 -3
  53. data/spec/controllers/admin/pages_controller_spec.rb +48 -48
  54. data/spec/controllers/admin/pictures_controller_spec.rb +19 -19
  55. data/spec/controllers/admin/resources_controller_spec.rb +2 -2
  56. data/spec/controllers/admin/trash_controller_spec.rb +5 -5
  57. data/spec/controllers/alchemy/admin/tags_controller_spec.rb +5 -5
  58. data/spec/controllers/alchemy/api/contents_controller_spec.rb +46 -11
  59. data/spec/controllers/alchemy/api/elements_controller_spec.rb +42 -14
  60. data/spec/controllers/alchemy/api/pages_controller_spec.rb +26 -16
  61. data/spec/controllers/attachments_controller_spec.rb +7 -7
  62. data/spec/controllers/elements_controller_spec.rb +16 -19
  63. data/spec/controllers/messages_controller_spec.rb +15 -15
  64. data/spec/controllers/pages_controller_spec.rb +16 -25
  65. data/spec/controllers/pictures_controller_spec.rb +75 -49
  66. data/spec/dummy/Rakefile +1 -1
  67. data/spec/dummy/app/assets/stylesheets/application.css +5 -3
  68. data/spec/dummy/config/application.rb +11 -1
  69. data/spec/dummy/config/boot.rb +1 -1
  70. data/spec/dummy/config/environment.rb +1 -1
  71. data/spec/dummy/config/environments/development.rb +14 -2
  72. data/spec/dummy/config/environments/production.rb +18 -21
  73. data/spec/dummy/config/environments/test.rb +9 -4
  74. data/spec/dummy/config/initializers/assets.rb +11 -0
  75. data/spec/dummy/config/initializers/cookies_serializer.rb +3 -0
  76. data/spec/dummy/config/initializers/mime_types.rb +0 -1
  77. data/spec/dummy/config/initializers/session_store.rb +1 -1
  78. data/spec/dummy/config/secrets.yml +22 -0
  79. data/spec/dummy/db/migrate/20130827094554_alchemy_two_point_six.rb +380 -0
  80. data/spec/dummy/db/migrate/20130828121054_remove_do_not_index_from_alchemy_essence_texts.rb +5 -0
  81. data/spec/dummy/db/migrate/20130828121120_remove_do_not_index_from_alchemy_essence_richtexts.rb +5 -0
  82. data/spec/dummy/db/migrate/20130918201742_add_published_at_to_alchemy_pages.rb +5 -0
  83. data/spec/dummy/db/migrate/20150122213511_acts_as_taggable_on_migration.acts_as_taggable_on_engine.rb +31 -0
  84. data/{db/migrate/20140107192720_add_missing_unique_indices_to_tags_and_taggings.rb → spec/dummy/db/migrate/20150122213512_add_missing_unique_indices.acts_as_taggable_on_engine.rb} +5 -6
  85. data/{db/migrate/20140701160159_add_taggings_counter_cache_to_tags.rb → spec/dummy/db/migrate/20150122213513_add_taggings_counter_cache_to_tags.acts_as_taggable_on_engine.rb} +2 -1
  86. data/{db/migrate/20140701160225_add_missing_taggable_index.rb → spec/dummy/db/migrate/20150122213514_add_missing_taggable_index.acts_as_taggable_on_engine.rb} +1 -0
  87. data/spec/dummy/db/schema.rb +27 -31
  88. data/spec/dummy/public/404.html +20 -11
  89. data/spec/dummy/public/422.html +20 -11
  90. data/spec/dummy/public/500.html +19 -10
  91. data/spec/features/admin/page_creation_feature_spec.rb +2 -2
  92. data/spec/libraries/resource_spec.rb +1 -1
  93. data/spec/libraries/shell_spec.rb +2 -0
  94. data/spec/models/page_spec.rb +1 -13
  95. data/spec/spec_helper.rb +6 -4
  96. data/spec/support/rspec-activemodel-mocks_patch.rb +8 -0
  97. metadata +63 -56
  98. data/app/controllers/alchemy/contents_controller.rb +0 -18
  99. data/spec/controllers/contents_controller_spec.rb +0 -22
  100. data/spec/dummy/app/models/dummy_model.rb +0 -3
  101. data/spec/dummy/db/migrate/20130827094554_alchemy_two_point_six.rb +0 -1
  102. data/spec/dummy/db/migrate/20130828121054_remove_do_not_index_from_alchemy_essence_texts.rb +0 -1
  103. data/spec/dummy/db/migrate/20130828121120_remove_do_not_index_from_alchemy_essence_richtexts.rb +0 -1
  104. data/spec/dummy/db/migrate/20130918201742_add_published_at_to_alchemy_pages.rb +0 -1
  105. data/spec/dummy/db/migrate/20140107192720_add_missing_unique_indices_to_tags_and_taggings.rb +0 -1
  106. data/spec/dummy/db/migrate/20140701160159_add_taggings_counter_cache_to_tags.rb +0 -1
  107. data/spec/dummy/db/migrate/20140701160225_add_missing_taggable_index.rb +0 -1
  108. data/spec/dummy/db/migrate/20150412103152_create_dummy_model.rb +0 -7
  109. data/spec/dummy/spec/javascripts +0 -1
  110. data/spec/models/dummy_model_spec.rb +0 -11
@@ -2,22 +2,26 @@ language: ruby
2
2
  sudo: false
3
3
  cache: bundler
4
4
  rvm:
5
- - 1.9.3
6
- - 2.0.0
7
- - 2.1
5
+ - 2.0.0
6
+ - 2.1
7
+ - 2.2.0
8
8
  branches:
9
9
  only:
10
- - 3.1-stable
11
- before_script: 'bundle exec rake alchemy:spec:prepare'
12
- script: 'bundle exec rspec'
10
+ - master
11
+ before_script: bundle exec rake alchemy:spec:prepare
12
+ script: bundle exec rspec
13
13
  env:
14
- - DB=mysql
15
- - DB=postgresql
16
- - RAILS_VERSION=4.0.13
14
+ - DB=mysql
15
+ - DB=postgresql
17
16
  notifications:
18
17
  irc:
19
18
  on_success: change
20
19
  on_failure: always
21
20
  use_notice: true
22
21
  channels:
23
- - "irc.freenode.org#alchemy_cms"
22
+ - irc.freenode.org#alchemy_cms
23
+ slack:
24
+ secure: QzOFw1Ph69pzwWBFgtIVkOnjbcRxB9HPRQ+RYjK+2tg+fsbiTJ+wYgHcZL49tPYcLAls4kymkFWzWBF3PCAXJMfKgUCqXzdQ2FuJC/JoVRTLll4wDnZFPG33jsm5tVznmycZ3ma4+ZWfJQ+C+elEBOba6v1kG9eGIy6sH2cvXfE=
25
+ addons:
26
+ code_climate:
27
+ secure: qmOMqc4FUBRP25XqaYIKuxZQ/GrGLKjIc3vUqZa+XfkQKh6xLXvOF7YUM/XJZ5u6D6hk0Ly8UxjctvDY+tQxEAK49lFwK51i7bODfkQjfVBrFzfht7QhxY5HJKx7F0HHmpyNJet4n8mR0gGlhwVyXv+Tz7Rm6O3Hq3+TEbY9+pk=
data/Gemfile CHANGED
@@ -2,21 +2,17 @@ source 'https://rubygems.org'
2
2
 
3
3
  gemspec
4
4
 
5
- if ENV['RAILS_VERSION']
6
- gem 'rails', ENV['RAILS_VERSION']
7
- end
8
-
9
5
  gem 'sqlite3' if ENV['DB'].nil? || ENV['DB'] == 'sqlite'
10
- gem 'mysql2', '~> 0.3.18' if ENV['DB'] == 'mysql'
6
+ gem 'mysql2' if ENV['DB'] == 'mysql'
11
7
  gem 'pg' if ENV['DB'] == 'postgresql'
12
8
 
13
9
  group :development, :test do
14
10
  gem 'jasmine-rails', github: 'searls/jasmine-rails'
15
11
  gem 'jasmine-jquery-rails', github: 'travisjeffery/jasmine-jquery-rails'
16
12
  if ENV['TRAVIS']
17
- gem 'coveralls', require: false
13
+ gem "codeclimate-test-reporter", require: false
18
14
  else
19
- gem 'simplecov', require: false
15
+ gem 'simplecov', require: false
20
16
  end
21
17
  unless ENV['CI']
22
18
  gem 'launchy'
@@ -27,6 +23,7 @@ group :development, :test do
27
23
  gem 'pry-byebug'
28
24
  gem 'spring'
29
25
  gem 'spring-commands-rspec'
26
+ gem 'rubocop', require: false
30
27
  end
31
28
  end
32
29
 
data/README.md CHANGED
@@ -1,5 +1,7 @@
1
1
  [![Gem Version](https://badge.fury.io/rb/alchemy_cms.svg)](http://badge.fury.io/rb/alchemy_cms)
2
- [![Build Status](https://travis-ci.org/AlchemyCMS/alchemy_cms.svg?branch=3.1-stable)](https://travis-ci.org/AlchemyCMS/alchemy_cms) [![Code Climate](https://codeclimate.com/github/AlchemyCMS/alchemy_cms.svg)](https://codeclimate.com/github/AlchemyCMS/alchemy_cms) [![Coverage Status](https://img.shields.io/coveralls/AlchemyCMS/alchemy_cms.svg)](https://coveralls.io/r/AlchemyCMS/alchemy_cms?branch=3.1-stable)
2
+ [![Build Status](https://travis-ci.org/AlchemyCMS/alchemy_cms.svg?branch=master)](https://travis-ci.org/AlchemyCMS/alchemy_cms) [![Code Climate](https://codeclimate.com/github/AlchemyCMS/alchemy_cms.svg)](https://codeclimate.com/github/AlchemyCMS/alchemy_cms) [![Test Coverage](https://codeclimate.com/github/AlchemyCMS/alchemy_cms/badges/coverage.svg)](https://codeclimate.com/github/AlchemyCMS/alchemy_cms)
3
+
4
+ **CAUTION: This master branch is a development branch that *can* contain bugs. For productive environments you should use the [current Ruby gem version](https://rubygems.org/gems/alchemy_cms/versions/3.0.0), or the [latest stable branch (3.1-stable)](https://github.com/AlchemyCMS/alchemy_cms/tree/3.1-stable).**
3
5
 
4
6
 
5
7
  ## About
@@ -29,9 +31,9 @@ Read more about Alchemy on the [website](http://alchemy-cms.com) and in the [gui
29
31
 
30
32
  ## Rails Version
31
33
 
32
- **This version of Alchemy CMS runs with Rails 4 (including 4.1)**
34
+ **This version of Alchemy CMS runs with Rails 4.2**
33
35
 
34
- * For Rails 4.2 support use the current [master branch](https://github.com/AlchemyCMS/alchemy_cms/tree/master).
36
+ * For a Rails 4.0/4.1 compatible version use the [`3.1-stable` branch](https://github.com/AlchemyCMS/alchemy_cms/tree/3.1-stable).
35
37
  * For a Rails 3.2 compatible version use the [`2.8-stable` branch](https://github.com/AlchemyCMS/alchemy_cms/tree/2.8-stable).
36
38
  * For a Rails 3.1 compatible version use the [`2.1-stable` branch](https://github.com/AlchemyCMS/alchemy_cms/tree/2.1-stable).
37
39
  * For a Rails 3.0 compatible version use the [`2.0-stable` branch](https://github.com/AlchemyCMS/alchemy_cms/tree/2.0-stable).
@@ -40,7 +42,9 @@ Read more about Alchemy on the [website](http://alchemy-cms.com) and in the [gui
40
42
 
41
43
  ## Ruby Version
42
44
 
43
- Alchemy runs with Ruby >= 1.9.3 (including Ruby 2.0 and 2.1).
45
+ Alchemy runs with Ruby >= 2.0.0.
46
+
47
+ For a Ruby 1.9.3 compatible version use the [`3.1-stable` branch](https://github.com/AlchemyCMS/alchemy_cms/tree/3.1-stable).
44
48
 
45
49
  For a Ruby 1.8.7 compatible version use the [`2.3-stable` branch](https://github.com/AlchemyCMS/alchemy_cms/tree/2.3-stable).
46
50
 
@@ -52,7 +56,7 @@ For a Ruby 1.8.7 compatible version use the [`2.3-stable` branch](https://github
52
56
  Use the installer:
53
57
 
54
58
  ```shell
55
- $ gem install alchemy_cms
59
+ $ gem install alchemy_cms --pre
56
60
  $ alchemy new my_magicpage
57
61
  ```
58
62
 
@@ -71,9 +75,11 @@ $ alchemy --help
71
75
  Put this into your `Gemfile`:
72
76
 
73
77
  ```ruby
74
- gem 'alchemy_cms', github: 'AlchemyCMS/alchemy_cms', branch: '3.1-stable'
78
+ gem 'alchemy_cms', github: 'AlchemyCMS/alchemy_cms', branch: 'master'
75
79
  ```
76
80
 
81
+ **NOTE:** You normally want to use a stable branch, like `3.0-stable`.
82
+
77
83
  If you want to use Russian translation and have better i18n support, you should put:
78
84
 
79
85
  ```ruby
@@ -98,14 +104,16 @@ the Devise based user model that Alchemy provides and was extracted [into its ow
98
104
  If you don't have your own user class, you can use the Alchemy user model. Just add the following gem into your `Gemfile`:
99
105
 
100
106
  ```ruby
101
- gem 'alchemy-devise', github: 'AlchemyCMS/alchemy-devise', branch: '2.1-stable'
107
+ gem 'alchemy-devise', github: 'AlchemyCMS/alchemy-devise', branch: 'master'
102
108
  ```
103
109
 
110
+ **NOTE:** You normally want to use a stable branch, like `2.0-stable`.
111
+
104
112
  Then run:
105
113
 
106
114
  ```shell
107
115
  $ bundle install
108
- $ bin/rails g alchemy:devise:install
116
+ $ bin/rake alchemy_devise:install:migrations
109
117
  ```
110
118
 
111
119
  ##### Use your User model
@@ -12,7 +12,7 @@ Gem::Specification.new do |gem|
12
12
  gem.summary = 'A powerful, userfriendly and flexible CMS for Rails 4'
13
13
  gem.description = 'Alchemy is a powerful, userfriendly and flexible Rails 4 CMS.'
14
14
  gem.requirements << 'ImageMagick (libmagick), v6.6 or greater.'
15
- gem.required_ruby_version = '>= 1.9.3'
15
+ gem.required_ruby_version = '>= 2.0.0'
16
16
  gem.license = 'BSD New'
17
17
  gem.files = `git ls-files`.split("\n")
18
18
  gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
@@ -20,22 +20,23 @@ Gem::Specification.new do |gem|
20
20
  gem.require_paths = ['lib']
21
21
 
22
22
  gem.add_runtime_dependency 'actionpack-page_caching', ['~> 1.0.0']
23
- gem.add_runtime_dependency 'active_model_serializers', ['>= 0.8.1', '< 0.9.1']
23
+ gem.add_runtime_dependency 'active_model_serializers', ['~> 0.9']
24
24
  gem.add_runtime_dependency 'acts_as_list', ['~> 0.3']
25
25
  gem.add_runtime_dependency 'acts-as-taggable-on', ['~> 3.1']
26
26
  gem.add_runtime_dependency 'awesome_nested_set', ['~> 3.0.0']
27
- gem.add_runtime_dependency 'cancancan', ['~> 1.9', '< 1.13.0']
27
+ gem.add_runtime_dependency 'cancancan', ['~> 1.9']
28
28
  gem.add_runtime_dependency 'coffee-rails', ['~> 4.0']
29
- gem.add_runtime_dependency 'compass-rails', ['~> 1.1']
29
+ gem.add_runtime_dependency 'compass-rails', ['~> 2.0', '>= 2.0.4']
30
30
  gem.add_runtime_dependency 'dragonfly', ['~> 1.0.1']
31
- gem.add_runtime_dependency 'jquery-rails', ['~> 3.1.0']
31
+ gem.add_runtime_dependency 'jquery-rails', ['~> 4.0.3']
32
32
  gem.add_runtime_dependency 'jquery-ui-rails', ['~> 5.0.0']
33
33
  gem.add_runtime_dependency 'kaminari', ['~> 0.15']
34
34
  gem.add_runtime_dependency 'magiclabs-userstamp', ['~> 2.1.0']
35
35
  gem.add_runtime_dependency 'non-stupid-digest-assets', ['~> 1.0.3']
36
- gem.add_runtime_dependency 'rails', ['>= 4.0', '< 4.2']
36
+ gem.add_runtime_dependency 'rails', ['>= 4.2.0', '< 5.0']
37
37
  gem.add_runtime_dependency 'request_store', ['~> 1.1.0']
38
- gem.add_runtime_dependency 'sass-rails', ['~> 4.0']
38
+ gem.add_runtime_dependency 'responders', ['~> 2.0']
39
+ gem.add_runtime_dependency 'sass-rails', ['~> 5.0']
39
40
  gem.add_runtime_dependency 'sassy-buttons', ['~> 0.2.6']
40
41
  gem.add_runtime_dependency 'select2-rails', ['>= 3.5.9.1', '< 4.0']
41
42
  gem.add_runtime_dependency 'simple_form', ['~> 3.0']
@@ -46,17 +46,16 @@ $.extend Alchemy,
46
46
  # fades the image after its been loaded
47
47
  ImageLoader: (scope = document, options = {color: '#fff'}) ->
48
48
  $('img', scope).each ->
49
- if !this.complete
50
- image = $(this).hide()
51
- $parent = image.parent()
52
- spinner = Alchemy.Spinner.small options
53
- spinner.spin $parent[0]
54
- image.on 'load', ->
55
- spinner.stop()
56
- image.fadeIn 400
57
- image.on 'error', ->
58
- spinner.stop()
59
- $parent.html('<span class="icon warn"/>')
49
+ image = $(this).hide()
50
+ $parent = image.parent()
51
+ spinner = Alchemy.Spinner.small options
52
+ spinner.spin $parent[0]
53
+ image.on 'load', ->
54
+ spinner.stop()
55
+ image.fadeIn 400
56
+ image.on 'error', ->
57
+ spinner.stop()
58
+ $parent.html('<span class="icon warn"/>')
60
59
 
61
60
  removePicture: (selector) ->
62
61
  $form_field = $(selector)
@@ -1,6 +1,6 @@
1
1
  // Alchemy CMS Sprockets Manifest
2
2
  // ------------------------------
3
- //= require jquery
3
+ //= require jquery2
4
4
  //= require jquery_ujs
5
5
  //= require turbolinks
6
6
  //= require jquery-ui/datepicker
@@ -1,5 +1,6 @@
1
1
  /* Alchemy CMS Sprockets Manifest
2
2
  * -------------------------------
3
+ *= require select2
3
4
  *= require_self
4
5
  */
5
6
 
@@ -1,5 +1,3 @@
1
- //= require select2
2
-
3
1
  select {
4
2
  @extend %button-defaults;
5
3
  height: 29px;
@@ -139,10 +137,6 @@ select {
139
137
 
140
138
  .select2-search {
141
139
  margin: $default-margin 0;
142
-
143
- .select2-input {
144
- width: inherit;
145
- }
146
140
  }
147
141
 
148
142
  &.select2-with-searchbox .select2-results > .select2-result:first-child {
@@ -33,10 +33,9 @@ module Alchemy
33
33
  end
34
34
 
35
35
  def order
36
- Content.transaction do
37
- params[:content_ids].each_with_index do |id, idx|
38
- Content.where(id: id).update_all(position: idx + 1)
39
- end
36
+ params[:content_ids].each do |id|
37
+ content = Content.find(id)
38
+ content.move_to_bottom
40
39
  end
41
40
  @notice = _t("Successfully saved content position")
42
41
  end
@@ -3,8 +3,6 @@ module Alchemy
3
3
  class PicturesController < Alchemy::Admin::BaseController
4
4
  helper 'alchemy/admin/tags'
5
5
 
6
- respond_to :html, :js
7
-
8
6
  before_action :load_picture,
9
7
  only: [:show, :edit, :update, :info, :destroy]
10
8
 
@@ -7,7 +7,7 @@ module Alchemy
7
7
  #
8
8
  def index
9
9
  @contents = Content.accessible_by(current_ability, :index)
10
- if params[:element_id]
10
+ if params[:element_id].present?
11
11
  @contents = @contents.where(element_id: params[:element_id])
12
12
  end
13
13
  respond_with @contents
@@ -9,10 +9,10 @@ module Alchemy
9
9
  #
10
10
  def index
11
11
  @elements = Element.accessible_by(current_ability, :index)
12
- if params[:page_id]
12
+ if params[:page_id].present?
13
13
  @elements = @elements.where(page_id: params[:page_id])
14
14
  end
15
- if params[:named]
15
+ if params[:named].present?
16
16
  @elements = @elements.named(params[:named])
17
17
  end
18
18
  respond_with @elements
@@ -6,7 +6,7 @@ module Alchemy
6
6
  #
7
7
  def index
8
8
  @pages = Page.accessible_by(current_ability, :index)
9
- if params[:page_layout]
9
+ if params[:page_layout].present?
10
10
  @pages = @pages.where(page_layout: params[:page_layout])
11
11
  end
12
12
  respond_with @pages
@@ -13,7 +13,6 @@ module Alchemy
13
13
  #
14
14
  # * html
15
15
  # * js (Tries to replace a given +container_id+ with the elements view partial content via jQuery.)
16
- # * json (A JSON object that includes all contents and their ingredients)
17
16
  #
18
17
  def show
19
18
  @page = @element.page
@@ -22,12 +21,7 @@ module Alchemy
22
21
  respond_to do |format|
23
22
  format.html
24
23
  format.js { @container_id = params[:container_id] }
25
- format.json do
26
- ActiveSupport::Deprecation.warn("The Alchemy elements json API moved to `api` namespace. Please use `/api/elements` for json requests instead.")
27
- render json: @element, serializer: LegacyElementSerializer
28
- end
29
24
  end
30
25
  end
31
-
32
26
  end
33
27
  end
@@ -26,10 +26,6 @@ module Alchemy
26
26
  render xml: {error: 'Not found'}, status: 404
27
27
  end
28
28
  end
29
- format.json do
30
- ActiveSupport::Deprecation.warn('The Alchemy pages json API moved to `api` namespace. Please use `/api/pages` for json requests instead.')
31
- render json: @page
32
- end
33
29
  end
34
30
  end
35
31
  end
@@ -125,13 +121,14 @@ module Alchemy
125
121
  end
126
122
  end
127
123
 
128
- def redirect_page(options={})
129
- defaults = {
130
- :lang => (multi_language? ? @page.language_code : nil),
131
- :urlname => @page.urlname
132
- }
133
- options = defaults.merge(options)
134
- redirect_to show_page_path(additional_params.merge(options)), :status => 301
124
+ # Redirects page to given url with 301 status while keeping all additional params
125
+ def redirect_page(options = {})
126
+ options = {
127
+ lang: (multi_language? ? @page.language_code : nil),
128
+ urlname: @page.urlname
129
+ }.merge(options)
130
+
131
+ redirect_to show_page_path(additional_params.merge(options)), status: 301
135
132
  end
136
133
 
137
134
  # Use the bare minimum to redirect to @page
@@ -145,9 +142,16 @@ module Alchemy
145
142
  redirect_to show_page_path(options), :status => 301
146
143
  end
147
144
 
145
+ # Returns url parameters that are not internal show page params.
146
+ #
147
+ # * action
148
+ # * controller
149
+ # * urlname
150
+ # * lang
151
+ #
148
152
  def additional_params
149
- params.each do |key, value|
150
- params[key] = nil if ["action", "controller", "urlname", "lang"].include?(key)
153
+ params.symbolize_keys.delete_if do |key, _|
154
+ [:action, :controller, :urlname, :lang].include?(key)
151
155
  end
152
156
  end
153
157
 
@@ -46,6 +46,7 @@ module Alchemy
46
46
  end
47
47
 
48
48
  def send_image(image, format)
49
+ request.session_options[:skip] = true
49
50
  ALLOWED_IMAGE_TYPES.each do |type|
50
51
  format.send(type) do
51
52
  if type == 'jpeg'
@@ -165,7 +165,7 @@ module Alchemy
165
165
  action: entry['action'],
166
166
  only_path: true,
167
167
  params: entry['params']
168
- }
168
+ }.delete_if { |_k, v| v.nil? }
169
169
  end
170
170
 
171
171
  # Retrieves the current Alchemy module from controller and index action.
@@ -69,24 +69,32 @@ module Alchemy
69
69
  class << self
70
70
 
71
71
  # Builds a new element as described in +/config/alchemy/elements.yml+
72
- def new_from_scratch(attributes)
72
+ #
73
+ # - Returns a new Alchemy::Element object if no name is given in attributes,
74
+ # because the definition can not be found w/o name
75
+ # - Raises Alchemy::ElementDefinitionError if no definition for given attributes[:name]
76
+ # could be found
77
+ #
78
+ def new_from_scratch(attributes = {})
73
79
  attributes = attributes.dup.symbolize_keys
80
+
74
81
  return new if attributes[:name].blank?
75
- return nil if definitions.blank?
76
- # clean the name from cell name
77
- attributes[:name] = attributes[:name].split('#').first
78
- if element_scratch = definitions.detect { |el| el['name'] == attributes[:name] }
79
- new(element_scratch.merge(attributes).except(*FORBIDDEN_DEFINITION_ATTRIBUTES))
80
- else
81
- raise ElementDefinitionError, "Element definition for #{attributes[:name]} not found. Please check your elements.yml"
82
- end
82
+
83
+ new_element_from_definition_by(attributes) ||
84
+ raise(ElementDefinitionError.new(attributes))
83
85
  end
84
86
 
85
- # Builds a new element as described in +/config/alchemy/elements.yml+ and saves it
87
+ # Creates a new element as described in +/config/alchemy/elements.yml+
88
+ #
89
+ # - Returns a new Alchemy::Element object if no name is given in attributes,
90
+ # because the definition can not be found w/o name
91
+ # - Raises Alchemy::ElementDefinitionError if no definition for given attributes[:name]
92
+ # could be found
93
+ #
86
94
  def create_from_scratch(attributes)
87
95
  element = new_from_scratch(attributes)
88
96
  element.save if element
89
- return element
97
+ element
90
98
  end
91
99
 
92
100
  # This methods does a copy of source and all depending contents and all of their depending essences.
@@ -127,6 +135,20 @@ module Alchemy
127
135
  }
128
136
  end
129
137
 
138
+ private
139
+
140
+ def new_element_from_definition_by(attributes)
141
+ remove_cell_name_from_element_name!(attributes)
142
+
143
+ element_scratch = definitions.detect { |el| el['name'] == attributes[:name] }
144
+ return if element_scratch.nil?
145
+
146
+ new(element_scratch.merge(attributes).except(*FORBIDDEN_DEFINITION_ATTRIBUTES))
147
+ end
148
+
149
+ def remove_cell_name_from_element_name!(attributes)
150
+ attributes[:name] = attributes[:name].split('#').first
151
+ end
130
152
  end
131
153
 
132
154
  # Returns next public element from same page.
@@ -192,9 +214,7 @@ module Alchemy
192
214
  # rss_title: true
193
215
  #
194
216
  def content_for_rss_title
195
- rss_title = content_descriptions.detect { |c| c['rss_title'] }
196
- return if rss_title.blank?
197
- contents.find_by_name(rss_title['name'])
217
+ content_for_rss_meta('title')
198
218
  end
199
219
 
200
220
  # Returns the content that is marked as rss description.
@@ -208,9 +228,7 @@ module Alchemy
208
228
  # rss_description: true
209
229
  #
210
230
  def content_for_rss_description
211
- rss_description = content_descriptions.detect { |c| c['rss_description'] }
212
- return if rss_description.blank?
213
- contents.find_by_name(rss_description['name'])
231
+ content_for_rss_meta('description')
214
232
  end
215
233
 
216
234
  # Returns the array with the hashes for all element contents in the elements.yml file
@@ -437,6 +455,12 @@ module Alchemy
437
455
 
438
456
  private
439
457
 
458
+ def content_for_rss_meta(type)
459
+ description = content_descriptions.detect { |c| c["rss_#{type}"] }
460
+ return if description.blank?
461
+ contents.find_by(name: description['name'])
462
+ end
463
+
440
464
  # creates the contents for this element as described in the elements.yml
441
465
  def create_contents
442
466
  contents = []