hancock_cms 1.0.1 → 1.0.2.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (120) hide show
  1. checksums.yaml +4 -4
  2. data/.gitattributes +4 -0
  3. data/app/assets/images/{rails-admin → hancock/rails_admin}/hancock_logo.svg +0 -0
  4. data/app/assets/javascripts/hancock/cms.coffee +1 -1
  5. data/app/assets/javascripts/hancock/rails_admin/cms.ui.coffee +10 -38
  6. data/app/assets/javascripts/hancock/rails_admin/en_ru_switcher.coffee +90 -0
  7. data/app/assets/javascripts/hancock/rails_admin/enum_with_custom.coffee +41 -0
  8. data/app/assets/javascripts/hancock/rails_admin/form_controls_fixed.coffee +44 -0
  9. data/app/assets/javascripts/hancock/rails_admin/leftside_hider.coffee +106 -0
  10. data/app/assets/javascripts/hancock/rails_admin/multiselect.coffee +8 -0
  11. data/app/assets/javascripts/hancock/rails_admin/navigation_dropdown.coffee +25 -0
  12. data/app/assets/javascripts/hancock/rails_admin/navigation_filter.coffee +108 -0
  13. data/app/assets/javascripts/hancock/rails_admin/navigation_scroll.coffee +12 -0
  14. data/app/assets/javascripts/jquery.placeholder.js +3 -2
  15. data/app/assets/javascripts/rails_admin/custom/ui.coffee +1 -0
  16. data/app/assets/stylesheets/hancock/cms/devise.sass +4 -1
  17. data/app/assets/stylesheets/hancock/rails_admin/cms.theming.sass +364 -147
  18. data/app/assets/stylesheets/hancock/rails_admin/fieldsets.sass +198 -0
  19. data/app/assets/stylesheets/rails_admin/custom/theming.sass +1 -1
  20. data/app/controllers/concerns/hancock/decorators/home.rb +1 -1
  21. data/app/controllers/concerns/hancock/errors.rb +4 -6
  22. data/app/controllers/hancock/registrations_controller.rb +2 -7
  23. data/app/controllers/hancock/sessions_controller.rb +3 -7
  24. data/app/helpers/hancock/powered_helper.rb +3 -3
  25. data/app/helpers/hancock/settings_helper.rb +44 -0
  26. data/app/helpers/rails_admin/application/hancock_helper.rb +19 -0
  27. data/app/helpers/rails_admin/hancock/form_builder.rb +44 -0
  28. data/app/helpers/rails_admin/main/hancock_helper.rb +27 -0
  29. data/app/models/concerns/hancock/boolean_field.rb +7 -2
  30. data/app/models/concerns/hancock/decorators/embedded_element.rb +1 -9
  31. data/app/models/concerns/hancock/enableable.rb +1 -0
  32. data/app/models/concerns/hancock/hash_field.rb +9 -8
  33. data/app/models/concerns/hancock/html_field.rb +6 -3
  34. data/app/models/concerns/hancock/insertion_field.rb +115 -0
  35. data/app/models/concerns/hancock/mappable.rb +1 -0
  36. data/app/models/concerns/hancock/model_localizeable.rb +4 -1
  37. data/app/models/concerns/hancock/rails_admin_patch.rb +22 -3
  38. data/app/models/concerns/hancock/sort_field.rb +26 -3
  39. data/app/models/concerns/hancock/sortable.rb +3 -0
  40. data/app/views/blocks/_footer.html.slim +1 -1
  41. data/app/views/devise/passwords/edit.html.slim +0 -2
  42. data/app/views/devise/passwords/new.html.slim +0 -2
  43. data/app/views/devise/registrations/edit.html.slim +0 -2
  44. data/app/views/devise/registrations/new.html.slim +0 -2
  45. data/app/views/devise/sessions/new.html.slim +0 -2
  46. data/app/views/hancock/home/index.html.slim +4 -1
  47. data/app/views/layouts/application.html.slim +7 -6
  48. data/app/views/layouts/hancock/devise/confirmations.html.slim +7 -4
  49. data/app/views/layouts/hancock/devise/passwords.html.slim +7 -4
  50. data/app/views/layouts/hancock/devise/registrations.html.slim +7 -4
  51. data/app/views/layouts/hancock/devise/sessions.html.slim +7 -4
  52. data/app/views/layouts/hancock/devise/unlocks.html.slim +7 -4
  53. data/app/views/layouts/rails_admin/_footer.html.slim +2 -2
  54. data/app/views/layouts/rails_admin/_footer_navigation.html.slim +20 -4
  55. data/app/views/layouts/rails_admin/_navigation.html.slim +13 -47
  56. data/app/views/layouts/rails_admin/_secondary_navigation.html.slim +5 -12
  57. data/app/views/layouts/rails_admin/_sidebar_navigation.html.slim +2 -0
  58. data/app/views/layouts/rails_admin/_sidebar_navigation_filter.html.slim +3 -0
  59. data/app/views/layouts/rails_admin/application.html.haml +3 -1
  60. data/app/views/rails_admin/main/_enum_for_settings_kinds.html.slim +24 -0
  61. data/app/views/rails_admin/main/_form_hancock_enum_with_custom.slim +20 -0
  62. data/app/views/rails_admin/main/_hancock_html.html.slim +2 -2
  63. data/app/views/rails_admin/main/_hancock_html_ml.html.slim +31 -34
  64. data/app/views/rails_admin/main/edit.html.haml +18 -0
  65. data/app/views/rails_admin/main/new.html.haml +17 -0
  66. data/app/views/shared/_admin_link.html.slim +4 -3
  67. data/config/initializers/rails_admin_mongoid_patch.rb +27 -0
  68. data/config/locales/en.hancock.yml +1 -0
  69. data/config/locales/ru.devise.yml +22 -18
  70. data/config/locales/ru.hancock.yml +2 -0
  71. data/config/locales/ru.rails_admin.yml +3 -0
  72. data/hancock_cms.gemspec +4 -1
  73. data/lib/filename_to_slug.rb +0 -20
  74. data/lib/generators/hancock/cms/ability_generator.rb +1 -0
  75. data/lib/generators/hancock/cms/admin_generator.rb +1 -0
  76. data/lib/generators/hancock/cms/application_generator.rb +1 -0
  77. data/lib/generators/hancock/cms/assets_generator.rb +1 -0
  78. data/lib/generators/hancock/cms/layout_generator.rb +1 -0
  79. data/lib/generators/hancock/cms/model_generator.rb +1 -0
  80. data/lib/generators/hancock/cms/models/templates/embedded_element.erb +2 -2
  81. data/lib/generators/hancock/cms/rack_generator.rb +1 -0
  82. data/lib/generators/hancock/cms/robots_generator.rb +1 -0
  83. data/lib/generators/hancock/cms/scripts_generator.rb +1 -0
  84. data/lib/generators/hancock/cms/setup_generator.rb +149 -32
  85. data/lib/generators/hancock/cms/templates/Gemfile.erb +1 -4
  86. data/lib/generators/hancock/cms/templates/ability.erb +1 -1
  87. data/lib/generators/hancock/cms/templates/admin.erb +12 -4
  88. data/lib/generators/hancock/cms/templates/robots.txt.erb +5 -1
  89. data/lib/generators/hancock/cms/templates/scripts/db_dump.sh.erb +1 -1
  90. data/lib/generators/hancock/cms/unicorn_god_generator.rb +1 -0
  91. data/lib/generators/hancock/cms/utils.rb +2 -0
  92. data/lib/hancock/admin/embedded_element.rb +7 -2
  93. data/lib/hancock/admin.rb +141 -17
  94. data/lib/hancock/controller.rb +9 -0
  95. data/lib/hancock/engine.rb +28 -36
  96. data/lib/hancock/model.rb +6 -0
  97. data/lib/hancock/models/embedded_element.rb +2 -0
  98. data/lib/hancock/models/mongoid/embedded_element.rb +17 -0
  99. data/lib/hancock/plugin_configuration.rb +1 -1
  100. data/lib/hancock/rails_admin_ext/config.rb +21 -4
  101. data/lib/hancock/rails_admin_ext/hancock_array.rb +19 -0
  102. data/lib/hancock/rails_admin_ext/hancock_enum.rb +10 -0
  103. data/lib/hancock/rails_admin_ext/hancock_enum_with_custom.rb +34 -0
  104. data/lib/hancock/rails_admin_ext/hancock_hash.rb +8 -1
  105. data/lib/hancock/rails_admin_ext/hancock_html.rb +17 -2
  106. data/lib/hancock/rails_admin_ext/hancock_multiselect.rb +1 -5
  107. data/lib/hancock/rails_admin_ext/hancock_slugs.rb +0 -4
  108. data/lib/hancock/rails_admin_ext/patches/field_patch.rb +2 -1
  109. data/lib/hancock/rails_admin_ext/patches/fieldset_patch.rb +14 -0
  110. data/lib/hancock/rails_admin_ext/patches/group_patch.rb +9 -0
  111. data/lib/hancock/rails_admin_ext/patches/hancock_cms_group.rb +2 -0
  112. data/lib/hancock/rails_admin_ext/patches/has_fields.rb +27 -0
  113. data/lib/hancock/rails_admin_ext/patches/navigation_patch.rb +25 -0
  114. data/lib/hancock/rails_admin_settings_patch.rb +195 -11
  115. data/lib/hancock/version.rb +1 -1
  116. data/lib/hancock_cms.rb +10 -9
  117. data/lib/manual_slug/active_record.rb +8 -8
  118. data/lib/rails_admin/custom_show_in_app.rb +21 -32
  119. data/template.rb +11 -10
  120. metadata +74 -5
@@ -7,27 +7,51 @@ module Hancock::Cms
7
7
  desc 'Hancock CMS Carcass generator'
8
8
  def install
9
9
 
10
+ def ask_with_timeout(question, timeout = 5)
11
+ ask(question)
12
+ # # temp
13
+ # begin
14
+ # Timeout::timeout(timeout) {
15
+ # ask("#{question} | U have only #{timeout} second(s)!")
16
+ # }
17
+ # rescue
18
+ # puts ""
19
+ # ""
20
+ # end
21
+ end
22
+
10
23
  ####### DEVISE #######
11
24
 
12
- generate "devise:install"
25
+ generate "devise:install" if ["yes", "y"].include?(ask_with_timeout("generate `devise:install`?(y or yes)").downcase.strip)
13
26
  gsub_file 'config/initializers/devise.rb', "'please-change-me-at-config-initializers-devise@example.com'", "'noreply@#{app_name.dasherize.downcase}.ru'"
27
+
28
+ if ["yes", "y"].include?(ask_with_timeout("Set Hancock's layout for devise? (y or yes)").downcase.strip)
29
+ _sessions_layout = Devise::SessionsController._layout == "hancock/devise/sessions"
30
+ _registration_layout = Devise::RegistrationsController._layout == "hancock/devise/registrations"
31
+ _confirmations_layout = Devise::ConfirmationsController._layout == "hancock/devise/confirmations"
32
+ _unlocks_layout = Devise::UnlocksController._layout == "hancock/devise/unlocks"
33
+ _passwords_layout = Devise::PasswordsController._layout == "hancock/devise/passwords"
34
+ if !_sessions_layout or !_registration_layout or !_confirmations_layout or !_unlocks_layout or !_passwords_layout
14
35
  inject_into_file 'config/initializers/devise.rb', after: /^end/ do <<-TEXT
15
36
 
16
37
  Rails.application.config.to_prepare do
17
- Devise::SessionsController.layout "hancock/devise/sessions"
18
- Devise::RegistrationsController.layout "hancock/devise/registrations"
19
- Devise::ConfirmationsController.layout "hancock/devise/confirmations"
20
- Devise::UnlocksController.layout "hancock/devise/unlocks"
21
- Devise::PasswordsController.layout "hancock/devise/passwords"
38
+ #{'Devise::SessionsController.layout "hancock/devise/sessions"' unless _sessions_layout }
39
+ #{'Devise::RegistrationsController.layout "hancock/devise/registrations"' unless _registration_layout }
40
+ #{'Devise::ConfirmationsController.layout "hancock/devise/confirmations"' unless _confirmations_layout }
41
+ #{'Devise::UnlocksController.layout "hancock/devise/unlocks"' unless _unlocks_layout }
42
+ #{'Devise::PasswordsController.layout "hancock/devise/passwords"' unless _passwords_layout }
22
43
  end
23
44
  TEXT
24
45
  end
25
-
26
- generate "devise", "User"
46
+ end
47
+ end
48
+ generate "devise", "User", "--routes=false" if ["yes", "y"].include?(ask_with_timeout("generate `devise User --routes=false`?(y or yes)").downcase.strip)
27
49
 
28
50
 
29
51
  ####### ROUTES #######
30
52
 
53
+
54
+ if ["yes", "y"].include?(ask_with_timeout("Set Hancock's routes? (y or yes)").downcase.strip)
31
55
  remove_file 'config/routes.rb'
32
56
  create_file 'config/routes.rb' do <<-TEXT
33
57
  Rails.application.routes.draw do
@@ -37,27 +61,95 @@ Rails.application.routes.draw do
37
61
  end
38
62
  TEXT
39
63
  end
64
+ end
40
65
 
41
66
 
42
67
  ####### INITIALIZERS #######
43
68
 
69
+ add_assets_precompiled = ["*.svg", 'ckeditor/*', 'codemirror.js', 'codemirror.css', 'codemirror/**/*']
70
+ if (Rails.application.config.assets.precompile & add_assets_precompiled).length < add_assets_precompiled.length
44
71
  inject_into_file 'config/initializers/assets.rb', before: /\z/ do <<-TEXT
45
72
  Rails.application.config.assets.precompile += %w( *.svg )
46
73
  Rails.application.config.assets.precompile += %w( ckeditor/* )
47
74
  Rails.application.config.assets.precompile += %w( codemirror.js codemirror.css codemirror/**/* )
48
75
  TEXT
49
76
  end
77
+ end
78
+
50
79
 
51
80
  if mongoid
52
- generate "ckeditor:install", "--orm=mongoid", "--backend=paperclip"
81
+ if defined?(Paperclip)
82
+ generate "ckeditor:install", "--orm=mongoid", "--backend=paperclip" if ["yes", "y"].include?(ask_with_timeout("generate `ckeditor:install --orm=mongoid --backend=paperclip`?(y or yes)").downcase.strip)
83
+ require 'ckeditor/orm/mongoid'
84
+ require Rails.root.join("app", "models", "ckeditor", "asset.rb")
85
+ if defined?(Ckeditor::Asset)
86
+ unless Ckeditor::Asset < Hancock::Model
87
+ inject_into_file 'app/models/ckeditor/asset.rb', before: /^end/ do <<-TEXT
88
+ include Hancock::Model
89
+ TEXT
90
+ end
91
+ end
92
+ end
93
+ if ["yes", "y"].include?(ask_with_timeout("Set Hancock's config for Ckeditor::Picture? (y or yes)").downcase.strip)
94
+ remove_file 'app/models/ckeditor/picture.rb'
95
+ create_file 'app/models/ckeditor/picture.rb' do <<-TEXT
96
+ class Ckeditor::Picture < Ckeditor::Asset
97
+ # has_mongoid_attached_file :data,
98
+ # url: '/ckeditor_assets/pictures/:id/:style_:basename.:extension',
99
+ # path: ':rails_root/public/ckeditor_assets/pictures/:id/:style_:basename.:extension',
100
+ # styles: { content: '800>', thumb: '118x100#' }
101
+
102
+ include Hancock::Gallery::Paperclipable
103
+ hancock_cms_attached_file :data,
104
+ url: '/ckeditor_assets/pictures/:id/:style/:basename.:extension',
105
+ path: ':rails_root/public/ckeditor_assets/pictures/:id/:style/:basename.:extension'
106
+ def data_styles
107
+ if data_svg?
108
+ {}
109
+ else
110
+ { content: '800>', thumb: '118x100#' }
111
+ end
112
+ end
113
+
114
+ validates_attachment_size :data, less_than: 2.megabytes
115
+ validates_attachment_presence :data
116
+ validates_attachment_content_type :data, content_type: /\\Aimage/
117
+
118
+ def url_content
119
+ # url(:content)
120
+ if data_svg?
121
+ url
122
+ else
123
+ url(:content)
124
+ end
125
+ end
126
+
127
+ def url_thumb
128
+ # url(:thumb)
129
+ if data_svg?
130
+ url
131
+ else
132
+ url(:thumb)
133
+ end
134
+ end
135
+ end
136
+ TEXT
137
+ end
138
+ end
139
+ end
140
+
53
141
  else
54
- generate "ckeditor:install", "--orm=active_record", "--backend=paperclip"
142
+ if defined?(Paperclip)
143
+ generate "ckeditor:install", "--orm=active_record", "--backend=paperclip" if ["yes", "y"].include?(ask_with_timeout("generate `ckeditor:install --orm=active_record --backend=paperclip`?(y or yes)").downcase.strip)
144
+ end
145
+ end
146
+ if File.exists?(Rails.root.join 'config/initializers/ckeditor.rb')
147
+ 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)"
148
+ gsub_file 'config/initializers/ckeditor.rb', "# config.authorize_with :cancan", "# config.authorize_with :cancancan"
149
+ gsub_file 'config/initializers/ckeditor.rb', "# config.assets_languages = ['en', 'uk']", "config.assets_languages = ['en', 'ru']"
55
150
  end
56
- 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)"
57
- gsub_file 'config/initializers/ckeditor.rb', "# config.authorize_with :cancan", "config.authorize_with :cancancan"
58
- gsub_file 'config/initializers/ckeditor.rb', "# config.assets_languages = ['en', 'uk']", "config.assets_languages = ['en', 'ru']"
59
151
 
60
- if mongoid
152
+ if mongoid and ["yes", "y"].include?(ask_with_timeout("Set Hancock's config for cookies_serializer? (y or yes)").downcase.strip)
61
153
  remove_file 'config/initializers/cookies_serializer.rb'
62
154
  create_file 'config/initializers/cookies_serializer.rb' do <<-TEXT
63
155
  # Be sure to restart your server when you modify this file.
@@ -73,7 +165,7 @@ gsub_file 'config/initializers/filter_parameter_logging.rb', "[:password]", "[:p
73
165
 
74
166
  # generate 'paperclip_optimizer:install'
75
167
  # remove_file 'config/initializers/paperclip_optimizer.rb'
76
- # generate "hancock:cms:paperclip_optimizer"
168
+ generate "hancock:cms:paperclip_optimizer" if ["yes", "y"].include?(ask_with_timeout("generate `hancock:cms:paperclip_optimizer`? (y or yes)").downcase.strip)
77
169
 
78
170
  # generate 'rails_email_preview:install'
79
171
  # remove_file 'app/mailer_previews/contact_mailer_preview.rb'
@@ -86,12 +178,13 @@ gsub_file 'config/initializers/filter_parameter_logging.rb', "[:password]", "[:p
86
178
  # TEXT
87
179
  # end
88
180
 
89
- generate "hancock:cms:config"
181
+ generate "hancock:cms:config" if ["yes", "y"].include?(ask_with_timeout("generate `hancock:cms:config`? (y or yes)").downcase.strip)
90
182
 
91
- generate "hancock:cms:rack"
183
+ generate "hancock:cms:rack" if ["yes", "y"].include?(ask_with_timeout("generate `hancock:cms:rack`? (y or yes)").downcase.strip)
92
184
 
93
- generate "hancock:cms:admin"
185
+ generate "hancock:cms:admin" if ["yes", "y"].include?(ask_with_timeout("generate `hancock:cms:admin`? (y or yes)").downcase.strip)
94
186
 
187
+ if ["yes", "y"].include?(ask_with_timeout("Set Hancock's config for session_store? (y or yes)").downcase.strip)
95
188
  remove_file 'config/initializers/session_store.rb'
96
189
  if mongoid
97
190
  create_file 'config/initializers/session_store.rb' do <<-TEXT
@@ -111,16 +204,20 @@ Rails.application.config.session_store :active_record_store
111
204
  TEXT
112
205
  end
113
206
  end
207
+ end
114
208
 
115
209
  # unless mongoid
116
210
  # generate 'simple_captcha'
117
211
  # end
118
212
 
119
- generate "simple_form:install"
213
+ generate "simple_form:install" if ["yes", "y"].include?(ask_with_timeout("generate `simple_form:install`? (y or yes)").downcase.strip)
214
+
120
215
 
121
216
 
122
217
  ####### CONTROLLERS #######
123
218
 
219
+
220
+ unless ApplicationController < Hancock::Controller
124
221
  remove_file 'app/controllers/application_controller.rb'
125
222
  create_file 'app/controllers/application_controller.rb' do <<-TEXT
126
223
  class ApplicationController < ActionController::Base
@@ -128,12 +225,19 @@ class ApplicationController < ActionController::Base
128
225
  end
129
226
  TEXT
130
227
  end
228
+ end
131
229
 
132
230
 
133
231
  ####### MODELS #######
134
232
 
135
- generate "hancock:cms:ability"
233
+ generate "hancock:cms:ability" if ["yes", "y"].include?(ask_with_timeout("generate `hancock:cms:ability`? (y or yes)").downcase.strip)
136
234
 
235
+ gsub_user_rb = begin
236
+ (User < Hancock::Model).nil?
237
+ rescue
238
+ true
239
+ end
240
+ if gsub_user_rb
137
241
  gsub_file 'app/models/user.rb', '# :confirmable, :lockable, :timeoutable and :omniauthable' do <<-TEXT
138
242
  include Hancock::Model
139
243
  include Hancock::Enableable
@@ -160,6 +264,7 @@ include Hancock::Model
160
264
  TEXT
161
265
  end
162
266
 
267
+ if ["yes", "y"].include?(ask_with_timeout("Set Hancock's User model? (y or yes)").downcase.strip)
163
268
  gsub_file 'app/models/user.rb', ':registerable,', ' :lockable,'
164
269
  if mongoid
165
270
  gsub_file 'app/models/user.rb', '# field :failed_attempts', 'field :failed_attempts'
@@ -180,13 +285,13 @@ inject_into_file 'app/models/user.rb', before: /^end/ do <<-TEXT
180
285
  AVAILABLE_ROLES = ["admin", "manager", "client"].freeze
181
286
 
182
287
  AVAILABLE_ROLES.each do |r|
183
- class_eval <<-EVAL
288
+ class_eval <<-RUBY
184
289
  def \#{r}?
185
290
  self.roles and self.roles.include?("\#{r}")
186
291
  end
187
292
 
188
293
  scope :\#{r.pluralize}, -> { any_in(roles: "\#{r}") }
189
- EVAL
294
+ RUBY
190
295
  end
191
296
 
192
297
  def self.generate_first_admin_user
@@ -220,6 +325,7 @@ inject_into_file 'app/models/user.rb', before: /^end/ do <<-TEXT
220
325
  end
221
326
 
222
327
  rails_admin do
328
+ navigation_icon 'icon-user'
223
329
  list do
224
330
  field :email
225
331
  field :name
@@ -289,45 +395,53 @@ inject_into_file 'app/models/user.rb', before: /^end/ do <<-TEXT
289
395
  TEXT
290
396
  end
291
397
  end
398
+ end
399
+ end
292
400
 
293
401
 
294
402
  ###### HANCOCK OTHERS ######
295
403
 
296
404
  unless mongoid
297
- generate "hancock:cms:migration"
298
- generate "rails_admin_settings:migration"
405
+ generate "hancock:cms:migration"
406
+ generate "rails_admin_settings:migration"
299
407
  end
300
408
 
409
+ if ["yes", "y"].include?(ask_with_timeout("Set Hancock's layout? (y or yes)").downcase.strip)
301
410
  remove_file 'app/views/layouts/application.html.erb'
302
411
  generate "hancock:cms:layout"
303
-
304
- unless mongoid
305
- rake "db:migrate"
306
412
  end
307
413
 
308
414
  run 'rails r "User.generate_first_admin_user"'
309
415
 
416
+ if ["yes", "y"].include?(ask_with_timeout("Set Hancock's assets? (y or yes)").downcase.strip)
310
417
  remove_file 'app/assets/stylesheets/application.css'
311
418
  remove_file 'app/assets/javascripts/application.js'
312
419
  generate "hancock:cms:assets", app_name
420
+ end
313
421
 
422
+ if ["yes", "y"].include?(ask_with_timeout("Set Hancock's robots.txt? (y or yes)").downcase.strip)
314
423
  remove_file 'public/robots.txt'
315
424
  generate "hancock:cms:robots", app_name
425
+ end
316
426
 
427
+ if ["yes", "y"].include?(ask_with_timeout("Set Hancock's unicorn config? (y or yes)").downcase.strip)
317
428
  #god+unicorn
318
429
  generate "hancock:cms:unicorn_god", app_name
430
+ end
431
+ if ["yes", "y"].include?(ask_with_timeout("Set Hancock's scripts? (y or yes)").downcase.strip)
319
432
  #scripts
320
433
  generate "hancock:cms:scripts", app_name
434
+ end
321
435
 
322
436
  FileUtils.cp(Pathname.new(destination_root).join('config', 'secrets.yml').to_s, Pathname.new(destination_root).join('config', 'secrets.yml.example').to_s)
323
437
 
324
438
  unless mongoid
325
- generate "paper_trail:install"
326
- generate "friendly_id"
327
- rake "db:migrate"
439
+ generate "paper_trail:install"
440
+ generate "friendly_id"
441
+ rake "db:migrate"
328
442
  end
329
443
 
330
- generate "rspec:install"
444
+ generate "rspec:install" if ["yes", "y"].include?(ask_with_timeout("generate `rspec:install`? (y or yes)").downcase.strip)
331
445
 
332
446
 
333
447
  ####### GIT #######
@@ -346,16 +460,19 @@ create_file '.gitignore' do <<-TEXT
346
460
  /log/*.log
347
461
  /tmp/*
348
462
  /public/assets
349
- /public/ckeditor_assets
463
+ # /public/ckeditor_assets
350
464
  Gemfile.lock
351
465
  TEXT
352
466
  end
353
467
 
354
468
  create_file 'extra/.gitkeep', ''
355
469
 
470
+
471
+ if ["yes", "y"].include?(ask_with_timeout("Do u want init git? (y or yes)").downcase.strip)
356
472
  git :init
357
473
  git add: "."
358
474
  git commit: %Q{ -m 'Initial commit' }
475
+ end
359
476
 
360
477
  end
361
478
 
@@ -8,7 +8,7 @@ gem 'sass-rails'
8
8
  gem 'compass-rails'
9
9
  gem 'compass'
10
10
 
11
- #{if mongoid then "gem 'hancock_cms_mongoid'" else "gem 'hancock_cms_activerecord'" end}, path: '/home/ack/www/hancock_cms' #'~> 0.3.7'
11
+ #{if mongoid then "gem 'hancock_cms_mongoid'" else "gem 'hancock_cms_activerecord'" end}
12
12
 
13
13
  gem 'devise'
14
14
 
@@ -20,9 +20,6 @@ gem 'cancancan'
20
20
  gem 'unicorn'
21
21
  gem 'x-real-ip'
22
22
 
23
- #temp
24
- #gem 'sentry-raven'
25
-
26
23
  group :development do
27
24
  gem 'better_errors'
28
25
  gem 'binding_of_caller'
@@ -14,7 +14,7 @@ class Ability
14
14
 
15
15
  can :index, :all
16
16
  can :read, :all
17
- can :history, :all
17
+ can :history, :all if Hancock.config.history_tracking
18
18
  can :export, :all
19
19
  can :toggle, :all
20
20
 
@@ -1,7 +1,12 @@
1
1
  require 'rails_admin/custom_show_in_app'
2
2
 
3
+ require_relative 'hancock_cms'
4
+ # Add `require_relative '%hancock_plugin_name%'` here for configure it.
5
+ # `require_relative 'hancock_cms'` reconfigure it by default.
6
+ # So u need do it again. If u have some changes.
7
+
3
8
  <% if Hancock.mongoid? %>
4
- RailsAdminSettings.track_history!
9
+ RailsAdminSettings.track_history! if Hancock.config.history_tracking
5
10
  <% end %>
6
11
 
7
12
  RailsAdmin.config do |config|
@@ -37,8 +42,10 @@ RailsAdmin.config do |config|
37
42
  edit
38
43
  delete
39
44
 
40
- history_index
41
- history_show
45
+ if Hancock.config.history_tracking
46
+ history_index
47
+ history_show
48
+ end
42
49
 
43
50
  toggle
44
51
  # toggle_menu # for Hancock::Pages
@@ -52,10 +59,11 @@ RailsAdmin.config do |config|
52
59
  config.excluded_models ||= []
53
60
  config.excluded_models << [
54
61
  'RailsAdmin::CustomShowInApp', 'HistoryTracker',
55
- 'Ckeditor::Asset', 'Ckeditor::AttachmentFile', 'Ckeditor::Picture',
62
+ 'Ckeditor::Asset', 'Ckeditor::AttachmentFile', 'Ckeditor::Picture', 'Ckeditor::Folder',
56
63
  'Hancock::EmbeddedElement'
57
64
  ]
58
65
  config.excluded_models.flatten!
66
+ config.excluded_models.uniq!
59
67
  end
60
68
 
61
69
  # [required] fix for timezones to be displayed in local time instead of UTC
@@ -1,5 +1,9 @@
1
- Host: <%= app_name.downcase %>.ru
1
+ Host: http://<%= app_name.downcase %>.ru
2
2
  User-Agent: *
3
3
  Allow: /
4
4
  Disallow: /admin
5
+ # Disallow: /account
6
+ Disallow: /ckeditor/*
7
+ # Disallow: /goto
8
+ # Disallow: /users
5
9
  Sitemap: http://<%= app_name.downcase %>.ru/sitemap.xml.gz
@@ -1,3 +1,3 @@
1
1
  #!/bin/sh
2
2
 
3
- mongodump --db <%= app_name.downcase %>
3
+ mongodump --db <%= app_name.underscore %>
@@ -11,5 +11,6 @@ module Hancock::Cms
11
11
  template 'unicorn.erb', "config/unicorn.rb"
12
12
  template 'unicorn.god.erb', "config/unicorn.god"
13
13
  end
14
+
14
15
  end
15
16
  end
@@ -4,6 +4,7 @@ module Hancock::Cms
4
4
  module Generators
5
5
  module Utils
6
6
  module InstanceMethods
7
+
7
8
  def display(output, color = :green)
8
9
  say(" - #{output}", color)
9
10
  end
@@ -15,6 +16,7 @@ module Hancock::Cms
15
16
  ask(" ? #{wording} Press <enter> for [#{default_value}] >", :yellow).presence || default_value
16
17
  end
17
18
  end
19
+
18
20
  end
19
21
  end
20
22
  end
@@ -1,21 +1,25 @@
1
1
  module Hancock
2
2
  module Admin
3
3
  module EmbeddedElement
4
+
4
5
  def self.config(nav_label = nil, fields = {})
5
6
  if nav_label.is_a?(Hash)
6
7
  nav_label, fields = nav_label[:nav_label], nav_label
7
8
  elsif nav_label.is_a?(Array)
8
9
  nav_label, fields = nil, nav_label
9
10
  end
11
+ fields ||= {}
12
+ field_names = [:enabled, :name]
13
+ field_showings = Hancock::Admin.get_field_showings(fields, field_names)
10
14
 
11
15
  Proc.new {
12
16
  navigation_label(nav_label || I18n.t('hancock.cms'))
13
17
  field :enabled, :toggle do
14
18
  searchable false
15
- end
19
+ end if field_showings[:enabled]
16
20
  field :name, :string do
17
21
  searchable true
18
- end
22
+ end if field_showings[:name]
19
23
 
20
24
  Hancock::RailsAdminGroupPatch::hancock_cms_group(self, fields)
21
25
 
@@ -24,6 +28,7 @@ module Hancock
24
28
  end
25
29
  }
26
30
  end
31
+
27
32
  end
28
33
  end
29
34
  end
data/lib/hancock/admin.rb CHANGED
@@ -1,18 +1,45 @@
1
1
  module Hancock
2
2
  module Admin
3
- def self.map_config(is_active = false)
3
+ def self.map_config(is_active = false, options = {})
4
+ if is_active.is_a?(Hash)
5
+ is_active, options = (is_active[:active] || false), is_active
6
+ end
7
+ fields = (options[:fields] ||= {})
8
+ field_names = [:slugs, :text_slug]
9
+ field_showings = get_field_showings(fields, field_names)
10
+
4
11
  Proc.new {
5
12
  active is_active
6
- label I18n.t('hancock.map')
7
- field :address, :string
8
- field :map_address, :string
9
- field :map_hint, :string
13
+ label options[:label] || I18n.t('hancock.map')
14
+
15
+ field :address, :string do
16
+ searchable true
17
+ end if field_showings[:address]
18
+
19
+ field :map_address, :string do
20
+ searchable true
21
+ end if field_showings[:map_address]
22
+
23
+ field :map_hint, :string do
24
+ searchable true
25
+ end if field_showings[:map_hint]
26
+
10
27
  field :coordinates, :string do
28
+ searchable true
11
29
  read_only true
12
30
  formatted_value{ bindings[:object].coordinates.to_json }
13
- end
14
- field :lat
15
- field :lon
31
+ end if field_showings[:coordinates]
32
+
33
+ field :lat do
34
+ searchable true
35
+ end if field_showings[:lat]
36
+
37
+ field :lon do
38
+ searchable true
39
+ end if field_showings[:lon]
40
+
41
+
42
+ Hancock::RailsAdminGroupPatch::hancock_cms_group(self, options[:fields])
16
43
 
17
44
  if block_given?
18
45
  yield self
@@ -20,28 +47,125 @@ module Hancock
20
47
  }
21
48
  end
22
49
 
23
- def self.url_block(is_active = false)
50
+ def self.url_block(is_active = false, options = {})
51
+ if is_active.is_a?(Hash)
52
+ is_active, options = (is_active[:active] || false), is_active
53
+ end
54
+ fields = (options[:fields] ||= {})
55
+ field_names = [:slugs, :text_slug]
56
+ field_showings = get_field_showings(fields, field_names)
57
+
24
58
  Proc.new {
25
59
  active is_active
26
- label I18n.t('hancock.url')
27
- field :slugs, :hancock_slugs
28
- field :text_slug
60
+ label options[:label] || I18n.t('hancock.url')
61
+ field :slugs, :hancock_slugs if field_showings[:slugs]
62
+ field :text_slug if field_showings[:text_slug]
63
+
64
+ Hancock::RailsAdminGroupPatch::hancock_cms_group(self, options[:fields])
65
+
66
+ if block_given?
67
+ yield self
68
+ end
29
69
  }
30
70
  end
31
71
 
32
72
  def self.content_block(is_active = false, options = {})
33
73
  if is_active.is_a?(Hash)
34
- is_active, fields = (is_active[:active] || false), is_active
74
+ is_active, options = (is_active[:active] || false), is_active
75
+ end
76
+ fields = (options[:fields] ||= {})
77
+ field_names = [:excerpt, :content]
78
+ field_showings = get_field_showings(fields, field_names)
79
+
80
+ Proc.new {
81
+ active is_active
82
+ label options[:label] || I18n.t('hancock.content')
83
+ field :excerpt, :hancock_html if field_showings[:excerpt]
84
+ field :content, :hancock_html if field_showings[:content]
85
+
86
+ Hancock::RailsAdminGroupPatch::hancock_cms_group(self, options[:fields] || {})
87
+
88
+ if block_given?
89
+ yield self
90
+ end
91
+ }
92
+ end
93
+
94
+ def self.categories_block(is_active = false, options = {})
95
+ if is_active.is_a?(Hash)
96
+ is_active, options = (is_active[:active] || false), is_active
97
+ end
98
+ fields = (options[:fields] ||= {})
99
+ field_names = [:main_category, :categories]
100
+ field_showings = get_field_showings(fields, field_names)
101
+
102
+ Proc.new {
103
+ active is_active
104
+ label options[:label] || I18n.t('hancock.categories')
105
+
106
+ field :main_category do
107
+ inline_add false
108
+ inline_edit false
109
+ end if field_showings[:main_category]
110
+ field :categories, :hancock_multiselect if field_showings[:categories]
111
+
112
+ Hancock::RailsAdminGroupPatch::hancock_cms_group(self, options[:fields] || {})
113
+
114
+ if block_given?
115
+ yield self
116
+ end
117
+ }
118
+ end
119
+
120
+
121
+ def self.insertions_block(is_active = false, options = {})
122
+ if is_active.is_a?(Hash)
123
+ is_active, options = (is_active[:active] || false), is_active
35
124
  end
125
+ fields = (options[:fields] ||= {})
126
+ field_names = [:possible_insertions]
127
+ field_showings = get_field_showings(fields, field_names)
36
128
 
37
- _excluded_fields = options.delete(:excluded_fields) || []
38
129
  Proc.new {
39
130
  active is_active
40
- label I18n.t('hancock.content')
41
- field :excerpt, :hancock_html unless _excluded_fields.include?(:excerpt)
42
- field :content, :hancock_html unless _excluded_fields.include?(:content)
131
+ label options[:label] || I18n.t('hancock.insertions')
132
+ field :possible_insertions do
133
+ read_only true
134
+ pretty_value do
135
+ ("<dl class='possible_insertions_list'>" + bindings[:object].possible_insertions.map do |_ins|
136
+ "<dt>#{_ins}</dt><dd>#{bindings[:object].send(_ins)}</dd>"
137
+ end.join + "</dl>").html_safe
138
+ end
139
+ end if field_showings[:possible_insertions]
140
+
141
+ Hancock::RailsAdminGroupPatch::hancock_cms_group(self, options[:fields] || {})
142
+
143
+ if block_given?
144
+ yield self
145
+ end
146
+
147
+ Hancock::RailsAdminGroupPatch::hancock_cms_group(self, options[:fields] || {})
148
+
149
+ if block_given?
150
+ yield self
151
+ end
43
152
  }
44
153
  end
45
154
 
155
+ def self.get_field_showings(fields, field_names)
156
+ field_showings = field_names.map { |f| {f => true } }.inject(&:merge) || {}
157
+ if fields.is_a?(Hash)
158
+ field_names.each do |f|
159
+ field_showings[f] = (fields[f] != false)
160
+ end
161
+ elsif fields.is_a?(Array)
162
+ _fields = fields.map { |f| f[:fields] }.inject(&:merge) || {}
163
+ field_names.each do |f|
164
+ field_showings[f] = (_fields[f] != false)
165
+ end
166
+ end
167
+ field_showings
168
+ end
169
+
46
170
  end
47
171
  end