19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
|
# File 'lib/fabulator/radiant/actions/page.rb', line 19
def run(context, autovivify = false)
@context.with(context) do |ctx|
parents = self.parent(ctx)
if parents.nil? || parents.empty? parents = self.select(ctx)
end
if parents.nil? || parents.empty? parents = [ ctx.root.anon_node('/') ]
end
parents = parents.collect{ |pp| pp.to([ Fabulator::RADIANT_NS, 'page' ], ctx) } - [ nil ]
return [] if parents.empty?
s = self.slug(ctx).first
return [] if s.nil? && !self.has_select?
using_children = false
if s.nil?
s = parents.first
else
using_children = true
s = s.to_s
end
ctx.set_scoped_info('radiant/page/parts', { })
self.run_actions(ctx)
page_parts_info = ctx.get_scoped_info('radiant/page/parts')
parents.each do |page_id|
page = ::Page.find(page_id.value)
child = nil
if using_children
child = page.children.select{ |c| c.slug == s }.first
if child.nil?
child = page.class.new_with_defaults()
child.slug = s
child.parent_id = page.id
end
else
child = page
end
begin
child.status = Status[self.status(ctx).first.to_s]
rescue
end
begin
child.description = self.description(ctx).first.to_s
rescue
end
begin
child.title = self.title(ctx).first.to_s
rescue
end
begin
child.breadcrumb = self.breadcrumb(ctx).first.to_s || child.title
rescue
child.breadcrumb = child.title
end
if child.breadcrumb.nil? || child.breadcrumb == ''
child.breadcrumb = child.title
end
child.class_name = child.class.name
page_parts_info.each_pair do |part_name, part_info|
part = child.part(part_name)
if part.nil?
part = ::PagePart.new(:name => part_name)
end
if part_info[:filter]
part.filter_id = part_info[:filter]
end
part.content = part_info[:content]
if !child.has_part?(part_name)
child.parts.concat part
end
end
child.save!
child.parts.each do |part|
if part.content.nil?
part.content = ''
part.save
end
end
end
end
[] end
|