vortex_client 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.rdoc CHANGED
@@ -3,6 +3,7 @@
3
3
  A set of utilities for managing content in the web content management system "Vortex":http://www.usit.uio.no/it/vortex/.
4
4
  All operations are done by using the webdav protocol.
5
5
 
6
+
6
7
  = Publishing content
7
8
 
8
9
  To publish an article.
@@ -35,6 +36,10 @@ To create a folder named "2010" in the "/news/" folder.
35
36
  collection = Vortex::ArticleListingCollection.new(:title => "News for 2009", :foldername => "2009")
36
37
  vortex.create(collection)
37
38
 
39
+ = Documentation
40
+
41
+ RDoc: http://rdoc.info/projects/thomasfl/vortex_client/
42
+
38
43
  == Note on Patches/Pull Requests
39
44
 
40
45
  * Fork the project.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.0
1
+ 0.2.0
@@ -1,10 +1,9 @@
1
1
  # -*- coding: utf-8 -*-
2
- require 'cgi'
3
2
  require 'iconv'
4
3
 
5
4
  module Vortex
6
5
 
7
- "String utilities"
6
+ # String utilities
8
7
 
9
8
  class StringUtils
10
9
 
@@ -27,17 +26,6 @@ module Vortex
27
26
  html_filename = html_filename[0..100]
28
27
  html_filename = html_filename.gsub(/_[^_]*$/,"") + ".html"
29
28
  end
30
-
31
- html_filename = html_filename.gsub("!","")
32
- html_filename = html_filename.sub(/^_/, "")
33
- html_filename = html_filename.gsub("»", "")
34
- html_filename = html_filename.gsub("%", "")
35
-
36
- h1 = html_filename
37
- html_filename = CGI::escape(html_filename) # URLencode just to be safe
38
- if(html_filename != h1)
39
- warn "create_filename_from_title() could not create a valid filename " + html_filename
40
- end
41
29
  return html_filename
42
30
  end
43
31
 
@@ -47,27 +35,23 @@ module Vortex
47
35
  camel_cased_word = camel_cased_word.to_s.gsub(/::/, '/').
48
36
  gsub(/([A-Z]+)([A-Z][a-z])/,'\1\2').
49
37
  gsub(/([a-z\d])([A-Z])/,'\1\2').downcase
50
- camel_cased_word = camel_cased_word.to_s.gsub(/ /,'-')
51
- camel_cased_word = camel_cased_word.gsub(/_+/,"_")
52
38
 
53
- camel_cased_word = camel_cased_word.gsub(/\//,"_")
54
- camel_cased_word = camel_cased_word.gsub(/\?/,"")
55
-
56
- camel_cased_word = camel_cased_word.gsub(/\(.*\)/,"")
57
- camel_cased_word = camel_cased_word.gsub(/'/,"")
58
- camel_cased_word = camel_cased_word.gsub(/:/,"")
59
- camel_cased_word = camel_cased_word.gsub(/\./,"") # Dot's ('.') don't look good in url's
60
- camel_cased_word = camel_cased_word.gsub(",","") # Commas don't look good in url's
61
- camel_cased_word = camel_cased_word.gsub(/"/,"") # and not '"' either
62
- camel_cased_word = camel_cased_word.gsub("§","") # Paragraps are no good
39
+ camel_cased_word = camel_cased_word.to_s.gsub(/ /,'-')
40
+ camel_cased_word = camel_cased_word.to_s.gsub(/^_/,'')
63
41
  camel_cased_word = camel_cased_word.gsub("__","_")
42
+
43
+ # sanitize the string
44
+ camel_cased_word = camel_cased_word.gsub(/[^a-z._0-9 -]/i, "").
45
+ tr(".", "_").gsub(/(\s+)/, "_").gsub(/_/, '-').downcase
46
+ camel_cased_word = camel_cased_word.to_s.gsub(/--*/,'-')
64
47
  return camel_cased_word
65
48
  end
66
49
 
67
50
 
68
51
  # Filter accents and some special characters
69
52
  def self.remove_accents(str)
70
- accents = { ['á','à','â','ä','ã','Ã','Ä','Â','À'] => 'a',
53
+ accents = {
54
+ ['á','à','â','ä','ã','Ã','Ä','Â','À'] => 'a',
71
55
  ['é','è','ê','ë','Ë','É','È','Ê'] => 'e',
72
56
  ['í','ì','î','ï','I','Î','Ì'] => 'i',
73
57
  ['ó','ò','ô','ö','õ','Õ','Ö','Ô','Ò'] => 'o',
@@ -80,6 +64,7 @@ module Vortex
80
64
  ['Æ'] => 'ae',
81
65
  ['Ø'] => 'o',
82
66
  ['Å'] => 'a',
67
+ ['§'] => ''
83
68
  }
84
69
  accents.each do |ac,rep|
85
70
  ac.each do |s|
@@ -87,8 +72,8 @@ module Vortex
87
72
  end
88
73
  end
89
74
 
90
- # Remove the rest of the accents
91
- conv = Iconv.new("ASCII//TRANSLIT", "UTF-8")
75
+ # Remove the rest of the accents and special characters
76
+ conv = Iconv.new("ASCII//TRANSLIT//IGNORE", "UTF-8")
92
77
  str = conv.iconv(str)
93
78
  return str
94
79
  end
data/lib/vortex_client.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  require 'net/dav'
2
2
  require 'vortex_client/string_utils'
3
3
  require 'highline/import'
4
+ require 'time'
4
5
 
5
6
  # Utilities for managing content in the web content management system Vortex.
6
7
  # All calls are done with the webdav protocol.
@@ -67,6 +68,7 @@ module Vortex
67
68
  self.put_string(uri, object.content)
68
69
  self.proppatch(uri, object.properties)
69
70
  # puts object.properties
71
+ return uri.to_s
70
72
  else
71
73
  warn "Unknown vortex resource: " + object.class.to_s
72
74
  end
@@ -90,7 +92,14 @@ module Vortex
90
92
  end
91
93
 
92
94
 
93
- # HtmlArticle: Plain HTML files with title, introduction and keywords set as webdav properties.
95
+ # Plain HTML files with title, introduction and keywords set as webdav properties.
96
+ #
97
+ # Examples:
98
+ #
99
+ # article = HtmlArticle.new(:title => "Sample Title",
100
+ # :introduction => "Introduction",
101
+ # :body => "<p>Hello world</p>")
102
+ # vortex.publish(article)
94
103
  class HtmlArticle < PlainFile
95
104
 
96
105
  attr_accessor :title, :introduction, :body, :filename, :modifiedDate, :publishedDate, :owner, :url, :author, :date
@@ -116,13 +125,29 @@ module Vortex
116
125
  props = '<v:resourceType xmlns:v="vrtx">article</v:resourceType>' +
117
126
  '<v:xhtml10-type xmlns:v="vrtx">article</v:xhtml10-type>' +
118
127
  '<v:userSpecifiedCharacterEncoding xmlns:v="vrtx">utf-8</v:userSpecifiedCharacterEncoding>'
128
+
129
+ if(@publishedDate and @publishedDate != "")
130
+ if(@publishedDate.kind_of? Time)
131
+ @publishedDate = @publishedDate.httpdate.to_s
132
+ end
133
+ props += '<v:published-date xmlns:v="vrtx">' + @publishedDate + '</v:published-date>'
134
+ end
135
+
119
136
  if(date and date != "")
120
- props += '<v:published-date xmlns:v="vrtx">' + date + '</v:published-date>' +
121
- '<d:getlastmodified>' + date + '</d:getlastmodified>' +
137
+ if(date.kind_of? Time)
138
+ date = @date.httpdate.to_s
139
+ end
140
+ if(@publishedDate == nil or @publishedDate != "")
141
+ props += '<v:published-date xmlns:v="vrtx">' + date + '</v:published-date>'
142
+ end
143
+ props += '<d:getlastmodified>' + date + '</d:getlastmodified>' +
122
144
  '<v:contentLastModified xmlns:v="vrtx">' + date + '</v:contentLastModified>' +
123
145
  '<v:propertiesLastModified xmlns:v="vrtx">' + date + '</v:propertiesLastModified>' +
124
146
  '<v:creationTime xmlns:v="vrtx">' + date + '</v:creationTime>'
125
147
  end
148
+ if(title)
149
+ props += '<v:userTitle xmlns:v="vrtx">' + title + '</v:userTitle>'
150
+ end
126
151
  if(owner)
127
152
  props += '<owner xmlns="vrtx">' + owner + '</owner>'
128
153
  end
@@ -0,0 +1,34 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'helper'
3
+
4
+ class TestVortexClientUtils < Test::Unit::TestCase
5
+ include Vortex
6
+
7
+ def setup
8
+ if(not(@vortex))
9
+ user = ENV['DAVUSER']
10
+ pass = ENV['DAVPASS']
11
+ @vortex = Connection.new("https://vortex-dav.uio.no/",user, pass)
12
+ end
13
+ end
14
+
15
+ should "publish articles" do
16
+ url = 'https://vortex-dav.uio.no/brukere/thomasfl/nyheter/sample-title-2.html'
17
+ if(@vortex.exists?(url))
18
+ @vortex.delete(url)
19
+ end
20
+
21
+ @vortex.cd('/brukere/thomasfl/nyheter/')
22
+ article = Vortex::HtmlArticle.new(:title => "Sample Title 2",
23
+ :introduction => "Sample introduction",
24
+ :body => "<p>Hello world</p>",
25
+ ## :date => Time.now,
26
+ :publishedDate => "05.01.2010 12:00",
27
+ :author => "Thomas Flemming")
28
+
29
+ @vortex.publish(article)
30
+ assert @vortex.exists?(url)
31
+ end
32
+
33
+ end
34
+
@@ -2,16 +2,19 @@
2
2
  require 'helper'
3
3
 
4
4
  class TestVortexClientUtils < Test::Unit::TestCase
5
+ include Vortex
5
6
 
6
- should "run all tests" do
7
- assert true
8
- end
7
+ should "make sentence in to valid url withthout any url encoding" do
8
+ assert_equal "hei-pa-deg", StringUtils.create_filename("Hei på deg")
9
+ assert StringUtils.create_filename('áàâäãÃÄÂÀ') =~ /^a*$/
10
+ assert StringUtils.create_filename('éèêëËÉÈÊ') =~ /^e*$/
11
+ assert StringUtils.create_filename('íìîïIÎÌ') => /^i*$/
12
+ assert StringUtils.create_filename('óòôöõÕÖÔÒ') => /^o*$/
9
13
 
10
- should "prompt for password if enviroment variable DAVUSER is not set" do
11
- # @vortex = Vortex::Connection.new("https://vortex-dav.uio.no/")
12
- # ENV['DAVUSER'] = nil
13
- # content = @vortex.get('https://vortex-dav.uio.no/brukere/thomasfl/test/test_1.html')
14
- # assert content.match('html.*body')
14
+ # 0000000001111111111222222222233333333334
15
+ # 1234567890123456789012345678901234567890
16
+ str = 'start! to ()[]{}__@__\/?/.,"§_»_%##!!!end;:stripped'
17
+ assert_equal 'start-to-end', StringUtils.create_filename(str)
15
18
  end
16
19
 
17
20
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vortex_client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Thomas Flemming
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-12-21 00:00:00 +01:00
12
+ date: 2010-01-05 00:00:00 +01:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -93,5 +93,6 @@ specification_version: 3
93
93
  summary: Vortex CMS client
94
94
  test_files:
95
95
  - test/helper.rb
96
+ - test/test_vortex_article_publish.rb
96
97
  - test/test_vortex_client.rb
97
98
  - test/test_vortex_utils.rb