ack_rocket_cms 0.7.2.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (132) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +21 -0
  3. data/.rspec +1 -0
  4. data/.ruby-gemset +1 -0
  5. data/.ruby-version +1 -0
  6. data/.travis.yml +19 -0
  7. data/Gemfile +5 -0
  8. data/Gemfile.lock +244 -0
  9. data/LICENSE.txt +22 -0
  10. data/README.md +74 -0
  11. data/Rakefile +1 -0
  12. data/app/assets/javascripts/head.load.js +707 -0
  13. data/app/assets/javascripts/jquery.placeholder.js +157 -0
  14. data/app/assets/javascripts/rocket_cms.js.coffee +10 -0
  15. data/app/assets/javascripts/rocket_cms/flash.js.coffee +3 -0
  16. data/app/assets/javascripts/rocket_cms/map.js.coffee +22 -0
  17. data/app/assets/stylesheets/rocket_cms.css.sass +6 -0
  18. data/app/assets/stylesheets/rocket_cms/flash.css.sass +66 -0
  19. data/app/assets/stylesheets/rocket_cms/normalize.css.scss +406 -0
  20. data/app/controllers/concerns/no_cache.rb +12 -0
  21. data/app/controllers/concerns/rs_errors.rb +63 -0
  22. data/app/controllers/concerns/rs_menu.rb +45 -0
  23. data/app/controllers/concerns/rs_pages.rb +41 -0
  24. data/app/controllers/contacts_controller.rb +3 -0
  25. data/app/controllers/home_controller.rb +5 -0
  26. data/app/controllers/news_controller.rb +3 -0
  27. data/app/controllers/pages_controller.rb +4 -0
  28. data/app/controllers/search_controller.rb +4 -0
  29. data/app/mailers/contact_mailer.rb +15 -0
  30. data/app/models/concerns/boolean_field.rb +17 -0
  31. data/app/models/concerns/enableable.rb +8 -0
  32. data/app/models/concerns/geocodeable.rb +4 -0
  33. data/app/models/concerns/mappable.rb +95 -0
  34. data/app/models/concerns/seoable.rb +42 -0
  35. data/app/models/concerns/sitemap_data.rb +20 -0
  36. data/app/models/concerns/sort_field.rb +17 -0
  37. data/app/models/concerns/sortable.rb +8 -0
  38. data/app/models/contact_message.rb +11 -0
  39. data/app/models/menu.rb +11 -0
  40. data/app/models/news.rb +10 -0
  41. data/app/models/page.rb +11 -0
  42. data/app/views/blocks/_footer.html.haml +1 -0
  43. data/app/views/contact_mailer/new_message_email.html.haml +16 -0
  44. data/app/views/contacts/index.html.haml +10 -0
  45. data/app/views/contacts/new.html.haml +10 -0
  46. data/app/views/contacts/sent.html.haml +4 -0
  47. data/app/views/errors/_base.html.haml +3 -0
  48. data/app/views/errors/error_403.html.haml +1 -0
  49. data/app/views/errors/error_404.html.haml +1 -0
  50. data/app/views/errors/error_500.html.haml +1 -0
  51. data/app/views/home/index.html.haml +1 -0
  52. data/app/views/layouts/application.html.haml +23 -0
  53. data/app/views/layouts/application.html.slim +24 -0
  54. data/app/views/news/index.html.haml +9 -0
  55. data/app/views/news/show.html.haml +8 -0
  56. data/app/views/pages/show.html.haml +1 -0
  57. data/app/views/rails_admin/main/_check_boxes.html.haml +27 -0
  58. data/app/views/rails_admin/main/_enum_check_boxes.html.haml +5 -0
  59. data/app/views/rails_admin/main/_enum_radio_buttons.html.haml +5 -0
  60. data/app/views/rails_admin/main/_form_raw.html.haml +1 -0
  61. data/app/views/search/index.html.haml +19 -0
  62. data/app/views/shared/_admin_link.html.haml +3 -0
  63. data/app/views/shared/_messages.html.haml +7 -0
  64. data/app/views/shared/_meta.html.haml +6 -0
  65. data/app/views/shared/_obj.html.haml +20 -0
  66. data/app/views/shared/_og.html.haml +4 -0
  67. data/config/locales/en.rocket_admin.yml +6 -0
  68. data/config/locales/en.rs.yml +20 -0
  69. data/config/locales/ru.cancan.yml +4 -0
  70. data/config/locales/ru.devise.yml +65 -0
  71. data/config/locales/ru.kaminari.yml +17 -0
  72. data/config/locales/ru.models.yml +92 -0
  73. data/config/locales/ru.mongoid.yml +450 -0
  74. data/config/locales/ru.rails_admin.yml +148 -0
  75. data/config/locales/ru.rocket_admin.yml +6 -0
  76. data/config/locales/ru.rs.yml +20 -0
  77. data/config/locales/ru.simple_captcha.yml +3 -0
  78. data/config/locales/ru.simple_form.yml +9 -0
  79. data/lib/filename_to_slug.rb +34 -0
  80. data/lib/generators/rocket_cms/ability_generator.rb +15 -0
  81. data/lib/generators/rocket_cms/admin_generator.rb +21 -0
  82. data/lib/generators/rocket_cms/capify_generator.rb +40 -0
  83. data/lib/generators/rocket_cms/layout_generator.rb +15 -0
  84. data/lib/generators/rocket_cms/migration_generator.rb +19 -0
  85. data/lib/generators/rocket_cms/templates/Capfile +17 -0
  86. data/lib/generators/rocket_cms/templates/ability.erb +28 -0
  87. data/lib/generators/rocket_cms/templates/admin.erb +81 -0
  88. data/lib/generators/rocket_cms/templates/deploy.erb +47 -0
  89. data/lib/generators/rocket_cms/templates/dl.erb +30 -0
  90. data/lib/generators/rocket_cms/templates/migration_contact_messages.rb +15 -0
  91. data/lib/generators/rocket_cms/templates/migration_news.rb +21 -0
  92. data/lib/generators/rocket_cms/templates/migration_pages.rb +36 -0
  93. data/lib/generators/rocket_cms/templates/production.erb +8 -0
  94. data/lib/generators/rocket_cms/templates/unicorn.erb +66 -0
  95. data/lib/generators/rocket_cms/utils.rb +22 -0
  96. data/lib/manual_slug.rb +11 -0
  97. data/lib/manual_slug/active_record.rb +32 -0
  98. data/lib/manual_slug/mongoid.rb +36 -0
  99. data/lib/rails_admin/custom_show_in_app.rb +39 -0
  100. data/lib/rocket_cms.rb +88 -0
  101. data/lib/rocket_cms/admin.rb +152 -0
  102. data/lib/rocket_cms/configuration.rb +67 -0
  103. data/lib/rocket_cms/controller.rb +24 -0
  104. data/lib/rocket_cms/controllers/contacts.rb +70 -0
  105. data/lib/rocket_cms/controllers/news.rb +31 -0
  106. data/lib/rocket_cms/controllers/pages.rb +19 -0
  107. data/lib/rocket_cms/controllers/search.rb +45 -0
  108. data/lib/rocket_cms/elastic_search.rb +31 -0
  109. data/lib/rocket_cms/engine.rb +39 -0
  110. data/lib/rocket_cms/migration.rb +31 -0
  111. data/lib/rocket_cms/model.rb +25 -0
  112. data/lib/rocket_cms/models/active_record/contact_message.rb +14 -0
  113. data/lib/rocket_cms/models/active_record/menu.rb +14 -0
  114. data/lib/rocket_cms/models/active_record/news.rb +23 -0
  115. data/lib/rocket_cms/models/active_record/page.rb +17 -0
  116. data/lib/rocket_cms/models/contact_message.rb +27 -0
  117. data/lib/rocket_cms/models/menu.rb +29 -0
  118. data/lib/rocket_cms/models/mongoid/contact_message.rb +20 -0
  119. data/lib/rocket_cms/models/mongoid/menu.rb +12 -0
  120. data/lib/rocket_cms/models/mongoid/news.rb +27 -0
  121. data/lib/rocket_cms/models/mongoid/page.rb +26 -0
  122. data/lib/rocket_cms/models/news.rb +50 -0
  123. data/lib/rocket_cms/models/page.rb +76 -0
  124. data/lib/rocket_cms/patch.rb +58 -0
  125. data/lib/rocket_cms/rails_admin_menu.rb +145 -0
  126. data/lib/rocket_cms/simple_form_patch.rb +12 -0
  127. data/lib/rocket_cms/tasks.rb +13 -0
  128. data/lib/rocket_cms/version.rb +3 -0
  129. data/release.sh +13 -0
  130. data/rocket_cms.gemspec +54 -0
  131. data/template.rb +557 -0
  132. metadata +533 -0
@@ -0,0 +1,12 @@
1
+ module NoCache
2
+ extend ActiveSupport::Concern
3
+ included do
4
+ before_filter :set_cache_buster
5
+ end
6
+
7
+ protected
8
+ def set_cache_buster
9
+ expires_now()
10
+ response.headers["Pragma"] = "no-cache"
11
+ end
12
+ end
@@ -0,0 +1,63 @@
1
+ module RsErrors
2
+ extend ActiveSupport::Concern
3
+ included do
4
+ if Rails.env.production? || Rails.env.staging?
5
+ rescue_from Exception, with: :render_500
6
+ rescue_from ActionController::RoutingError, with: :render_404
7
+ rescue_from ActionController::UnknownController, with: :render_404
8
+ rescue_from AbstractController::ActionNotFound, with: :render_404
9
+ if RocketCMS.mongoid?
10
+ rescue_from Mongoid::Errors::DocumentNotFound, with: :render_404
11
+ rescue_from Mongoid::Errors::InvalidFind, with: :render_404
12
+ end
13
+ if RocketCMS.active_record?
14
+ rescue_from ActiveRecord::RecordNotFound, with: :render_404
15
+ end
16
+ end
17
+
18
+ if defined?(CanCan)
19
+ rescue_from CanCan::AccessDenied do |exception|
20
+ if !user_signed_in?
21
+ #scope = rails_admin? ? main_app : self
22
+ #redirect_to scope.new_user_session_path, alert: "Необходимо авторизоваться"
23
+ authenticate_user!
24
+ else
25
+ redirect_to '/', alert: "Доступ запрещен"
26
+ end
27
+ end
28
+ end
29
+ end
30
+
31
+ protected
32
+ def render_404(exception = nil)
33
+ Rails.logger.error "404: #{request.url}"
34
+ unless exception.nil?
35
+ Rails.logger.error exception.message
36
+ Rails.logger.error exception.backtrace.join("\n")
37
+ capture_exception(exception) if defined?(Raven)
38
+ end
39
+ render_error(404)
40
+ end
41
+
42
+ def render_500(exception)
43
+ Rails.logger.error "500: #{request.url}"
44
+ Rails.logger.error exception.message
45
+ Rails.logger.error exception.backtrace.join("\n")
46
+ capture_exception(exception) if defined?(Raven)
47
+ begin
48
+ if rails_admin_controller?
49
+ return render text: 'Внутренняя ошибка'
50
+ end
51
+ rescue
52
+ end
53
+ render_error(500)
54
+ end
55
+
56
+ def render_error(code = 500)
57
+ render template: "errors/error_#{code}", formats: [:html], handlers: [:haml, :slim], layout: RocketCMS.configuration.error_layout, status: code
58
+ end
59
+
60
+ def rails_admin?
61
+ self.is_a?(RailsAdmin::ApplicationController)
62
+ end
63
+ end
@@ -0,0 +1,45 @@
1
+ module RsMenu
2
+ extend ActiveSupport::Concern
3
+ included do
4
+ helper_method :navigation
5
+ end
6
+
7
+ def render_with_subs(items, primary, item)
8
+ subs = items.select { |i| i.parent_id == item.id && !i.name.blank? && i.enabled }
9
+ if subs.empty?
10
+ block = nil
11
+ else
12
+ block = Proc.new do |sub_nav|
13
+ subs.each { |sub| render_with_subs(items, sub_nav, sub) }
14
+ end
15
+ end
16
+ cr = item.clean_regexp
17
+ navigation_item(primary, item, block)
18
+ end
19
+
20
+ def navigation_item(primary, item, block=nil)
21
+ url = item.redirect.blank? ? item.fullpath : item.redirect
22
+ if block.nil?
23
+ primary.item(item.slug, item.name, url, item.nav_options)
24
+ else
25
+ primary.item(item.slug, item.name, url, item.nav_options, &block)
26
+ end
27
+ end
28
+
29
+ def navigation(type)
30
+ Proc.new do |primary|
31
+ SimpleNavigation.config.autogenerate_item_ids = false
32
+ begin
33
+ items = ::Menu.find(type.to_s).pages.enabled.sorted.to_a
34
+ items.select { |i| i.parent_id.nil? && !i.name.blank? && i.enabled }.each do |item|
35
+ render_with_subs(items, primary, item) if primary
36
+ end
37
+ rescue Exception => exception
38
+ Rails.logger.error exception.message
39
+ Rails.logger.error exception.backtrace.join("\n")
40
+ capture_exception(exception) if respond_to?(:capture_exception)
41
+ items || []
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,41 @@
1
+ module RsPages
2
+ extend ActiveSupport::Concern
3
+ included do
4
+ before_filter :find_page
5
+ end
6
+
7
+ private
8
+
9
+ def find_page
10
+ @seo_page = find_seo_page request.path
11
+ if !@seo_page.nil? && !@seo_page.redirect.blank?
12
+ redirect_to @seo_page.redirect, status: :moved_permanently
13
+ end
14
+ end
15
+
16
+ def find_seo_page(path)
17
+ do_redirect = false
18
+ if path[0] != '/'
19
+ path = '/' + path
20
+ end
21
+ if path.length > 1 && path[-1] == '/'
22
+ path = path[0..-2]
23
+ do_redirect = true
24
+ end
25
+
26
+ page = Page.enabled.where(fullpath: path).first
27
+ if page.nil?
28
+ do_redirect = true
29
+ spath = path.chomp(File.extname(path))
30
+ if spath != path
31
+ page = Page.enabled.where(fullpath: spath).first
32
+ end
33
+ end
34
+ if !page.nil? && do_redirect
35
+ redirect_to path, status: :moved_permanently
36
+ end
37
+
38
+ page
39
+ end
40
+
41
+ end
@@ -0,0 +1,3 @@
1
+ class ContactsController < ApplicationController
2
+ include RocketCMS::Controllers::Contacts
3
+ end
@@ -0,0 +1,5 @@
1
+ class HomeController < ApplicationController
2
+ def index
3
+ end
4
+ end
5
+
@@ -0,0 +1,3 @@
1
+ class NewsController < ApplicationController
2
+ include RocketCMS::Controllers::News
3
+ end
@@ -0,0 +1,4 @@
1
+ class PagesController < ApplicationController
2
+ include RocketCMS::Controllers::Pages
3
+ end
4
+
@@ -0,0 +1,4 @@
1
+ #todo multimodelsearch
2
+ class SearchController < ApplicationController
3
+ include RocketCMS::Controllers::Search
4
+ end
@@ -0,0 +1,15 @@
1
+ class ContactMailer < ActionMailer::Base
2
+ def new_message_email(message)
3
+ @message = message
4
+
5
+ #if message.attachment?
6
+ # attachments[message.attachment.identifier] = File.read(message.attachment.current_path)
7
+ #end
8
+
9
+ mail(
10
+ from: Settings.default_email_from(default: 'noreply@rscx.ru'),
11
+ to: Settings.form_email(default: 'i43ack@gmail.com'),
12
+ subject: "[#{Settings.email_topic(default: 'с сайта')}] #{message.name} #{message.email}"
13
+ )
14
+ end
15
+ end
@@ -0,0 +1,17 @@
1
+ module BooleanField
2
+ extend ActiveSupport::Concern
3
+ module ClassMethods
4
+ def boolean_field(name, default = true)
5
+ if RocketCMS.mongoid?
6
+ field name, type: Mongoid::Boolean, default: default
7
+ end
8
+ scope name, -> { where(name => true) }
9
+
10
+ if name == 'active'
11
+ scope :inactive, -> { where(active: false) }
12
+ elsif name == 'enabled'
13
+ scope :disabled, -> { where(enabled: false) }
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,8 @@
1
+ module Enableable
2
+ extend ActiveSupport::Concern
3
+ include BooleanField
4
+
5
+ included do
6
+ boolean_field(:enabled)
7
+ end
8
+ end
@@ -0,0 +1,4 @@
1
+ module Geocodeable
2
+ extend ActiveSupport::Concern
3
+ include Mappable
4
+ end
@@ -0,0 +1,95 @@
1
+ module Mappable
2
+ extend ActiveSupport::Concern
3
+
4
+ included do
5
+
6
+ if RocketCMS.mongoid?
7
+ include Geocoder::Model::Mongoid
8
+ field :coordinates, type: Array
9
+ field :address, type: String
10
+
11
+ field :map_address, type: String
12
+ field :map_hint, type: String
13
+
14
+ field :lat, type: Float
15
+ field :lon, type: Float
16
+ end
17
+
18
+ geocoded_by :geo_address
19
+ after_validation :do_geocode
20
+ end
21
+
22
+ if RocketCMS.active_record?
23
+ def coordinates
24
+ if latitude.nil? || longitude.nil?
25
+ nil
26
+ else
27
+ [longitude, latitude]
28
+ end
29
+ end
30
+ end
31
+
32
+ def do_geocode
33
+ if geo_address.blank?
34
+ if RocketCMS.mongoid?
35
+ self.coordinates = nil
36
+ else
37
+ self.latitude = nil
38
+ self.longitude = nil
39
+ end
40
+ else
41
+ if (lat.nil? || lon.nil?) && (new_record? || address_changed? || coordinates.nil? || map_address_changed?)
42
+ geocode
43
+ end
44
+ end
45
+ end
46
+
47
+ def get_lat
48
+ if lat.blank?
49
+ if coordinates.nil?
50
+ nil
51
+ else
52
+ coordinates[1]
53
+ end
54
+ else
55
+ lat
56
+ end
57
+ end
58
+ def get_lon
59
+ if lon.blank?
60
+ if coordinates.nil?
61
+ nil
62
+ else
63
+ coordinates[0]
64
+ end
65
+ else
66
+ lon
67
+ end
68
+ end
69
+
70
+ def has_map?
71
+ (!lat.blank? && !lon.blank?) || !coordinates.nil?
72
+ end
73
+
74
+ def to_map
75
+ {
76
+ id: id.to_s,
77
+ hint: map_hint,
78
+ addr: address,
79
+ lat: get_lat,
80
+ lon: get_lon,
81
+ }
82
+ end
83
+
84
+ def geo_address
85
+ if map_address.blank?
86
+ address
87
+ else
88
+ map_address
89
+ end
90
+ end
91
+
92
+ def self.admin
93
+ RocketCMS.map_config
94
+ end
95
+ end
@@ -0,0 +1,42 @@
1
+ module Seoable
2
+ extend ActiveSupport::Concern
3
+ if RocketCMS.mongoid?
4
+ include ::Mongoid::Paperclip
5
+ end
6
+
7
+ included do
8
+ if RocketCMS.mongoid?
9
+ field :name, type: String, localize: RocketCMS.configuration.localize
10
+ field :h1, type: String, localize: RocketCMS.configuration.localize
11
+
12
+ field :title, type: String, localize: RocketCMS.configuration.localize
13
+ field :keywords, type: String, localize: RocketCMS.configuration.localize
14
+ field :description, type: String, localize: RocketCMS.configuration.localize
15
+ field :robots, type: String, localize: RocketCMS.configuration.localize
16
+
17
+ field :og_title, type: String, localize: RocketCMS.configuration.localize
18
+ has_mongoid_attached_file :og_image, styles: {thumb: "800x600>"}
19
+ elsif RocketCMS.active_record?
20
+ has_attached_file :og_image, styles: {thumb: "800x600>"}
21
+ end
22
+ validates_attachment_content_type :og_image, content_type: %w(image/gif image/jpeg image/jpg image/png), if: :og_image?
23
+ end
24
+
25
+ def page_title
26
+ title.blank? ? name : title
27
+ end
28
+
29
+ def get_og_title
30
+ og_title.blank? ? name : og_title
31
+ end
32
+
33
+ def self.admin
34
+ RocketCMS.seo_config
35
+ end
36
+
37
+ # deprecated
38
+ def self.seo_config
39
+ RocketCMS.seo_config
40
+ end
41
+ end
42
+
@@ -0,0 +1,20 @@
1
+ module SitemapData
2
+ extend ActiveSupport::Concern
3
+
4
+ SITEMAP_CHANGEFREQ_ARRAY = %w(always hourly daily weekly monthly yearly never)
5
+
6
+ included do
7
+ if RocketCMS.mongoid?
8
+ field :sitemap_show, type: Boolean, default: true
9
+ field :sitemap_lastmod, type: DateTime
10
+ field :sitemap_changefreq, type: String, default: 'daily'
11
+ field :sitemap_priority, type: Float
12
+ elsif RocketCMS.active_record?
13
+ end
14
+ end
15
+
16
+ def self.admin
17
+ RocketCMS.sitemap_data_config
18
+ end
19
+ end
20
+
@@ -0,0 +1,17 @@
1
+ module SortField
2
+ extend ActiveSupport::Concern
3
+
4
+ module ClassMethods
5
+ def sort_field(prefix = '')
6
+ prefix = "#{prefix}_" unless prefix == ''
7
+
8
+ if RocketCMS.mongoid?
9
+ field "#{prefix}sort".to_sym, type: Integer
10
+ scope "#{prefix}sorted".to_sym, -> { asc("#{prefix}sort".to_sym) }
11
+ end
12
+ if RocketCMS.active_record?
13
+ scope "#{prefix}sorted".to_sym, -> { order("#{prefix}sort".to_sym => :asc) }
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,8 @@
1
+ module Sortable
2
+ extend ActiveSupport::Concern
3
+ include SortField
4
+
5
+ included do
6
+ sort_field
7
+ end
8
+ end
@@ -0,0 +1,11 @@
1
+ if RocketCMS.active_record?
2
+ class ContactMessage < ActiveRecord::Base
3
+ end
4
+ end
5
+
6
+ class ContactMessage
7
+ include RocketCMS::Models::ContactMessage
8
+ RocketCMS.apply_patches self
9
+ rails_admin &RocketCMS.contact_message_config
10
+ end
11
+