Class: Vortex::HtmlArticle

Inherits:
PlainFile show all
Defined in:
lib/vortex_client.rb

Overview

HtmlArticle: Plain HTML files with title, introduction and keywords set as WebDAV properties.

Examples:

article = HtmlArticle.new(:title => "Sample Title",
                          :introduction => "Introduction",
                          :body => "<p>Hello world</p>")
vortex.publish(article)

Direct Known Subclasses

StructuredArticle

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ HtmlArticle

Create a new article of type html-article: plain html file with introduction stored as a webdav property.



198
199
200
# File 'lib/vortex_client.rb', line 198

def initialize(options={})
  options.each{|k,v|send("#{k}=",v)}
end

Instance Attribute Details

#authorObject

Returns the value of attribute author.



195
196
197
# File 'lib/vortex_client.rb', line 195

def author
  @author
end

#bodyObject

Returns the value of attribute body.



195
196
197
# File 'lib/vortex_client.rb', line 195

def body
  @body
end

#dateObject

Returns the value of attribute date.



195
196
197
# File 'lib/vortex_client.rb', line 195

def date
  @date
end

#filenameObject

Returns the value of attribute filename.



195
196
197
# File 'lib/vortex_client.rb', line 195

def filename
  @filename
end

#introductionObject

Returns the value of attribute introduction.



195
196
197
# File 'lib/vortex_client.rb', line 195

def introduction
  @introduction
end

#modifiedDateObject

Returns the value of attribute modifiedDate.



195
196
197
# File 'lib/vortex_client.rb', line 195

def modifiedDate
  @modifiedDate
end

#ownerObject

Returns the value of attribute owner.



195
196
197
# File 'lib/vortex_client.rb', line 195

def owner
  @owner
end

#pictureObject

Returns the value of attribute picture.



195
196
197
# File 'lib/vortex_client.rb', line 195

def picture
  @picture
end

#publishedDateObject

Returns the value of attribute publishedDate.



195
196
197
# File 'lib/vortex_client.rb', line 195

def publishedDate
  @publishedDate
end

#tagsObject

Returns the value of attribute tags.



195
196
197
# File 'lib/vortex_client.rb', line 195

def tags
  @tags
end

#titleObject

Returns the value of attribute title.



195
196
197
# File 'lib/vortex_client.rb', line 195

def title
  @title
end

#urlObject

Returns the value of attribute url.



195
196
197
# File 'lib/vortex_client.rb', line 195

def url
  @url
end

Instance Method Details

#contentObject



295
296
297
298
299
300
301
302
303
304
305
# File 'lib/vortex_client.rb', line 295

def content
  content = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" ' +
    '"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">' +
    '<html xmlns="http://www.w3.org/1999/xhtml"><head><title>' + title + '</title>' +
    ' <link href="http://www.uio.no/profil/kupu/kupucontentstyles.css" type="text/css" rel="stylesheet"/>' +
    '</head><body>'
  if(body)
    content += body
  end
  content += '</body></html>'
end

#escape_html(str) ⇒ Object



221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
# File 'lib/vortex_client.rb', line 221

def escape_html(str)
  new_str = str.gsub("&#xD;","")        #remove line break
  new_str = new_str.gsub("\"","&quot;") #swaps " to html-encoding
  new_str = new_str.gsub("'","&#39;")   #swaps ' to html-encoding
  new_str = new_str.gsub("<","&lt;")
  new_str = new_str.gsub(">","&gt;")
  new_str = new_str.gsub(/'/, "\"") # Fnutter gir "not valid xml error"
  new_str = new_str.gsub("&nbsp;", " ") # &nbsp; gir også "not valid xml error"
  new_str = new_str.gsub("–", "-") # Tankestrek til minustegn
  new_str = new_str.gsub("’","&#39;")  # Fnutt
  new_str = new_str.gsub("‘","&#39;")  # Fnutt
  new_str = new_str.gsub("“","&#39;")  # Fnutt
  new_str = new_str.gsub("”","&#39;")  # Fnutt
  new_str = new_str.gsub("","&#39;")  # Norske gåseøyne til fnutt
  return new_str
end

#propertiesObject



238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
# File 'lib/vortex_client.rb', line 238

def properties
  props = '<v:resourceType xmlns:v="vrtx">article</v:resourceType>' +
    '<v:xhtml10-type xmlns:v="vrtx">article</v:xhtml10-type>' +
    '<v:userSpecifiedCharacterEncoding xmlns:v="vrtx">utf-8</v:userSpecifiedCharacterEncoding>'

  if(@publishedDate and @publishedDate != "")
    if(@publishedDate.kind_of? Time)
      @publishedDate = @publishedDate.httpdate.to_s
    end
    props += '<v:published-date xmlns:v="vrtx">' + @publishedDate + '</v:published-date>'
  end

  if(date and date != "")
    if(date.kind_of? Time)
      date = @date.httpdate.to_s
    end
    if(@publishedDate == nil or @publishedDate != "")
      props += '<v:published-date xmlns:v="vrtx">' + date + '</v:published-date>'
    end
    props += '<d:getlastmodified>' + date + '</d:getlastmodified>' +
    '<v:contentLastModified xmlns:v="vrtx">' + date + '</v:contentLastModified>' +
    '<v:propertiesLastModified xmlns:v="vrtx">' + date + '</v:propertiesLastModified>' +
    '<v:creationTime xmlns:v="vrtx">' + date + '</v:creationTime>'
  end

  if(picture)
    props += '<v:picture xmlns:v="vrtx">' + picture + '</v:picture>'
  end

  if(title)
    props += '<v:userTitle xmlns:v="vrtx">' + title + '</v:userTitle>'
  end
  if(owner)
    props += '<owner xmlns="vrtx">' + owner + '</owner>'
  end
  if(introduction and introduction != "")
    props += '<introduction xmlns="vrtx">' + escape_html(introduction) + '</introduction>'
  end
  if(author and author != "")
    props += '<v:authors xmlns:v="vrtx">' +
      '<vrtx:values xmlns:vrtx="http://vortikal.org/xml-value-list">' +
         '<vrtx:value>' + author + '</vrtx:value>' +
       '</vrtx:values>' +
    '</v:authors>'
  end

  if(tags and tags.kind_of?(Array) and tags.size > 0)
    props += '<v:tags xmlns:v="vrtx">' +
      '<vrtx:values xmlns:vrtx="http://vortikal.org/xml-value-list">'
    tags.each do |tag|
        props += "<vrtx:value>#{tag}</vrtx:value>"
    end
    props += '</vrtx:values></v:tags>'
  end
  return props
end

#to_sObject



202
203
204
# File 'lib/vortex_client.rb', line 202

def to_s
  "#<Vortex::HtmlArticle "+instance_variables.collect{|var|var+": "+instance_variable_get(var).to_s}.join(",")+">"
end