13
14
15
16
17
18
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
123
124
|
# File 'lib/mega_bar/mega_route.rb', line 13
def self.load(context)
routes = []
ases = []
MegaBar::Page.all.each do |pg|
MegaBar::Layout.by_page(pg.id).each do |llayout|
llayout.layout_sections.each do | layout_section |
MegaBar::Block.by_layout_section(layout_section.id).each do | block |
p = block.path_base? ? block.path_base : pg.path
if context.kind_of?(Array)
exclude = false
context.each do |c|
exclude = true if p.starts_with? c
end
next if exclude
else
if p.starts_with? context
p = p[context.size..-1]
else
next
end
end
path = ''
p1 = p.split('/')
p1.each do | seg |
next if (seg.empty? || seg.starts_with?(':'))
path += seg.singularize + '_'
end
path = path.chomp('_').pluralize
if block.html?
p = block.path_base? ? block.path_base : pg.path
routes << {path: p, method: 'get', controller: 'flats', action: 'index', as: 'flats_' + block.id.to_s}
else
if MegaBar::ModelDisplay.by_block(block.id).size > 0
begin
controller = MegaRoute.controller_from_block(context, block)
rescue
next
end
MegaBar::ModelDisplay.by_block(block.id).order(collection_or_member: :asc, action: :asc).each do | md |
modle = MegaBar::Model.find(md.model_id)
pf = ''
as = nil
concerns = nil
case md.action
when 'show'
pf = p + '/:id'
as = path.singularize
meth = 'get'
when 'index'
pf = p
as = path
concerns = 'paginatable'
meth = [:get]
when 'new'
pf = p + '/new'
as = 'new_' + path
meth = 'get'
when 'edit'
pf = p + '/:id/edit'
as = 'edit_' + path
meth = 'get'
else
pf = p.to_s + "/" + md.action.to_s
if md.collection_or_member == 'collection'
concerns = 'paginatable'
meth = [:get, :post]
end
end
route = {path: pf, method: meth, action: md.action, controller: controller}
route = route.merge({as: as}) if as
route = route.merge({concerns: concerns}) if concerns
routes << route
routes << {path: pf + '/filter', method: [:get, :post], action: md.action, controller: controller} if md.collection_or_member == 'collection'
end
routes << {path: p + '/move/:id', method: 'get', action: 'move', controller: controller }
routes << {path: p + '/:id', method: 'patch', action: 'update', controller: controller}
routes << {path: p, method: 'post', action: 'create', controller: controller}
routes << {path: p + '/:id', method: 'delete', action: 'destroy', controller: controller}
end
end
end
end
end
end
routes.uniq
rescue ActiveRecord::StatementInvalid
[]
end
|