hancock_cms 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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,30 @@
1
+ Hancock.configure do |config|
2
+ ##### defaults #####
3
+ # config.main_index_layout = 'application'
4
+ # config.error_layout = 'application'
5
+ #
6
+ # config.localize = false
7
+ #
8
+ # config.ability_manager_config = []
9
+ ### example ###
10
+ # config.ability_manager_config << {
11
+ # method: :can,
12
+ # model: RailsAdminSettings::Setting,
13
+ # actions: [:edit, :update]
14
+ # }
15
+ ### example ###
16
+ # config.ability_admin_config = []
17
+ # config.ability_admin_config << {
18
+ # method: :can,
19
+ # model: RailsAdminSettings::Setting,
20
+ # actions: :manage
21
+ # }
22
+ #
23
+ # config.recaptcha_support = defined?(Recaptcha)
24
+ # config.simple_captcha_support = defined?(SimpleCaptcha)
25
+ #
26
+ # config.admin_enter_captcha = config.recaptcha_support or config.simple_captcha_support
27
+ # config.registration_captcha = config.admin_enter_captcha
28
+ #
29
+ # config.captcha_on_development = false
30
+ end
@@ -0,0 +1,42 @@
1
+ class <%= camelcased_class_name %>
2
+ include Hancock::Model
3
+ # include Hancock::Enableable
4
+ # include Hancock::Cacheable
5
+ # include ManualSlug
6
+
7
+ # acts_as_nested_set
8
+ # scope :sorted, -> { order_by([:lft, :asc]) }
9
+
10
+ field :name
11
+ # manual_slug :name
12
+
13
+ # def self.default_cache_keys
14
+ # []
15
+ # end
16
+
17
+ ############# rails_admin ##############
18
+ #
19
+ # def self.admin_can_user_defined_actions
20
+ # [].freeze
21
+ # end
22
+ # def self.admin_cannot_user_defined_actions
23
+ # [].freeze
24
+ # end
25
+ # def self.manager_can_user_defined_actions
26
+ # [].freeze
27
+ # end
28
+ # def self.manager_cannot_user_defined_actions
29
+ # [].freeze
30
+ # end
31
+ # def self.rails_admin_user_defined_visible_actions
32
+ # [].freeze
33
+ # end
34
+
35
+ rails_admin do
36
+ # field :enabled, :toggle
37
+ field :name
38
+ # group :url, &Hancock::Admin.url_block
39
+ # group :cache, &Hancock::Admin.caching_block
40
+ end
41
+
42
+ end
@@ -0,0 +1,80 @@
1
+ # Set global optimisation options for all Paperclip models
2
+
3
+ # By default, image_optim enables all the compression binaries it supports and
4
+ # requires them to be present on your system, failing if one is actually missing.
5
+
6
+ # We disable everything by default and ignore missing ones with `skip_missing_workers`.
7
+ # This way, should a new version add support for a library we do not yet disable here,
8
+ # things won't suddenly break.
9
+ if defined?(Paperclip::PaperclipOptimizer)
10
+ Paperclip::PaperclipOptimizer.default_options = {
11
+ skip_missing_workers: true,
12
+ advpng: true,
13
+ gifsicle: true,
14
+ jhead: true,
15
+ jpegoptim: true,
16
+ jpegrecompress: true,
17
+ jpegtran: true,
18
+ optipng: true,
19
+ pngcrush: true,
20
+ pngout: false,
21
+ pngquant: true,
22
+ svgo: false,
23
+
24
+ nice: 5,
25
+ verbose: true
26
+ }
27
+ end
28
+
29
+ # All available image_optim options. See https://github.com/toy/image_optim for more information
30
+
31
+ # Paperclip::PaperclipOptimizer.default_options = {
32
+ # skip_missing_workers: false, # Skip workers with missing or problematic binaries (defaults to false)
33
+ # nice: 10, # Nice level (defaults to 10)
34
+ # threads: 1, # Number of threads or disable (defaults to number of processors)
35
+ # verbose: false, # Verbose output (defaults to false)
36
+ # pack: nil, # Require image_optim_pack or disable it, by default image_optim_pack will be used if available,
37
+ # # will turn on :skip-missing-workers unless explicitly disabled (defaults to nil)
38
+ # allow_lossy: false, # Allow lossy workers and optimizations (defaults to false)
39
+ # advpng: {
40
+ # leve: 4 # Compression level: 0 - don't compress, 1 - fast, 2 - normal, 3 - extra, 4 - extreme (defaults to 4)
41
+ # },
42
+ # gifsicle: {
43
+ # interlace: true, # Interlace: true - interlace on, false - interlace off, nil - as is in original image
44
+ # # (defaults to running two instances, one with interlace off and one with on)
45
+ # level: 3, # Compression level: 1 - light and fast, 2 - normal, 3 - heavy (slower) (defaults to 3)
46
+ # careful: false # Avoid bugs with some software (defaults to false)
47
+ # },
48
+ # jhead: true, # no options
49
+ # jpegoptim: {
50
+ # strip: :all, # List of extra markers to strip: :comments, :exif, :iptc, :icc or :all (defaults to :all)
51
+ # max_quality: 100 # Maximum image quality factor 0..100 (defaults to 100)
52
+ # },
53
+ # jpegrecompress: {
54
+ # quality: 3 # JPEG quality preset: 0 - low, 1 - medium, 2 - high, 3 - veryhigh (defaults to 3)
55
+ # },
56
+ # jpegtran: {
57
+ # copy_chunks: false, # Copy all chunks (defaults to false)
58
+ # progressive: true, # Create progressive JPEG file (defaults to true)
59
+ # jpegrescan: false # Use jpegtran through jpegrescan, ignore progressive option (defaults to false)
60
+ # },
61
+ # optipng: {
62
+ # level: 6, # Optimization level preset: 0 is least, 7 is best (defaults to 6)
63
+ # interlace: false # Interlace: true - interlace on, false - interlace off, nil - as is in original image (defaults to false)
64
+ # },
65
+ # pngcrush: {
66
+ # chunks: :alla, # List of chunks to remove or :alla - all except tRNS/transparency or
67
+ # # :allb - all except tRNS and gAMA/gamma (defaults to :alla)
68
+ # fix: false, # Fix otherwise fatal conditions such as bad CRCs (defaults to false)
69
+ # brute: false # Brute force try all methods, very time-consuming and generally not worthwhile (defaults to false)
70
+ # },
71
+ # pngout: {
72
+ # copy_chunks: false, # Copy optional chunks (defaults to false)
73
+ # strategy: 0 # Strategy: 0 - xtreme, 1 - intense, 2 - longest Match, 3 - huffman Only, 4 - uncompressed (defaults to 0)
74
+ # },
75
+ # pngquant: {
76
+ # quality: 100..100, # min..max - don't save below min, use less colors below max (both in range 0..100; in yaml - !ruby/range 0..100) (defaults to 100..100)
77
+ # speed: 3 # speed/quality trade-off: 1 - slow, 3 - default, 11 - fast & rough (defaults to 3)
78
+ # },
79
+ # svgo: true # no options
80
+ # }
@@ -0,0 +1,15 @@
1
+ if Rails.env.development?
2
+ module Rack
3
+ class CommonLogger
4
+ alias_method :log_without_assets, :log
5
+ ASSETS_PREFIX = "/#{Rails.application.config.assets.prefix[/\A\/?(.*?)\/?\z/, 1]}/"
6
+ def log(env, status, header, began_at)
7
+ unless env['REQUEST_PATH'].start_with?(ASSETS_PREFIX) || env['REQUEST_PATH'].start_with?('/uploads') || env['REQUEST_PATH'].start_with?('/system')
8
+ log_without_assets(env, status, header, began_at)
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
14
+
15
+ Rack::Utils.multipart_part_limit = 0
@@ -0,0 +1,5 @@
1
+ Host: <%= app_name.downcase %>.ru
2
+ User-Agent: *
3
+ Allow: /
4
+ Disallow: /admin
5
+ Sitemap: http://<%= app_name.downcase %>.ru/sitemap.xml.gz
@@ -0,0 +1,3 @@
1
+ #!/bin/sh
2
+
3
+ RAILS_ENV=production rake assets:precompile
@@ -0,0 +1,4 @@
1
+ #!/bin/sh
2
+
3
+ rm Gemfile.lock
4
+ bundle install --without development test
@@ -0,0 +1,3 @@
1
+ #!/bin/sh
2
+
3
+ mongodump --db <%= app_name.downcase %>
@@ -0,0 +1,3 @@
1
+ #!/bin/sh
2
+
3
+ mongorestore --drop
@@ -0,0 +1,4 @@
1
+ #!/bin/sh
2
+
3
+ RAILS_ENV=production rake assets:clobber
4
+ RAILS_ENV=production rake assets:precompile
@@ -0,0 +1,3 @@
1
+ #!/bin/sh
2
+
3
+ kill $(cat ./tmp/pids/unicorn.pid)
@@ -0,0 +1,3 @@
1
+ #!/bin/sh
2
+
3
+ kill -HUP $(cat ./tmp/pids/unicorn.pid)
@@ -0,0 +1,3 @@
1
+ #!/bin/sh
2
+
3
+ kill -USR2 $(cat ./tmp/pids/unicorn.pid)
@@ -0,0 +1,5 @@
1
+ #!/bin/sh
2
+
3
+ PORT=3000
4
+ echo 'server will by started at '$PORT
5
+ rails s -b 0.0.0.0 -p $PORT -e development
@@ -0,0 +1,5 @@
1
+ #!/bin/sh
2
+
3
+ PORT=4000
4
+ echo 'server will by started at '$PORT
5
+ rails s -b 0.0.0.0 -p $PORT -e development
@@ -0,0 +1,57 @@
1
+
2
+ rails_root = "/home/<%= app_name.downcase %>/www/<%= app_name.downcase %>"
3
+
4
+ worker_processes 2
5
+ working_directory rails_root
6
+
7
+ # This loads the application in the master process before forking
8
+ # worker processes
9
+ # Read more about it here:
10
+ # http://unicorn.bogomips.org/Unicorn/Configurator.html
11
+ preload_app true
12
+
13
+ timeout 30
14
+
15
+ # This is where we specify the socket.
16
+ # We will point the upstream Nginx module to this socket later on
17
+ listen "#{rails_root}/tmp/sockets/unicorn.sock", :backlog => 64
18
+
19
+ pid "#{rails_root}/tmp/pids/unicorn.pid"
20
+
21
+ # Set the path of the log files inside the log folder of the testapp
22
+ stderr_path "#{rails_root}/log/unicorn.stderr.log"
23
+ stdout_path "#{rails_root}/log/unicorn.stdout.log"
24
+
25
+
26
+ before_fork do |server, worker|
27
+ server.logger.info("worker=#{worker.nr} spawning in #{Dir.pwd}")
28
+
29
+ # graceful shutdown.
30
+ old_pid_file = "#{rails_root}/tmp/pids/unicorn.pid.oldbin"
31
+ if File.exists?(old_pid_file) && server.pid != old_pid_file
32
+ begin
33
+ old_pid = File.read(old_pid_file).to_i
34
+ server.logger.info("sending QUIT to #{old_pid}")
35
+ # we're killing old unicorn master right there
36
+ Process.kill("QUIT", old_pid)
37
+ rescue Errno::ENOENT, Errno::ESRCH
38
+ # someone else did our job for us
39
+ end
40
+ end
41
+ end
42
+
43
+ ## no need for noSQL
44
+ # before_fork do |server, worker|
45
+ # # This option works in together with preload_app true setting
46
+ # # What is does is prevent the master process from holding
47
+ # # the database connection
48
+ # defined?(ActiveRecord::Base) and
49
+ # ActiveRecord::Base.connection.disconnect!
50
+ # end
51
+ #
52
+ # after_fork do |server, worker|
53
+ # # Here we are establishing the connection after forking worker
54
+ # # processes
55
+ # defined?(ActiveRecord::Base) and
56
+ # ActiveRecord::Base.establish_connection
57
+ # end
@@ -0,0 +1,59 @@
1
+ # http://unicorn.bogomips.org/SIGNALS.html
2
+
3
+ rails_env = ENV['RAILS_ENV'] || 'production'
4
+ rails_root = ENV['RAILS_ROOT'] || File.dirname(File.dirname(__FILE__))
5
+
6
+ God.watch do |w|
7
+ w.name = "unicorn_<%= app_name.downcase %>"
8
+ w.interval = 30.seconds # default
9
+
10
+ # unicorn needs to be run from the rails root
11
+ w.start = "cd #{rails_root} && unicorn -c #{rails_root}/config/unicorn.rb -E #{rails_env} -D"
12
+
13
+ # QUIT gracefully shuts down workers
14
+ w.stop = "kill -KILL `cat #{rails_root}/tmp/pids/unicorn.pid`"
15
+
16
+ # USR2 causes the master to re-create itself and spawn a new worker pool
17
+ w.restart = "kill -USR2 `cat #{rails_root}/tmp/pids/unicorn.pid`"# && cd #{rails_root} && unicorn -c #{rails_root}/config/unicorn.rb -E #{rails_env} -D"
18
+
19
+ w.start_grace = 10.seconds
20
+ w.restart_grace = 10.seconds
21
+ w.pid_file = "#{rails_root}/tmp/pids/unicorn.pid"
22
+
23
+ w.uid = '<%= app_name.downcase %>'
24
+ w.gid = '<%= app_name.downcase %>'
25
+
26
+ w.behavior(:clean_pid_file)
27
+
28
+ w.start_if do |start|
29
+ start.condition(:process_running) do |c|
30
+ c.interval = 5.seconds
31
+ c.running = false
32
+ end
33
+ end
34
+
35
+ w.restart_if do |restart|
36
+ restart.condition(:memory_usage) do |c|
37
+ c.above = 150.megabytes
38
+ c.times = [3, 5] # 3 out of 5 intervals
39
+ end
40
+
41
+ restart.condition(:cpu_usage) do |c|
42
+ c.above = 50.percent
43
+ c.times = 5
44
+ end
45
+ end
46
+
47
+ # lifecycle
48
+ w.lifecycle do |on|
49
+ on.condition(:flapping) do |c|
50
+ c.to_state = [:start, :restart]
51
+ c.times = 5
52
+ c.within = 5.minute
53
+ c.transition = :unmonitored
54
+ c.retry_in = 10.minutes
55
+ c.retry_times = 5
56
+ c.retry_within = 2.hours
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,15 @@
1
+ require 'rails/generators'
2
+
3
+ module Hancock::Cms
4
+ class UnicornGodGenerator < Rails::Generators::Base
5
+ source_root File.expand_path('../templates', __FILE__)
6
+
7
+ argument :app_name, type: :string
8
+
9
+ desc 'Hancock CMS unicorn+god configs generator'
10
+ def install
11
+ template 'unicorn.erb', "config/unicorn.rb"
12
+ template 'unicorn.god.erb', "config/unicorn.god"
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,21 @@
1
+ # shamelessly stolen from https://github.com/sferik/rails_admin/blob/master/lib/generators/rails_admin/utils.rb
2
+
3
+ module Hancock::Cms
4
+ module Generators
5
+ module Utils
6
+ module InstanceMethods
7
+ def display(output, color = :green)
8
+ say(" - #{output}", color)
9
+ end
10
+
11
+ def ask_for(wording, default_value = nil, override_if_present_value = nil)
12
+ if override_if_present_value.present?
13
+ display("Using [#{override_if_present_value}] for question '#{wording}'") && override_if_present_value
14
+ else
15
+ ask(" ? #{wording} Press <enter> for [#{default_value}] >", :yellow).presence || default_value
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,60 @@
1
+ module Hancock
2
+ module Admin
3
+ def self.map_config(is_active = false)
4
+ Proc.new {
5
+ active is_active
6
+ label I18n.t('hancock.map')
7
+ field :address, :string
8
+ field :map_address, :string
9
+ field :map_hint, :string
10
+ field :coordinates, :string do
11
+ read_only true
12
+ formatted_value{ bindings[:object].coordinates.to_json }
13
+ end
14
+ field :lat
15
+ field :lon
16
+
17
+ if block_given?
18
+ yield self
19
+ end
20
+ }
21
+ end
22
+
23
+ def self.caching_block(is_active = false)
24
+ Proc.new {
25
+ active is_active
26
+ label I18n.t('hancock.cache')
27
+ field :perform_caching, :toggle
28
+ field :cache_keys_str, :text
29
+
30
+ if block_given?
31
+ yield self
32
+ end
33
+ }
34
+ end
35
+
36
+ def self.url_block(is_active = false)
37
+ Proc.new {
38
+ active is_active
39
+ label I18n.t('hancock.url')
40
+ field :slugs, :hancock_slugs
41
+ field :text_slug
42
+ }
43
+ end
44
+
45
+ def self.content_block(is_active = false, options = {})
46
+ if is_active.is_a?(Hash)
47
+ is_active, fields = (is_active[:active] || false), is_active
48
+ end
49
+
50
+ _excluded_fields = options.delete(:excluded_fields) || []
51
+ Proc.new {
52
+ active is_active
53
+ label I18n.t('hancock.content')
54
+ field :excerpt, :hancock_html unless _excluded_fields.include?(:excerpt)
55
+ field :content, :hancock_html unless _excluded_fields.include?(:content)
56
+ }
57
+ end
58
+
59
+ end
60
+ end