roo 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/History.txt ADDED
@@ -0,0 +1,4 @@
1
+ == 0.0.1 2007-05-25
2
+
3
+ * 1 major enhancement:
4
+ * Initial release
data/License.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2007 FIXME full name
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Manifest.txt ADDED
@@ -0,0 +1,17 @@
1
+ History.txt
2
+ License.txt
3
+ Manifest.txt
4
+ README.txt
5
+ Rakefile
6
+ lib/roo.rb
7
+ lib/roo/version.rb
8
+ lib/roo/openoffice.rb
9
+ scripts/txt2html
10
+ setup.rb
11
+ test/test_helper.rb
12
+ test/test_roo.rb
13
+ website/index.html
14
+ website/index.txt
15
+ website/javascripts/rounded_corners_lite.inc.js
16
+ website/stylesheets/screen.css
17
+ website/template.rhtml
data/README.txt ADDED
@@ -0,0 +1,3 @@
1
+ README for roo
2
+ ==============
3
+
data/Rakefile ADDED
@@ -0,0 +1,127 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+ require 'rake/clean'
4
+ require 'rake/testtask'
5
+ require 'rake/packagetask'
6
+ require 'rake/gempackagetask'
7
+ require 'rake/rdoctask'
8
+ require 'rake/contrib/rubyforgepublisher'
9
+ require 'fileutils'
10
+ require 'hoe'
11
+
12
+ include FileUtils
13
+ require File.join(File.dirname(__FILE__), 'lib', 'roo', 'version')
14
+
15
+ AUTHOR = 'Thomas Preymesser' # can also be an array of Authors
16
+ EMAIL = "thopre@gmail.com"
17
+ DESCRIPTION = "roo can access the contents of OpenOffice-Spreadsheets"
18
+ GEM_NAME = 'roo' # what ppl will type to install your gem
19
+
20
+ @config_file = "~/.rubyforge/user-config.yml"
21
+ @config = nil
22
+ def rubyforge_username
23
+ unless @config
24
+ begin
25
+ @config = YAML.load(File.read(File.expand_path(@config_file)))
26
+ rescue
27
+ puts <<-EOS
28
+ ERROR: No rubyforge config file found: #{@config_file}"
29
+ Run 'rubyforge setup' to prepare your env for access to Rubyforge
30
+ - See http://newgem.rubyforge.org/rubyforge.html for more details
31
+ EOS
32
+ exit
33
+ end
34
+ end
35
+ @rubyforge_username ||= @config["username"]
36
+ end
37
+
38
+ RUBYFORGE_PROJECT = 'roo' # The unix name for your project
39
+ HOMEPATH = "http://#{RUBYFORGE_PROJECT}.rubyforge.org"
40
+ DOWNLOAD_PATH = "http://rubyforge.org/projects/#{RUBYFORGE_PROJECT}"
41
+
42
+ NAME = "roo"
43
+ REV = nil
44
+ # UNCOMMENT IF REQUIRED:
45
+ # REV = `svn info`.each {|line| if line =~ /^Revision:/ then k,v = line.split(': '); break v.chomp; else next; end} rescue nil
46
+ VERS = Roo::VERSION::STRING + (REV ? ".#{REV}" : "")
47
+ CLEAN.include ['**/.*.sw?', '*.gem', '.config', '**/.DS_Store']
48
+ RDOC_OPTS = ['--quiet', '--title', 'roo documentation',
49
+ "--opname", "index.html",
50
+ "--line-numbers",
51
+ "--main", "README",
52
+ "--inline-source"]
53
+
54
+ class Hoe
55
+ def extra_deps
56
+ @extra_deps.reject { |x| Array(x).first == 'hoe' }
57
+ end
58
+ end
59
+
60
+ # Generate all the Rake tasks
61
+ # Run 'rake -T' to see list of generated tasks (from gem root directory)
62
+ hoe = Hoe.new(GEM_NAME, VERS) do |p|
63
+ p.author = AUTHOR
64
+ p.description = DESCRIPTION
65
+ p.email = EMAIL
66
+ p.summary = DESCRIPTION
67
+ p.url = HOMEPATH
68
+ p.rubyforge_name = RUBYFORGE_PROJECT if RUBYFORGE_PROJECT
69
+ p.test_globs = ["test/**/test_*.rb"]
70
+ p.clean_globs = CLEAN #An array of file patterns to delete on clean.
71
+
72
+ # == Optional
73
+ p.changes = p.paragraphs_of("History.txt", 0..1).join("\n\n")
74
+ #p.extra_deps = [] # An array of rubygem dependencies [name, version], e.g. [ ['active_support', '>= 1.3.1'] ]
75
+ p.extra_deps = [
76
+ ['ruport', '>= 1.0.0'],
77
+ ['ruport-util', '>= 0.5.0'],
78
+ ]
79
+ #p.spec_extras = {} # A hash of extra values to set in the gemspec.
80
+ end
81
+
82
+ CHANGES = hoe.paragraphs_of('History.txt', 0..1).join("\n\n")
83
+ PATH = (RUBYFORGE_PROJECT == GEM_NAME) ? RUBYFORGE_PROJECT : "#{RUBYFORGE_PROJECT}/#{GEM_NAME}"
84
+ hoe.remote_rdoc_dir = File.join(PATH.gsub(/^#{RUBYFORGE_PROJECT}\/?/,''), 'rdoc')
85
+
86
+ desc 'Generate website files'
87
+ task :website_generate do
88
+ Dir['website/**/*.txt'].each do |txt|
89
+ sh %{ ruby scripts/txt2html #{txt} > #{txt.gsub(/txt$/,'html')} }
90
+ end
91
+ end
92
+
93
+ desc 'Upload website files to rubyforge'
94
+ task :website_upload do
95
+ host = "#{rubyforge_username}@rubyforge.org"
96
+ remote_dir = "/var/www/gforge-projects/#{PATH}/"
97
+ local_dir = 'website'
98
+ sh %{rsync -av #{local_dir}/ #{host}:#{remote_dir}}
99
+ end
100
+
101
+ desc 'Generate and upload website files'
102
+ task :website => [:website_generate, :website_upload]
103
+
104
+ desc 'Release the website and new gem version'
105
+ task :deploy => [:check_version, :website, :release] do
106
+ puts "Remember to create SVN tag:"
107
+ puts "svn copy svn+ssh://#{rubyforge_username}@rubyforge.org/var/svn/#{PATH}/trunk " +
108
+ "svn+ssh://#{rubyforge_username}@rubyforge.org/var/svn/#{PATH}/tags/REL-#{VERS} "
109
+ puts "Suggested comment:"
110
+ puts "Tagging release #{CHANGES}"
111
+ end
112
+
113
+ desc 'Runs tasks website_generate and install_gem as a local deployment of the gem'
114
+ task :local_deploy => [:website_generate, :install_gem]
115
+
116
+ task :check_version do
117
+ unless ENV['VERSION']
118
+ puts 'Must pass a VERSION=x.y.z release version'
119
+ exit
120
+ end
121
+ unless ENV['VERSION'] == VERS
122
+ puts "Please update your version.rb to match the release version, currently #{VERS}"
123
+ exit
124
+ end
125
+ end
126
+
127
+
data/lib/roo.rb ADDED
@@ -0,0 +1,7 @@
1
+ module Roo
2
+ end
3
+
4
+ require 'ruport'
5
+ require 'ruport/util'
6
+ require 'roo/version'
7
+ require 'openoffice'
@@ -0,0 +1,180 @@
1
+
2
+ require 'rubygems'
3
+ require 'rexml/document'
4
+ require 'matrix'
5
+ require 'fileutils'
6
+ require 'zip/zipfilesystem'
7
+
8
+ class Openoffice
9
+
10
+ def initialize(filename=nil)
11
+ @filename = filename
12
+ unless File.exists?("/tmp/oo_"+$$.to_s)
13
+ FileUtils::mkdir("/tmp/oo_"+$$.to_s) #TODO:
14
+ end
15
+ # `unzip -o "#{filename}"`
16
+ extract_content
17
+ file = File.new("roo_content.xml")
18
+ @doc = REXML::Document.new file
19
+ @cell = Hash.new
20
+ @cell_type = Hash.new
21
+ end
22
+
23
+ def cell(row,col)
24
+ if col.class == String
25
+ col = "ABCDEFGHIJKLMNOPQRSTUVWXYZ".index(col)+1
26
+ end
27
+ read_cells unless @cells_read
28
+ @cell["#{row},#{col}"]
29
+ end
30
+
31
+ def celltype(row,col)
32
+ read_cells unless @cells_read
33
+ @cell_type["#{row},#{col}"]
34
+ end
35
+
36
+ # read all cells in the selected sheet
37
+ def read_cells
38
+ oo_document_count = 0
39
+ @doc.each_element do |oo_document|
40
+ oo_document_count += 1
41
+ oo_element_count = 0
42
+ oo_document.each_element do |oo_element|
43
+ oo_element_count += 1
44
+ # p oo_element.name
45
+ if oo_element.name == "body"
46
+ # puts "Body gefunden "
47
+ oo_element.each_element do |be|
48
+ # p be.name
49
+ if be.name == "spreadsheet"
50
+ be.each_element do |se|
51
+ # p se
52
+ if se.name == "table"
53
+ if se.attributes['name']==@default_sheet
54
+
55
+ x=1
56
+ y=1
57
+ # puts "table gefunden"
58
+ #se.each_element
59
+ se.each_element do |te|
60
+ # p te.name
61
+ if te.name == "table-column"
62
+ # p te.attributes
63
+ rep = te.attributes["number-columns-repeated"]
64
+ # p "rep = "+rep.to_s
65
+ elsif te.name == "table-row"
66
+ # p te
67
+ te.each_element do |tr|
68
+ # p tr
69
+ if tr.name == 'table-cell'
70
+ vt = tr.attributes['value-type']
71
+ v = tr.attributes['value']
72
+ # puts "#{vt} #{v}"
73
+ @cell_type["#{y},#{x}"] = vt
74
+ if @cell_type["#{y},#{x}"] == 'float'
75
+ @cell["#{y},#{x}"] = v.to_f
76
+ elsif @cell_type["#{y},#{x}"] == 'string'
77
+ tr.each_element do |str|
78
+ if str.name == 'p'
79
+ @cell["#{y},#{x}"] = str.text
80
+ end
81
+ end
82
+ elsif @cell_type["#{y},#{x}"] == 'date'
83
+ @cell["#{y},#{x}"] = tr.attributes['date-value']
84
+ else
85
+ @cell["#{y},#{x}"] = v
86
+ end
87
+ x += 1
88
+ end
89
+ end
90
+ y += 1
91
+ x = 1
92
+ end
93
+ end
94
+ # p se.attributes['name']
95
+ # return_sheets << se.attributes['name']
96
+ end # richtiges sheet
97
+ end
98
+ end
99
+ end
100
+ end
101
+ end
102
+ end
103
+ # puts oo_element_count.to_s+" oo_element_count "
104
+ end
105
+ # puts oo_document_count.to_s+" oo_document_count "
106
+ # p @cell
107
+ @cells_read = true
108
+ end
109
+
110
+ # returns a list of sheets in this document
111
+ def sheets
112
+ return_sheets = []
113
+ # p valid_xml?(doc)
114
+ oo_document_count = 0
115
+ @doc.each_element do |oo_document|
116
+ oo_document_count += 1
117
+ #p oo_document
118
+ oo_element_count = 0
119
+ oo_document.each_element do |oo_element|
120
+ oo_element_count += 1
121
+ # p oo_element.name
122
+ if oo_element.name == "body"
123
+ # puts "Body gefunden "
124
+ oo_element.each_element do |be|
125
+ # p be.name
126
+ if be.name == "spreadsheet"
127
+ be.each_element do |se|
128
+ # p se
129
+ if se.name == "table"
130
+ # puts "table gefunden"
131
+ #se.each_element
132
+ # p se.attributes['name']
133
+ return_sheets << se.attributes['name']
134
+ end
135
+ end
136
+ end
137
+ end
138
+ end
139
+ end
140
+ # puts oo_element_count.to_s+" oo_element_count "
141
+ end
142
+ # puts oo_document_count.to_s+" oo_document_count "
143
+ return_sheets
144
+ end
145
+
146
+ def default_sheet=(s)
147
+ @default_sheet = s
148
+ end
149
+
150
+ private
151
+
152
+ def process_zipfile(zip, path='')
153
+ if zip.file.file? path
154
+ # puts %{#{path}: "#{zip.read(path)}"}
155
+ # puts %{#{path}:}
156
+
157
+ if path == "content.xml"
158
+ open('roo_content.xml','w') {|f|
159
+ f << zip.read(path)
160
+ }
161
+ end
162
+ else
163
+ unless path.empty?
164
+ path += '/'
165
+ # puts path
166
+ end
167
+ zip.dir.foreach(path) do |filename|
168
+ process_zipfile(zip, path+filename)
169
+ end
170
+ end
171
+ end
172
+
173
+
174
+ def extract_content
175
+ Zip::ZipFile.open(@filename) do |zip|
176
+ process_zipfile(zip)
177
+ end
178
+ end
179
+
180
+ end
@@ -0,0 +1,9 @@
1
+ module Roo #:nodoc:
2
+ module VERSION #:nodoc:
3
+ MAJOR = 0
4
+ MINOR = 0
5
+ TINY = 1
6
+
7
+ STRING = [MAJOR, MINOR, TINY].join('.')
8
+ end
9
+ end
data/scripts/txt2html ADDED
@@ -0,0 +1,67 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rubygems'
4
+ require 'redcloth'
5
+ require 'syntax/convertors/html'
6
+ require 'erb'
7
+ require File.dirname(__FILE__) + '/../lib/roo/version.rb'
8
+
9
+ version = Roo::VERSION::STRING
10
+ download = 'http://rubyforge.org/projects/roo'
11
+
12
+ class Fixnum
13
+ def ordinal
14
+ # teens
15
+ return 'th' if (10..19).include?(self % 100)
16
+ # others
17
+ case self % 10
18
+ when 1: return 'st'
19
+ when 2: return 'nd'
20
+ when 3: return 'rd'
21
+ else return 'th'
22
+ end
23
+ end
24
+ end
25
+
26
+ class Time
27
+ def pretty
28
+ return "#{mday}#{mday.ordinal} #{strftime('%B')} #{year}"
29
+ end
30
+ end
31
+
32
+ def convert_syntax(syntax, source)
33
+ return Syntax::Convertors::HTML.for_syntax(syntax).convert(source).gsub(%r!^<pre>|</pre>$!,'')
34
+ end
35
+
36
+ if ARGV.length >= 1
37
+ src, template = ARGV
38
+ template ||= File.dirname(__FILE__) + '/../website/template.rhtml'
39
+
40
+ else
41
+ puts("Usage: #{File.split($0).last} source.txt [template.rhtml] > output.html")
42
+ exit!
43
+ end
44
+
45
+ template = ERB.new(File.open(template).read)
46
+
47
+ title = nil
48
+ body = nil
49
+ File.open(src) do |fsrc|
50
+ title_text = fsrc.readline
51
+ body_text = fsrc.read
52
+ syntax_items = []
53
+ body_text.gsub!(%r!<(pre|code)[^>]*?syntax=['"]([^'"]+)[^>]*>(.*?)</>!m){
54
+ ident = syntax_items.length
55
+ element, syntax, source = $1, $2, $3
56
+ syntax_items << "<#{element} class='syntax'>#{convert_syntax(syntax, source)}</#{element}>"
57
+ "syntax-temp-#{ident}"
58
+ }
59
+ title = RedCloth.new(title_text).to_html.gsub(%r!<.*?>!,'').strip
60
+ body = RedCloth.new(body_text).to_html
61
+ body.gsub!(%r!(?:<pre><code>)?syntax-temp-(d+)(?:</code></pre>)?!){ syntax_items[$1.to_i] }
62
+ end
63
+ stat = File.stat(src)
64
+ created = stat.ctime
65
+ modified = stat.mtime
66
+
67
+ $stdout << template.result(binding)