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
|
# File 'app/models/pageable.rb', line 49
def page(name, path, options = {}, &block)
page_definition_options = options.clone
this_controller_name = "#{self.name.underscore}".gsub("_controller", "")
uid = "#{this_controller_name}##{name}"
parent_uid = if parent_opt = options.delete(:parent)
parent_opt = parent_opt.to_s
if parent_opt.include?("#")
parent_opt
else
"#{this_controller_name}##{parent_opt}"
end
end
resource_type = options.delete(:resource).try(:to_s)
i18n_scope = "pages.#{self.name.underscore.split('/').last}##{name}"
title = options.delete(:title) || I18n.t("#{i18n_scope}.title", :default => "#{name}".humanize)
if Page.table_exists?
page = Page.find_or_create_by_uid(uid, :title => title, :name => name)
if parent_uid
parent = Page.find_by_uid(parent_uid)
page.move_to_child_of(parent) unless page.parent == parent
end
if resource_type
page.update_attribute(:resource_type, resource_type) unless page.resource_type == resource_type
end
if page.path != path
page.update_attribute(:path, path)
end
end
map(name, path, options = {}, &block)
@pages ||= ActiveSupport::HashWithIndifferentAccess.new
@pages[name] = page
end
|