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,32 @@
1
+ ul.nav.navbar-nav.root_links
2
+ - actions(:root).each do |action|
3
+ - next if action.action_name.to_s == "dashboard"
4
+ - data_method = nil if action.http_methods.include?(:get)
5
+ - data_method = "post" if action.http_methods.include?(:post)
6
+ - data_method = "put" if action.http_methods.include?(:put)
7
+ - data_method = "delete" if action.http_methods.include?(:delete)
8
+
9
+ li{class="#{action.action_name}_root_link top-nav-control-panel"}
10
+ = link_to wording_for(:menu, action), { action: action.action_name, controller: 'rails_admin/main' }, class: (action.pjax? ? "pjax" : ""), data: data_method ? {method: data_method, confirm: t("admin.actions.#{action.action_name}.confirm")} : nil
11
+
12
+
13
+ - if main_app_root_path = (main_app.root_path rescue false)
14
+ li.top-nav-goto-home = link_to main_app_root_path, title: "На главную".freeze
15
+ span
16
+ i.fa.fa-home
17
+
18
+ - if _current_user
19
+ - if logout_path.present?
20
+ li.top-nav-logout = link_to logout_path, title: "Выйти".freeze, method: logout_method
21
+ span
22
+ i.fa.fa-sign-out
23
+
24
+ / - if main_app_root_path = (main_app.root_path rescue false)
25
+ / li= link_to t('admin.home.name').capitalize, main_app_root_path
26
+ / - if _current_user
27
+ / - if user_link = edit_user_link
28
+ / li= user_link
29
+ / - if logout_path.present?
30
+ / li= link_to content_tag('span', t('admin.misc.log_out'), class: 'label label-important'), logout_path, method: logout_method
31
+ / - if _current_user.respond_to?(:email) && _current_user.email.present?
32
+ / li= image_tag "#{(request.ssl? ? 'https://secure' : 'http://www')}.gravatar.com/avatar/#{Digest::MD5.hexdigest _current_user.email}?s=30", style: 'padding-top:5px'
@@ -0,0 +1,68 @@
1
+ !!! 5
2
+ %html{lang: I18n.locale}
3
+ %head
4
+ %meta{content: "IE=edge", "http-equiv" => "X-UA-Compatible"}
5
+ %meta{content: "text/html; charset=utf-8", "http-equiv" => "Content-Type"}
6
+ %meta{content: "width=device-width, initial-scale=1", name: "viewport; charset=utf-8"}
7
+ %meta{content: "NONE,NOARCHIVE", name: "robots"}
8
+ = csrf_meta_tag
9
+ = stylesheet_link_tag "rails_admin/rails_admin.css", media: :all
10
+ = javascript_include_tag "rails_admin/rails_admin.js"
11
+ -# Initialize JS simple i18n
12
+ :javascript
13
+ RailsAdmin.I18n.init('#{I18n.locale}', JSON.parse("#{j I18n.t("admin.js").to_json}"))
14
+
15
+ %body.rails_admin
16
+
17
+ %nav.admin-navbar.admin-navbar-fixed.bg-red{:role => "navigation"}
18
+ = render "layouts/rails_admin/navigation"
19
+
20
+ .admin-menubar.admin-menubar-fixed.admin-menubar-dark
21
+ .toolbar
22
+ = render "layouts/rails_admin/sidebar_navigation"
23
+ .admin-menubar-footer
24
+ = render "layouts/rails_admin/footer_navigation"
25
+
26
+ %main.admin-content
27
+ .admin-wrapper
28
+ .content{:'data-pjax-container' => true}= render template: 'layouts/rails_admin/pjax'
29
+
30
+ %footer.admin-footer
31
+ = render "layouts/rails_admin/footer"
32
+
33
+ -#%nav.navbar-hancock.navbar-fixed
34
+ -# = render "layouts/rails_admin/navigation"
35
+ -#
36
+ -#%main.root
37
+ -# .sidebar.fixed-sidebar
38
+ -# .sidebar-backdrop
39
+ -# .toolbar
40
+ -# = render "layouts/rails_admin/sidebar_navigation"
41
+ -#
42
+ -# .content-wrapper
43
+ -# .content{:'data-pjax-container' => true}= render template: 'layouts/rails_admin/pjax'
44
+ -#
45
+ -#%footer.footer
46
+ -# = render "layouts/rails_admin/footer"
47
+
48
+ -#%body.rails_admin
49
+ -# #loading.label.label-warning{style: 'display:none; position:fixed; right:20px; bottom:20px; z-index:100000'}= t('admin.loading')
50
+ -# %nav.navbar.navbar-default.navbar-fixed-top
51
+ -# = render "layouts/rails_admin/navigation"
52
+ -#
53
+ -# .menu-bar
54
+ -# = render "layouts/rails_admin/sidebar_navigation"
55
+ -#
56
+ -# .page-content
57
+ -# .content{:'data-pjax-container' => true}= render template: 'layouts/rails_admin/pjax'
58
+ -#
59
+ -#
60
+ -#
61
+ -# #status-bar
62
+
63
+ -#.container-fluid
64
+ -# .row
65
+ -# .col-sm-3.col-md-2.sidebar-nav.hancock-nav
66
+ -# = render "layouts/rails_admin/sidebar_navigation"
67
+ -# .col-sm-9.col-sm-offset-3.col-md-10.col-md-offset-2.sidebar-content
68
+ -# .content{:'data-pjax-container' => true}= render template: 'layouts/rails_admin/pjax'
@@ -0,0 +1,17 @@
1
+ :javascript
2
+ $('.nav.nav-pills li.active').removeClass('active');
3
+ $('.nav.nav-pills li[data-model="#{@abstract_model.to_param}"]').addClass('active');
4
+
5
+ %title= "#{@abstract_model.try(:pretty_name) || @page_name} | #{[_get_plugin_name[0] || 'Rails', _get_plugin_name[1] || 'Admin'].join(' ')}"
6
+ .page-header
7
+ %h1= @page_name
8
+ - flash && flash.each do |key, value|
9
+ .alert.alert-dismissible{class: flash_alert_class(key)}
10
+ %button.close{type: 'button', :'data-dismiss' => "alert"} ×
11
+ = value
12
+ = breadcrumb
13
+ %ul.nav.nav-tabs
14
+ = menu_for((@abstract_model ? (@object.try(:persisted?) ? :member : :collection) : :root), @abstract_model, @object)
15
+ %ul.nav.nav-tabs.filter
16
+ = content_for :contextual_tabs
17
+ = yield
@@ -0,0 +1,27 @@
1
+ - if params[:associations].nil?
2
+ = render 'rails_admin/main/enum_check_boxes', field: field, form: form
3
+ - else
4
+ ruby:
5
+ related_id = params[:associations] && params[:associations][field.name.to_s]
6
+ config = field.associated_model_config
7
+ source_abstract_model = RailsAdmin.config(form.object.class).abstract_model
8
+
9
+ if form.object.new_record? && related_id.present? && related_id != 'new'
10
+ selected = [config.abstract_model.get(related_id)]
11
+ else
12
+ selected = form.object.send(field.name)
13
+ end
14
+ selected_ids = selected.map{|s| s.send(field.associated_primary_key)}
15
+
16
+ current_action = params[:action].in?(['create', 'new']) ? 'create' : 'update'
17
+
18
+ xhr = !field.associated_collection_cache_all
19
+
20
+ collection = if xhr
21
+ selected.map { |o| [o.send(field.associated_object_label_method), o.send(field.associated_primary_key)] }
22
+ else
23
+ i = 0
24
+ controller.list_entries(config, :index, field.associated_collection_scope, false).map { |o| [o.send(field.associated_object_label_method), o.send(field.associated_primary_key)] }.sort_by {|a| [selected_ids.index(a[1]) || selected_ids.size, i+=1] }
25
+ end
26
+
27
+ = form.collection_check_boxes field.method_name, collection, :last, :first, {}, {} { |i| i.label( class: 'checkbox' ) { i.check_box + i.text } }
@@ -0,0 +1,5 @@
1
+ ruby:
2
+ values = form.object.class.send(field.method_name).values.map { |v|
3
+ [t("enumerize.#{form.object.class.name.downcase}.#{field.method_name}.#{v}", default: t("enumerize.defaults.#{field.method_name}.#{v}")), v]
4
+ }
5
+ = form.collection_check_boxes field.method_name, values, :last, :first, {}, {} { |i| i.label( class: 'checkbox' ) { i.check_box + i.text } }
@@ -0,0 +1,5 @@
1
+ ruby:
2
+ values = form.object.class.send(field.method_name).values.map { |v|
3
+ [t("enumerize.#{form.object.class.name.downcase}.#{field.method_name}.#{v}", default: t("enumerize.defaults.#{field.method_name}.#{v}")), v]
4
+ }
5
+ = form.collection_radio_buttons field.method_name, values, :last, :first, {}, {} { |i| i.label(class: 'radio') { i.radio_button + i.text } }
@@ -0,0 +1,48 @@
1
+ ruby:
2
+ related_id = params[:associations] && params[:associations][field.name.to_s]
3
+ config = field.associated_model_config
4
+ source_abstract_model = RailsAdmin.config(form.object.class).abstract_model
5
+
6
+ if form.object.new_record? && related_id.present? && related_id != 'new'
7
+ selected = [config.abstract_model.get(related_id)]
8
+ else
9
+ selected = form.object.send(field.name)
10
+ end
11
+ selected_ids = selected.map{|s| s.send(field.associated_primary_key)}
12
+
13
+ current_action = params[:action].in?(['create', 'new']) ? 'create' : 'update'
14
+
15
+ xhr = !field.associated_collection_cache_all
16
+
17
+ collection = if xhr
18
+ selected.map { |o| [o.send(field.associated_object_label_method), o.send(field.associated_primary_key)] }
19
+ else
20
+ i = 0
21
+ controller.list_entries(config, :index, field.associated_collection_scope, false).map { |o| [o.send(field.associated_object_label_method), o.send(field.associated_primary_key)] }.sort_by {|a| [selected_ids.index(a[1]) || selected_ids.size, i+=1] }
22
+ end
23
+
24
+ js_data = {
25
+ xhr: xhr,
26
+ #:'edit-url' => (authorized?(:edit, config.abstract_model) ? edit_path(model_name: config.abstract_model.to_param, id: '__ID__') : ''),
27
+ remote_source: index_path(config.abstract_model, source_object_id: form.object.id, source_abstract_model: source_abstract_model.to_param, associated_collection: field.name, current_action: current_action, compact: true),
28
+ sortable: !!field.orderable,
29
+ removable: !!field.removable,
30
+ cacheAll: !!field.associated_collection_cache_all,
31
+ regional: {
32
+ chooseAll: t("admin.misc.chose_all"),
33
+ chosen: t("admin.misc.chosen", name: config.label_plural),
34
+ clearAll: t("admin.misc.clear_all"),
35
+ search: t("admin.misc.search"),
36
+ up: t("admin.misc.up"),
37
+ down: t("admin.misc.down")
38
+ }
39
+ }
40
+
41
+ input{name=form.dom_name(field) type="hidden" value=""}
42
+
43
+ - selected_ids = (hdv = field.form_default_value).nil? ? selected_ids : hdv
44
+ = form.select field.method_name, collection, { selected: selected_ids, object: form.object }, field.html_attributes.reverse_merge({data: { filteringmultiselect: true, options: js_data.to_json }, multiple: true, class: 'hancock_multiselect'})
45
+ - if authorized?(:new, config.abstract_model) && field.inline_add
46
+ - path_hash = { model_name: config.abstract_model.to_param, modal: true }
47
+ - path_hash.merge!({ associations: { field.inverse_of => (form.object.persisted? ? form.object.id : 'new') } }) if field.inverse_of
48
+ = link_to "<i class=\"icon-plus icon-white\"></i> ".html_safe + wording_for(:link, :new, config.abstract_model), '#', data: { link: new_path(path_hash) }, class: "create btn btn-info", style: 'margin-left:10px'
@@ -0,0 +1 @@
1
+ = field.pretty_value
@@ -0,0 +1,9 @@
1
+ ruby:
2
+ _opts = {}
3
+ _opts[:rows] = 10
4
+ _opts[:cols] = 80
5
+ _opts[:class] = 'form-control'
6
+ _opts[:value] = field.formatted_value
7
+ _opts[:style] = "font-family: monospace"
8
+
9
+ = form.text_area field.string_method, _opts
@@ -0,0 +1,10 @@
1
+ ruby:
2
+ _opts = {}
3
+ _opts[:rows] = 10
4
+ _opts[:cols] = 80
5
+ _opts[:class] = 'form-control'
6
+ #_opts[:value] = field.formatted_value
7
+ _opts[:style] = "font-family: monospace"
8
+ / = form.text_area field.string_method, _opts
9
+
10
+ = render 'form', form: form, field: field, field_type: :text_area, html_attributes: _opts
@@ -0,0 +1,16 @@
1
+ ruby:
2
+ js_data = {
3
+ jspath: field.location ? field.location : field.base_location + "ckeditor.js",
4
+ base_location: field.base_location,
5
+ options: {
6
+ customConfig: field.config_js ? field.config_js : field.base_location + "config.js"
7
+ }
8
+ }
9
+ _html_attributes = field.html_attributes.reverse_merge(data: { richtext: 'ckeditor', options: js_data.to_json, value: field.form_value[:html] })
10
+ = form.text_area field.html_method, _html_attributes
11
+
12
+ label{style='display: block;'}
13
+ - _hash = { value: field.form_value[:clear], checked: field.form_value[:clear].in?([true, '1']), required: false, class: "form-control"}
14
+ - _html_attributes = field.html_attributes.reverse_merge(_hash)
15
+ span{style='float: left'}= form.send field.boolean_view_helper, field.clear_method, _html_attributes
16
+ div{style='margin-left: 35px; line-height: 40px;'} Убирать теги
@@ -0,0 +1,53 @@
1
+ ul.nav.nav-tabs
2
+ - uuid = "#{field.name}_#{field.object_id}_unique_id"
3
+ - I18n.available_locales.each do |locale|
4
+ li(class="#{'active' if locale == I18n.locale}")
5
+ a(href="##{locale}_#{uuid}" data-toggle="tab" class="#{uuid}")= locale
6
+ .tab-content
7
+ / = form.fields_for field.translations_field do |localized_field|
8
+ - I18n.available_locales.each do |locale|
9
+ - _class = "#{[( 'active' if locale == I18n.locale ), uuid].join(" ")}"
10
+ .fields.tab-pane(style='padding:5px; margin: 0;' id="#{locale}_#{uuid}" class="#{_class}")
11
+ = form.fields_for field.html_translations_field do |html_localized_field|
12
+ ruby:
13
+ js_data = {
14
+ jspath: field.location ? field.location : field.base_location + "ckeditor.js",
15
+ base_location: field.base_location,
16
+ options: {
17
+ customConfig: field.config_js ? field.config_js : field.base_location + "config.js"
18
+ }
19
+ }
20
+ _html_attributes = field.html_attributes.reverse_merge(data: {
21
+ richtext: 'ckeditor',
22
+ options: js_data.to_json
23
+ })
24
+ _html_attributes[:value] = field.form_value[:html] ? field.form_value[:html][locale] : ""
25
+ = html_localized_field.send :text_area, locale , _html_attributes
26
+
27
+ = form.fields_for field.clear_translations_field do |clear_localized_field|
28
+ label{style='display: block;'}
29
+ ruby:
30
+ _value = field.form_value[:clear] ? field.form_value[:clear][locale] : true
31
+ _hash = {
32
+ value: _value,
33
+ checked: _value.in?([true, '1']),
34
+ required: false,
35
+ class: "form-control"
36
+ }
37
+ _html_attributes = field.html_attributes.reverse_merge(_hash)
38
+ span{style='float: left'}= clear_localized_field.send field.boolean_view_helper, locale , _html_attributes
39
+ div{style='margin-left: 35px; line-height: 40px;'} Убирать теги
40
+
41
+
42
+
43
+
44
+ javascript:
45
+ var #{field.name}#{field.object_id} = (new Date().getTime()) + Math.floor(Math.random()*100000);
46
+ $("ul.nav.nav-tabs a.#{uuid}").each(function(e){
47
+ this.href = $(this).attr('href').replace('_unique_id', #{field.name}#{field.object_id});
48
+ $(this).removeClass('#{uuid}');
49
+ });
50
+ $(".tab-content .#{uuid}").each(function(e){
51
+ this.id = this.id.replace('_unique_id', #{field.name}#{field.object_id});
52
+ $(this).removeClass('#{uuid}');
53
+ });
@@ -0,0 +1,3 @@
1
+ - if user_signed_in? && respond_to?(:can?) && can?(:access, :rails_admin) && can?(:edit, obj)
2
+ .admin_link
3
+ = link_to t('hancock.edit'), rails_admin.edit_path(obj.class.model_name.i18n_key.to_s.gsub('/', '~'), obj.id), 'data-no-turbolink' => true
@@ -0,0 +1,7 @@
1
+ - unless flash.empty?
2
+ .flash
3
+ - flash.each do |type, message|
4
+ - next if message.blank?
5
+ div{class="message #{type}"}
6
+ a.close_flash &times;
7
+ = simple_format(message.strip) if message.is_a?(String)
@@ -0,0 +1,57 @@
1
+ if defined?(Mongoid)
2
+
3
+ module Mongoid
4
+
5
+ # Helps to override find method in an embedded document.
6
+ # Usage :
7
+ # - add to your model "include Mongoid::EmbeddedFindable"
8
+ # - override find method with:
9
+ # def self.find(id)
10
+ # find_through(Book, 'chapter', id)
11
+ # end
12
+ module EmbeddedFindable
13
+
14
+ extend ActiveSupport::Concern
15
+
16
+ included do
17
+
18
+ # Search an embedded document by id.
19
+ #
20
+ # Document is stored within embedding_class collection, and can be accessed through provided relation.
21
+ # Also supports chained relationships (if the searched document is nested in several embedded documents)
22
+ #
23
+ # Example, with a chapter embedded in a book, the book being embedded in a library.
24
+ # use find_through(Library, "books", book_id) in Book class
25
+ # and find_through(Library, "books.chapters", chapter_id) in Chapter class
26
+ def self.find_through(embedding_class, relation, id = nil)
27
+ return nil if id.nil? || id.blank?
28
+
29
+ id = BSON::ObjectId.from_string(id) if id.is_a?(String)
30
+ relation = relation.to_s unless relation.is_a?(String)
31
+
32
+ relation_parts = relation.split('.')
33
+ parent = embedding_class.send(:all)
34
+
35
+ while relation_parts.length > 0
36
+ item = if parent.is_a?(Mongoid::Criteria) || parent.is_a?(Array)
37
+ parent.where("#{relation_parts.join('.')}._id" => id).first
38
+ else
39
+ parent
40
+ end
41
+ return nil if item.nil?
42
+ parent = item.send(relation_parts.shift)
43
+ end
44
+
45
+ if parent.is_a?(Mongoid::Criteria) || parent.is_a?(Array)
46
+ parent.where('_id' => id).first
47
+ else
48
+ parent
49
+ end
50
+ end
51
+
52
+ end
53
+
54
+ end
55
+
56
+ end
57
+ end
@@ -0,0 +1,11 @@
1
+ if defined?(RailsAdmin)
2
+ RailsAdmin.config do |config|
3
+ config.excluded_models ||= []
4
+ if Hancock.mongoid?
5
+ config.excluded_models << [
6
+ 'Hancock::EmbeddedElement'
7
+ ]
8
+ end
9
+ config.excluded_models.flatten!
10
+ end
11
+ end
@@ -0,0 +1,70 @@
1
+ if defined?(SimpleCaptcha)
2
+
3
+ module SimpleCaptcha #:nodoc
4
+ module ViewHelper #:nodoc
5
+ # def show_simple_captcha(options={})
6
+ # key = simple_captcha_key(options[:object])
7
+ # options[:field_value] = set_simple_captcha_data(key, options)
8
+ #
9
+ # defaults = {
10
+ # :image => simple_captcha_image(key, options),
11
+ # :label => options[:label] || I18n.t('simple_captcha.label'),
12
+ # :field => simple_captcha_field(options),
13
+ # :error_messages => options[:error_messages]
14
+ # }
15
+ #
16
+ # render :partial => 'hancock/simple_captcha/simple_captcha', :locals => { :simple_captcha_options => defaults }
17
+ # end
18
+
19
+ def simple_captcha_hancock_field(options={})
20
+ if options[:object]
21
+
22
+ if self.class == ::SimpleForm::FormBuilder
23
+ text_field(:captcha, {value: '', autocomplete: 'off', placeholder: options[:placeholder]}) +
24
+ hidden_field(:captcha_key, {value: options[:field_value]})
25
+ else
26
+ text_field(options[:object].class.name.underscore.parameterize("_"), :captcha, {value: '', autocomplete: 'off', placeholder: options[:placeholder]}) +
27
+ hidden_field(options[:object].class.name.underscore.parameterize("_"), :captcha_key, {value: options[:field_value]})
28
+ end
29
+ else
30
+ text_field_tag(:captcha, nil, {autocomplete: 'off', placeholder: options[:placeholder]})
31
+ end
32
+ end
33
+
34
+ def show_simple_captcha(options={})
35
+ key = simple_captcha_key(options[:object])
36
+ options[:placeholder] ||= I18n.t('simple_captcha.placeholder')
37
+ options[:field_value] = set_simple_captcha_data(key, options)
38
+
39
+ defaults = {
40
+ :image => simple_captcha_image(key, options),
41
+ :label => options[:label] || I18n.t('simple_captcha.label'),
42
+ :field => simple_captcha_hancock_field(options),
43
+ :error_messages => options[:error_messages],
44
+ :update_captcha => options[:update_captcha]
45
+ }
46
+
47
+ render :partial => 'hancock/simple_captcha/simple_captcha', :locals => { :simple_captcha_options => defaults }
48
+ end
49
+
50
+ end
51
+ end
52
+
53
+ SimpleCaptcha.setup do |sc|
54
+ sc.image_size = "200x50"
55
+ sc.length = 4
56
+ sc.charset = "0123456789"
57
+
58
+ sc.add_image_style("hancock_cms_style", [
59
+ "-alpha set",
60
+ "-fill 'orange'",
61
+ "-background 'transparent'",
62
+ "-size 200x50", "xc:transparent"
63
+ ].freeze)
64
+
65
+ sc.image_style = 'hancock_cms_style'.freeze
66
+
67
+ sc.tmp_path = "tmp/sc"
68
+ end
69
+
70
+ end