Class: OnlineDocumentSection

Inherits:
WebsiteSection show all
Defined in:
app/models/online_document_section.rb

Constant Summary

Constants inherited from WebsiteSection

WebsiteSection::KNIT_KIT_ROOT, WebsiteSection::WEBSITE_SECTIONS_TEMP_LAYOUT_PATH

Instance Method Summary collapse

Methods inherited from WebsiteSection

#articles, #child_by_path, #children_in_menu, #create_layout, #display_in_menu?, #get_published_layout, #get_tags, #get_topics, #iid, #is_blog?, #is_document_section?, #is_section?, #is_secured?, #paths, #positioned_children, register_type, #render_base_layout?, #secure, #should_generate_new_friendly_id?, #type, #update_path!, #website

Instance Method Details

#build_section_hashObject



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'app/models/online_document_section.rb', line 52

def build_section_hash
  {
      :name => self.title,
      :has_layout => false,
      :use_markdown => self.use_markdown,
      :type => self.class.to_s,
      :in_menu => self.in_menu,
      :path => self.path,
      :permalink => self.permalink,
      :internal_identifier => self.internal_identifier,
      :position => self.position,
      :online_document_sections => self.children.each.map { |child| child.build_section_hash },
      :articles => [],
      :documented_item => {
          :name => documented_item_content.title,
          :display_title => documented_item_content.display_title,
          :internal_identifier => documented_item_content.internal_identifier
      }
  }
end

#copy(title = nil, copy_children = false, created_by = nil) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'app/models/online_document_section.rb', line 18

def copy(title=nil, copy_children=false, created_by=nil)
  new_section = OnlineDocumentSection.new

  new_section.title = title.nil? ? self.title : title
  new_section.layout = self.layout
  new_section.in_menu = self.in_menu
  new_section.use_markdown = self.use_markdown
  new_section.render_base_layout = self.render_base_layout
  new_section.website_id = self.website_id

  new_section.save!

  # copy documented content
  documented_item = DocumentedItem.where('online_document_section_id = ?', self.id).first
  documented_content = DocumentedContent.find(documented_item.documented_content_id)
  new_documented_content = documented_content.dup

  # clear out internal identifier
  new_documented_content.internal_identifier = nil

  new_documented_content.created_by = created_by
  new_documented_content.save!
  DocumentedItem.create!(:documented_content_id => new_documented_content.id, :online_document_section_id => new_section.id)

  if copy_children
    self.children.each do |child_section|
      new_child_section = child_section.copy(nil, copy_children, created_by)
      new_child_section.move_to_child_of(new_section)
    end
  end

  new_section
end

#documented_item_content_htmlObject



6
7
8
9
10
# File 'app/models/online_document_section.rb', line 6

def documented_item_content_html
  documented_item_content.body_html
rescue
  nil
end

#documented_item_published_content_html(active_publication) ⇒ Object



12
13
14
15
16
# File 'app/models/online_document_section.rb', line 12

def documented_item_published_content_html(active_publication)
  documented_item_published_content(active_publication).body_html
rescue
  nil
end