Class: Confluence::Page

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

Direct Known Subclasses

Bookmark

Defined Under Namespace

Classes: Details, DetailsCollection

Constant Summary collapse

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Findable

find

Methods inherited from Record

#[], #[]=, client, #client, client=, #labels, #labels=, record_attr_accessor, #record_id

Constructor Details

#initialize(hash) ⇒ Page

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

#detailsObject

Returns the value of attribute details.



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

def details
  @details
end

Instance Method Details

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



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

#attachmentsObject



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

#children(klass = self.class) ⇒ Object



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

#removeObject



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

def remove
  client.removePage(page_id)
end

#store(args = {}) ⇒ Object



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

#to_hashObject



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