releaf-content 0.2.1 → 1.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/LICENSE +19 -21
- data/app/assets/javascripts/{releaf/controllers → controllers}/releaf/content/nodes.js +0 -0
- data/app/assets/stylesheets/{releaf/controllers → controllers}/releaf/content/nodes.scss +0 -0
- data/app/builders/releaf/content/builders/action_dialog.rb +9 -1
- data/app/builders/releaf/content/builders/tree.rb +1 -1
- data/app/builders/releaf/content/content_type_dialog_builder.rb +2 -2
- data/app/builders/releaf/content/nodes/form_builder.rb +3 -3
- data/app/builders/releaf/content/nodes/index_builder.rb +1 -1
- data/app/builders/releaf/content/nodes/toolbox_builder.rb +0 -5
- data/app/controllers/releaf/content/nodes_controller.rb +109 -129
- data/app/middleware/releaf/content/routes_reloader.rb +12 -4
- data/app/services/releaf/content/node/copy.rb +90 -0
- data/app/services/releaf/content/node/move.rb +21 -0
- data/app/services/releaf/content/node/save_under_parent.rb +22 -0
- data/app/services/releaf/content/node/service.rb +17 -0
- data/app/validators/releaf/content/node/singleness_validator.rb +1 -24
- data/lib/releaf-content.rb +85 -6
- data/lib/releaf/content/acts_as_node.rb +0 -5
- data/lib/releaf/content/acts_as_node/active_record/acts/node.rb +2 -8
- data/lib/releaf/content/configuration.rb +61 -0
- data/lib/releaf/content/engine.rb +1 -34
- data/lib/releaf/content/node.rb +30 -101
- data/lib/releaf/content/node_mapper.rb +28 -2
- data/lib/releaf/content/route.rb +37 -25
- data/spec/builders/content/nodes/action_dialog_spec.rb +39 -0
- data/spec/builders/content/nodes/form_builder_spec.rb +47 -3
- data/spec/builders/content/nodes/toolbox_builder_spec.rb +1 -32
- data/spec/controllers/releaf/content/nodes_controller_spec.rb +42 -11
- data/spec/features/nodes_services_spec.rb +207 -0
- data/spec/features/nodes_spec.rb +328 -30
- data/spec/lib/releaf/content/acts_as_node_spec.rb +4 -32
- data/spec/lib/releaf/content/configuration_spec.rb +159 -0
- data/spec/lib/releaf/content/engine_spec.rb +149 -0
- data/spec/lib/releaf/content/node_spec.rb +66 -324
- data/spec/lib/releaf/content/route_spec.rb +223 -34
- data/spec/middleware/routes_reloader_spec.rb +62 -14
- data/spec/routing/node_mapper_spec.rb +223 -55
- data/spec/services/releaf/content/node/copy_spec.rb +115 -0
- data/spec/services/releaf/content/node/move_spec.rb +20 -0
- data/spec/services/releaf/content/node/save_under_parent_spec.rb +49 -0
- data/spec/services/releaf/content/node/service_spec.rb +19 -0
- metadata +38 -21
- data/app/builders/releaf/content/go_to_dialog_builder.rb +0 -9
- data/app/views/releaf/content/nodes/go_to_dialog.ruby +0 -1
- data/lib/releaf/content/builders_autoload.rb +0 -18
- data/releaf-content.gemspec +0 -20
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a92a25dd1de2d98500cd222715e05dd21e94cb18
|
4
|
+
data.tar.gz: a7848332149b045a748fc54c0902b196bdd5fa78
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 88f2a678dd20c27235a12788e5b35df3472afc85770592b60f89fed4b4ce1986351b7ed1309228e02eeac60cd56cefe4b02c21dd4c20fe9e22d6baa9cdf8012b
|
7
|
+
data.tar.gz: c80f6a024ac41fccc540b88259485ddc7afd94dc40bba9e640aed34ce62926629156e19ab8225b18280b0c1c21984249ad44ce768c7b07e4cf5c7ce3cded7152
|
data/LICENSE
CHANGED
@@ -1,24 +1,22 @@
|
|
1
1
|
Copyright (c) 2012, CubeSystems <info@cubesystems.lv>
|
2
|
-
All rights reserved.
|
3
2
|
|
4
|
-
|
5
|
-
modification, are permitted provided that the following conditions are met:
|
6
|
-
* Redistributions of source code must retain the above copyright
|
7
|
-
notice, this list of conditions and the following disclaimer.
|
8
|
-
* Redistributions in binary form must reproduce the above copyright
|
9
|
-
notice, this list of conditions and the following disclaimer in the
|
10
|
-
documentation and/or other materials provided with the distribution.
|
11
|
-
* Neither the name of the CubeSystems nor the names of its contributors may
|
12
|
-
be used to endorse or promote products derived from this software without
|
13
|
-
specific prior written permission.
|
3
|
+
MIT License
|
14
4
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
File without changes
|
File without changes
|
@@ -53,8 +53,16 @@ module Releaf::Content::Builders
|
|
53
53
|
super << confirm_button
|
54
54
|
end
|
55
55
|
|
56
|
+
def confirm_button_text
|
57
|
+
t(action.to_s.humanize)
|
58
|
+
end
|
59
|
+
|
60
|
+
def confirm_button_attributes
|
61
|
+
{class: "primary", type: "submit", data: { type: 'ok', disable: true}}
|
62
|
+
end
|
63
|
+
|
56
64
|
def confirm_button
|
57
|
-
button(
|
65
|
+
button(confirm_button_text, "check", confirm_button_attributes)
|
58
66
|
end
|
59
67
|
end
|
60
68
|
end
|
@@ -56,7 +56,7 @@ module Releaf::Content::Builders
|
|
56
56
|
def tree_resource_collapser(resource, expanded)
|
57
57
|
return if resource.children.empty?
|
58
58
|
tag(:div, class: "collapser-cell") do
|
59
|
-
button(nil, (expanded ? 'chevron-down' : 'chevron-right'), class: %w(secondary collapser trigger), title: t(expanded ? "
|
59
|
+
button(nil, (expanded ? 'chevron-down' : 'chevron-right'), class: %w(secondary collapser trigger), title: t(expanded ? "Collapse" : "Expand"))
|
60
60
|
end
|
61
61
|
end
|
62
62
|
|
@@ -54,7 +54,7 @@ module Releaf::Content
|
|
54
54
|
end
|
55
55
|
|
56
56
|
def content_type_item(content_type)
|
57
|
-
url = url_for(controller:
|
57
|
+
url = url_for(controller: controller.controller_path, action: "new", parent_id: params[:parent_id], content_type: content_type.name)
|
58
58
|
tag(:li) do
|
59
59
|
link_to(I18n.t(content_type.name.underscore, scope: 'admin.content_types'), url)
|
60
60
|
end
|
@@ -68,7 +68,7 @@ module Releaf::Content
|
|
68
68
|
end
|
69
69
|
|
70
70
|
def section_header_text
|
71
|
-
t("
|
71
|
+
t("Create new resource")
|
72
72
|
end
|
73
73
|
end
|
74
74
|
end
|
@@ -54,7 +54,7 @@ module Releaf::Content::Nodes
|
|
54
54
|
end
|
55
55
|
|
56
56
|
def render_slug
|
57
|
-
url = url_for(controller:
|
57
|
+
url = url_for(controller: controller.controller_path, action: "generate_url", parent_id: object.parent_id, id: object.id)
|
58
58
|
input = {
|
59
59
|
data: {'generator-url' => url}
|
60
60
|
}
|
@@ -90,13 +90,13 @@ module Releaf::Content::Nodes
|
|
90
90
|
end
|
91
91
|
|
92
92
|
def slug_base_url
|
93
|
-
"#{request.protocol}#{request.host_with_port}#{object.parent.try(:path)}/"
|
93
|
+
"#{request.protocol}#{request.host_with_port}#{object.parent.try(:path)}" + (object.trailing_slash_for_path? ? "" : "/")
|
94
94
|
end
|
95
95
|
|
96
96
|
def slug_link
|
97
97
|
link_to(object.path) do
|
98
98
|
safe_join do
|
99
|
-
[slug_base_url, tag(:span, object.slug),
|
99
|
+
[slug_base_url, tag(:span, object.slug), (object.trailing_slash_for_path? ? "/" : "")]
|
100
100
|
end
|
101
101
|
end
|
102
102
|
end
|
@@ -5,7 +5,6 @@ module Releaf::Content::Nodes
|
|
5
5
|
|
6
6
|
unless resource.new_record?
|
7
7
|
list << add_child_button
|
8
|
-
list << go_to_button unless params[:context] == "index"
|
9
8
|
list << copy_button
|
10
9
|
list << move_button
|
11
10
|
end
|
@@ -17,10 +16,6 @@ module Releaf::Content::Nodes
|
|
17
16
|
button(t('Add child'), nil, class: "ajaxbox", href: url_for(action: "content_type_dialog", parent_id: resource.id))
|
18
17
|
end
|
19
18
|
|
20
|
-
def go_to_button
|
21
|
-
button(t('Go to'), nil, class: "ajaxbox", href: url_for(action: "go_to_dialog"))
|
22
|
-
end
|
23
|
-
|
24
19
|
def copy_button
|
25
20
|
button(t('Copy'), nil, class: "ajaxbox", href: url_for(action: "copy_dialog", id: resource.id))
|
26
21
|
end
|
@@ -1,166 +1,146 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
respond_to :json, only: [:create, :update, :copy, :move]
|
1
|
+
class Releaf::Content::NodesController < Releaf::ActionController
|
2
|
+
respond_to :json, only: [:create, :update, :copy, :move]
|
4
3
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
end
|
9
|
-
|
10
|
-
def generate_url
|
11
|
-
tmp_resource = prepare_resource
|
12
|
-
tmp_resource.name = params[:name]
|
13
|
-
tmp_resource.reasign_slug
|
14
|
-
|
15
|
-
respond_to do |format|
|
16
|
-
format.js { render text: tmp_resource.slug }
|
17
|
-
end
|
18
|
-
end
|
4
|
+
def features
|
5
|
+
super - [:create_another, :search]
|
6
|
+
end
|
19
7
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
end
|
8
|
+
def generate_url
|
9
|
+
tmp_resource = prepare_resource
|
10
|
+
tmp_resource.name = params[:name]
|
11
|
+
tmp_resource.reasign_slug
|
25
12
|
|
26
|
-
|
27
|
-
|
13
|
+
respond_to do |format|
|
14
|
+
format.js { render text: tmp_resource.slug }
|
28
15
|
end
|
16
|
+
end
|
29
17
|
|
30
|
-
|
31
|
-
|
18
|
+
def content_type_dialog
|
19
|
+
@content_types = resource_class.valid_node_content_classes(params[:parent_id]).sort do |a, b|
|
20
|
+
I18n.t(a.name.underscore, scope: 'admin.content_types') <=> I18n.t(b.name.underscore, scope: 'admin.content_types')
|
32
21
|
end
|
22
|
+
end
|
33
23
|
|
34
|
-
|
35
|
-
|
36
|
-
|
24
|
+
def copy_dialog
|
25
|
+
copy_move_dialog_common
|
26
|
+
end
|
37
27
|
|
38
|
-
|
39
|
-
|
40
|
-
|
28
|
+
def move_dialog
|
29
|
+
copy_move_dialog_common
|
30
|
+
end
|
41
31
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
end
|
32
|
+
def copy
|
33
|
+
copy_move_common do |resource|
|
34
|
+
resource.copy params[:new_parent_id]
|
46
35
|
end
|
36
|
+
end
|
47
37
|
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
end
|
38
|
+
def move
|
39
|
+
copy_move_common do |resource|
|
40
|
+
resource.move params[:new_parent_id]
|
52
41
|
end
|
42
|
+
end
|
53
43
|
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
render layout: nil
|
60
|
-
end
|
61
|
-
end
|
44
|
+
# override base_controller method for adding content tree ancestors
|
45
|
+
# to breadcrumbs
|
46
|
+
def add_resource_breadcrumb(resource)
|
47
|
+
ancestor_nodes(resource).each do |node|
|
48
|
+
@breadcrumbs << { name: node, url: url_for( action: :edit, id: node.id ) }
|
62
49
|
end
|
50
|
+
super
|
51
|
+
end
|
63
52
|
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
ancestors += [resource.parent]
|
72
|
-
end
|
73
|
-
else
|
74
|
-
ancestors = resource.ancestors
|
75
|
-
end
|
76
|
-
|
77
|
-
ancestors.each do |ancestor|
|
78
|
-
@breadcrumbs << { name: ancestor, url: url_for( action: :edit, id: ancestor.id ) }
|
79
|
-
end
|
80
|
-
|
81
|
-
super
|
53
|
+
def ancestor_nodes(resource)
|
54
|
+
if resource.persisted?
|
55
|
+
resource.ancestors.reorder(:depth)
|
56
|
+
elsif resource.new_record? && resource.parent
|
57
|
+
resource.parent.ancestors.reorder(:depth) + [resource.parent]
|
58
|
+
else
|
59
|
+
[]
|
82
60
|
end
|
61
|
+
end
|
83
62
|
|
84
|
-
|
85
|
-
|
86
|
-
|
63
|
+
def self.resource_class
|
64
|
+
# find first key in content resources config that has this class as controller
|
65
|
+
model_class_name = Releaf::Content.resources.find{|_model_name, options| options[:controller] == name }.first
|
66
|
+
model_class_name.constantize
|
67
|
+
end
|
87
68
|
|
88
|
-
|
69
|
+
protected
|
89
70
|
|
90
|
-
|
91
|
-
|
92
|
-
|
71
|
+
def prepare_index
|
72
|
+
@collection = resource_class.roots
|
73
|
+
end
|
93
74
|
|
94
|
-
|
75
|
+
private
|
95
76
|
|
96
|
-
|
97
|
-
|
77
|
+
def copy_move_common
|
78
|
+
@resource = resource_class.find(params[:id])
|
98
79
|
|
99
|
-
|
100
|
-
|
101
|
-
|
80
|
+
if params[:new_parent_id].nil?
|
81
|
+
@resource.errors.add(:base, 'parent not selected')
|
82
|
+
respond_with(@resource)
|
83
|
+
else
|
84
|
+
begin
|
85
|
+
@resource = yield(@resource)
|
86
|
+
rescue ActiveRecord::RecordInvalid => e
|
87
|
+
respond_with(e.record)
|
102
88
|
else
|
103
|
-
|
104
|
-
|
105
|
-
rescue ActiveRecord::RecordInvalid => e
|
106
|
-
respond_with(e.record)
|
107
|
-
else
|
108
|
-
resource_class.updated
|
109
|
-
respond_with(@resource, redirect: true, location: url_for(action: :index))
|
110
|
-
end
|
89
|
+
resource_class.updated
|
90
|
+
respond_with(@resource, redirect: true, location: url_for(action: :index))
|
111
91
|
end
|
112
92
|
end
|
93
|
+
end
|
113
94
|
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
95
|
+
def action_responders
|
96
|
+
super.merge(
|
97
|
+
copy: Releaf::Responders::AfterSaveResponder,
|
98
|
+
move: Releaf::Responders::AfterSaveResponder
|
99
|
+
)
|
100
|
+
end
|
120
101
|
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
102
|
+
def copy_move_dialog_common
|
103
|
+
@resource = resource_class.find params[:id]
|
104
|
+
@collection = resource_class.roots
|
105
|
+
end
|
125
106
|
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
end
|
107
|
+
def prepare_resource
|
108
|
+
if params[:id]
|
109
|
+
resource_class.find(params[:id])
|
110
|
+
elsif params[:parent_id].present?
|
111
|
+
parent = resource_class.find(params[:parent_id])
|
112
|
+
parent.children.new
|
113
|
+
else
|
114
|
+
resource_class.new
|
135
115
|
end
|
116
|
+
end
|
136
117
|
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
118
|
+
def new_resource
|
119
|
+
super
|
120
|
+
@resource.content_type = node_content_class.name
|
121
|
+
@resource.parent_id = params[:parent_id]
|
122
|
+
@resource.item_position ||= resource_class.children_max_item_position(@resource.parent) + 1
|
142
123
|
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
end
|
124
|
+
if node_content_class < ActiveRecord::Base
|
125
|
+
@resource.build_content
|
126
|
+
@resource.content_id_will_change!
|
147
127
|
end
|
128
|
+
end
|
148
129
|
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
130
|
+
# Returns valid content type class
|
131
|
+
def node_content_class
|
132
|
+
raise ArgumentError, "invalid content_type" unless ActsAsNode.classes.include? params[:content_type]
|
133
|
+
params[:content_type].constantize
|
134
|
+
end
|
154
135
|
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
136
|
+
def permitted_params
|
137
|
+
list = super
|
138
|
+
list += [{content_attributes: permitted_content_attributes}]
|
139
|
+
list -= %w[content_type]
|
140
|
+
list
|
141
|
+
end
|
161
142
|
|
162
|
-
|
163
|
-
|
164
|
-
end
|
143
|
+
def permitted_content_attributes
|
144
|
+
@resource.content_class.acts_as_node_params if @resource.content_class.respond_to? :acts_as_node_params
|
165
145
|
end
|
166
146
|
end
|
@@ -6,20 +6,28 @@ module Releaf::Content
|
|
6
6
|
end
|
7
7
|
|
8
8
|
def call(env)
|
9
|
-
self.class.
|
9
|
+
self.class.reload_if_needed
|
10
10
|
@app.call(env)
|
11
11
|
end
|
12
12
|
|
13
|
+
def self.reset!
|
14
|
+
@updated_at = nil
|
15
|
+
end
|
16
|
+
|
13
17
|
def self.routes_loaded
|
14
18
|
@updated_at = Time.now
|
15
19
|
end
|
16
20
|
|
17
|
-
def self.
|
18
|
-
|
19
|
-
return unless ::Node.updated_at.present? && @updated_at && @updated_at < ::Node.updated_at
|
21
|
+
def self.reload_if_needed
|
22
|
+
return unless needs_reload?
|
20
23
|
Rails.application.reload_routes!
|
21
24
|
routes_loaded
|
22
25
|
end
|
23
26
|
|
27
|
+
def self.needs_reload?
|
28
|
+
Releaf::Content.models.any? do | node_class |
|
29
|
+
node_class.updated_at.present? && (@updated_at.nil? || @updated_at < node_class.updated_at)
|
30
|
+
end
|
31
|
+
end
|
24
32
|
end
|
25
33
|
end
|