hancock_cms 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (182) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +23 -0
  3. data/.rspec +1 -0
  4. data/.ruby-gemset +1 -0
  5. data/.ruby-version +1 -0
  6. data/Gemfile +4 -0
  7. data/LICENSE.txt +22 -0
  8. data/README.md +113 -0
  9. data/Rakefile +1 -0
  10. data/app/assets/images/devices/login-bg.jpg +0 -0
  11. data/app/assets/images/rails-admin/hancock_logo.svg +5 -0
  12. data/app/assets/javascripts/hancock/app/back_to_top.coffee +24 -0
  13. data/app/assets/javascripts/hancock/cms.coffee +11 -0
  14. data/app/assets/javascripts/hancock/cms/flash.coffee +3 -0
  15. data/app/assets/javascripts/hancock/cms/init.coffee +1 -0
  16. data/app/assets/javascripts/hancock/cms/map.coffee +22 -0
  17. data/app/assets/javascripts/hancock/rails_admin/cms.ui.coffee +43 -0
  18. data/app/assets/javascripts/hancock/rails_admin/custom/ui.coffee +0 -0
  19. data/app/assets/javascripts/head.load.js +707 -0
  20. data/app/assets/javascripts/jquery.placeholder.js +157 -0
  21. data/app/assets/javascripts/rails_admin/custom/ui.coffee +2 -0
  22. data/app/assets/stylesheets/hancock/cms.sass +9 -0
  23. data/app/assets/stylesheets/hancock/cms/devise.sass +157 -0
  24. data/app/assets/stylesheets/hancock/cms/flash.sass +69 -0
  25. data/app/assets/stylesheets/hancock/cms/mixins.sass +98 -0
  26. data/app/assets/stylesheets/hancock/cms/normalize.scss +407 -0
  27. data/app/assets/stylesheets/hancock/cms/powered.sass +18 -0
  28. data/app/assets/stylesheets/hancock/rails_admin/cms.theming.sass +703 -0
  29. data/app/assets/stylesheets/hancock/rails_admin/custom/theming.sass +1 -0
  30. data/app/assets/stylesheets/hancock/toplink/toplink.sass +24 -0
  31. data/app/assets/stylesheets/rails_admin/custom/theming.sass +4 -0
  32. data/app/controllers/concerns/hancock/current_user.rb +12 -0
  33. data/app/controllers/concerns/hancock/decorators/home.rb +12 -0
  34. data/app/controllers/concerns/hancock/decorators/registrations.rb +5 -0
  35. data/app/controllers/concerns/hancock/decorators/sessions.rb +5 -0
  36. data/app/controllers/concerns/hancock/errors.rb +94 -0
  37. data/app/controllers/concerns/hancock/fancybox.rb +14 -0
  38. data/app/controllers/concerns/hancock/no_cache.rb +12 -0
  39. data/app/controllers/hancock/home_controller.rb +10 -0
  40. data/app/controllers/hancock/registrations_controller.rb +23 -0
  41. data/app/controllers/hancock/sessions_controller.rb +24 -0
  42. data/app/helpers/hancock/gzip_helper.rb +27 -0
  43. data/app/helpers/hancock/home_helper.rb +2 -0
  44. data/app/helpers/hancock/powered_helper.rb +42 -0
  45. data/app/models/concerns/hancock/boolean_field.rb +21 -0
  46. data/app/models/concerns/hancock/cacheable.rb +33 -0
  47. data/app/models/concerns/hancock/decorators/embedded_element.rb +28 -0
  48. data/app/models/concerns/hancock/enableable.rb +8 -0
  49. data/app/models/concerns/hancock/geocodeable.rb +4 -0
  50. data/app/models/concerns/hancock/hash_field.rb +113 -0
  51. data/app/models/concerns/hancock/html_field.rb +33 -0
  52. data/app/models/concerns/hancock/mappable.rb +91 -0
  53. data/app/models/concerns/hancock/model_localizeable.rb +33 -0
  54. data/app/models/concerns/hancock/rails_admin_patch.rb +86 -0
  55. data/app/models/concerns/hancock/sort_field.rb +20 -0
  56. data/app/models/concerns/hancock/sortable.rb +8 -0
  57. data/app/models/hancock/embedded_element.rb +17 -0
  58. data/app/views/blocks/_favicon.html.slim +60 -0
  59. data/app/views/blocks/_footer.html.slim +1 -0
  60. data/app/views/blocks/_header.html.slim +3 -0
  61. data/app/views/devise/passwords/edit.html.slim +29 -0
  62. data/app/views/devise/passwords/new.html.slim +19 -0
  63. data/app/views/devise/registrations/edit.html.slim +31 -0
  64. data/app/views/devise/registrations/new.html.slim +39 -0
  65. data/app/views/devise/sessions/new.html.slim +39 -0
  66. data/app/views/devise/shared/_links.html.slim +11 -0
  67. data/app/views/hancock/errors/_base.html.slim +3 -0
  68. data/app/views/hancock/errors/error_403.html.slim +1 -0
  69. data/app/views/hancock/errors/error_404.html.slim +1 -0
  70. data/app/views/hancock/errors/error_500.html.slim +1 -0
  71. data/app/views/hancock/home/index.html.slim +1 -0
  72. data/app/views/hancock/simple_captcha/_simple_captcha.html.slim +13 -0
  73. data/app/views/hancock/toplink/_toplink.html.slim +2 -0
  74. data/app/views/layouts/application.html.slim +35 -0
  75. data/app/views/layouts/hancock/devise/confirmations.html.slim +22 -0
  76. data/app/views/layouts/hancock/devise/passwords.html.slim +22 -0
  77. data/app/views/layouts/hancock/devise/registrations.html.slim +22 -0
  78. data/app/views/layouts/hancock/devise/sessions.html.slim +22 -0
  79. data/app/views/layouts/hancock/devise/unlocks.html.slim +22 -0
  80. data/app/views/layouts/rails_admin/_footer.html.slim +2 -0
  81. data/app/views/layouts/rails_admin/_footer_navigation.html.slim +20 -0
  82. data/app/views/layouts/rails_admin/_navigation.html.slim +73 -0
  83. data/app/views/layouts/rails_admin/_secondary_navigation.html.slim +32 -0
  84. data/app/views/layouts/rails_admin/application.html.haml +68 -0
  85. data/app/views/layouts/rails_admin/pjax.html.haml +17 -0
  86. data/app/views/rails_admin/main/_check_boxes.html.slim +27 -0
  87. data/app/views/rails_admin/main/_enum_check_boxes.html.slim +5 -0
  88. data/app/views/rails_admin/main/_enum_radio_buttons.html.slim +5 -0
  89. data/app/views/rails_admin/main/_form_hancock_multiselect.html.slim +48 -0
  90. data/app/views/rails_admin/main/_form_raw.html.slim +1 -0
  91. data/app/views/rails_admin/main/_hancock_hash.html.slim +9 -0
  92. data/app/views/rails_admin/main/_hancock_hash_ml.html.slim +10 -0
  93. data/app/views/rails_admin/main/_hancock_html.html.slim +16 -0
  94. data/app/views/rails_admin/main/_hancock_html_ml.html.slim +53 -0
  95. data/app/views/shared/_admin_link.html.slim +3 -0
  96. data/app/views/shared/_messages.html.slim +7 -0
  97. data/config/initializers/embedded_findable.rb +57 -0
  98. data/config/initializers/hancock_cms.rb +11 -0
  99. data/config/initializers/simple_captcha.rb +70 -0
  100. data/config/locales/en.hancock.yml +29 -0
  101. data/config/locales/en.hancock_admin.yml +6 -0
  102. data/config/locales/ru.cancan.yml +4 -0
  103. data/config/locales/ru.devise.yml +65 -0
  104. data/config/locales/ru.hancock.yml +36 -0
  105. data/config/locales/ru.hancock_admin.yml +6 -0
  106. data/config/locales/ru.models.yml +82 -0
  107. data/config/locales/ru.mongoid.yml +450 -0
  108. data/config/locales/ru.rails_admin.yml +168 -0
  109. data/hancock_cms.gemspec +46 -0
  110. data/lib/filename_to_slug.rb +32 -0
  111. data/lib/generators/hancock/cms/ability_generator.rb +14 -0
  112. data/lib/generators/hancock/cms/admin_generator.rb +21 -0
  113. data/lib/generators/hancock/cms/application_generator.rb +14 -0
  114. data/lib/generators/hancock/cms/assets_generator.rb +35 -0
  115. data/lib/generators/hancock/cms/config_generator.rb +13 -0
  116. data/lib/generators/hancock/cms/controllers/decorators_generator.rb +27 -0
  117. data/lib/generators/hancock/cms/gemfile_generator.rb +13 -0
  118. data/lib/generators/hancock/cms/layout_generator.rb +14 -0
  119. data/lib/generators/hancock/cms/model_generator.rb +39 -0
  120. data/lib/generators/hancock/cms/models/embedded_element_generator.rb +56 -0
  121. data/lib/generators/hancock/cms/models/templates/embedded_element.erb +47 -0
  122. data/lib/generators/hancock/cms/paperclip_optimizer_generator.rb +13 -0
  123. data/lib/generators/hancock/cms/rack_generator.rb +12 -0
  124. data/lib/generators/hancock/cms/robots_generator.rb +14 -0
  125. data/lib/generators/hancock/cms/scripts_generator.rb +31 -0
  126. data/lib/generators/hancock/cms/templates/Gemfile.erb +69 -0
  127. data/lib/generators/hancock/cms/templates/ability.erb +49 -0
  128. data/lib/generators/hancock/cms/templates/admin.erb +74 -0
  129. data/lib/generators/hancock/cms/templates/application.erb +42 -0
  130. data/lib/generators/hancock/cms/templates/assets/javascripts/application.coffee.erb +5 -0
  131. data/lib/generators/hancock/cms/templates/assets/stylesheets/application.sass.erb +88 -0
  132. data/lib/generators/hancock/cms/templates/hancock_cms.erb +30 -0
  133. data/lib/generators/hancock/cms/templates/model.erb +42 -0
  134. data/lib/generators/hancock/cms/templates/paperclip_optimizer.erb +80 -0
  135. data/lib/generators/hancock/cms/templates/rack.erb +15 -0
  136. data/lib/generators/hancock/cms/templates/robots.txt.erb +5 -0
  137. data/lib/generators/hancock/cms/templates/scripts/assets_precompile.sh +3 -0
  138. data/lib/generators/hancock/cms/templates/scripts/bundle_production.sh +4 -0
  139. data/lib/generators/hancock/cms/templates/scripts/db_dump.sh.erb +3 -0
  140. data/lib/generators/hancock/cms/templates/scripts/db_restore.sh +3 -0
  141. data/lib/generators/hancock/cms/templates/scripts/full_assets_precompile.sh +4 -0
  142. data/lib/generators/hancock/cms/templates/scripts/restart_thru_kill.sh +3 -0
  143. data/lib/generators/hancock/cms/templates/scripts/send_hup.sh +3 -0
  144. data/lib/generators/hancock/cms/templates/scripts/send_usr2.sh +3 -0
  145. data/lib/generators/hancock/cms/templates/scripts/server.sh +5 -0
  146. data/lib/generators/hancock/cms/templates/scripts/server_alt.sh +5 -0
  147. data/lib/generators/hancock/cms/templates/unicorn.erb +57 -0
  148. data/lib/generators/hancock/cms/templates/unicorn.god.erb +59 -0
  149. data/lib/generators/hancock/cms/unicorn_god_generator.rb +15 -0
  150. data/lib/generators/hancock/cms/utils.rb +21 -0
  151. data/lib/hancock/admin.rb +60 -0
  152. data/lib/hancock/admin/embedded_element.rb +26 -0
  153. data/lib/hancock/configuration.rb +48 -0
  154. data/lib/hancock/controller.rb +30 -0
  155. data/lib/hancock/engine.rb +48 -0
  156. data/lib/hancock/migration.rb +15 -0
  157. data/lib/hancock/model.rb +53 -0
  158. data/lib/hancock/models/embedded_element.rb +12 -0
  159. data/lib/hancock/models/mongoid/embedded_element.rb +14 -0
  160. data/lib/hancock/plugin.rb +25 -0
  161. data/lib/hancock/plugin_configuration.rb +30 -0
  162. data/lib/hancock/rails_admin_ext/config.rb +129 -0
  163. data/lib/hancock/rails_admin_ext/hancock_hash.rb +84 -0
  164. data/lib/hancock/rails_admin_ext/hancock_html.rb +79 -0
  165. data/lib/hancock/rails_admin_ext/hancock_multiselect.rb +44 -0
  166. data/lib/hancock/rails_admin_ext/hancock_slugs.rb +35 -0
  167. data/lib/hancock/rails_admin_ext/patches/field_patch.rb +14 -0
  168. data/lib/hancock/rails_admin_ext/patches/group_patch.rb +41 -0
  169. data/lib/hancock/rails_admin_ext/patches/hancock_cms_group.rb +61 -0
  170. data/lib/hancock/rails_admin_ext/patches/new_controller_patch.rb +54 -0
  171. data/lib/hancock/routes.rb +20 -0
  172. data/lib/hancock/simple_form_patch.rb +12 -0
  173. data/lib/hancock/tasks.rb +13 -0
  174. data/lib/hancock/version.rb +3 -0
  175. data/lib/hancock_cms.rb +130 -0
  176. data/lib/manual_slug.rb +10 -0
  177. data/lib/manual_slug/active_record.rb +32 -0
  178. data/lib/manual_slug/mongoid.rb +40 -0
  179. data/lib/rails_admin/custom_show_in_app.rb +43 -0
  180. data/release.sh +12 -0
  181. data/template.rb +564 -0
  182. metadata +455 -0
@@ -0,0 +1,84 @@
1
+ require 'rails_admin/config/fields/types/text'
2
+ require 'json'
3
+
4
+ module RailsAdmin
5
+ module Config
6
+ module Fields
7
+ module Types
8
+ class HancockHash < RailsAdmin::Config::Fields::Types::Text
9
+ # Register field type for the type loader
10
+ RailsAdmin::Config::Fields::Types::register(self)
11
+ include RailsAdmin::Engine.routes.url_helpers
12
+
13
+ register_instance_option :string_method do
14
+ "#{name}_str"
15
+ end
16
+
17
+ register_instance_option :hash_method do
18
+ "#{name}_hash"
19
+ end
20
+
21
+ register_instance_option :value do
22
+ formatted_value
23
+ end
24
+
25
+ register_instance_option :tabbed do
26
+ true
27
+ end
28
+
29
+
30
+ ############ localize ######################
31
+ register_instance_option :translations_field do
32
+ (string_method.to_s + '_translations').to_sym
33
+ end
34
+
35
+ register_instance_option :localized? do
36
+ @abstract_model.model_name.constantize.public_instance_methods.include?(translations_field)
37
+ end
38
+
39
+ register_instance_option :pretty_value do
40
+ if localized?
41
+ I18n.available_locales.map { |l|
42
+ ret = nil
43
+ I18n.with_locale(l) do
44
+ _hash = bindings[:object].send(hash_method) || {}
45
+ ret = ("#{l}:<pre>" + JSON.pretty_generate(_hash) + "</pre>")
46
+ end
47
+ ret
48
+ }.join.html_safe
49
+ else
50
+ _hash = bindings[:object].send(hash_method) || {}
51
+ ("<pre>" + JSON.pretty_generate(_hash) + "</pre>").html_safe
52
+ end
53
+ end
54
+
55
+ register_instance_option :formatted_value do
56
+ if localized?
57
+ _val = bindings[:object].send((hash_method.to_s + '_translations').to_sym)
58
+ _val.each_pair { |l, _hash|
59
+ begin
60
+ _val[l] = JSON.pretty_generate(_hash)
61
+ rescue
62
+ end
63
+ }
64
+ else
65
+ begin
66
+ JSON.pretty_generate(bindings[:object].send hash_method)
67
+ rescue
68
+ bindings[:object].send hash_method
69
+ end
70
+ end
71
+ end
72
+
73
+ register_instance_option :allowed_methods do
74
+ localized? ? [string_method, translations_field] : [string_method]
75
+ end
76
+
77
+ register_instance_option :partial do
78
+ localized? ? :hancock_hash_ml : :hancock_hash
79
+ end
80
+ end
81
+ end
82
+ end
83
+ end
84
+ end
@@ -0,0 +1,79 @@
1
+ require 'rails_admin/config/fields/types/ck_editor'
2
+
3
+ module RailsAdmin
4
+ module Config
5
+ module Fields
6
+ module Types
7
+ class HancockHtml < RailsAdmin::Config::Fields::Types::CKEditor
8
+ # Register field type for the type loader
9
+ RailsAdmin::Config::Fields::Types::register(self)
10
+ include RailsAdmin::Engine.routes.url_helpers
11
+
12
+ register_instance_option :html_method do
13
+ "#{name}_html".to_sym
14
+ end
15
+
16
+ register_instance_option :clear_method do
17
+ "#{name}_clear".to_sym
18
+ end
19
+
20
+ register_instance_option :pretty_value do
21
+ bindings[:object].send(html_method)
22
+ end
23
+
24
+ register_instance_option :formatted_value do
25
+ pretty_value
26
+ end
27
+
28
+ register_instance_option :export_value do
29
+ pretty_value
30
+ end
31
+
32
+ register_instance_option :boolean_view_helper do
33
+ :check_box
34
+ end
35
+
36
+ register_instance_option :tabbed do
37
+ true
38
+ end
39
+
40
+
41
+ ############ localize ######################
42
+ register_instance_option :html_translations_field do
43
+ (html_method.to_s + '_translations').to_sym
44
+ end
45
+ register_instance_option :clear_translations_field do
46
+ (clear_method.to_s + '_translations').to_sym
47
+ end
48
+
49
+ register_instance_option :form_value do
50
+ if localized?
51
+ {
52
+ html: bindings[:object].send(html_translations_field),
53
+ clear: bindings[:object].send(clear_translations_field)
54
+ }
55
+ else
56
+ {
57
+ html: bindings[:object].send(html_method),
58
+ clear: bindings[:object].send(clear_method)
59
+ }
60
+ end
61
+ end
62
+
63
+ register_instance_option :localized? do
64
+ @abstract_model.model_name.constantize.public_instance_methods.include?(html_translations_field) and
65
+ @abstract_model.model_name.constantize.public_instance_methods.include?(clear_translations_field)
66
+ end
67
+
68
+ register_instance_option :allowed_methods do
69
+ localized? ? [html_method, clear_method, html_translations_field, clear_translations_field] : [html_method, clear_method]
70
+ end
71
+
72
+ register_instance_option :partial do
73
+ localized? ? :hancock_html_ml : :hancock_html
74
+ end
75
+ end
76
+ end
77
+ end
78
+ end
79
+ end
@@ -0,0 +1,44 @@
1
+ require 'rails_admin/config/fields/types/has_many_association'
2
+
3
+ module RailsAdmin
4
+ module Config
5
+ module Fields
6
+ module Types
7
+ class HancockMultiselect < RailsAdmin::Config::Fields::Types::HasManyAssociation
8
+ # Register field type for the type loader
9
+ RailsAdmin::Config::Fields::Types.register(self)
10
+
11
+ register_instance_option :partial do
12
+ :form_hancock_multiselect
13
+ end
14
+
15
+ # orderable associated objects
16
+ register_instance_option :orderable do
17
+ false
18
+ end
19
+
20
+ register_instance_option :inline_add do
21
+ false
22
+ end
23
+
24
+ register_instance_option :help do
25
+ 'Двойной клик перемещает между списками'
26
+ end
27
+
28
+ def nested_form
29
+ false
30
+ end
31
+
32
+ # def method_name
33
+ # "#{super.to_s.singularize}_ids".to_sym
34
+ # end
35
+
36
+ # Reader for validation errors of the bound object
37
+ def errors
38
+ bindings[:object].errors[name]
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,35 @@
1
+ require 'rails_admin/config/fields/types/enum'
2
+
3
+ module RailsAdmin
4
+ module Config
5
+ module Fields
6
+ module Types
7
+ class HancockSlugs < RailsAdmin::Config::Fields::Types::Enum
8
+ # Register field type for the type loader
9
+ RailsAdmin::Config::Fields::Types::register(self)
10
+
11
+ register_instance_option :searchable do
12
+ true
13
+ end
14
+
15
+ register_instance_option :enum_method do
16
+ :slugs
17
+ end
18
+
19
+ register_instance_option :visible do
20
+ bindings[:view].current_user.admin?
21
+ end
22
+
23
+ register_instance_option :multiple do
24
+ true
25
+ end
26
+
27
+ register_instance_option :pretty_value do
28
+ value.join("<br>").html_safe if value
29
+ end
30
+
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,14 @@
1
+ require 'rails_admin'
2
+ module RailsAdmin
3
+ module Config
4
+ module Fields
5
+
6
+ class Base
7
+ register_instance_option :weight do
8
+ name.to_sym == :default ? -1_000_000 : 0
9
+ end
10
+ end
11
+
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,41 @@
1
+ require 'rails_admin'
2
+ module RailsAdmin
3
+ module Config
4
+ module Fields
5
+
6
+ class Group
7
+ register_instance_option :weight do
8
+ name.to_sym == :default ? -1_000_000 : 0
9
+ end
10
+
11
+ def visible_fields
12
+ section.with(bindings).visible_fields.select { |f|
13
+ f.group == self
14
+ }.sort do |a, b|
15
+ a.weight <=> b.weight
16
+ end
17
+ end
18
+ end
19
+
20
+ end
21
+ end
22
+ end
23
+
24
+ module RailsAdmin
25
+ module Config
26
+ module HasGroups
27
+
28
+ def visible_groups
29
+ parent.groups.collect { |f|
30
+ f.section = self
31
+ f.with(bindings)
32
+ }.select { |g|
33
+ g.visible? and g.visible_fields.present?
34
+ }.sort do |a, b|
35
+ a.weight <=> b.weight
36
+ end
37
+ end
38
+
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,61 @@
1
+ require 'rails_admin'
2
+ module Hancock::RailsAdminGroupPatch
3
+ class << self
4
+ def hancock_cms_group(config, fields = {})
5
+ return unless fields
6
+
7
+ if fields.is_a?(Array)
8
+ fields.reject { |f| f.empty? }.each do |_group|
9
+ _name_default = :default
10
+ _name = _group.delete(:name) || _name_default
11
+ _active_default = _name == :default
12
+ _group[:active] ||= _active_default
13
+ _fields_default = {}
14
+ _group_fields = (_group.delete(:fields) || _fields_default)
15
+
16
+ config.group _name do
17
+ _group.each_pair do |name, val|
18
+
19
+ # TODO: find more logical solution
20
+ begin
21
+ begin
22
+ send name, val
23
+ rescue
24
+ send name
25
+ end
26
+ end
27
+ end
28
+
29
+ _group_fields.each_pair do |name, type|
30
+ if type.blank?
31
+ field name
32
+ else
33
+ if type.is_a?(Array)
34
+ field name, type[0], &type[1]
35
+ else
36
+ field name, type
37
+ end
38
+ end
39
+ end
40
+
41
+
42
+ end
43
+ end
44
+
45
+ else
46
+ fields.each_pair do |name, type|
47
+ if type.nil?
48
+ config.field name
49
+ else
50
+ if type.is_a?(Array)
51
+ config.field name, type[0], &type[1]
52
+ else
53
+ config.field name, type
54
+ end
55
+ end
56
+ end
57
+ end
58
+
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,54 @@
1
+ require 'rails_admin/config/actions/new'
2
+
3
+ module RailsAdmin
4
+ module Config
5
+ module Actions
6
+ class New < RailsAdmin::Config::Actions::Base
7
+ RailsAdmin::Config::Actions.register(self)
8
+
9
+ register_instance_option :controller do
10
+ proc do
11
+ if request.get? # NEW
12
+
13
+ @object = @abstract_model.new
14
+ @authorization_adapter && @authorization_adapter.attributes_for(:new, @abstract_model).each do |name, value|
15
+ @object.send("#{name}=", value)
16
+ end
17
+ if object_params = params[@abstract_model.to_param]
18
+ params[@abstract_model.param_key] ||= object_params
19
+ sanitize_params_for!(request.xhr? ? :modal : :create)
20
+ @object.set_attributes(@object.attributes.merge(object_params.to_h))
21
+ end
22
+ respond_to do |format|
23
+ format.html { render @action.template_name }
24
+ format.js { render @action.template_name, layout: false }
25
+ end
26
+
27
+ elsif request.post? # CREATE
28
+
29
+ @modified_assoc = []
30
+ @object = @abstract_model.new
31
+ sanitize_params_for!(request.xhr? ? :modal : :create)
32
+
33
+ @object.set_attributes(params[@abstract_model.param_key])
34
+ @authorization_adapter && @authorization_adapter.attributes_for(:create, @abstract_model).each do |name, value|
35
+ @object.send("#{name}=", value)
36
+ end
37
+
38
+ if @object.save
39
+ @auditing_adapter && @auditing_adapter.create_object(@object, @abstract_model, _current_user)
40
+ respond_to do |format|
41
+ format.html { redirect_to_on_success }
42
+ format.js { render json: {id: @object.id.to_s, label: @model_config.with(object: @object).object_label} }
43
+ end
44
+ else
45
+ handle_save_error
46
+ end
47
+
48
+ end
49
+ end
50
+ end
51
+ end
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,20 @@
1
+ module ActionDispatch::Routing
2
+ class Mapper
3
+
4
+ def hancock_cms_routes(config = {})
5
+ routes_config = {
6
+ root_path: "home#index"
7
+ }
8
+ routes_config.merge!(config)
9
+
10
+ scope module: 'hancock' do
11
+
12
+ if routes_config[:root_path]
13
+ root to: routes_config[:root_path]
14
+ end
15
+ end
16
+
17
+ end
18
+
19
+ end
20
+ end
@@ -0,0 +1,12 @@
1
+ # https://github.com/rs-pro/russian/blob/master/lib/russian/active_model_ext/custom_error_message.rb
2
+ require 'simple_form/components/errors'
3
+ module SimpleForm
4
+ module Components
5
+ module Errors
6
+ protected
7
+ def errors_on_attribute
8
+ object.errors[attribute_name].map {|m| m.sub(/^\^/, '')}
9
+ end
10
+ end
11
+ end
12
+ end