Class: Confluence::Page

Inherits:
Record
  • Object
show all
Extended by:
Findable
Defined in:
lib/confluence/page.rb

Defined Under Namespace

Classes: Details, DetailsCollection

Constant Summary

INVALID_TITLE_CHARS =
":@/\\|^#;[]{}<>"

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (Page) initialize(hash)

Returns a new instance of Page



75
76
77
78
79
# File 'lib/confluence/page.rb', line 75

def initialize(hash)
  super(hash)

  @details = DetailsCollection.new(content)
end

Instance Attribute Details

- (Object) details

Returns the value of attribute details



73
74
75
# File 'lib/confluence/page.rb', line 73

def details
  @details
end

Instance Method Details

- (Object) add_attachment(filename, content_type, data = IO.read(filename), comment = "")



124
125
126
127
128
# File 'lib/confluence/page.rb', line 124

def add_attachment(filename, content_type, data = IO.read(filename), comment = "")
  attachment = Attachment.new :pageId => page_id, :fileName => filename, :contentType => content_type, :comment => comment
  attachment.data = data
  attachment.store
end

- (Object) attachments



86
87
88
89
# File 'lib/confluence/page.rb', line 86

def attachments
  attachments = client.getAttachments(page_id)
  attachments.collect { |hash| Attachment.new(hash) } if attachments
end

- (Object) children(klass = self.class)



81
82
83
84
# File 'lib/confluence/page.rb', line 81

def children(klass = self.class)
  children = client.getChildren(page_id)
  children.collect { |hash| klass.find(:id => hash["id"]) } if children
end

- (Object) remove



120
121
122
# File 'lib/confluence/page.rb', line 120

def remove
  client.removePage(page_id)
end

- (Object) store(args = {})



91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# File 'lib/confluence/page.rb', line 91

def store(args = {})
  unless self.version
    # check for existing page by id or title
    existing_page = if page_id
      Page.find :id => page_id
    else
      Page.find :space => space, :title => title
    end
    
    # take page_id and version from existing page if available
    if existing_page
      if args[:recreate_if_exists]
        # remove existing page
        existing_page.remove
      else
        # update page with page_id and version info
        self.page_id = existing_page.page_id
        self.version = existing_page.version
      end
    end
  end
  
  # reinitialize page after storing it
  initialize(client.storePage(self.to_hash))
  
  # return self
  self
end

- (Object) to_hash



130
131
132
133
134
135
136
137
138
139
140
141
142
# File 'lib/confluence/page.rb', line 130

def to_hash
  # record hash
  record_hash = super
  
  # always include content in hash
  record_hash["content"] ||= ""
  
  # prepend details sections before content
  record_hash["content"].insert(0, details.to_s)
  
  # result
  record_hash
end