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,13 @@
1
+ # require this file to load the tasks
2
+ require 'rake'
3
+
4
+ # Require generator at runtime. If we don't do this the ActionView helpers are included
5
+ # before the Rails environment can be loaded by other Rake tasks, which causes problems
6
+ # for those tasks when rendering using ActionView.
7
+ namespace :hancock do
8
+ # Require generator only. When installed as a plugin the require will fail, so in
9
+ # that case, load the environment first.
10
+ task :require do
11
+ Rake::Task['environment'].invoke
12
+ end
13
+ end
@@ -0,0 +1,3 @@
1
+ module Hancock
2
+ VERSION = "1.0.0".freeze
3
+ end
@@ -0,0 +1,130 @@
1
+ unless defined?(Hancock) && Hancock.respond_to?(:orm) && [:active_record, :mongoid].include?(Hancock.orm)
2
+ puts "please use hancock_cms_mongoid or hancock_cms_activerecord and not hancock directly"
3
+ exit 1
4
+ end
5
+
6
+ require 'hancock/version'
7
+ require 'hancock/plugin'
8
+ require 'hancock/plugin_configuration'
9
+ require 'hancock/configuration'
10
+ require 'devise'
11
+ require 'hancock/routes'
12
+
13
+ require 'simple_form'
14
+ require 'hancock/simple_form_patch'
15
+
16
+ require 'geocoder'
17
+
18
+ # require 'simple_captcha'
19
+ # require 'validates_email_format_of'
20
+ require 'filename_to_slug'
21
+
22
+ require 'codemirror-rails'
23
+
24
+
25
+ require 'rails_admin'
26
+ require 'hancock/rails_admin_ext/config'
27
+
28
+ require 'hancock/rails_admin_ext/hancock_hash'
29
+ require 'hancock/rails_admin_ext/hancock_html'
30
+ require 'hancock/rails_admin_ext/hancock_slugs'
31
+ require 'hancock/rails_admin_ext/hancock_multiselect'
32
+
33
+ require 'hancock/rails_admin_ext/patches/field_patch'
34
+ require 'hancock/rails_admin_ext/patches/new_controller_patch'
35
+ require 'hancock/rails_admin_ext/patches/group_patch'
36
+ require 'hancock/rails_admin_ext/patches/hancock_cms_group'
37
+
38
+
39
+ require 'rails_admin_nested_set'
40
+ require 'rails_admin_toggleable'
41
+
42
+ require 'ack_rails_admin_settings'
43
+
44
+ # require 'x-real-ip'
45
+
46
+ require 'ckeditor'
47
+
48
+ # require 'kaminari'
49
+ # require 'addressable/uri'
50
+ # require 'turbolinks'
51
+
52
+ require 'hancock/model'
53
+ require 'hancock/engine'
54
+ require 'hancock/controller'
55
+
56
+
57
+ module Hancock
58
+
59
+ MODELS = []
60
+ PLUGINS = []
61
+
62
+ include Hancock::Plugin
63
+
64
+ class << self
65
+
66
+ def rails4?
67
+ true
68
+ end
69
+
70
+ def rails5?
71
+ false
72
+ end
73
+
74
+ def register_model(model)
75
+ Hancock::MODELS << model unless Hancock::MODELS.include?(model)
76
+ end
77
+ def models_goto_hancock
78
+ MODELS.map { |m|
79
+ puts m.name
80
+ m.goto_hancock
81
+ }
82
+ end
83
+ def register_plugin(plugin)
84
+ Hancock::PLUGINS << plugin unless Hancock::MODELS.include?(plugin)
85
+ end
86
+
87
+ def clear_history_from_empty_objects
88
+ ::HistoryTracker.all.map do |h|
89
+ begin
90
+ begin
91
+ h.delete if h.trackable.nil?
92
+ rescue
93
+ h.delete
94
+ end
95
+ rescue
96
+ end
97
+ end
98
+ end
99
+
100
+ def clear_history!
101
+ ::HistoryTracker.delete_all
102
+ end
103
+
104
+ end
105
+
106
+ autoload :Migration, 'hancock/migration'
107
+
108
+ autoload :Admin, 'hancock/admin'
109
+ module Admin
110
+ autoload :EmbeddedElement, 'hancock/admin/embedded_element'
111
+ end
112
+
113
+ module Models
114
+ autoload :EmbeddedElement, 'hancock/models/embedded_element'
115
+
116
+ module Mongoid
117
+ autoload :EmbeddedElement, 'hancock/models/mongoid/embedded_element'
118
+ end
119
+
120
+ module ActiveRecord
121
+ end
122
+ end
123
+
124
+ module Controllers
125
+ end
126
+ end
127
+
128
+ require 'manual_slug'
129
+
130
+ require 'scrollbar-rails'
@@ -0,0 +1,10 @@
1
+ module ManualSlug
2
+ autoload :Mongoid, 'manual_slug/mongoid'
3
+ autoload :ActiveRecord, 'manual_slug/active_record'
4
+ extend ActiveSupport::Concern
5
+ if Hancock.mongoid?
6
+ include ManualSlug::Mongoid
7
+ else
8
+ include ManualSlug::ActiveRecord
9
+ end
10
+ end
@@ -0,0 +1,32 @@
1
+ module ManualSlug::ActiveRecord
2
+ extend ActiveSupport::Concern
3
+
4
+ included do
5
+ extend FriendlyId
6
+ end
7
+
8
+ def text_slug
9
+ slug
10
+ end
11
+ def text_slug=(s)
12
+ self.slug = s
13
+ end
14
+
15
+ module ClassMethods
16
+ def manual_slug(field, options = {}, callback = true)
17
+ friendly_id field, use: [:slugged, :finders]
18
+ define_method(:should_generate_new_friendly_id?) do
19
+ slug.blank?
20
+ end
21
+
22
+ skip_callback :validation, :before, :set_slug
23
+ before_validation do
24
+ if self.slug.blank?
25
+ self.send(:set_slug)
26
+ end
27
+ true
28
+ end if callback
29
+ end
30
+ end
31
+ end
32
+
@@ -0,0 +1,40 @@
1
+ module ManualSlug::Mongoid
2
+ extend ActiveSupport::Concern
3
+ include ::Mongoid::Slug
4
+
5
+ def text_slug
6
+ ((self._slugs.nil? or self._slugs.empty?) ? '' : self._slugs.last)
7
+ end
8
+ def text_slug=(slug)
9
+ self._slugs ||= []
10
+ if slug.blank?
11
+ self._slugs = []
12
+ else
13
+ self._slugs.delete(slug)
14
+ self._slugs << slug
15
+ end
16
+ end
17
+
18
+ module ClassMethods
19
+ def manual_slug(_field, options = {}, callback = true)
20
+ options.merge!(permanent: true, history: true)
21
+ slug _field, options
22
+ #overwrite for default value
23
+ field :_slugs, type: Array, localize: options[:localize], default: [], overwrite: true
24
+
25
+
26
+ # we will create slugs manually when needed
27
+ skip_callback :create, :before, :build_slug
28
+
29
+ before_validation do
30
+ self._slugs = self._slugs.map{ |s| s.strip }.reject {|s| s.blank? } if self._slugs
31
+
32
+ if self._slugs.blank?
33
+ self.build_slug
34
+ end
35
+
36
+ true
37
+ end if callback
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,43 @@
1
+ module RailsAdmin
2
+ module Config
3
+ module Actions
4
+ class CustomShowInApp < RailsAdmin::Config::Actions::Base
5
+ RailsAdmin::Config::Actions.register(self)
6
+
7
+ register_instance_option :member do
8
+ true
9
+ end
10
+
11
+ register_instance_option :visible? do
12
+ authorized? && (bindings[:controller].main_app.url_for(bindings[:object]) rescue false)
13
+ end
14
+
15
+ register_instance_option :controller do
16
+ Proc.new do
17
+ # if @object.class.name == 'Hancock::Pages::Page'
18
+ # if @object.fullpath.blank?
19
+ # redirect_to main_app.page_url(@object)
20
+ # else
21
+ # redirect_to @object.fullpath
22
+ # end
23
+ # elsif @object.class.name == 'Hancock::News::News'
24
+ # redirect_to main_app.news_url(@object)
25
+ # elsif @object.class.name == 'Obj'
26
+ # redirect_to main_app.object_url(@object.category, @object)
27
+ # else
28
+ # redirect_to main_app.url_for(@object)
29
+ # end
30
+ end
31
+ end
32
+
33
+ register_instance_option :link_icon do
34
+ 'icon-eye-open'
35
+ end
36
+
37
+ register_instance_option :pjax? do
38
+ false
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
data/release.sh ADDED
@@ -0,0 +1,12 @@
1
+ #!/usr/bin/bash
2
+ bundle update
3
+ git add --all .
4
+ git commit -am "${*:1}"
5
+ git push -u origin rails4
6
+ rake release
7
+ cd mongoid
8
+ bundle update && rake release
9
+ cd ..
10
+ cd activerecord
11
+ bundle update && rake release
12
+ cd ..
data/template.rb ADDED
@@ -0,0 +1,564 @@
1
+ rails_spec = (Gem.loaded_specs["railties"] || Gem.loaded_specs["rails"])
2
+ version = rails_spec.version.to_s
3
+
4
+ mongoid = options[:skip_active_record]
5
+
6
+ if Gem::Version.new(version) < Gem::Version.new('4.2.7') or Gem::Version.new(version) >= Gem::Version.new('5.0.0')
7
+ puts "You are using an incorrect version of Rails (#{version})"
8
+ puts "Please update for 4.2.7"
9
+ puts "Stopping"
10
+ exit 1
11
+ end
12
+
13
+ remove_file 'README.md'
14
+ create_file 'README.md', "## #{app_name}\nProject generated by HancockCMS\nORM: #{if mongoid then 'Mongoid' else 'ActiveRecord' end}\n\n"
15
+
16
+
17
+ ####### GEMFILE #######
18
+
19
+ remove_file 'Gemfile'
20
+ create_file 'Gemfile' do <<-TEXT
21
+ source 'https://rubygems.org'
22
+
23
+ gem 'rails', '4.2.7.1'
24
+ #{if mongoid then "gem 'mongoid'" else "gem 'pg'" end}
25
+
26
+ gem 'sass'
27
+ gem 'sass-rails'
28
+ gem 'compass'
29
+ gem 'compass-rails'
30
+
31
+ # #{if mongoid then "gem 'glebtv-mongoid-paperclip'" else "gem 'paperclip'" end}
32
+ # gem "image_optim"
33
+ # gem "paperclip-optimizer"
34
+ # gem 'ack-paperclip-meta', github: "red-rocks/paperclip-meta"
35
+
36
+ # gem 'rails_admin_multiple_file_upload'
37
+ # gem 'rails_admin_user_abilities', github: "red-rocks/rails_admin_user_abilities"
38
+ # gem 'rails_admin_model_settings', github: "red-rocks/rails_admin_model_settings"
39
+
40
+
41
+ #{if mongoid then "gem 'hancock_cms_mongoid'" else "gem 'hancock_cms_activerecord'" end}, github: 'red-rocks/hancock_cms', branch: 'rails4'
42
+
43
+ gem 'devise'
44
+
45
+ gem 'slim-rails'
46
+ gem 'rs_russian'
47
+ gem 'cancancan'
48
+
49
+ # gem 'cloner'
50
+ gem 'unicorn'
51
+ gem 'x-real-ip'
52
+
53
+ gem 'sentry-raven'
54
+
55
+ group :development do
56
+ gem 'better_errors'
57
+ gem 'binding_of_caller'
58
+ gem 'pry-rails'
59
+ gem 'spring'
60
+
61
+ # gem 'capistrano', require: false
62
+ #
63
+ # gem 'rvm1-capistrano3', require: false
64
+ # gem 'glebtv-capistrano-unicorn', require: false
65
+ # gem 'capistrano-bundler', require: false
66
+ # gem 'capistrano-rails', require: false
67
+
68
+ # gem 'hipchat'
69
+ # gem 'coffee-rails-source-maps'
70
+ # gem 'compass-rails-source-maps'
71
+
72
+ gem 'ack_favicon_maker_rails', github: 'ack43/favicon_maker_rails'
73
+
74
+ # gem 'rails_email_preview', '~> 1.0.3'
75
+
76
+ gem 'image_optim_pack'
77
+
78
+ gem 'puma'
79
+ end
80
+
81
+ group :test do
82
+ gem 'rspec-rails'
83
+ gem 'database_cleaner'
84
+ gem 'email_spec'
85
+ #{if mongoid then "gem 'mongoid-rspec'" else "" end}
86
+ gem 'ffaker'
87
+ gem 'factory_girl_rails'
88
+ end
89
+
90
+ # #{if mongoid then "gem 'mongo_session_store-rails4'" else "gem 'activerecord-session_store'" end}
91
+
92
+ gem 'slim'
93
+ gem 'sprockets'
94
+
95
+ gem 'uglifier'
96
+
97
+ group :production do
98
+ gem "god"
99
+ end
100
+
101
+ gem 'glebtv_mongoid_userstamp', '0.6.0'
102
+ TEXT
103
+ end
104
+
105
+ RVM_RUBY_VERSION = "2.3.1"
106
+ create_file '.ruby-version', "#{RVM_RUBY_VERSION}\n"
107
+ create_file '.ruby-gemset', "#{app_name.underscore}\n"
108
+
109
+ # run "rvm use #{RVM_RUBY_VERSION} && rvm gemset create #{app_name}"
110
+ # run "rvm use #{RVM_RUBY_VERSION}@#{app_name} && gem install bundler"
111
+ # run "rvm gemset list"
112
+ run 'bundle install --without production'
113
+
114
+
115
+ ####### CONFIG #######
116
+
117
+ create_file 'config/locales/ru.yml' do <<-TEXT
118
+ ru:
119
+ attributes:
120
+ is_default: По умолчанию
121
+ mongoid:
122
+ models:
123
+ item: Товар
124
+ attributes:
125
+ item:
126
+ price: Цена
127
+ TEXT
128
+ end
129
+ remove_file "config/locales/devise.en.yml"
130
+ remove_file "config/locales/en.yml"
131
+
132
+ create_file 'config/navigation.rb' do <<-TEXT
133
+ # empty file to please simple_navigation, we are not using it
134
+ # See https://github.com/red-rocks/hancock_cms/blob/master/app/controllers/concerns/hancock/menu.rb
135
+ TEXT
136
+ end
137
+
138
+ if mongoid
139
+ create_file 'config/mongoid.yml' do <<-TEXT
140
+ development:
141
+ clients:
142
+ default:
143
+ database: #{app_name.underscore}
144
+ hosts:
145
+ - localhost:27017
146
+ production:
147
+ clients:
148
+ default:
149
+ database: #{app_name.underscore}
150
+ hosts:
151
+ - localhost:27017
152
+ test:
153
+ clients:
154
+ default:
155
+ database: #{app_name.underscore}_test
156
+ hosts:
157
+ - localhost:27017
158
+ TEXT
159
+ end
160
+ FileUtils.cp(Pathname.new(destination_root).join('config', 'mongoid.yml').to_s, Pathname.new(destination_root).join('config', 'mongoid.yml.example').to_s)
161
+ else
162
+ remove_file 'config/database.yml'
163
+ create_file 'config/database.yml' do <<-TEXT
164
+ development:
165
+ adapter: postgresql
166
+ encoding: unicode
167
+ database: #{app_name.underscore}_development
168
+ pool: 5
169
+ username: #{app_name.underscore}
170
+ password: #{app_name.underscore}
171
+ template: template0
172
+ TEXT
173
+ end
174
+ FileUtils.cp(Pathname.new(destination_root).join('config', 'database.yml').to_s, Pathname.new(destination_root).join('config', 'database.yml.example').to_s)
175
+ say "Please create a PostgreSQL user #{app_name.underscore} with password #{app_name.underscore} and a database #{app_name.underscore}_development owned by him for development NOW.", :red
176
+ ask("Press <enter> when done.", true)
177
+ end
178
+
179
+ remove_file 'config/application.rb'
180
+ create_file 'config/application.rb' do <<-TEXT
181
+ require File.expand_path('../boot', __FILE__)
182
+
183
+ # Pick the frameworks you want:
184
+ require "active_model/railtie"
185
+ #{'#' if mongoid}require "active_record/railtie"
186
+ require "action_controller/railtie"
187
+ # require "action_mailer/railtie" # mailer is off by default
188
+ require "action_mailer/railtie"
189
+ require "action_view/railtie"
190
+ require "sprockets/railtie"
191
+ # require "rails/test_unit/railtie"
192
+
193
+ # Require the gems listed in Gemfile, including any gems
194
+ # you've limited to :test, :development, or :production.
195
+ Bundler.require(*Rails.groups)
196
+
197
+ module #{app_name.underscore.camelcase}
198
+ class Application < Rails::Application
199
+ config.generators do |g|
200
+ g.test_framework :rspec
201
+ g.view_specs false
202
+ g.helper_specs false
203
+ g.feature_specs false
204
+ g.template_engine :slim
205
+ g.stylesheets false
206
+ g.javascripts false
207
+ g.helper false
208
+ g.fixture_replacement :factory_girl, :dir => 'spec/factories'
209
+ end
210
+
211
+ config.i18n.locale = :ru
212
+ config.i18n.default_locale = :ru
213
+ config.i18n.available_locales = [:ru, :en]
214
+ config.i18n.enforce_available_locales = true
215
+ #{'config.active_record.schema_format = :sql' unless mongoid}
216
+
217
+ #{'config.autoload_paths += %W(#{config.root}/extra)'}
218
+ #{'config.eager_load_paths += %W(#{config.root}/extra)'}
219
+
220
+ config.time_zone = 'Europe/Moscow'
221
+ config.assets.paths << Rails.root.join("app", "assets", "fonts")
222
+ end
223
+ end
224
+ TEXT
225
+ end
226
+
227
+
228
+ ####### DEVISE #######
229
+
230
+ generate "devise:install"
231
+ gsub_file 'config/initializers/devise.rb', "'please-change-me-at-config-initializers-devise@example.com'", "'noreply@#{app_name.dasherize.downcase}.ru'"
232
+ inject_into_file 'config/initializers/devise.rb', after: /^end/ do <<-TEXT
233
+ Rails.application.config.to_prepare do
234
+ Devise::SessionsController.layout "hancock/devise/sessions"
235
+ Devise::RegistrationsController.layout "hancock/devise/registrations"
236
+ Devise::ConfirmationsController.layout "hancock/devise/confirmations"
237
+ Devise::UnlocksController.layout "hancock/devise/unlocks"
238
+ Devise::PasswordsController.layout "hancock/devise/passwords"
239
+ end
240
+ TEXT
241
+ end
242
+
243
+ generate "devise", "User"
244
+
245
+
246
+ ####### ROUTES #######
247
+
248
+ remove_file 'config/routes.rb'
249
+ create_file 'config/routes.rb' do <<-TEXT
250
+ Rails.application.routes.draw do
251
+ devise_for :users, controllers: {sessions: 'hancock/sessions'}
252
+
253
+ mount RailsAdmin::Engine => '/admin', as: 'rails_admin'
254
+ mount Ckeditor::Engine => '/ckeditor'
255
+
256
+ hancock_cms_routes
257
+ end
258
+ TEXT
259
+ end
260
+
261
+
262
+ ####### INITIALIZERS #######
263
+
264
+ inject_into_file 'config/initializers/assets.rb', before: /\z/ do <<-TEXT
265
+ Rails.application.config.assets.precompile += %w( *.svg )
266
+ Rails.application.config.assets.precompile += %w( ckeditor/* )
267
+ Rails.application.config.assets.precompile += %w( codemirror.js codemirror.css codemirror/**/* )
268
+ TEXT
269
+ end
270
+
271
+ if mongoid
272
+ generate "ckeditor:install", "--orm=mongoid", "--backend=paperclip"
273
+ else
274
+ generate "ckeditor:install", "--orm=active_record", "--backend=paperclip"
275
+ end
276
+ gsub_file 'config/initializers/ckeditor.rb', "# config.image_file_types = %w(jpg jpeg png gif tiff)", "config.image_file_types = %w(jpg jpeg png gif tiff svg)"
277
+ gsub_file 'config/initializers/ckeditor.rb', "# config.authorize_with :cancan", "config.authorize_with :cancancan"
278
+ gsub_file 'config/initializers/ckeditor.rb', "# config.assets_languages = ['en', 'uk']", "config.assets_languages = ['en', 'ru']"
279
+
280
+ if mongoid
281
+ remove_file 'config/initializers/cookies_serializer.rb'
282
+ create_file 'config/initializers/cookies_serializer.rb' do <<-TEXT
283
+ # Be sure to restart your server when you modify this file.
284
+ # json serializer breaks Devise + Mongoid. DO NOT ENABLE
285
+ # See https://github.com/plataformatec/devise/pull/2882
286
+ # Rails.application.config.action_dispatch.cookies_serializer = :json
287
+ Rails.application.config.action_dispatch.cookies_serializer = :marshal
288
+ TEXT
289
+ end
290
+ end
291
+
292
+ gsub_file 'config/initializers/filter_parameter_logging.rb', "[:password]", "[:password, :password_confirmation]"
293
+
294
+ # generate 'paperclip_optimizer:install'
295
+ # remove_file 'config/initializers/paperclip_optimizer.rb'
296
+ # generate "hancock:cms:paperclip_optimizer"
297
+
298
+ # generate 'rails_email_preview:install'
299
+ # remove_file 'app/mailer_previews/contact_mailer_preview.rb'
300
+ # create_file 'app/mailer_previews/contact_mailer_preview.rb' do <<-TEXT
301
+ # class ContactMailerPreview
302
+ # def new_message_email
303
+ # Hancock::Feedback::ContactMailer.new_message_email(Hancock::Feedback::ContactMessage.all.to_a.sample)
304
+ # end
305
+ # end
306
+ # TEXT
307
+ # end
308
+
309
+ generate "hancock:cms:config"
310
+
311
+ generate "hancock:cms:rack"
312
+
313
+ generate "hancock:cms:admin"
314
+
315
+ remove_file 'config/initializers/session_store.rb'
316
+ if mongoid
317
+ create_file 'config/initializers/session_store.rb' do <<-TEXT
318
+ # Be sure to restart your server when you modify this file.
319
+
320
+ #Rails.application.config.session_store :cookie_store, key: '_#{app_name.tableize.singularize}_session'
321
+ Rails.application.config.session_store :mongoid_store
322
+ TEXT
323
+ end
324
+ else
325
+ generate 'active_record_store:session_migration'
326
+ create_file 'config/initializers/session_store.rb' do <<-TEXT
327
+ # Be sure to restart your server when you modify this file.
328
+
329
+ #Rails.application.config.session_store :cookie_store, key: '_#{app_name.tableize.singularize}_session'
330
+ Rails.application.config.session_store :active_record_store
331
+ TEXT
332
+ end
333
+ end
334
+
335
+ # unless mongoid
336
+ # generate 'simple_captcha'
337
+ # end
338
+
339
+ generate "simple_form:install"
340
+
341
+
342
+ ####### CONTROLLERS #######
343
+
344
+ remove_file 'app/controllers/application_controller.rb'
345
+ create_file 'app/controllers/application_controller.rb' do <<-TEXT
346
+ class ApplicationController < ActionController::Base
347
+ include Hancock::Controller
348
+ end
349
+ TEXT
350
+ end
351
+
352
+
353
+ ####### MODELS #######
354
+
355
+ generate "hancock:cms:ability"
356
+
357
+ gsub_file 'app/models/user.rb', '# :confirmable, :lockable, :timeoutable and :omniauthable' do <<-TEXT
358
+ include Hancock::Model
359
+ include Hancock::Enableable
360
+ include Hancock::RailsAdminPatch
361
+ def self.manager_can_default_actions
362
+ [:show, :read]
363
+ end
364
+ def manager_cannot_actions
365
+ [:new, :create, :delete, :destroy]
366
+ end
367
+
368
+ cattr_accessor :current_user
369
+
370
+ # Include default devise modules. Others available are:
371
+ # :confirmable, :lockable, :timeoutable and :omniauthable
372
+ TEXT
373
+ end
374
+
375
+ gsub_file 'app/models/user.rb', ':registerable,', ' :lockable,'
376
+ if mongoid
377
+ gsub_file 'app/models/user.rb', '# field :failed_attempts', 'field :failed_attempts'
378
+ gsub_file 'app/models/user.rb', '# field :unlock_token', 'field :unlock_token'
379
+ gsub_file 'app/models/user.rb', '# field :locked_at', 'field :locked_at'
380
+
381
+ inject_into_file 'app/models/user.rb', before: /^end/ do <<-TEXT
382
+
383
+ field :name, type: String
384
+ field :login, type: String
385
+ field :roles, type: Array, default: []
386
+
387
+ before_save do
388
+ self.roles ||= []
389
+ self.roles.reject! { |r| r.blank? }
390
+ end
391
+
392
+ AVAILABLE_ROLES = ["admin", "manager", "client"]
393
+
394
+ AVAILABLE_ROLES.each do |r|
395
+ class_eval <<-EVAL
396
+ def \#{r}?
397
+ self.roles and self.roles.include?("\#{r}")
398
+ end
399
+
400
+ scope :\#{r.pluralize}, -> { any_in(roles: "\#{r}") }
401
+ EVAL
402
+ end
403
+
404
+ def self.generate_first_admin_user
405
+ if ::User.admins.all.count == 0
406
+ _email_pass = 'admin@#{app_name.dasherize.downcase}.ru'
407
+ if ::User.new(roles: ["admin"], email: _email_pass, password: _email_pass, password_confirmation: _email_pass).save
408
+ puts "AdminUser with email and password '\#{_email_pass}' was created!"
409
+ else
410
+ puts 'Creating AdminUser error'
411
+ end
412
+ else
413
+ puts 'AdminUsers are here already'
414
+ end
415
+ end
416
+
417
+ def self.generate_first_manager_user
418
+ if ::User.managers.all.count == 0
419
+ _email_pass = 'manager@#{app_name.dasherize.downcase}.ru'
420
+ if ::User.create(roles: ["manager"], email: _email_pass, password: _email_pass, password_confirmation: _email_pass)
421
+ puts "ManagerUser with email and password '\#{_email_pass}' was created!"
422
+ else
423
+ puts 'Creating ManagerUser error'
424
+ end
425
+ else
426
+ puts 'ManagerUsers are here already'
427
+ end
428
+ end
429
+
430
+ rails_admin do
431
+ list do
432
+ field :email
433
+ field :name
434
+ field :login
435
+ field :roles do
436
+ pretty_value do
437
+ render_object = (bindings[:controller] || bindings[:view])
438
+ render_object.content_tag(:p, bindings[:object].roles.join(", ")) if render_object
439
+ end
440
+ end
441
+ end
442
+
443
+ edit do
444
+ group :login do
445
+ active false
446
+ field :email, :string do
447
+ visible do
448
+ render_object = (bindings[:controller] || bindings[:view])
449
+ render_object and (render_object.current_user.admin? or (render_object.current_user.manager? and render_object.current_user == bindings[:object]))
450
+ end
451
+ end
452
+ field :name, :string
453
+ field :login, :string do
454
+ visible do
455
+ render_object = (bindings[:controller] || bindings[:view])
456
+ render_object and render_object.current_user.admin?
457
+ end
458
+ end
459
+ end
460
+
461
+ group :roles do
462
+ active false
463
+ field :roles, :enum do
464
+ enum do
465
+ AVAILABLE_ROLES
466
+ end
467
+
468
+ multiple do
469
+ true
470
+ end
471
+
472
+ visible do
473
+ render_object = (bindings[:controller] || bindings[:view])
474
+ render_object and render_object.current_user.admin?
475
+ end
476
+ end
477
+ end
478
+
479
+ group :password do
480
+ active false
481
+ field :password do
482
+ visible do
483
+ render_object = (bindings[:controller] || bindings[:view])
484
+ render_object and (render_object.current_user.admin? or render_object.current_user == bindings[:object])
485
+ end
486
+ end
487
+ field :password_confirmation do
488
+ visible do
489
+ render_object = (bindings[:controller] || bindings[:view])
490
+ render_object and (render_object.current_user.admin? or render_object.current_user == bindings[:object])
491
+ end
492
+ end
493
+ end
494
+ end
495
+
496
+ end
497
+ TEXT
498
+ end
499
+ end
500
+
501
+
502
+ ###### HANCOCK OTHERS ######
503
+
504
+ unless mongoid
505
+ generate "hancock:cms:migration"
506
+ generate "rails_admin_settings:migration"
507
+ end
508
+
509
+ remove_file 'app/views/layouts/application.html.erb'
510
+ generate "hancock:cms:layout"
511
+
512
+ unless mongoid
513
+ rake "db:migrate"
514
+ end
515
+
516
+ remove_file 'app/assets/stylesheets/application.css'
517
+ remove_file 'app/assets/javascripts/application.js'
518
+ generate "hancock:cms:assets", app_name
519
+
520
+ remove_file 'public/robots.txt'
521
+ generate "hancock:cms:robots", app_name
522
+
523
+ #god+unicorn
524
+ generate "hancock:cms:unicorn_god", app_name
525
+ #scripts
526
+ generate "hancock:cms:scripts", app_name
527
+
528
+ FileUtils.cp(Pathname.new(destination_root).join('config', 'secrets.yml').to_s, Pathname.new(destination_root).join('config', 'secrets.yml.example').to_s)
529
+
530
+ unless mongoid
531
+ generate "paper_trail:install"
532
+ generate "friendly_id"
533
+ rake "db:migrate"
534
+ end
535
+
536
+ generate "rspec:install"
537
+
538
+
539
+ ####### GIT #######
540
+
541
+ remove_file '.gitignore'
542
+ create_file '.gitignore' do <<-TEXT
543
+ # See https://help.github.com/articles/ignoring-files for more about ignoring files.
544
+ #
545
+ # If you find yourself ignoring temporary files generated by your text editor
546
+ # or operating system, you probably want to add a global ignore instead:
547
+ # git config --global core.excludesfile '~/.gitignore_global'
548
+ .idea
549
+ .idea/*
550
+
551
+ /.bundle
552
+ /log/*.log
553
+ /tmp/*
554
+ /public/assets
555
+ /public/ckeditor_assets
556
+ Gemfile.lock
557
+ TEXT
558
+ end
559
+
560
+ create_file 'extra/.gitkeep', ''
561
+
562
+ git :init
563
+ git add: "."
564
+ git commit: %Q{ -m 'Initial commit' }