rocket_cms 0.1.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (99) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +17 -0
  3. data/.rspec +1 -0
  4. data/.ruby-gemset +1 -0
  5. data/.ruby-version +2 -0
  6. data/.travis.yml +19 -0
  7. data/Gemfile +4 -0
  8. data/LICENSE.txt +22 -0
  9. data/README.md +36 -0
  10. data/Rakefile +1 -0
  11. data/app/assets/javascripts/head.load.js +707 -0
  12. data/app/assets/javascripts/jquery.placeholder.js +157 -0
  13. data/app/assets/javascripts/rocket_cms.js.coffee +10 -0
  14. data/app/assets/javascripts/rocket_cms/flash.js.coffee +3 -0
  15. data/app/assets/javascripts/rocket_cms/map.js.coffee +22 -0
  16. data/app/assets/stylesheets/rocket_cms.css.sass +2 -0
  17. data/app/assets/stylesheets/rocket_cms/flash.css.sass +66 -0
  18. data/app/assets/stylesheets/rocket_cms/normalize.css.scss +406 -0
  19. data/app/controllers/concerns/no_cache.rb +12 -0
  20. data/app/controllers/concerns/rs_errors.rb +58 -0
  21. data/app/controllers/concerns/rs_menu.rb +45 -0
  22. data/app/controllers/concerns/rs_pages.rb +41 -0
  23. data/app/controllers/contacts_controller.rb +29 -0
  24. data/app/controllers/news_controller.rb +22 -0
  25. data/app/controllers/pages_controller.rb +12 -0
  26. data/app/controllers/search_controller.rb +25 -0
  27. data/app/mailers/contact_mailer.rb +15 -0
  28. data/app/models/ckeditor/asset.rb +5 -0
  29. data/app/models/ckeditor/attachment_file.rb +15 -0
  30. data/app/models/ckeditor/picture.rb +16 -0
  31. data/app/models/concerns/boolean_field.rb +9 -0
  32. data/app/models/concerns/enableable.rb +8 -0
  33. data/app/models/concerns/geocodeable.rb +4 -0
  34. data/app/models/concerns/manual_slug.rb +38 -0
  35. data/app/models/concerns/mappable.rb +77 -0
  36. data/app/models/concerns/seoable.rb +35 -0
  37. data/app/models/concerns/sort_field.rb +12 -0
  38. data/app/models/concerns/sortable.rb +8 -0
  39. data/app/models/concerns/trackable.rb +8 -0
  40. data/app/models/contact_message.rb +6 -0
  41. data/app/models/menu.rb +6 -0
  42. data/app/models/news.rb +5 -0
  43. data/app/models/page.rb +6 -0
  44. data/app/views/contact_mailer/new_message_email.html.haml +15 -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/news/index.html.haml +8 -0
  52. data/app/views/news/show.html.haml +8 -0
  53. data/app/views/pages/show.html.haml +1 -0
  54. data/app/views/rails_admin/main/_check_boxes.html.haml +27 -0
  55. data/app/views/rails_admin/main/_form_raw.html.haml +1 -0
  56. data/app/views/search/index.html.haml +19 -0
  57. data/app/views/shared/_admin_link.html.haml +3 -0
  58. data/app/views/shared/_messages.html.haml +7 -0
  59. data/app/views/shared/_meta.html.haml +6 -0
  60. data/app/views/shared/_obj.html.haml +14 -0
  61. data/app/views/shared/_og.html.haml +4 -0
  62. data/config/locales/en.rocket_admin.yml +6 -0
  63. data/config/locales/en.rs.yml +17 -0
  64. data/config/locales/ru.cancan.yml +4 -0
  65. data/config/locales/ru.devise.yml +65 -0
  66. data/config/locales/ru.kaminari.yml +17 -0
  67. data/config/locales/ru.models.yml +78 -0
  68. data/config/locales/ru.mongoid.yml +450 -0
  69. data/config/locales/ru.rails_admin.yml +147 -0
  70. data/config/locales/ru.rocket_admin.yml +6 -0
  71. data/config/locales/ru.rs.yml +17 -0
  72. data/config/locales/ru.simple_captcha.yml +3 -0
  73. data/config/locales/ru.simple_form.yml +9 -0
  74. data/lib/filename_to_slug.rb +32 -0
  75. data/lib/generators/rocket_cms/admin_generator.rb +20 -0
  76. data/lib/generators/rocket_cms/templates/ability.erb +17 -0
  77. data/lib/generators/rocket_cms/templates/admin.erb +71 -0
  78. data/lib/generators/rocket_cms/utils.rb +22 -0
  79. data/lib/history_tracker.rb +4 -0
  80. data/lib/rails_admin/custom_show_in_app.rb +39 -0
  81. data/lib/rocket_cms.rb +57 -0
  82. data/lib/rocket_cms/admin.rb +128 -0
  83. data/lib/rocket_cms/configuration.rb +54 -0
  84. data/lib/rocket_cms/controller.rb +24 -0
  85. data/lib/rocket_cms/elastic_search.rb +32 -0
  86. data/lib/rocket_cms/engine.rb +4 -0
  87. data/lib/rocket_cms/model.rb +16 -0
  88. data/lib/rocket_cms/models/contact_message.rb +37 -0
  89. data/lib/rocket_cms/models/menu.rb +16 -0
  90. data/lib/rocket_cms/models/news.rb +61 -0
  91. data/lib/rocket_cms/models/page.rb +86 -0
  92. data/lib/rocket_cms/patch.rb +58 -0
  93. data/lib/rocket_cms/rails_admin_menu.rb +137 -0
  94. data/lib/rocket_cms/railtie.rb +39 -0
  95. data/lib/rocket_cms/tasks.rb +14 -0
  96. data/lib/rocket_cms/version.rb +3 -0
  97. data/lib/smart_excerpt.rb +98 -0
  98. data/rocket_cms.gemspec +50 -0
  99. metadata +533 -0
@@ -0,0 +1,6 @@
1
+ en:
2
+ admin:
3
+ actions:
4
+ custom_show_in_app:
5
+ title: 'В приложении'
6
+ menu: "Показать на сайте"
@@ -0,0 +1,17 @@
1
+ ru:
2
+ rs:
3
+ cms: "CMS"
4
+ menu: "Меню"
5
+ settings: 'Настройки'
6
+ news: 'Новости'
7
+ with_final_slash: "c начальным слешем"
8
+ page_url_regex: "Регулярное выражение, по которому определяется является ли этот пункт активным"
9
+ final_in_menu: "В меню сразу отдается конечная ссылка"
10
+ no_contact_info: "Пожалуйста введите ваш е-мейл или телефон чтобы мы могли связаться с вами."
11
+ map: 'Карта'
12
+ edit: Редактировать
13
+ m:
14
+ enabled: 'добавлено в меню "%{menu}"'
15
+ disabled: 'удалено из меню "%{menu}"'
16
+ error: "Ошибка: %{err}"
17
+ no_id: "Не указан ID"
@@ -0,0 +1,3 @@
1
+ ru:
2
+ simple_captcha:
3
+ label: "Введите код с картинки"
@@ -0,0 +1,9 @@
1
+ ru:
2
+ simple_form:
3
+ "yes": 'Да'
4
+ "no": 'Нет'
5
+ required:
6
+ text: 'Обязательное поле'
7
+ mark: '*'
8
+ error_notification:
9
+ default_message: "Пожалуйста, исправьте неточности в заполнении полей"
@@ -0,0 +1,32 @@
1
+ require 'stringex'
2
+ require 'digest/md5'
3
+
4
+ class String
5
+ def filename_to_slug
6
+ s = self.to_url
7
+ if s.blank?
8
+ return Digest::MD5.hexdigest(self)
9
+ end
10
+ s
11
+ end
12
+ end
13
+
14
+ module FilenameToSlug
15
+ extend ActiveSupport::Concern
16
+ included do
17
+ before_post_process :filename_to_slug
18
+ end
19
+
20
+ def filename_to_slug
21
+ if self.class.attachment_definitions
22
+ self.class.attachment_definitions.each do |k,v|
23
+ if self.send(k).file?
24
+ full_file_name = self.send("#{k}_file_name")
25
+ extension = File.extname(full_file_name)[1..-1]
26
+ file_name = full_file_name[0..full_file_name.size-extension.size-1]
27
+ self.send("#{k}").instance_write(:file_name, "#{file_name.filename_to_slug}.#{extension.filename_to_slug}")
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,20 @@
1
+ # shamelessly stolen from https://github.com/sferik/rails_admin/blob/master/lib/generators/rails_admin/utils.rb
2
+
3
+ require 'rails/generators'
4
+ require File.expand_path('../utils', __FILE__)
5
+
6
+ module RocketCms
7
+ class AdminGenerator < Rails::Generators::Base
8
+ source_root File.expand_path('../templates', __FILE__)
9
+ include Generators::Utils::InstanceMethods
10
+
11
+ argument :_namespace, type: :string, required: false, desc: 'RailsAdmin url namespace'
12
+ desc 'RocketCMS RailsAdmin config generator'
13
+
14
+ def install
15
+ namespace = ask_for('Where do you want to mount rails_admin?', 'admin', _namespace)
16
+ route("mount RailsAdmin::Engine => '/#{namespace}', as: 'rails_admin'")
17
+ template 'admin.erb', 'config/initializers/rails_admin.rb'
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,17 @@
1
+ class Ability
2
+ include CanCan::Ability
3
+
4
+ def initialize(user)
5
+ unless user.nil?
6
+ can :read, :all
7
+ can :manage, :all
8
+ cannot :manage, Menu
9
+ admin_ui
10
+ end
11
+ end
12
+
13
+ def admin_ui
14
+ can :access, :rails_admin # grant access to rails_admin
15
+ can :dashboard # grant access to the dashboard
16
+ end
17
+ end
@@ -0,0 +1,71 @@
1
+ require 'rails_admin/custom_show_in_app'
2
+
3
+ RailsAdmin.config do |config|
4
+ ## == Devise ==
5
+ # this is required if not using cancan
6
+ #config.authenticate_with do
7
+ #warden.authenticate! scope: :user
8
+ #end
9
+
10
+ config.current_user_method(&:current_user)
11
+
12
+ ## == Cancan ==
13
+ config.authorize_with :cancan
14
+
15
+ ## == MongoidAudit
16
+ config.audit_with :mongoid_audit, 'HistoryTracker'
17
+
18
+ config.actions do
19
+ dashboard # mandatory
20
+
21
+ # collection actions
22
+ index
23
+ new
24
+ export
25
+ bulk_delete
26
+
27
+ # member actions
28
+ show
29
+ edit
30
+ delete
31
+
32
+ history_index
33
+ history_show
34
+
35
+ nested_set do
36
+ visible do
37
+ ['Page', 'Slide', 'Partner'].include? bindings[:abstract_model].model_name
38
+ end
39
+ end
40
+
41
+ custom_show_in_app do
42
+ visible do
43
+ ['Page', 'News'].include? bindings[:abstract_model].model_name
44
+ end
45
+ end
46
+
47
+ toggle
48
+ end
49
+
50
+ config.main_app_name = ['<%= Rails.application.class.name.split('::')[0] %>', 'Админка']
51
+
52
+ config.excluded_models = [
53
+ 'RailsAdmin::CustomShowInApp', 'HistoryTracker',
54
+ 'Ckeditor::Asset', 'Ckeditor::AttachmentFile', 'Ckeditor::Picture',
55
+ ]
56
+ end
57
+
58
+ # [required] fix for timezones to be displayed in local time instead of UTC
59
+ module RailsAdmin
60
+ module Config
61
+ module Fields
62
+ module Types
63
+ class Datetime
64
+ def value
65
+ bindings[:object].send(name)
66
+ end
67
+ end
68
+ end
69
+ end
70
+ end
71
+ end
@@ -0,0 +1,22 @@
1
+ # shamelessly stolen from https://github.com/sferik/rails_admin/blob/master/lib/generators/rails_admin/utils.rb
2
+
3
+ module RocketCms
4
+ module Generators
5
+ module Utils
6
+ module InstanceMethods
7
+ def display(output, color = :green)
8
+ say(" - #{output}", color)
9
+ end
10
+
11
+ def ask_for(wording, default_value = nil, override_if_present_value = nil)
12
+ if override_if_present_value.present?
13
+ display("Using [#{override_if_present_value}] for question '#{wording}'") && override_if_present_value
14
+ else
15
+ ask(" ? #{wording} Press <enter> for [#{default_value}] >", :yellow).presence || default_value
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
22
+
@@ -0,0 +1,4 @@
1
+ # app/models/history_tracker.rb
2
+ class HistoryTracker
3
+ include Mongoid::Audit::Tracker
4
+ end
@@ -0,0 +1,39 @@
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 == 'Page'
18
+ redirect_to main_app.page_url(@object)
19
+ elsif @object.class.name == 'News'
20
+ redirect_to main_app.news_url(@object)
21
+ elsif @object.class.name == 'Obj'
22
+ redirect_to main_app.object_url(@object.category, @object)
23
+ else
24
+ redirect_to main_app.url_for(@object)
25
+ end
26
+ end
27
+ end
28
+
29
+ register_instance_option :link_icon do
30
+ 'icon-eye-open'
31
+ end
32
+
33
+ register_instance_option :pjax? do
34
+ false
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
data/lib/rocket_cms.rb ADDED
@@ -0,0 +1,57 @@
1
+ require 'rocket_cms/version'
2
+
3
+ require 'mongoid'
4
+ # require 'yajl/json_gem'
5
+ require 'devise'
6
+
7
+ require 'simple_form'
8
+ require 'glebtv-simple_captcha'
9
+
10
+ require 'validates_email_format_of'
11
+
12
+ require 'htmlentities'
13
+ require 'sanitize'
14
+ require 'smart_excerpt'
15
+
16
+ # uploads
17
+ require 'glebtv-mongoid-paperclip'
18
+ require 'filename_to_slug'
19
+
20
+ require 'rails_admin'
21
+ # require 'rs_russian'
22
+
23
+ require 'glebtv-mongoid_nested_set'
24
+ require 'rails_admin_nested_set'
25
+ require 'rails_admin_toggleable'
26
+ require 'glebtv-ckeditor'
27
+ require 'rails_admin_settings'
28
+ require 'mongoid-audit'
29
+ require 'history_tracker' # audit model
30
+
31
+ require 'mongoid_slug'
32
+
33
+ require 'x-real-ip'
34
+ require 'sitemap_generator'
35
+ require 'kaminari'
36
+ require 'addressable/uri'
37
+ require 'turbolinks'
38
+ require 'simple-navigation'
39
+
40
+ require 'rocket_cms/configuration'
41
+ require 'rocket_cms/patch'
42
+ require 'rocket_cms/admin'
43
+ require 'rocket_cms/elastic_search' # FTS, optional
44
+ require 'rocket_cms/model'
45
+ require 'rocket_cms/rails_admin_menu'
46
+ require 'rocket_cms/engine'
47
+ require 'rocket_cms/railtie'
48
+ require 'rocket_cms/controller'
49
+
50
+ module RocketCMS
51
+ module Models
52
+ autoload :Menu, 'rocket_cms/models/menu'
53
+ autoload :Page, 'rocket_cms/models/page'
54
+ autoload :News, 'rocket_cms/models/news'
55
+ autoload :ContactMessage, 'rocket_cms/models/contact_message'
56
+ end
57
+ end
@@ -0,0 +1,128 @@
1
+ module RocketCMS
2
+ class << self
3
+ def map_config
4
+ Proc.new {
5
+ active true
6
+ label I18n.t('rs.map')
7
+ field :address, :string
8
+ field :map_address, :string
9
+ field :map_hint, :string
10
+ field :coordinates, :string do
11
+ read_only true
12
+ end
13
+ field :lat
14
+ field :lon
15
+ }
16
+ end
17
+
18
+ def seo_config
19
+ Proc.new {
20
+ active false
21
+ label "SEO"
22
+ field :h1, :string
23
+ field :title, :string
24
+ field :keywords, :string
25
+ field :description, :string
26
+ field :robots, :string
27
+
28
+ field :og_title, :string
29
+ field :og_image
30
+ }
31
+ end
32
+
33
+ def page_config
34
+ Proc.new {
35
+ RocketCMS.apply_patches self
36
+ navigation_label I18n.t('rs.cms')
37
+ list do
38
+ field :enabled, :toggle
39
+ field :menus, :menu
40
+ field :name
41
+ field :fullpath do
42
+ pretty_value do
43
+ bindings[:view].content_tag(:a, bindings[:object].fullpath, href: bindings[:object].fullpath)
44
+ end
45
+ end
46
+ field :redirect
47
+ field :slug
48
+ RocketCMS.apply_patches self
49
+ end
50
+ edit do
51
+ field :name
52
+ field :content, :ck_editor
53
+ RocketCMS.apply_patches self
54
+ group :menu do
55
+ label I18n.t('rs.menu')
56
+ field :menus
57
+ field :fullpath, :string do
58
+ help I18n.t('rs.with_final_slash')
59
+ end
60
+ field :regexp, :string do
61
+ help I18n.t('rs.page_url_regex')
62
+ end
63
+ field :redirect, :string do
64
+ help I18n.t('rs.final_in_menu')
65
+ end
66
+ field :text_slug do
67
+ read_only true
68
+ end
69
+ end
70
+ group :seo, &RocketCMS.seo_config
71
+ end
72
+ RocketCMS.only_patches self, [:show, :export]
73
+ nested_set({
74
+ max_depth: RocketCMS.configuration.menu_max_depth
75
+ })
76
+ }
77
+ end
78
+
79
+ def menu_config
80
+ Proc.new {
81
+ navigation_label 'CMS'
82
+ field :text_slug
83
+ field :name
84
+ RocketCMS.apply_patches self
85
+ RocketCMS.only_patches self, [:show, :list, :edit, :export]
86
+ }
87
+ end
88
+
89
+ def contact_message_config
90
+ Proc.new {
91
+ navigation_label I18n.t('rs.settings')
92
+ field :c_at do
93
+ read_only true
94
+ end
95
+ field :name
96
+ field :content
97
+ field :email
98
+ field :phone
99
+
100
+ RocketCMS.apply_patches self
101
+ RocketCMS.only_patches self, [:show, :list, :edit, :export]
102
+ }
103
+ end
104
+
105
+ def news_config
106
+ Proc.new {
107
+ navigation_label I18n.t('rs.cms')
108
+
109
+ field :enabled, :toggle
110
+ field :time
111
+ field :name
112
+ unless RocketCMS.configuration.news_image_styles.nil?
113
+ field :image
114
+ end
115
+ field :excerpt
116
+ RocketCMS.apply_patches self
117
+
118
+ edit do
119
+ field :content, :ck_editor
120
+ RocketCMS.apply_patches self
121
+ group :seo, &RocketCMS.seo_config
122
+ end
123
+
124
+ RocketCMS.only_patches self, [:show, :list, :export]
125
+ }
126
+ end
127
+ end
128
+ end