hancock_cms_cache 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (52) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +9 -0
  3. data/.ruby-gemset +1 -0
  4. data/.ruby-version +1 -0
  5. data/Gemfile +4 -0
  6. data/README.md +35 -0
  7. data/Rakefile +2 -0
  8. data/app/assets/javascripts/hancock/rails_admin/plugins/cache.coffee +4 -0
  9. data/app/assets/javascripts/hancock/rails_admin/plugins/cache/custom/ui.coffee +0 -0
  10. data/app/assets/stylesheets/hancock/rails_admin/plugins/cache.sass +3 -0
  11. data/app/assets/stylesheets/hancock/rails_admin/plugins/cache/custom/theming.sass +0 -0
  12. data/app/controllers/concerns/hancock/cache/action.rb +58 -0
  13. data/app/controllers/concerns/hancock/cache/ajax_csrf.rb +25 -0
  14. data/app/controllers/concerns/hancock/cache/fragments.rb +34 -0
  15. data/app/controllers/concerns/hancock/cache/no_cache.rb +12 -0
  16. data/app/helpers/hancock/cache/cache_helper.rb +167 -0
  17. data/app/models/concerns/hancock/cache/cacheable.rb +164 -0
  18. data/app/models/concerns/hancock/cache/cleared_stack.rb +43 -0
  19. data/app/models/concerns/hancock/cache/decorators/fragment.rb +41 -0
  20. data/app/models/concerns/hancock/cache/loadable.rb +44 -0
  21. data/app/models/concerns/hancock/cache/snapshotable.rb +49 -0
  22. data/app/models/hancock/cache/fragment.rb +11 -0
  23. data/app/views/hancock/_assets.html.slim +24 -0
  24. data/app/views/layouts/application.html.slim +33 -0
  25. data/app/views/rails_admin/main/hancock_cache_global_clear.html.slim +25 -0
  26. data/bin/console +14 -0
  27. data/bin/setup +8 -0
  28. data/config/initializers/cache_detector.rb +53 -0
  29. data/config/initializers/hancock_cache.rb +7 -0
  30. data/config/locales/hancock.cache.ru.yml +59 -0
  31. data/hancock_cms_cache.gemspec +34 -0
  32. data/lib/generators/hancock/cache/config/config_generator.rb +13 -0
  33. data/lib/generators/hancock/cache/config/templates/hancock_cache.erb +14 -0
  34. data/lib/generators/hancock/cache/models/decorators_generator.rb +24 -0
  35. data/lib/generators/hancock/cache/models/fragment_generator.rb +39 -0
  36. data/lib/generators/hancock/cache/models/templates/fragment.erb +38 -0
  37. data/lib/hancock/cache/admin.rb +37 -0
  38. data/lib/hancock/cache/admin/fragment.rb +140 -0
  39. data/lib/hancock/cache/configuration.rb +38 -0
  40. data/lib/hancock/cache/engine.rb +20 -0
  41. data/lib/hancock/cache/models/fragment.rb +310 -0
  42. data/lib/hancock/cache/models/mongoid/fragment.rb +259 -0
  43. data/lib/hancock/cache/rails_admin_ext/hancock_cache_clear.rb +95 -0
  44. data/lib/hancock/cache/rails_admin_ext/hancock_cache_dump_snapshot.rb +92 -0
  45. data/lib/hancock/cache/rails_admin_ext/hancock_cache_global_clear.rb +74 -0
  46. data/lib/hancock/cache/rails_admin_ext/hancock_cache_restore_snapshot.rb +92 -0
  47. data/lib/hancock/cache/rails_admin_ext/hancock_touch.rb +95 -0
  48. data/lib/hancock/cache/rails_admin_settings_patch.rb +185 -0
  49. data/lib/hancock/cache/version.rb +5 -0
  50. data/lib/hancock_cms_cache.rb +34 -0
  51. data/release.sh +6 -0
  52. metadata +141 -0
@@ -0,0 +1,92 @@
1
+ require 'rails_admin/config/actions'
2
+
3
+ module RailsAdmin
4
+ module Config
5
+ module Actions
6
+ class HancockCacheRestoreSnapshot < Base
7
+ RailsAdmin::Config::Actions.register(self)
8
+
9
+ # Is the action acting on the root level (Example: /admin/contact)
10
+ register_instance_option :root? do
11
+ false
12
+ end
13
+
14
+ register_instance_option :collection? do
15
+ false
16
+ end
17
+
18
+ # Is the action on an object scope (Example: /admin/team/1/edit)
19
+ register_instance_option :member? do
20
+ true
21
+ end
22
+
23
+ register_instance_option :controller do
24
+ proc do
25
+ ajax_link = Proc.new do |fv, badge|
26
+ # can_edit_obj = can?(:edit, @object)
27
+ # render json: {
28
+ # text: fv.html_safe,
29
+ # href: hancock_cache_clear_path(model_name: @abstract_model, id: @object.id),
30
+ # class: 'label ' + badge,
31
+ # url: index_path(model_name: @abstract_model)
32
+ # }
33
+ end
34
+ if params['id'].present?
35
+ begin
36
+ @object = @abstract_model.model.unscoped.find(params['id'])
37
+ if @object.restore_snapshot!
38
+ if params['ajax'].present?
39
+ ajax_link.call('♻', 'label-success')
40
+ else
41
+ flash[:success] = I18n.t('admin.hancock_cache_restore_snapshot.restored', obj: @object)
42
+ end
43
+ else
44
+ if params['ajax'].present?
45
+ render plain: @object.errors.full_messages.join(', '), layout: false, status: 422
46
+ else
47
+ flash[:error] = @object.errors.full_messages.join(', ')
48
+ end
49
+ end
50
+ rescue Exception => e
51
+ if params['ajax'].present?
52
+ render plain: I18n.t('admin.hancock_cache_restore_snapshot.error', err: e.to_s), status: 422
53
+ else
54
+ flash[:error] = I18n.t('admin.hancock_cache_restore_snapshot.error', err: e.to_s)
55
+ end
56
+ end
57
+ else
58
+ if params['ajax'].present?
59
+ render plain: I18n.t('admin.hancock_cache_restore_snapshot.no_id'), status: 422
60
+ else
61
+ flash[:error] = I18n.t('admin.hancock_cache_restore_snapshot.no_id')
62
+ end
63
+ end
64
+
65
+ unless params['ajax'].present?
66
+ begin
67
+ fallback_location = index_path(model_name: @abstract_model, id: @object.id)
68
+ rescue
69
+ fallback_location = index_path(model_name: @abstract_model)
70
+ end
71
+ redirect_back(fallback_location: fallback_location)
72
+ end
73
+
74
+ end
75
+ end
76
+
77
+ register_instance_option :link_icon do
78
+ 'icon-print'
79
+ end
80
+
81
+ register_instance_option :pjax? do
82
+ false
83
+ end
84
+
85
+ register_instance_option :http_methods do
86
+ [:get]
87
+ end
88
+
89
+ end
90
+ end
91
+ end
92
+ end
@@ -0,0 +1,95 @@
1
+ require 'rails_admin/config/actions'
2
+
3
+ module RailsAdmin
4
+ module Config
5
+ module Actions
6
+ class HancockTouch < Base
7
+ RailsAdmin::Config::Actions.register(self)
8
+
9
+ # Is the action acting on the root level (Example: /admin/contact)
10
+ register_instance_option :root? do
11
+ false
12
+ end
13
+
14
+ register_instance_option :collection? do
15
+ false
16
+ end
17
+
18
+ # Is the action on an object scope (Example: /admin/team/1/edit)
19
+ register_instance_option :member? do
20
+ true
21
+ end
22
+
23
+ register_instance_option :controller do
24
+ proc do
25
+ ajax_link = Proc.new do |fv, badge|
26
+ # can_edit_obj = can?(:edit, @object)
27
+ # render json: {
28
+ # text: fv.html_safe,
29
+ # href: hancock_touch_path(model_name: @abstract_model, id: @object.id),
30
+ # class: 'label ' + badge,
31
+ # url: index_path(model_name: @abstract_model)
32
+ # }
33
+ end
34
+ if params['id'].present?
35
+ begin
36
+ @object = @abstract_model.model.unscoped.find(params['id'])
37
+ if @object.touch
38
+ if params['ajax'].present?
39
+ ajax_link.call('♻', 'label-success')
40
+ else
41
+ flash[:success] = I18n.t('admin.hancock_touch.touched', obj: @object)
42
+ end
43
+ else
44
+ if params['ajax'].present?
45
+ render plain: @object.errors.full_messages.join(', '), layout: false, status: 422
46
+ else
47
+ flash[:error] = @object.errors.full_messages.join(', ')
48
+ end
49
+ end
50
+ rescue Exception => e
51
+ if params['ajax'].present?
52
+ render plain: I18n.t('admin.hancock_touch.error', err: e.to_s), status: 422
53
+ else
54
+ flash[:error] = I18n.t('admin.hancock_touch.error', err: e.to_s)
55
+ end
56
+ end
57
+ else
58
+ if params['ajax'].present?
59
+ render plain: I18n.t('admin.hancock_touch.no_id'), status: 422
60
+ else
61
+ flash[:error] = I18n.t('admin.hancock_touch.no_id')
62
+ end
63
+ end
64
+
65
+ unless params['ajax'].present?
66
+ begin
67
+ redirect_back(fallback_location: dashboard_path)
68
+ rescue
69
+ begin
70
+ redirect_to index_path(model_name: @abstract_model, id: @object.id)
71
+ rescue
72
+ redirect_to index_path(model_name: @abstract_model)
73
+ end
74
+ end
75
+ end
76
+
77
+ end
78
+ end
79
+
80
+ register_instance_option :link_icon do
81
+ 'icon-refresh'
82
+ end
83
+
84
+ register_instance_option :pjax? do
85
+ false
86
+ end
87
+
88
+ register_instance_option :http_methods do
89
+ [:get]
90
+ end
91
+
92
+ end
93
+ end
94
+ end
95
+ end
@@ -0,0 +1,185 @@
1
+ module Hancock::Cache
2
+ module RailsAdminSettingsPatch
3
+ extend ActiveSupport::Concern
4
+
5
+ included do
6
+ include ::Hancock::Cache::Cacheable
7
+
8
+ def full_cached?
9
+ self.cache_keys.count > 0 and self.cache_keys.count == self.cache_fragments.enabled.count
10
+ end
11
+
12
+ def reset_loadable
13
+ self.loadable = !self.full_cached?
14
+ end
15
+ def reset_loadable!
16
+ self.reset_loadable
17
+ self.save
18
+ end
19
+ def self.reset_loadable!
20
+ self.all.map(&:reset_loadable!)
21
+ end
22
+
23
+ rails_admin do
24
+ navigation_label I18n.t('admin.settings.label')
25
+
26
+ list do
27
+ field :label do
28
+ visible false
29
+ searchable true
30
+ weight 1
31
+ end
32
+ field :enabled, :toggle do
33
+ weight 2
34
+ end
35
+ field :loadable, :toggle do
36
+ weight 3
37
+ end
38
+ field :ns do
39
+ searchable true
40
+ weight 4
41
+ end
42
+ field :key do
43
+ searchable true
44
+ weight 5
45
+ end
46
+ field :name do
47
+ weight 6
48
+ end
49
+ field :kind do
50
+ searchable true
51
+ weight 7
52
+ end
53
+ field :raw do
54
+ weight 8
55
+ searchable true
56
+ pretty_value do
57
+ if bindings[:object].file_kind?
58
+ "<a href='#{CGI::escapeHTML(bindings[:object].file.url)}'>#{CGI::escapeHTML(bindings[:object].to_path)}</a>".html_safe.freeze
59
+ elsif bindings[:object].image_kind?
60
+ "<a href='#{CGI::escapeHTML(bindings[:object].file.url)}'><img src='#{CGI::escapeHTML(bindings[:object].file.url)}' /></a>".html_safe.freeze
61
+ else
62
+ value
63
+ end
64
+ end
65
+ end
66
+ field :cache_keys_str, :text do
67
+ weight 9
68
+ searchable true
69
+ end
70
+ if ::Settings.table_exists?
71
+ nss = ::RailsAdminSettings::Setting.distinct(:ns).map { |c| "ns_#{c.gsub('-', '_')}".to_sym }
72
+ scopes([nil] + nss)
73
+ end
74
+ end
75
+
76
+ edit do
77
+ field :enabled, :toggle do
78
+ weight 1
79
+ visible do
80
+ if bindings[:object].for_admin?
81
+ render_object = (bindings[:controller] || bindings[:view])
82
+ render_object and (render_object.current_user.admin?)
83
+ else
84
+ true
85
+ end
86
+ end
87
+ end
88
+ field :loadable, :toggle do
89
+ weight 2
90
+ visible do
91
+ render_object = (bindings[:controller] || bindings[:view])
92
+ render_object and (render_object.current_user.admin?)
93
+ end
94
+ end
95
+ field :for_admin, :toggle do
96
+ weight 3
97
+ visible do
98
+ render_object = (bindings[:controller] || bindings[:view])
99
+ render_object and (render_object.current_user.admin?)
100
+ end
101
+ end
102
+ field :ns do
103
+ weight 4
104
+ read_only true
105
+ help false
106
+ visible do
107
+ render_object = (bindings[:controller] || bindings[:view])
108
+ render_object and (render_object.current_user.admin?)
109
+ end
110
+ end
111
+ field :key do
112
+ weight 5
113
+ read_only true
114
+ help false
115
+ visible do
116
+ render_object = (bindings[:controller] || bindings[:view])
117
+ render_object and (render_object.current_user.admin?)
118
+ end
119
+ end
120
+ field :label, :string do
121
+ weight 6
122
+ read_only do
123
+ render_object = (bindings[:controller] || bindings[:view])
124
+ !render_object or !(render_object.current_user.admin?)
125
+ end
126
+ help false
127
+ end
128
+ field :kind, :enum do
129
+ weight 7
130
+ read_only do
131
+ render_object = (bindings[:controller] || bindings[:view])
132
+ !render_object or !(render_object.current_user.admin?)
133
+ end
134
+ enum do
135
+ RailsAdminSettings.kinds
136
+ end
137
+ partial "enum_for_settings_kinds".freeze
138
+ help false
139
+ end
140
+ field :raw do
141
+ weight 8
142
+ partial "setting_value".freeze
143
+ visible do
144
+ !bindings[:object].upload_kind?
145
+ end
146
+ read_only do
147
+ if bindings[:object].for_admin?
148
+ render_object = (bindings[:controller] || bindings[:view])
149
+ !(render_object and (render_object.current_user.admin?))
150
+ else
151
+ false
152
+ end
153
+ end
154
+ end
155
+ if Settings.file_uploads_supported
156
+ field :file, Settings.file_uploads_engine do
157
+ weight 9
158
+ visible do
159
+ bindings[:object].upload_kind?
160
+ end
161
+ read_only do
162
+ if bindings[:object].for_admin?
163
+ render_object = (bindings[:controller] || bindings[:view])
164
+ !(render_object and (render_object.current_user.admin?))
165
+ else
166
+ false
167
+ end
168
+ end
169
+ end
170
+ end
171
+
172
+ group(:cache, &::Hancock::Cache::Admin.caching_block do |_group|
173
+ _group.visible do
174
+ render_object = (bindings[:controller] || bindings[:view])
175
+ render_object and render_object.current_user.admin?
176
+ end
177
+ end)
178
+
179
+ end
180
+ end
181
+
182
+ end
183
+
184
+ end
185
+ end
@@ -0,0 +1,5 @@
1
+ module Hancock
2
+ module Cache
3
+ VERSION = "1.0.2".freeze
4
+ end
5
+ end
@@ -0,0 +1,34 @@
1
+ require "hancock/cache/version"
2
+ require 'hancock/cache/engine'
3
+ require 'hancock/cache/configuration'
4
+
5
+ require 'hancock/cache/admin'
6
+
7
+ require 'hancock/cache/rails_admin_ext/hancock_cache_clear'
8
+ require 'hancock/cache/rails_admin_ext/hancock_cache_global_clear'
9
+ require 'hancock/cache/rails_admin_ext/hancock_cache_dump_snapshot'
10
+ require 'hancock/cache/rails_admin_ext/hancock_cache_restore_snapshot'
11
+ require 'hancock/cache/rails_admin_ext/hancock_touch'
12
+
13
+ require 'hancock/cache/rails_admin_settings_patch'
14
+
15
+ module Hancock::Cache
16
+ include Hancock::Plugin
17
+
18
+ autoload :Admin, 'hancock/cache/admin'
19
+ module Admin
20
+ autoload :Fragment, 'hancock/cache/admin/fragment'
21
+ end
22
+
23
+ module Models
24
+ autoload :Fragment, 'hancock/cache/models/fragment'
25
+
26
+ module Mongoid
27
+ autoload :Fragment, 'hancock/cache/models/mongoid/fragment'
28
+ end
29
+
30
+ # module ActiveRecord
31
+ # autoload :Fragment, 'hancock/cache/models/active_record/fragment'
32
+ # end
33
+ end
34
+ end
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/bash
2
+ bundle update
3
+ git add --all .
4
+ git commit -am "${*:1}"
5
+ git push -u origin master
6
+ rake release
metadata ADDED
@@ -0,0 +1,141 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: hancock_cms_cache
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Alexander Kiseliev
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-04-01 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.12'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.12'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: hancock_cms
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: 1.0.2
48
+ - - "<"
49
+ - !ruby/object:Gem::Version
50
+ version: 2.1.x
51
+ type: :runtime
52
+ prerelease: false
53
+ version_requirements: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ version: 1.0.2
58
+ - - "<"
59
+ - !ruby/object:Gem::Version
60
+ version: 2.1.x
61
+ description: hancock_cms_cache
62
+ email:
63
+ - dev@redrocks.pro
64
+ executables: []
65
+ extensions: []
66
+ extra_rdoc_files: []
67
+ files:
68
+ - ".gitignore"
69
+ - ".ruby-gemset"
70
+ - ".ruby-version"
71
+ - Gemfile
72
+ - README.md
73
+ - Rakefile
74
+ - app/assets/javascripts/hancock/rails_admin/plugins/cache.coffee
75
+ - app/assets/javascripts/hancock/rails_admin/plugins/cache/custom/ui.coffee
76
+ - app/assets/stylesheets/hancock/rails_admin/plugins/cache.sass
77
+ - app/assets/stylesheets/hancock/rails_admin/plugins/cache/custom/theming.sass
78
+ - app/controllers/concerns/hancock/cache/action.rb
79
+ - app/controllers/concerns/hancock/cache/ajax_csrf.rb
80
+ - app/controllers/concerns/hancock/cache/fragments.rb
81
+ - app/controllers/concerns/hancock/cache/no_cache.rb
82
+ - app/helpers/hancock/cache/cache_helper.rb
83
+ - app/models/concerns/hancock/cache/cacheable.rb
84
+ - app/models/concerns/hancock/cache/cleared_stack.rb
85
+ - app/models/concerns/hancock/cache/decorators/fragment.rb
86
+ - app/models/concerns/hancock/cache/loadable.rb
87
+ - app/models/concerns/hancock/cache/snapshotable.rb
88
+ - app/models/hancock/cache/fragment.rb
89
+ - app/views/hancock/_assets.html.slim
90
+ - app/views/layouts/application.html.slim
91
+ - app/views/rails_admin/main/hancock_cache_global_clear.html.slim
92
+ - bin/console
93
+ - bin/setup
94
+ - config/initializers/cache_detector.rb
95
+ - config/initializers/hancock_cache.rb
96
+ - config/locales/hancock.cache.ru.yml
97
+ - hancock_cms_cache.gemspec
98
+ - lib/generators/hancock/cache/config/config_generator.rb
99
+ - lib/generators/hancock/cache/config/templates/hancock_cache.erb
100
+ - lib/generators/hancock/cache/models/decorators_generator.rb
101
+ - lib/generators/hancock/cache/models/fragment_generator.rb
102
+ - lib/generators/hancock/cache/models/templates/fragment.erb
103
+ - lib/hancock/cache/admin.rb
104
+ - lib/hancock/cache/admin/fragment.rb
105
+ - lib/hancock/cache/configuration.rb
106
+ - lib/hancock/cache/engine.rb
107
+ - lib/hancock/cache/models/fragment.rb
108
+ - lib/hancock/cache/models/mongoid/fragment.rb
109
+ - lib/hancock/cache/rails_admin_ext/hancock_cache_clear.rb
110
+ - lib/hancock/cache/rails_admin_ext/hancock_cache_dump_snapshot.rb
111
+ - lib/hancock/cache/rails_admin_ext/hancock_cache_global_clear.rb
112
+ - lib/hancock/cache/rails_admin_ext/hancock_cache_restore_snapshot.rb
113
+ - lib/hancock/cache/rails_admin_ext/hancock_touch.rb
114
+ - lib/hancock/cache/rails_admin_settings_patch.rb
115
+ - lib/hancock/cache/version.rb
116
+ - lib/hancock_cms_cache.rb
117
+ - release.sh
118
+ homepage: https://github.com/red-rocks/hancock_cms_cache
119
+ licenses: []
120
+ metadata: {}
121
+ post_install_message:
122
+ rdoc_options: []
123
+ require_paths:
124
+ - lib
125
+ required_ruby_version: !ruby/object:Gem::Requirement
126
+ requirements:
127
+ - - ">="
128
+ - !ruby/object:Gem::Version
129
+ version: '0'
130
+ required_rubygems_version: !ruby/object:Gem::Requirement
131
+ requirements:
132
+ - - ">="
133
+ - !ruby/object:Gem::Version
134
+ version: '0'
135
+ requirements: []
136
+ rubyforge_project:
137
+ rubygems_version: 2.5.2
138
+ signing_key:
139
+ specification_version: 4
140
+ summary: hancock_cms_cache
141
+ test_files: []