hancock_cms 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +23 -0
- data/.rspec +1 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +113 -0
- data/Rakefile +1 -0
- data/app/assets/images/devices/login-bg.jpg +0 -0
- data/app/assets/images/rails-admin/hancock_logo.svg +5 -0
- data/app/assets/javascripts/hancock/app/back_to_top.coffee +24 -0
- data/app/assets/javascripts/hancock/cms.coffee +11 -0
- data/app/assets/javascripts/hancock/cms/flash.coffee +3 -0
- data/app/assets/javascripts/hancock/cms/init.coffee +1 -0
- data/app/assets/javascripts/hancock/cms/map.coffee +22 -0
- data/app/assets/javascripts/hancock/rails_admin/cms.ui.coffee +43 -0
- data/app/assets/javascripts/hancock/rails_admin/custom/ui.coffee +0 -0
- data/app/assets/javascripts/head.load.js +707 -0
- data/app/assets/javascripts/jquery.placeholder.js +157 -0
- data/app/assets/javascripts/rails_admin/custom/ui.coffee +2 -0
- data/app/assets/stylesheets/hancock/cms.sass +9 -0
- data/app/assets/stylesheets/hancock/cms/devise.sass +157 -0
- data/app/assets/stylesheets/hancock/cms/flash.sass +69 -0
- data/app/assets/stylesheets/hancock/cms/mixins.sass +98 -0
- data/app/assets/stylesheets/hancock/cms/normalize.scss +407 -0
- data/app/assets/stylesheets/hancock/cms/powered.sass +18 -0
- data/app/assets/stylesheets/hancock/rails_admin/cms.theming.sass +703 -0
- data/app/assets/stylesheets/hancock/rails_admin/custom/theming.sass +1 -0
- data/app/assets/stylesheets/hancock/toplink/toplink.sass +24 -0
- data/app/assets/stylesheets/rails_admin/custom/theming.sass +4 -0
- data/app/controllers/concerns/hancock/current_user.rb +12 -0
- data/app/controllers/concerns/hancock/decorators/home.rb +12 -0
- data/app/controllers/concerns/hancock/decorators/registrations.rb +5 -0
- data/app/controllers/concerns/hancock/decorators/sessions.rb +5 -0
- data/app/controllers/concerns/hancock/errors.rb +94 -0
- data/app/controllers/concerns/hancock/fancybox.rb +14 -0
- data/app/controllers/concerns/hancock/no_cache.rb +12 -0
- data/app/controllers/hancock/home_controller.rb +10 -0
- data/app/controllers/hancock/registrations_controller.rb +23 -0
- data/app/controllers/hancock/sessions_controller.rb +24 -0
- data/app/helpers/hancock/gzip_helper.rb +27 -0
- data/app/helpers/hancock/home_helper.rb +2 -0
- data/app/helpers/hancock/powered_helper.rb +42 -0
- data/app/models/concerns/hancock/boolean_field.rb +21 -0
- data/app/models/concerns/hancock/cacheable.rb +33 -0
- data/app/models/concerns/hancock/decorators/embedded_element.rb +28 -0
- data/app/models/concerns/hancock/enableable.rb +8 -0
- data/app/models/concerns/hancock/geocodeable.rb +4 -0
- data/app/models/concerns/hancock/hash_field.rb +113 -0
- data/app/models/concerns/hancock/html_field.rb +33 -0
- data/app/models/concerns/hancock/mappable.rb +91 -0
- data/app/models/concerns/hancock/model_localizeable.rb +33 -0
- data/app/models/concerns/hancock/rails_admin_patch.rb +86 -0
- data/app/models/concerns/hancock/sort_field.rb +20 -0
- data/app/models/concerns/hancock/sortable.rb +8 -0
- data/app/models/hancock/embedded_element.rb +17 -0
- data/app/views/blocks/_favicon.html.slim +60 -0
- data/app/views/blocks/_footer.html.slim +1 -0
- data/app/views/blocks/_header.html.slim +3 -0
- data/app/views/devise/passwords/edit.html.slim +29 -0
- data/app/views/devise/passwords/new.html.slim +19 -0
- data/app/views/devise/registrations/edit.html.slim +31 -0
- data/app/views/devise/registrations/new.html.slim +39 -0
- data/app/views/devise/sessions/new.html.slim +39 -0
- data/app/views/devise/shared/_links.html.slim +11 -0
- data/app/views/hancock/errors/_base.html.slim +3 -0
- data/app/views/hancock/errors/error_403.html.slim +1 -0
- data/app/views/hancock/errors/error_404.html.slim +1 -0
- data/app/views/hancock/errors/error_500.html.slim +1 -0
- data/app/views/hancock/home/index.html.slim +1 -0
- data/app/views/hancock/simple_captcha/_simple_captcha.html.slim +13 -0
- data/app/views/hancock/toplink/_toplink.html.slim +2 -0
- data/app/views/layouts/application.html.slim +35 -0
- data/app/views/layouts/hancock/devise/confirmations.html.slim +22 -0
- data/app/views/layouts/hancock/devise/passwords.html.slim +22 -0
- data/app/views/layouts/hancock/devise/registrations.html.slim +22 -0
- data/app/views/layouts/hancock/devise/sessions.html.slim +22 -0
- data/app/views/layouts/hancock/devise/unlocks.html.slim +22 -0
- data/app/views/layouts/rails_admin/_footer.html.slim +2 -0
- data/app/views/layouts/rails_admin/_footer_navigation.html.slim +20 -0
- data/app/views/layouts/rails_admin/_navigation.html.slim +73 -0
- data/app/views/layouts/rails_admin/_secondary_navigation.html.slim +32 -0
- data/app/views/layouts/rails_admin/application.html.haml +68 -0
- data/app/views/layouts/rails_admin/pjax.html.haml +17 -0
- data/app/views/rails_admin/main/_check_boxes.html.slim +27 -0
- data/app/views/rails_admin/main/_enum_check_boxes.html.slim +5 -0
- data/app/views/rails_admin/main/_enum_radio_buttons.html.slim +5 -0
- data/app/views/rails_admin/main/_form_hancock_multiselect.html.slim +48 -0
- data/app/views/rails_admin/main/_form_raw.html.slim +1 -0
- data/app/views/rails_admin/main/_hancock_hash.html.slim +9 -0
- data/app/views/rails_admin/main/_hancock_hash_ml.html.slim +10 -0
- data/app/views/rails_admin/main/_hancock_html.html.slim +16 -0
- data/app/views/rails_admin/main/_hancock_html_ml.html.slim +53 -0
- data/app/views/shared/_admin_link.html.slim +3 -0
- data/app/views/shared/_messages.html.slim +7 -0
- data/config/initializers/embedded_findable.rb +57 -0
- data/config/initializers/hancock_cms.rb +11 -0
- data/config/initializers/simple_captcha.rb +70 -0
- data/config/locales/en.hancock.yml +29 -0
- data/config/locales/en.hancock_admin.yml +6 -0
- data/config/locales/ru.cancan.yml +4 -0
- data/config/locales/ru.devise.yml +65 -0
- data/config/locales/ru.hancock.yml +36 -0
- data/config/locales/ru.hancock_admin.yml +6 -0
- data/config/locales/ru.models.yml +82 -0
- data/config/locales/ru.mongoid.yml +450 -0
- data/config/locales/ru.rails_admin.yml +168 -0
- data/hancock_cms.gemspec +46 -0
- data/lib/filename_to_slug.rb +32 -0
- data/lib/generators/hancock/cms/ability_generator.rb +14 -0
- data/lib/generators/hancock/cms/admin_generator.rb +21 -0
- data/lib/generators/hancock/cms/application_generator.rb +14 -0
- data/lib/generators/hancock/cms/assets_generator.rb +35 -0
- data/lib/generators/hancock/cms/config_generator.rb +13 -0
- data/lib/generators/hancock/cms/controllers/decorators_generator.rb +27 -0
- data/lib/generators/hancock/cms/gemfile_generator.rb +13 -0
- data/lib/generators/hancock/cms/layout_generator.rb +14 -0
- data/lib/generators/hancock/cms/model_generator.rb +39 -0
- data/lib/generators/hancock/cms/models/embedded_element_generator.rb +56 -0
- data/lib/generators/hancock/cms/models/templates/embedded_element.erb +47 -0
- data/lib/generators/hancock/cms/paperclip_optimizer_generator.rb +13 -0
- data/lib/generators/hancock/cms/rack_generator.rb +12 -0
- data/lib/generators/hancock/cms/robots_generator.rb +14 -0
- data/lib/generators/hancock/cms/scripts_generator.rb +31 -0
- data/lib/generators/hancock/cms/templates/Gemfile.erb +69 -0
- data/lib/generators/hancock/cms/templates/ability.erb +49 -0
- data/lib/generators/hancock/cms/templates/admin.erb +74 -0
- data/lib/generators/hancock/cms/templates/application.erb +42 -0
- data/lib/generators/hancock/cms/templates/assets/javascripts/application.coffee.erb +5 -0
- data/lib/generators/hancock/cms/templates/assets/stylesheets/application.sass.erb +88 -0
- data/lib/generators/hancock/cms/templates/hancock_cms.erb +30 -0
- data/lib/generators/hancock/cms/templates/model.erb +42 -0
- data/lib/generators/hancock/cms/templates/paperclip_optimizer.erb +80 -0
- data/lib/generators/hancock/cms/templates/rack.erb +15 -0
- data/lib/generators/hancock/cms/templates/robots.txt.erb +5 -0
- data/lib/generators/hancock/cms/templates/scripts/assets_precompile.sh +3 -0
- data/lib/generators/hancock/cms/templates/scripts/bundle_production.sh +4 -0
- data/lib/generators/hancock/cms/templates/scripts/db_dump.sh.erb +3 -0
- data/lib/generators/hancock/cms/templates/scripts/db_restore.sh +3 -0
- data/lib/generators/hancock/cms/templates/scripts/full_assets_precompile.sh +4 -0
- data/lib/generators/hancock/cms/templates/scripts/restart_thru_kill.sh +3 -0
- data/lib/generators/hancock/cms/templates/scripts/send_hup.sh +3 -0
- data/lib/generators/hancock/cms/templates/scripts/send_usr2.sh +3 -0
- data/lib/generators/hancock/cms/templates/scripts/server.sh +5 -0
- data/lib/generators/hancock/cms/templates/scripts/server_alt.sh +5 -0
- data/lib/generators/hancock/cms/templates/unicorn.erb +57 -0
- data/lib/generators/hancock/cms/templates/unicorn.god.erb +59 -0
- data/lib/generators/hancock/cms/unicorn_god_generator.rb +15 -0
- data/lib/generators/hancock/cms/utils.rb +21 -0
- data/lib/hancock/admin.rb +60 -0
- data/lib/hancock/admin/embedded_element.rb +26 -0
- data/lib/hancock/configuration.rb +48 -0
- data/lib/hancock/controller.rb +30 -0
- data/lib/hancock/engine.rb +48 -0
- data/lib/hancock/migration.rb +15 -0
- data/lib/hancock/model.rb +53 -0
- data/lib/hancock/models/embedded_element.rb +12 -0
- data/lib/hancock/models/mongoid/embedded_element.rb +14 -0
- data/lib/hancock/plugin.rb +25 -0
- data/lib/hancock/plugin_configuration.rb +30 -0
- data/lib/hancock/rails_admin_ext/config.rb +129 -0
- data/lib/hancock/rails_admin_ext/hancock_hash.rb +84 -0
- data/lib/hancock/rails_admin_ext/hancock_html.rb +79 -0
- data/lib/hancock/rails_admin_ext/hancock_multiselect.rb +44 -0
- data/lib/hancock/rails_admin_ext/hancock_slugs.rb +35 -0
- data/lib/hancock/rails_admin_ext/patches/field_patch.rb +14 -0
- data/lib/hancock/rails_admin_ext/patches/group_patch.rb +41 -0
- data/lib/hancock/rails_admin_ext/patches/hancock_cms_group.rb +61 -0
- data/lib/hancock/rails_admin_ext/patches/new_controller_patch.rb +54 -0
- data/lib/hancock/routes.rb +20 -0
- data/lib/hancock/simple_form_patch.rb +12 -0
- data/lib/hancock/tasks.rb +13 -0
- data/lib/hancock/version.rb +3 -0
- data/lib/hancock_cms.rb +130 -0
- data/lib/manual_slug.rb +10 -0
- data/lib/manual_slug/active_record.rb +32 -0
- data/lib/manual_slug/mongoid.rb +40 -0
- data/lib/rails_admin/custom_show_in_app.rb +43 -0
- data/release.sh +12 -0
- data/template.rb +564 -0
- metadata +455 -0
@@ -0,0 +1 @@
|
|
1
|
+
|
@@ -0,0 +1,24 @@
|
|
1
|
+
.toplink
|
2
|
+
display: block
|
3
|
+
position: fixed
|
4
|
+
bottom: 15px
|
5
|
+
right: 15px
|
6
|
+
text-align: center
|
7
|
+
font-size: 30px
|
8
|
+
line-height: 48px
|
9
|
+
height: 50px
|
10
|
+
width: 50px
|
11
|
+
border-radius: 3px
|
12
|
+
-webkit-border-radius: 3px
|
13
|
+
-moz-border-radius: 3px
|
14
|
+
z-index: 100
|
15
|
+
outline: none !important
|
16
|
+
background: rgba(0,0,0,0.3)
|
17
|
+
color: #fff !important
|
18
|
+
transform: translate3d(0,70px,0)
|
19
|
+
@include transition(all 0.3s ease-in-out)
|
20
|
+
&:hover
|
21
|
+
background: #ff2b58
|
22
|
+
|
23
|
+
.toplink.active
|
24
|
+
transform: translate3d(0,0,0)
|
@@ -0,0 +1,94 @@
|
|
1
|
+
module Hancock::Errors
|
2
|
+
extend ActiveSupport::Concern
|
3
|
+
included do
|
4
|
+
if Rails.env.production? || Rails.env.staging? || (respond_to?(:hancock_check_errors) and hancock_check_errors)
|
5
|
+
rescue_from Exception, with: :render_500
|
6
|
+
rescue_from ActionController::RoutingError, with: :render_404
|
7
|
+
rescue_from ActionController::UnknownController, with: :render_404
|
8
|
+
rescue_from ActionController::MissingFile, with: :render_404
|
9
|
+
rescue_from AbstractController::ActionNotFound, with: :render_404
|
10
|
+
if Hancock.mongoid?
|
11
|
+
rescue_from Mongoid::Errors::DocumentNotFound, with: :render_404
|
12
|
+
rescue_from Mongoid::Errors::InvalidFind, with: :render_404
|
13
|
+
end
|
14
|
+
if Hancock.active_record?
|
15
|
+
rescue_from ActiveRecord::RecordNotFound, with: :render_404
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
if defined?(CanCan)
|
20
|
+
rescue_from CanCan::AccessDenied do |exception|
|
21
|
+
Rails.logger.error "__________________________".freeze
|
22
|
+
Rails.logger.error "Error 403".freeze
|
23
|
+
Rails.logger.error (params ? params.inspect : "no params data".freeze)
|
24
|
+
Rails.logger.error (current_user ? current_user.inspect : "no current_user".freeze)
|
25
|
+
unless exception.nil?
|
26
|
+
Rails.logger.error exception.message
|
27
|
+
Rails.logger.error exception.backtrace.join("\n")
|
28
|
+
capture_exception(exception) if defined?(Raven)
|
29
|
+
end
|
30
|
+
Rails.logger.error "__________________________"
|
31
|
+
if !user_signed_in?
|
32
|
+
#scope = rails_admin? ? main_app : self
|
33
|
+
#redirect_to scope.new_user_session_path, alert: "Необходимо авторизоваться"
|
34
|
+
authenticate_user!
|
35
|
+
else
|
36
|
+
if rails_admin? and can?(:access, :rails_admin)
|
37
|
+
redirect_to dashboard_path
|
38
|
+
else
|
39
|
+
redirect_to main_app.root_path, alert: t('hancock.errors.access_denied')
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
rescue_from ActionController::InvalidAuthenticityToken do |exception|
|
46
|
+
redirect_to :back, alert: t('hancock.errors.form_expired')
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
private
|
51
|
+
def render_404(exception = nil)
|
52
|
+
Rails.logger.error "__________________________".freeze
|
53
|
+
Rails.logger.error "Error 404".freeze
|
54
|
+
Rails.logger.error (params ? params.inspect : "no params data".freeze)
|
55
|
+
Rails.logger.error (current_user ? current_user.inspect : "no current_user".freeze)
|
56
|
+
unless exception.nil?
|
57
|
+
Rails.logger.error exception.message
|
58
|
+
Rails.logger.error exception.backtrace.join("\n")
|
59
|
+
capture_exception(exception) if defined?(Raven)
|
60
|
+
end
|
61
|
+
Rails.logger.error "__________________________".freeze
|
62
|
+
render_error(404)
|
63
|
+
end
|
64
|
+
|
65
|
+
def render_500(exception = nil)
|
66
|
+
Rails.logger.error "__________________________".freeze
|
67
|
+
Rails.logger.error "Error 500".freeze
|
68
|
+
Rails.logger.error (params ? params.inspect : "no params data".freeze)
|
69
|
+
Rails.logger.error (current_user ? current_user.inspect : "no current_user".freeze)
|
70
|
+
unless exception.nil?
|
71
|
+
Rails.logger.error exception.message
|
72
|
+
Rails.logger.error exception.backtrace.join("\n")
|
73
|
+
capture_exception(exception) if defined?(Raven)
|
74
|
+
end
|
75
|
+
Rails.logger.error "__________________________".freeze
|
76
|
+
begin
|
77
|
+
if rails_admin?
|
78
|
+
render text: t('hancock.errors.internal_error_full', klass: exception.class.name, message: exception.message), status: 500
|
79
|
+
return
|
80
|
+
end
|
81
|
+
rescue Exception => e
|
82
|
+
puts "error while rendering rails admin exception".freeze
|
83
|
+
puts e.class.name
|
84
|
+
puts e.message
|
85
|
+
puts e.backtrace.join("\n")
|
86
|
+
end
|
87
|
+
render_error(500)
|
88
|
+
end
|
89
|
+
|
90
|
+
def render_error(code = 500)
|
91
|
+
render template: "hancock/errors/error_#{code}", formats: [:html], handlers: [:slim], layout: Hancock.config.error_layout, status: code
|
92
|
+
end
|
93
|
+
|
94
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module Hancock::Fancybox
|
2
|
+
extend ActiveSupport::Concern
|
3
|
+
included do
|
4
|
+
helper_method :request_for_fancybox?
|
5
|
+
end
|
6
|
+
|
7
|
+
def render_for_fancybox
|
8
|
+
render layout: false if request_for_fancybox?
|
9
|
+
end
|
10
|
+
|
11
|
+
def request_for_fancybox?
|
12
|
+
request.xhr? and params[:load_by_fancybox] == "true"
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
class Hancock::RegistrationsController < Devise::RegistrationsController
|
2
|
+
prepend_before_action :check_recaptcha, only: [:create]
|
3
|
+
|
4
|
+
private
|
5
|
+
def check_recaptcha
|
6
|
+
if Hancock.config.recaptcha_support and (!Rails.env.development? or Hancock.config.captcha_on_development)
|
7
|
+
if verify_recaptcha
|
8
|
+
true
|
9
|
+
else
|
10
|
+
self.resource = resource_class.new sign_up_params
|
11
|
+
self.resource.valid?
|
12
|
+
@recaptcha_error = "Вы робот?".freeze
|
13
|
+
respond_with_navigational(resource) { render :new }
|
14
|
+
end
|
15
|
+
|
16
|
+
else
|
17
|
+
true
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
include Hancock::Decorators::Registrations
|
22
|
+
|
23
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
class Hancock::SessionsController < Devise::SessionsController
|
2
|
+
prepend_before_action :check_recaptcha, only: [:create]
|
3
|
+
|
4
|
+
private
|
5
|
+
def check_recaptcha
|
6
|
+
if Hancock.config.recaptcha_support and (!Rails.env.development? or Hancock.config.captcha_on_development)
|
7
|
+
if verify_recaptcha
|
8
|
+
true
|
9
|
+
else
|
10
|
+
self.resource = resource_class.new sign_in_params
|
11
|
+
resource.errors.add(:email, "Неверный e-mail или пароль".freeze)
|
12
|
+
resource.errors.add(:password, "Неверный e-mail или пароль".freeze)
|
13
|
+
@recaptcha_error = "Вы робот?".freeze
|
14
|
+
respond_with_navigational(resource) { render :new }
|
15
|
+
end
|
16
|
+
|
17
|
+
else
|
18
|
+
true
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
include Hancock::Decorators::Sessions
|
23
|
+
|
24
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module Hancock::GzipHelper
|
2
|
+
def gzip_javascript_include_tag(*sources)
|
3
|
+
# Grab the asset html include tag
|
4
|
+
tag = javascript_include_tag(*sources)
|
5
|
+
|
6
|
+
# If we are in production and the requesting client accepts gzip encoding, swap for the gzip asset
|
7
|
+
if Rails.env.production? && request.accept_encoding =~ /gzip/i
|
8
|
+
tag = tag.gsub(/\.js/i, ".js.gz")
|
9
|
+
end
|
10
|
+
|
11
|
+
# Return the asset whether or not it was modified
|
12
|
+
tag.html_safe
|
13
|
+
end
|
14
|
+
|
15
|
+
def gzip_stylesheet_link_tag(*sources)
|
16
|
+
# Grab the asset html include tag
|
17
|
+
tag = stylesheet_link_tag(*sources)
|
18
|
+
|
19
|
+
# If we are in production and the requesting client accepts gzip encoding, swap for the gzip asset
|
20
|
+
if Rails.env.production? && request.accept_encoding =~ /gzip/i
|
21
|
+
tag = tag.gsub(/\.css/i, ".css.gz")
|
22
|
+
end
|
23
|
+
|
24
|
+
# Return the asset whether or not it was modified
|
25
|
+
tag.html_safe
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
module Hancock::PoweredHelper
|
2
|
+
|
3
|
+
# TODO CMS site block
|
4
|
+
# def render_hancock_powered_on_block
|
5
|
+
# content_tag :div, class: 'hancock-powered-on' do
|
6
|
+
# ret = []
|
7
|
+
# ret << content_tag(:span, class: 'powered-on') do
|
8
|
+
# "Сайт работает на "
|
9
|
+
# end
|
10
|
+
# _attrs = {
|
11
|
+
# class: "powered_on",
|
12
|
+
# target: "_blank",
|
13
|
+
# title: "Hancock CMS",
|
14
|
+
# data: {
|
15
|
+
# "hancock-goto-disabled": true
|
16
|
+
# }
|
17
|
+
# }
|
18
|
+
# ret << link_to("Hancock CMS", "http://hancock.redrocks.pro/", _attrs)
|
19
|
+
# ret.join.html_safe
|
20
|
+
# end
|
21
|
+
# end
|
22
|
+
|
23
|
+
def render_hancock_created_by_block
|
24
|
+
content_tag :div, class: 'hancock-created-by' do
|
25
|
+
ret = []
|
26
|
+
ret << content_tag(:span, class: 'created-by') do
|
27
|
+
"Сайт разработан".freeze
|
28
|
+
end
|
29
|
+
_attrs = {
|
30
|
+
class: "created_by",
|
31
|
+
target: "_blank",
|
32
|
+
title: "Hancock Creative studio",
|
33
|
+
data: {
|
34
|
+
"hancock-goto-disabled": true
|
35
|
+
}
|
36
|
+
}.freeze
|
37
|
+
ret << link_to("Redrocks studio".freeze, "http://redrocks.pro/".freeze, _attrs)
|
38
|
+
ret.join.html_safe
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module Hancock::BooleanField
|
2
|
+
extend ActiveSupport::Concern
|
3
|
+
module ClassMethods
|
4
|
+
def boolean_field(name, default = true)
|
5
|
+
if default.is_a?(Hash)
|
6
|
+
default = default[:default]
|
7
|
+
end
|
8
|
+
|
9
|
+
if Hancock.mongoid?
|
10
|
+
field name, type: Mongoid::Boolean, default: default
|
11
|
+
end
|
12
|
+
scope name, -> { where(name => true) }
|
13
|
+
|
14
|
+
if name == 'active'
|
15
|
+
scope :inactive, -> { where(active: false) }
|
16
|
+
elsif name == 'enabled'
|
17
|
+
scope :disabled, -> { where(enabled: false) }
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
if Hancock.mongoid?
|
2
|
+
|
3
|
+
module Hancock::Cacheable
|
4
|
+
extend ActiveSupport::Concern
|
5
|
+
|
6
|
+
included do
|
7
|
+
field :cache_keys_str, type: String, default: -> { default_cache_keys.join("\n") }
|
8
|
+
def self.default_cache_keys
|
9
|
+
[]
|
10
|
+
end
|
11
|
+
def default_cache_keys
|
12
|
+
self.class.default_cache_keys
|
13
|
+
end
|
14
|
+
|
15
|
+
def cache_keys
|
16
|
+
cache_keys_str.split(/\s+/).map { |k| k.strip }.reject { |k| k.blank? }
|
17
|
+
end
|
18
|
+
field :perform_caching, type: Boolean, default: true
|
19
|
+
|
20
|
+
after_save :clear_cache
|
21
|
+
after_destroy :clear_cache
|
22
|
+
def clear_cache
|
23
|
+
if perform_caching
|
24
|
+
cache_keys.each do |k|
|
25
|
+
Rails.cache.delete(k)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module Hancock::Decorators
|
2
|
+
module EmbeddedElement
|
3
|
+
extend ActiveSupport::Concern
|
4
|
+
|
5
|
+
included do
|
6
|
+
|
7
|
+
# def image_styles
|
8
|
+
# super
|
9
|
+
# end
|
10
|
+
#
|
11
|
+
# def image_jcrop_options
|
12
|
+
# super
|
13
|
+
# end
|
14
|
+
#
|
15
|
+
# ############# rails_admin ##############
|
16
|
+
# def self.rails_admin_add_fields
|
17
|
+
# [] #super
|
18
|
+
# end
|
19
|
+
#
|
20
|
+
# def self.rails_admin_add_config(config)
|
21
|
+
# #super(config)
|
22
|
+
# end
|
23
|
+
|
24
|
+
end
|
25
|
+
|
26
|
+
|
27
|
+
end
|
28
|
+
end
|