hancock_cms_pages 1.0.0 → 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/controllers/concerns/hancock/pages/blocksetable.rb +48 -14
- data/app/controllers/concerns/hancock/pages/localizeable.rb +5 -5
- data/app/controllers/concerns/hancock/pages/nav_menu.rb +10 -5
- data/app/controllers/concerns/hancock/pages/seo_pages.rb +3 -3
- data/app/helpers/hancock/pages/blocksets_helper.rb +26 -0
- data/app/helpers/hancock/pages/pages_helper.rb +11 -0
- data/app/models/concerns/hancock/pages/connectable.rb +1 -1
- data/app/views/blocks/_cached_blockset_navigation.html.slim +26 -0
- data/app/views/blocks/_cached_navigation.html.slim +26 -0
- data/app/views/blocks/_header.html.slim +9 -1
- data/app/views/hancock/pages/pages/show.html.slim +14 -1
- data/app/views/shared/_obj.html.slim +21 -25
- data/config/locales/hancock.pages.ru.yml +5 -0
- data/hancock_cms_pages.gemspec +3 -3
- data/lib/generators/hancock/pages/config/{install_generator.rb → config_generator.rb} +0 -0
- data/lib/generators/hancock/pages/config/templates/hancock_pages.erb +19 -6
- data/lib/generators/hancock/pages/controllers/decorators_generator.rb +24 -0
- data/lib/generators/hancock/pages/{migration_generator.rb → migrations/migrations_generator.rb} +3 -3
- data/lib/generators/hancock/pages/{templates → migrations/templates}/migration_blocks.rb +0 -0
- data/lib/generators/hancock/pages/{templates → migrations/templates}/migration_pages.rb +0 -0
- data/lib/generators/hancock/pages/models/templates/block.erb +5 -5
- data/lib/generators/hancock/pages/models/templates/blockset.erb +5 -5
- data/lib/generators/hancock/pages/models/templates/menu.erb +5 -5
- data/lib/generators/hancock/pages/models/templates/page.erb +7 -7
- data/lib/hancock/pages/admin.rb +35 -8
- data/lib/hancock/pages/admin/block.rb +14 -1
- data/lib/hancock/pages/admin/blockset.rb +34 -11
- data/lib/hancock/pages/admin/menu.rb +3 -1
- data/lib/hancock/pages/admin/page.rb +35 -5
- data/lib/hancock/pages/configuration.rb +28 -5
- data/lib/hancock/pages/controllers/pages.rb +10 -1
- data/lib/hancock/pages/engine.rb +59 -0
- data/lib/hancock/pages/models/active_record/blockset.rb +2 -1
- data/lib/hancock/pages/models/block.rb +234 -55
- data/lib/hancock/pages/models/blockset.rb +50 -38
- data/lib/hancock/pages/models/menu.rb +24 -15
- data/lib/hancock/pages/models/mongoid/block.rb +13 -0
- data/lib/hancock/pages/models/mongoid/blockset.rb +3 -0
- data/lib/hancock/pages/models/mongoid/menu.rb +4 -1
- data/lib/hancock/pages/models/mongoid/page.rb +19 -6
- data/lib/hancock/pages/models/page.rb +196 -90
- data/lib/hancock/pages/rails_admin_ext/hancock_connectable.rb +2 -0
- data/lib/hancock/pages/rails_admin_ext/menu.rb +11 -7
- data/lib/hancock/pages/version.rb +1 -1
- data/lib/hancock/pages/views_whitelist.rb +103 -0
- data/lib/hancock_cms_pages.rb +4 -6
- data/release.sh +1 -1
- metadata +19 -14
- data/app/helpers/hancock/pages/pages_helpers.rb +0 -2
@@ -5,6 +5,7 @@ module RailsAdmin
|
|
5
5
|
module Fields
|
6
6
|
module Types
|
7
7
|
class HancockConnectable < RailsAdmin::Config::Fields::Types::HasManyAssociation
|
8
|
+
|
8
9
|
RailsAdmin::Config::Fields::Types::register(self)
|
9
10
|
include RailsAdmin::Engine.routes.url_helpers
|
10
11
|
|
@@ -26,6 +27,7 @@ module RailsAdmin
|
|
26
27
|
scope.unconnected(me).enabled.sorted
|
27
28
|
end
|
28
29
|
end
|
30
|
+
|
29
31
|
end
|
30
32
|
end
|
31
33
|
end
|
@@ -12,15 +12,19 @@ module RailsAdmin
|
|
12
12
|
register_instance_option :pretty_value do
|
13
13
|
obj = bindings[:object]
|
14
14
|
ret = []
|
15
|
-
|
16
|
-
|
15
|
+
cache_opts = {}
|
16
|
+
unless ::Hancock::Pages.config.cache_support
|
17
|
+
cache_opts = {expires_in: 10.minutes}
|
18
|
+
end
|
19
|
+
menus = Rails.cache.fetch 'menus', cache_opts do
|
20
|
+
if ::Hancock.mongoid?
|
17
21
|
::Hancock::Pages::Menu.all.map { |m| {id: m.id.to_s, name: m.name } }
|
18
22
|
else
|
19
23
|
::Hancock::Pages::Menu.all.map { |m| {id: m.id, name: m.name } }
|
20
24
|
end
|
21
25
|
end
|
22
26
|
menus.each do |m|
|
23
|
-
if Hancock.mongoid?
|
27
|
+
if ::Hancock.mongoid?
|
24
28
|
on = obj.menu_ids.include?(BSON::ObjectId.from_string(m[:id]))
|
25
29
|
else
|
26
30
|
on = obj.menu_ids.include?(m[:id].to_i)
|
@@ -109,28 +113,28 @@ module RailsAdmin
|
|
109
113
|
end
|
110
114
|
else
|
111
115
|
if params['ajax'].present?
|
112
|
-
render
|
116
|
+
render plain: @object.errors.full_messages.join(', '), layout: false, status: 422
|
113
117
|
else
|
114
118
|
flash[:error] = @object.errors.full_messages.join(', ')
|
115
119
|
end
|
116
120
|
end
|
117
121
|
rescue Exception => e
|
118
122
|
if params['ajax'].present?
|
119
|
-
render
|
123
|
+
render plain: I18n.t('hancock.menu.error', err: e.to_s), status: 422
|
120
124
|
else
|
121
125
|
flash[:error] = I18n.t('hancock.menu.error', err: e.to_s)
|
122
126
|
end
|
123
127
|
end
|
124
128
|
else
|
125
129
|
if params['ajax'].present?
|
126
|
-
render
|
130
|
+
render plain: I18n.t('hancock.menu.no_id'), status: 422
|
127
131
|
else
|
128
132
|
flash[:error] = I18n.t('hancock.menu.no_id')
|
129
133
|
end
|
130
134
|
|
131
135
|
end
|
132
136
|
|
133
|
-
|
137
|
+
redirect_back(fallback_location: dashboard_path) unless params['ajax'].present?
|
134
138
|
end
|
135
139
|
end
|
136
140
|
|
@@ -0,0 +1,103 @@
|
|
1
|
+
module Hancock::Pages::ViewsWhitelist
|
2
|
+
|
3
|
+
def self.included(base)
|
4
|
+
|
5
|
+
class << base
|
6
|
+
def whitelist
|
7
|
+
Settings.hancock_pages_blocks_whitelist
|
8
|
+
end
|
9
|
+
def whitelist_obj
|
10
|
+
Settings.getnc(:hancock_pages_blocks_whitelist)
|
11
|
+
end
|
12
|
+
def whitelist_as_array(exclude_blacklist = false)
|
13
|
+
_list = whitelist.lines.map(&:strip).uniq
|
14
|
+
(exclude_blacklist ? (_list - blacklist_as_array) : _list)
|
15
|
+
end
|
16
|
+
def can_render_in_block?(path)
|
17
|
+
whitelist_as_array(true).include?(path)
|
18
|
+
end
|
19
|
+
|
20
|
+
def blacklist
|
21
|
+
Settings.ns('admin').hancock_pages_blocks_blacklist
|
22
|
+
end
|
23
|
+
def blacklist_obj
|
24
|
+
Settings.ns('admin').getnc(:hancock_pages_blocks_blacklist)
|
25
|
+
end
|
26
|
+
def blacklist_as_array
|
27
|
+
blacklist.lines.map(&:strip).uniq
|
28
|
+
end
|
29
|
+
|
30
|
+
def whitelist_human_names
|
31
|
+
Settings.hancock_pages_blocks_human_names
|
32
|
+
end
|
33
|
+
def whitelist_human_names_obj
|
34
|
+
Settings.getnc(:hancock_pages_blocks_human_names)
|
35
|
+
end
|
36
|
+
|
37
|
+
def format_virtual_path(virtual_path, is_partial = nil)
|
38
|
+
if virtual_path.is_a?(Hash)
|
39
|
+
virtual_path, is_partial = virtual_path[:virtual_path], virtual_path[:is_partial]
|
40
|
+
end
|
41
|
+
_virtual_path = virtual_path.clone
|
42
|
+
path_parts = _virtual_path.split("/")
|
43
|
+
is_partial = path_parts.last[0] == "_" if is_partial.nil?
|
44
|
+
if is_partial
|
45
|
+
fname = path_parts.pop
|
46
|
+
_virtual_path = (path_parts << fname[1..-1]).join("/")
|
47
|
+
end
|
48
|
+
_virtual_path
|
49
|
+
end
|
50
|
+
|
51
|
+
|
52
|
+
def whitelist_enum
|
53
|
+
# whitelist_as_array.map do |f|
|
54
|
+
(whitelist_as_array - blacklist_as_array).uniq.map do |f|
|
55
|
+
whitelist_human_names[f] ? ["#{whitelist_human_names[f]} (#{f})", f] : f
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
|
60
|
+
def add_view_in_whitelist(path = "", name = "")
|
61
|
+
if path.is_a?(Hash)
|
62
|
+
path, name = path[:path], path[:name]
|
63
|
+
end
|
64
|
+
return nil if path.blank?
|
65
|
+
path.strip!
|
66
|
+
current_whitelist_array = whitelist_as_array
|
67
|
+
ret = true
|
68
|
+
unless current_whitelist_array.include?(path)
|
69
|
+
ret = false
|
70
|
+
current_whitelist_array << path
|
71
|
+
whitelist_obj.update(raw: current_whitelist_array.join("\n"))
|
72
|
+
end
|
73
|
+
unless name.blank?
|
74
|
+
current_whitelist_human_names = whitelist_human_names
|
75
|
+
unless current_whitelist_human_names.keys.include?(path)
|
76
|
+
current_whitelist_human_names[path] = name
|
77
|
+
whitelist_human_names_obj.update(raw: current_whitelist_human_names.to_yaml)
|
78
|
+
end
|
79
|
+
end
|
80
|
+
return ret
|
81
|
+
end
|
82
|
+
|
83
|
+
def add_view_in_blacklist(path)
|
84
|
+
if path.is_a?(Hash)
|
85
|
+
path = path[:path]
|
86
|
+
end
|
87
|
+
return nil if path.blank?
|
88
|
+
path.strip!
|
89
|
+
current_blacklist_array = blacklist_as_array
|
90
|
+
ret = true
|
91
|
+
if current_blacklist_array.include?(path)
|
92
|
+
ret = false
|
93
|
+
current_blacklist_array << path
|
94
|
+
blacklist_obj.update(raw: current_blacklist_array.join("\n"))
|
95
|
+
end
|
96
|
+
return ret
|
97
|
+
end
|
98
|
+
|
99
|
+
end
|
100
|
+
|
101
|
+
end
|
102
|
+
|
103
|
+
end
|
data/lib/hancock_cms_pages.rb
CHANGED
@@ -1,13 +1,9 @@
|
|
1
|
-
# unless defined?(Hancock) && Hancock.respond_to?(:orm) && [:active_record, :mongoid].include?(Hancock.orm)
|
2
|
-
# puts "please use hancock_cms_mongoid or hancock_cms_activerecord"
|
3
|
-
# puts "also: please use hancock_cms_news_mongoid or hancock_cms_news_activerecord and not hancock_cms_news directly"
|
4
|
-
# exit 1
|
5
|
-
# end
|
6
|
-
|
7
1
|
require "hancock/pages/version"
|
8
2
|
require 'hancock/pages/engine'
|
9
3
|
require 'hancock/pages/configuration'
|
10
4
|
|
5
|
+
require "hancock/pages/views_whitelist"
|
6
|
+
|
11
7
|
require "hancock/pages/routes"
|
12
8
|
|
13
9
|
require 'hancock/pages/rails_admin_ext/hancock_connectable'
|
@@ -18,6 +14,8 @@ require 'simple-navigation'
|
|
18
14
|
module Hancock::Pages
|
19
15
|
include Hancock::Plugin
|
20
16
|
|
17
|
+
include Hancock::Pages::ViewsWhitelist
|
18
|
+
|
21
19
|
autoload :Admin, 'hancock/pages/admin'
|
22
20
|
module Admin
|
23
21
|
autoload :Page, 'hancock/pages/admin/page'
|
data/release.sh
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hancock_cms_pages
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alexander Kiseliev
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-04-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -44,20 +44,20 @@ dependencies:
|
|
44
44
|
requirements:
|
45
45
|
- - ">="
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version:
|
48
|
-
- - "
|
47
|
+
version: 1.0.2
|
48
|
+
- - "<"
|
49
49
|
- !ruby/object:Gem::Version
|
50
|
-
version:
|
50
|
+
version: 2.1.x
|
51
51
|
type: :runtime
|
52
52
|
prerelease: false
|
53
53
|
version_requirements: !ruby/object:Gem::Requirement
|
54
54
|
requirements:
|
55
55
|
- - ">="
|
56
56
|
- !ruby/object:Gem::Version
|
57
|
-
version:
|
58
|
-
- - "
|
57
|
+
version: 1.0.2
|
58
|
+
- - "<"
|
59
59
|
- !ruby/object:Gem::Version
|
60
|
-
version:
|
60
|
+
version: 2.1.x
|
61
61
|
- !ruby/object:Gem::Dependency
|
62
62
|
name: simple-navigation
|
63
63
|
requirement: !ruby/object:Gem::Requirement
|
@@ -72,7 +72,7 @@ dependencies:
|
|
72
72
|
- - ">="
|
73
73
|
- !ruby/object:Gem::Version
|
74
74
|
version: '0'
|
75
|
-
description:
|
75
|
+
description: hancock_cms_pages
|
76
76
|
email:
|
77
77
|
- dev@redrocks.pro
|
78
78
|
executables: []
|
@@ -97,8 +97,9 @@ files:
|
|
97
97
|
- app/controllers/concerns/hancock/pages/nav_menu.rb
|
98
98
|
- app/controllers/concerns/hancock/pages/seo_pages.rb
|
99
99
|
- app/controllers/hancock/pages/pages_controller.rb
|
100
|
+
- app/helpers/hancock/pages/blocksets_helper.rb
|
100
101
|
- app/helpers/hancock/pages/canonical_helper.rb
|
101
|
-
- app/helpers/hancock/pages/
|
102
|
+
- app/helpers/hancock/pages/pages_helper.rb
|
102
103
|
- app/models/concerns/hancock/pages/canonicalable.rb
|
103
104
|
- app/models/concerns/hancock/pages/connectable.rb
|
104
105
|
- app/models/concerns/hancock/pages/decorators/block.rb
|
@@ -109,6 +110,8 @@ files:
|
|
109
110
|
- app/models/hancock/pages/blockset.rb
|
110
111
|
- app/models/hancock/pages/menu.rb
|
111
112
|
- app/models/hancock/pages/page.rb
|
113
|
+
- app/views/blocks/_cached_blockset_navigation.html.slim
|
114
|
+
- app/views/blocks/_cached_navigation.html.slim
|
112
115
|
- app/views/blocks/_header.html.slim
|
113
116
|
- app/views/hancock/pages/pages/show.html.slim
|
114
117
|
- app/views/rails_admin/main/_hancock_connectable.html.slim
|
@@ -118,9 +121,12 @@ files:
|
|
118
121
|
- config/initializers/hancock_pages.rb
|
119
122
|
- config/locales/hancock.pages.ru.yml
|
120
123
|
- hancock_cms_pages.gemspec
|
121
|
-
- lib/generators/hancock/pages/config/
|
124
|
+
- lib/generators/hancock/pages/config/config_generator.rb
|
122
125
|
- lib/generators/hancock/pages/config/templates/hancock_pages.erb
|
123
|
-
- lib/generators/hancock/pages/
|
126
|
+
- lib/generators/hancock/pages/controllers/decorators_generator.rb
|
127
|
+
- lib/generators/hancock/pages/migrations/migrations_generator.rb
|
128
|
+
- lib/generators/hancock/pages/migrations/templates/migration_blocks.rb
|
129
|
+
- lib/generators/hancock/pages/migrations/templates/migration_pages.rb
|
124
130
|
- lib/generators/hancock/pages/models/block_generator.rb
|
125
131
|
- lib/generators/hancock/pages/models/blockset_generator.rb
|
126
132
|
- lib/generators/hancock/pages/models/decorators_generator.rb
|
@@ -130,8 +136,6 @@ files:
|
|
130
136
|
- lib/generators/hancock/pages/models/templates/blockset.erb
|
131
137
|
- lib/generators/hancock/pages/models/templates/menu.erb
|
132
138
|
- lib/generators/hancock/pages/models/templates/page.erb
|
133
|
-
- lib/generators/hancock/pages/templates/migration_blocks.rb
|
134
|
-
- lib/generators/hancock/pages/templates/migration_pages.rb
|
135
139
|
- lib/hancock/pages/admin.rb
|
136
140
|
- lib/hancock/pages/admin/block.rb
|
137
141
|
- lib/hancock/pages/admin/blockset.rb
|
@@ -156,6 +160,7 @@ files:
|
|
156
160
|
- lib/hancock/pages/rails_admin_ext/menu.rb
|
157
161
|
- lib/hancock/pages/routes.rb
|
158
162
|
- lib/hancock/pages/version.rb
|
163
|
+
- lib/hancock/pages/views_whitelist.rb
|
159
164
|
- lib/hancock_cms_pages.rb
|
160
165
|
- release.sh
|
161
166
|
homepage: https://github.com/red-rocks/hancock_cms_pages
|