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,67 @@
1
+ module RocketCMS
2
+ def self.configuration
3
+ @configuration ||= Configuration.new
4
+ end
5
+ def self.config
6
+ @configuration ||= Configuration.new
7
+ end
8
+
9
+ def self.configure
10
+ yield configuration
11
+ end
12
+
13
+ class Configuration
14
+ attr_accessor :news_image_styles
15
+ attr_accessor :news_per_page
16
+ attr_accessor :news_excerpt
17
+
18
+ attr_accessor :error_layout
19
+ attr_accessor :menu_max_depth
20
+
21
+ attr_accessor :search_enabled
22
+ attr_accessor :search_per_page
23
+ attr_accessor :search_models
24
+
25
+ attr_accessor :contacts_captcha
26
+ attr_accessor :contacts_fields
27
+ attr_accessor :contacts_message_required
28
+ attr_accessor :contacts_captcha_error_message
29
+
30
+ attr_accessor :localize
31
+
32
+ attr_accessor :recreate_contact_message_action
33
+
34
+ def initialize
35
+ @news_image_styles = {
36
+ main: '400x200>',
37
+ thumb: '200x100>',
38
+ }
39
+ @news_per_page = 10
40
+ @news_excerpt = 12
41
+
42
+ @error_layout = 'application'
43
+ @menu_max_depth = 2
44
+
45
+ @search_enabled = false
46
+ @search_per_page = 10
47
+ @search_models = []
48
+
49
+ @contacts_captcha = false
50
+ @contacts_fields = {}
51
+ @contacts_message_required = true
52
+
53
+ @contacts_captcha_error_message = "Код проверки введен неверно"
54
+ @recreate_contact_message_action = "new"
55
+
56
+ @localize = false
57
+ end
58
+
59
+ def search_enabled=(val)
60
+ @search_enabled = val
61
+ if @search_enabled
62
+ @search_models << 'Page'
63
+ @search_models << 'News'
64
+ end
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,24 @@
1
+ module RocketCMS::Controller
2
+ extend ActiveSupport::Concern
3
+ included do
4
+ include RsErrors
5
+ include RsPages
6
+ include RsMenu
7
+ protect_from_forgery with: :exception
8
+ helper_method :page_title
9
+ end
10
+
11
+ protected
12
+
13
+ def page_title
14
+ if @seo_page.nil?
15
+ Settings ? Settings.default_title : "" #temp
16
+ else
17
+ @seo_page.page_title
18
+ end
19
+ end
20
+
21
+ def ckeditor_authenticate
22
+ redirect_to '/' unless user_signed_in? && current_user.has_role?('admin')
23
+ end
24
+ end
@@ -0,0 +1,70 @@
1
+ module RocketCMS
2
+ module Controllers
3
+ module Contacts
4
+ extend ActiveSupport::Concern
5
+ def index
6
+ @contact_message = ContactMessage.new
7
+ after_initialize
8
+ end
9
+
10
+ def new
11
+ @contact_message = model.new
12
+ after_initialize
13
+ end
14
+
15
+ def create
16
+ @contact_message = model.new(message_params)
17
+ after_initialize
18
+ if RocketCMS.configuration.contacts_captcha
19
+ meth = :save_with_captcha
20
+ else
21
+ meth = :save
22
+ end
23
+ if @contact_message.send(meth)
24
+ after_create
25
+ if request.xhr? && process_ajax
26
+ ajax_success
27
+ else
28
+ redirect_after_done
29
+ end
30
+ else
31
+ render_error
32
+ end
33
+ end
34
+
35
+ def sent
36
+ end
37
+
38
+ private
39
+ def render_error
40
+ if request.xhr? && process_ajax
41
+ render json: {errors: @contact_message.errors}, status: 422
42
+ else
43
+ flash.now[:alert] = @contact_message.errors.full_messages.join("\n")
44
+ render action: RocketCMS.configuration.recreate_contact_message_action, status: 422
45
+ end
46
+ end
47
+ def process_ajax
48
+ true
49
+ end
50
+ def ajax_success
51
+ render json: {ok: true}
52
+ end
53
+ def redirect_after_done
54
+ redirect_to :contacts_sent
55
+ end
56
+ def after_initialize
57
+ # overrideable hook for updating message
58
+ end
59
+ def after_create
60
+ # overrideable hook for updating message
61
+ end
62
+ def model
63
+ ContactMessage
64
+ end
65
+ def message_params
66
+ params.require(:contact_message).permit(RocketCMS.configuration.contacts_fields.keys + [:name, :email, :phone, :content, :captcha, :captcha_key])
67
+ end
68
+ end
69
+ end
70
+ end
@@ -0,0 +1,31 @@
1
+ module RocketCMS
2
+ module Controllers
3
+ module News
4
+ extend ActiveSupport::Concern
5
+
6
+ def index
7
+ @news = model.enabled.after_now.by_date
8
+
9
+ unless RocketCMS.configuration.news_per_page.nil?
10
+ @news = @news.page(params[:page])
11
+ end
12
+ end
13
+
14
+ def show
15
+ @news = model.after_now.find(params[:id])
16
+ end
17
+
18
+ private
19
+ def model
20
+ ::News
21
+ end
22
+ def page_title
23
+ if @news.class.name == model.name
24
+ @news.page_title
25
+ else
26
+ super
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,19 @@
1
+ module RocketCMS
2
+ module Controllers
3
+ module Pages
4
+ extend ActiveSupport::Concern
5
+ def show
6
+ if @seo_page.nil? || !@seo_page.persisted?
7
+ unless params[:id].blank?
8
+ @seo_page = Page.enabled.find(params[:id])
9
+ end
10
+ end
11
+ if @seo_page.nil?
12
+ render_404
13
+ return
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
19
+
@@ -0,0 +1,45 @@
1
+ module RocketCMS
2
+ module Controllers
3
+ module Search
4
+ extend ActiveSupport::Concern
5
+ # def index
6
+ # if params[:query].blank?
7
+ # @results = []
8
+ # else
9
+ # @results = Mongoid::Elasticsearch.search({
10
+ # body: {
11
+ # query: {
12
+ # query_string: {
13
+ # query: Mongoid::Elasticsearch::Utils.clean(params[:query])
14
+ # }
15
+ # },
16
+ # highlight: {
17
+ # fields: {
18
+ # name: {},
19
+ # content: {}
20
+ # }
21
+ # }
22
+ # }},
23
+ # page: params[:page],
24
+ # per_page: RocketCMS.configuration.search_per_page,
25
+ # )
26
+ # end
27
+ # end
28
+
29
+ def index
30
+ if params[:q].blank?
31
+ @results = []
32
+ else
33
+ query = params[:q].to_s.gsub(/\P{Word}+/, ' ').gsub(/ +/, ' ').strip
34
+ @results = Page.search(query,
35
+ per_page: 10,
36
+ highlight: true,
37
+ suggest: true,
38
+ page: params[:page],
39
+ per_page: RocketCMS.configuration.search_per_page
40
+ )
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,31 @@
1
+ module RocketCMS::ElasticSearch
2
+ extend ActiveSupport::Concern
3
+ included do
4
+ searchkick(
5
+ language: "Russian",
6
+ suggest: ["name"],
7
+ settings: {
8
+ analysis: {
9
+ analyzer: {
10
+ default_index: {
11
+ type: "custom",
12
+ tokenizer: "standard",
13
+ filter: ["standard", "lowercase", "asciifolding", "searchkick_index_shingle", "searchkick_stemmer", "snowball"]
14
+
15
+ # https://github.com/imotov/elasticsearch-analysis-morphology
16
+ # filter: ["standard", "lowercase", "asciifolding", "searchkick_index_shingle", "searchkick_stemmer", "snowball", "russian_morphology", "english_morphology"]
17
+ }
18
+ }
19
+ }
20
+ }
21
+ )
22
+
23
+ def search_data
24
+ {
25
+ _id: _id,
26
+ name: name,
27
+ content: SmartExcerpt.strip_tags(content),
28
+ }
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,39 @@
1
+ module RocketCMS
2
+ class Engine < ::Rails::Engine
3
+ rake_tasks do
4
+ require File.expand_path('../tasks', __FILE__)
5
+ end
6
+
7
+ initializer "rocket_cms.email_defaults" do
8
+ # Write default email settings to DB so they can be changed.
9
+
10
+ #temp
11
+ begin
12
+ if Settings.table_exists?
13
+ Settings.default_email_from(default: 'noreply@gpk-holding.ru')
14
+ Settings.form_email(default: 'admin@gpk-holding.ru')
15
+ Settings.email_topic(default: 'с сайта')
16
+ end
17
+ rescue
18
+ end
19
+ end
20
+
21
+ initializer 'rocket_cms.paperclip' do
22
+ require 'paperclip/style'
23
+ module ::Paperclip
24
+ class Style
25
+ alias_method :processor_options_without_auto_orient, :processor_options
26
+ def processor_options
27
+ processor_options_without_auto_orient.merge(auto_orient: false)
28
+ end
29
+ end
30
+ end
31
+ end
32
+
33
+ config.after_initialize do
34
+ # trigger autoload so models are registered in Mongoid::Elasticearch
35
+ RocketCMS.configuration.search_models.map(&:constantize)
36
+ end
37
+ end
38
+ end
39
+
@@ -0,0 +1,31 @@
1
+ module RocketCMS
2
+ module Migration
3
+ extend self
4
+
5
+ def seo_fields(t)
6
+ t.string :name, null: false
7
+ t.string :h1
8
+ t.string :title
9
+ t.text :keywords
10
+ t.text :description
11
+ t.string :robots
12
+ t.string :og_title
13
+ t.attachment :og_image
14
+
15
+ #if RocketCMS.localize
16
+ #t.column :name_translations, 'hstore'
17
+ #t.column :name_translations, 'hstore'
18
+ #end
19
+ end
20
+
21
+ def map_fields(t)
22
+ t.text :address
23
+ t.text :map_address
24
+ t.text :map_hint
25
+ t.float :latitude
26
+ t.float :longitude
27
+ t.float :lat
28
+ t.float :lon
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,25 @@
1
+ module RocketCMS
2
+ module Model
3
+ extend ActiveSupport::Concern
4
+ included do
5
+ if RocketCMS.mongoid?
6
+ include Mongoid::Document
7
+ include Mongoid::Timestamps::Short
8
+ end
9
+ include ActiveModel::ForbiddenAttributesProtection
10
+ include BooleanField
11
+ include SortField
12
+
13
+ if RocketCMS.mongoid?
14
+ include Mongoid::Paperclip
15
+ end
16
+
17
+ include SmartExcerpt
18
+ include SimpleCaptcha::ModelHelpers
19
+
20
+ if RocketCMS.mongoid? && defined?(Trackable)
21
+ include Trackable
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,14 @@
1
+ module RocketCMS
2
+ module Models
3
+ module ActiveRecord
4
+ module ContactMessage
5
+ extend ActiveSupport::Concern
6
+ included do
7
+ has_paper_trail
8
+ validates_lengths_from_database
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
14
+
@@ -0,0 +1,14 @@
1
+ module RocketCMS
2
+ module Models
3
+ module ActiveRecord
4
+ module Menu
5
+ extend ActiveSupport::Concern
6
+ included do
7
+ has_paper_trail
8
+ validates_lengths_from_database
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
14
+
@@ -0,0 +1,23 @@
1
+ module RocketCMS
2
+ module Models
3
+ module ActiveRecord
4
+ module News
5
+ extend ActiveSupport::Concern
6
+ included do
7
+ unless RocketCMS.configuration.news_image_styles.nil?
8
+ has_attached_file :image, styles: RocketCMS.configuration.news_image_styles
9
+ validates_attachment_content_type :image, content_type: %w(image/gif image/jpeg image/jpg image/png), if: :image?
10
+ end
11
+
12
+ has_paper_trail
13
+
14
+ validates_lengths_from_database only: [:name, :title, :content, :excerpt, :h1, :keywords, :robots, :og_title]
15
+
16
+ scope :after_now, -> { where("time < ?", Time.now) }
17
+ scope :by_date, -> { order(time: :desc) }
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
23
+