Class: Sitemap
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Sitemap
- Defined in:
- app/models/sitemap.rb
Class Method Summary collapse
-
.find_by_path(*path_args) ⇒ Object
Private Methods.
-
.from_request_params(params) ⇒ Object
Class Methods.
- .lost_and_found ⇒ Object
- .main_menu ⇒ Object
- .new_main_menu_page(name) ⇒ Object
-
.reload_root ⇒ Object
Callbacks.
- .root ⇒ Object
- .settings ⇒ Object
Instance Method Summary collapse
- #as_json(*a) ⇒ Object
- #on_before_destroy ⇒ Object
- #reload_root ⇒ Object
- #resource_attributes=(attrib = {}) ⇒ Object
- #url ⇒ Object
Class Method Details
.find_by_path(*path_args) ⇒ Object
Private Methods
116 117 118 119 120 121 122 123 124 125 126 |
# File 'app/models/sitemap.rb', line 116 def self.find_by_path(*path_args) path_args.flatten! path = path_args.reverse path.delete(nil) obj = Sitemap. while (path_piece=path.pop) obj = obj.children.select{|t| t..downcase==path_piece.downcase.gsub(/_/, ' ')}[0] break unless obj end return obj end |
.from_request_params(params) ⇒ Object
Class Methods
83 84 85 86 |
# File 'app/models/sitemap.rb', line 83 def self.from_request_params(params) puts params.slice(:level1, :level2, :level3, :level4).values.inspect + "\n"*30 find_by_path params.slice(:level1, :level2, :level3, :level4).values end |
.lost_and_found ⇒ Object
88 89 90 |
# File 'app/models/sitemap.rb', line 88 def self.lost_and_found root.children.select{|t| t.=='Lost + Found'}[0] end |
.main_menu ⇒ Object
92 93 94 |
# File 'app/models/sitemap.rb', line 92 def self. root.children.select{|t| t.=='Main Menu'}[0] end |
.new_main_menu_page(name) ⇒ Object
100 101 102 103 104 105 |
# File 'app/models/sitemap.rb', line 100 def self.(name) Sitemap.create( :parent=>self., :menu_text=>name, :resource=>Page.create(:title=>name), :position=>Sitemap..children.count) end |
.reload_root ⇒ Object
Callbacks
58 59 60 |
# File 'app/models/sitemap.rb', line 58 def self.reload_root Sitemap.instance_variable_set('@_root', nil) end |
.root ⇒ Object
96 97 98 |
# File 'app/models/sitemap.rb', line 96 def self.root @_root ||= Sitemap.('root', nil) end |
.settings ⇒ Object
107 108 109 |
# File 'app/models/sitemap.rb', line 107 def self.settings root.children.select{|t| t.=='Settings'}[0] end |
Instance Method Details
#as_json(*a) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'app/models/sitemap.rb', line 20 def as_json(*a) { :position=>self.position, :data=>{ :title=>self., :icon=>icon_name, }, :attr=>{ :id=>"node_#{id}", :rel=>resource_type.underscore, :data_menu_text => self., :data_resource_type => self.resource_type, :data_resource_id => self.resource_id, :data_id => self.id }, :state=>treeview_state, :children=> children.sorted }.as_json(*a) end |
#on_before_destroy ⇒ Object
66 67 68 |
# File 'app/models/sitemap.rb', line 66 def on_before_destroy resource.destroy if resource && resource.sitemaps.size==1 end |
#reload_root ⇒ Object
62 63 64 |
# File 'app/models/sitemap.rb', line 62 def reload_root Sitemap.reload_root end |
#resource_attributes=(attrib = {}) ⇒ Object
40 41 42 43 44 45 |
# File 'app/models/sitemap.rb', line 40 def resource_attributes=(attrib={}) raise "Cant build resource without resource_type" if resource_type.empty? resource = create_resource resource.attributes = attrib resource.save end |
#url ⇒ Object
47 48 49 50 51 52 53 54 55 |
# File 'app/models/sitemap.rb', line 47 def url if self == Sitemap. '/' elsif resource.is_a? ExternalLink resource.url else %(#{(a=parent.url)=='/'?'':a}/#{.gsub(/ /, '_')}) end end |