Class: SimpleContentManagement::SimplePage

Inherits:
ActiveRecord::Base
  • Object
show all
Includes:
Breadcrumbs, ContentText
Defined in:
app/models/simple_content_management/simple_page.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from ContentText

#update_content_text, #update_content_text!

Class Method Details

.registered_content_pagesObject



63
64
65
# File 'app/models/simple_content_management/simple_page.rb', line 63

def registered_content_pages
	@registered_content_pages ||= YAML.load_file File.join Rails.root, "config", "content_pages.yml"
end

Instance Method Details

#destroyObject



50
51
52
# File 'app/models/simple_content_management/simple_page.rb', line 50

def destroy
	update_attribute :deleted, true
end

#labelObject



54
55
56
# File 'app/models/simple_content_management/simple_page.rb', line 54

def label
	title
end

#path_namesObject



46
47
48
# File 'app/models/simple_content_management/simple_page.rb', line 46

def path_names
	new_record? ? simple_routes.map(&:path) : simple_routes.active.pluck("path")
end

#reconstruct_breadcrumbsObject



58
59
60
# File 'app/models/simple_content_management/simple_page.rb', line 58

def reconstruct_breadcrumbs
	self.preferred_menu_item = simple_menu_items.first unless preferred_menu_item.present? || simple_menu_items.first.nil?
end

#simple_menu_itemsObject



13
14
15
# File 'app/models/simple_content_management/simple_page.rb', line 13

def simple_menu_items
	SimpleContentManagement::SimpleMenuItem.where(uri: path_names.map{ |path| "/#{path}.html" } + (path_names.include?("particulier") ? ["/"] : []))
end

#simple_routes_listObject



17
18
19
# File 'app/models/simple_content_management/simple_page.rb', line 17

def simple_routes_list
	path_names.join ","
end

#simple_routes_list=(routes_list) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'app/models/simple_content_management/simple_page.rb', line 21

def simple_routes_list=(routes_list)
	path_names = routes_list.split ","

	# destroy routes that are no longer required
	self.simple_routes.each do |simple_route|
		if path_names.include? simple_route.path
			path_names.delete simple_route.path
		else
			simple_route.destroy
		end
	end

	# ensure any existing routes are set active to the current page.
	if id.nil?
		SimpleContentManagement::SimpleRoute.where(path: path_names, deleted: false).update_all deleted: true
	else	
		SimpleContentManagement::SimpleRoute.where(path: path_names, deleted: false).where("simple_page_id <> ?", id).update_all deleted: true
	end

	# create the remaining routes
	path_names.each do |path_name|
		self.simple_routes.build path: path_name
	end
end