class SBF::Client::Page
Attributes
id[R]
locked_at[RW]
locked_by_profile_id[RW]
lookup[RW]
may_edit[R]
title[RW]
title_tag[RW]
Public Instance Methods
add_draft_sections(sections)
click to toggle source
# File lib/stbaldricks/entities/page.rb, line 62 def add_draft_sections(sections) sections.each do |cid, data| # convert symbol to integer cid = cid.to_s.to_i content = published_content.find { |c| c.id == cid } update_draft_content_section(content, data, cid) unless content.nil? end end
draft_content()
click to toggle source
# File lib/stbaldricks/entities/page.rb, line 48 def draft_content content.select { |x| x.is_draft == true } end
editor_content()
click to toggle source
# File lib/stbaldricks/entities/page.rb, line 52 def editor_content published_content.map do |published| draft_content.find { |d| published.id == d.id } || published end end
lock_expired?(ttl = 300)
click to toggle source
# File lib/stbaldricks/entities/page.rb, line 58 def lock_expired?(ttl = 300) locked_at.nil? || Time.now >= Time.parse(locked_at) + ttl end
meta_content()
click to toggle source
# File lib/stbaldricks/entities/page.rb, line 35 def meta_content content.select { |x| x.type == SBF::Client::Page::Content::Type::META } end
published_content()
click to toggle source
# File lib/stbaldricks/entities/page.rb, line 39 def published_content # Sort content so meta type is at the bottom. This preserves order for rendering on page content.select { |x| x.is_draft == false }.sort! do |a, b| next b.type <=> a.type unless b.type == a.type a.sort_order <=> b.sort_order end end
Private Instance Methods
update_draft_content_section(content, data, cid)
click to toggle source
# File lib/stbaldricks/entities/page.rb, line 72 def update_draft_content_section(content, data, cid) # update or create draft version of content draft = draft_content.find { |d| d.id == cid } if draft.nil? self.content << SBF::Client::Page::Content.new(content.to_hash.merge(is_draft: true, title: data[:title], text: data[:text])) else draft.title = data[:title] draft.text = data[:text] end end