Class: Page
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Page
- Includes:
- Entity, Lockable, Postable
- Defined in:
- app/models/page.rb
Class Method Summary collapse
- .create_page(params) ⇒ Object
- .from_path(path) ⇒ Object
- .in_sitemap ⇒ Object
- .ordered ⇒ Object
- .preview_from_path(path) ⇒ Object
- .search(query) ⇒ Object
- .sitemap ⇒ Object
- .update_page(params) ⇒ Object
Instance Method Summary collapse
- #edit_url ⇒ Object
- #has_comments? ⇒ Boolean
- #in_sitemap? ⇒ Boolean
- #preview_url ⇒ Object
- #to_backup_entries ⇒ Object
- #url ⇒ Object
Class Method Details
.create_page(params) ⇒ Object
38 39 40 41 42 |
# File 'app/models/page.rb', line 38 def create_page(params) path = params[:path].downcase raise "Invalid path" unless path =~ /^[-_a-z0-9]+$/ Page.create :title => params[:title], :path => path, :content => params[:content], :locked => true end |
.from_path(path) ⇒ Object
88 89 90 91 92 |
# File 'app/models/page.rb', line 88 def from_path(path) page = posted.where(:path => path).first raise ActiveRecord::RecordNotFound.new("No page found!") unless page page end |
.in_sitemap ⇒ Object
74 75 76 |
# File 'app/models/page.rb', line 74 def in_sitemap where :in_sitemap => true end |
.ordered ⇒ Object
78 79 80 |
# File 'app/models/page.rb', line 78 def ordered order "pages.title ASC" end |
.preview_from_path(path) ⇒ Object
82 83 84 85 86 |
# File 'app/models/page.rb', line 82 def preview_from_path(path) page = where(:path => path).first raise ActiveRecord::RecordNotFound.new("No page found!") unless page page end |
.search(query) ⇒ Object
66 67 68 |
# File 'app/models/page.rb', line 66 def search(query) ordered.where "LOWER(title) LIKE :query OR LOWER(path) LIKE :query OR LOWER(content) LIKE :query", :query => "%#{query.downcase}%" end |
.sitemap ⇒ Object
70 71 72 |
# File 'app/models/page.rb', line 70 def sitemap posted.in_sitemap end |
.update_page(params) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'app/models/page.rb', line 44 def update_page(params) path = params[:path].downcase raise "Invalid path" unless path =~ /^[-_a-z0-9]+$/ page = Page.find params[:id].to_i page.ensure_unlocked! page.title = params[:title] page.path = path page.content = params[:content] page.locked = true page.comments = !!params[:comments] page.in_sitemap = !!params[:in_sitemap] if params[:posted] page.posted_at = Date.today else page.posted_at = nil end page.save! page end |
Instance Method Details
#edit_url ⇒ Object
25 26 27 |
# File 'app/models/page.rb', line 25 def edit_url "/admin/page/#{id}/edit" end |
#has_comments? ⇒ Boolean
29 30 31 |
# File 'app/models/page.rb', line 29 def has_comments? comments end |
#in_sitemap? ⇒ Boolean
33 34 35 |
# File 'app/models/page.rb', line 33 def in_sitemap? in_sitemap end |
#preview_url ⇒ Object
21 22 23 |
# File 'app/models/page.rb', line 21 def preview_url "/admin/page/#{path}/preview" end |
#to_backup_entries ⇒ Object
11 12 13 14 15 |
# File 'app/models/page.rb', line 11 def to_backup_entries page = Backup::Entry.new id, path, "markdown", content = Backup::Entry.new id, "#{path}.meta", "json", to_json(:except => :content) [page, ] end |
#url ⇒ Object
17 18 19 |
# File 'app/models/page.rb', line 17 def url "/#{path}" end |