osheet 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/.bundle/config +2 -0
- data/.gitignore +6 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +33 -0
- data/README.rdoc +103 -61
- data/Rakefile +5 -56
- data/examples/basic.rb +73 -0
- data/examples/formats.rb +366 -0
- data/examples/trivial.rb +21 -0
- data/lib/osheet/associations.rb +62 -0
- data/lib/osheet/cell.rb +44 -10
- data/lib/osheet/column.rb +34 -7
- data/lib/osheet/format/accounting.rb +21 -0
- data/lib/osheet/format/currency.rb +23 -0
- data/lib/osheet/format/custom.rb +13 -0
- data/lib/osheet/format/datetime.rb +13 -0
- data/lib/osheet/format/fraction.rb +33 -0
- data/lib/osheet/format/general.rb +9 -0
- data/lib/osheet/format/number.rb +13 -0
- data/lib/osheet/format/numeric.rb +113 -0
- data/lib/osheet/format/percentage.rb +25 -0
- data/lib/osheet/format/scientific.rb +25 -0
- data/lib/osheet/format/special.rb +28 -0
- data/lib/osheet/format/text.rb +11 -0
- data/lib/osheet/format.rb +30 -0
- data/lib/osheet/row.rb +32 -7
- data/lib/osheet/style.rb +65 -0
- data/lib/osheet/style_set.rb +39 -0
- data/lib/osheet/styled_element.rb +18 -0
- data/lib/osheet/template.rb +32 -0
- data/lib/osheet/template_set.rb +57 -0
- data/lib/osheet/version.rb +1 -11
- data/lib/osheet/workbook.rb +32 -16
- data/lib/osheet/workbook_element.rb +21 -0
- data/lib/osheet/worksheet.rb +18 -20
- data/lib/osheet/worksheet_element.rb +15 -0
- data/lib/osheet/xmlss_writer/base.rb +42 -0
- data/lib/osheet/xmlss_writer/elements.rb +68 -0
- data/lib/osheet/xmlss_writer/styles.rb +176 -0
- data/lib/osheet/xmlss_writer.rb +1 -0
- data/lib/osheet.rb +7 -27
- data/osheet.gemspec +26 -0
- data/test/cell_test.rb +83 -0
- data/test/column_test.rb +81 -0
- data/test/env.rb +9 -0
- data/test/format/accounting_test.rb +158 -0
- data/test/format/currency_test.rb +158 -0
- data/test/format/custom_test.rb +22 -0
- data/test/format/datetime_test.rb +22 -0
- data/test/format/fraction_test.rb +84 -0
- data/test/format/general_test.rb +21 -0
- data/test/format/number_test.rb +93 -0
- data/test/format/percentage_test.rb +116 -0
- data/test/format/scientific_test.rb +116 -0
- data/test/format/special_test.rb +51 -0
- data/test/format/text_test.rb +18 -0
- data/test/format_test.rb +35 -0
- data/test/helper.rb +101 -0
- data/test/osheet_test.rb +14 -0
- data/test/row_test.rb +78 -0
- data/test/style_set_test.rb +50 -0
- data/test/style_test.rb +92 -0
- data/test/template_set_test.rb +76 -0
- data/test/template_test.rb +63 -0
- data/test/workbook_test.rb +142 -0
- data/test/worksheet_test.rb +77 -0
- data/test/xmlss_writer/base_test.rb +92 -0
- data/test/xmlss_writer/elements_test.rb +168 -0
- data/test/xmlss_writer/styles_test.rb +253 -0
- metadata +141 -30
- data/lib/osheet/base.rb +0 -95
data/.bundle/config
ADDED
data/.gitignore
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
osheet (0.1.0)
|
5
|
+
enumeration (~> 1.1.0)
|
6
|
+
xmlss (~> 0.0.2)
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: http://rubygems.org/
|
10
|
+
specs:
|
11
|
+
enumeration (1.1.0)
|
12
|
+
json (1.5.1)
|
13
|
+
kelredd-useful (0.4.1)
|
14
|
+
json
|
15
|
+
leftright (0.9.0)
|
16
|
+
nokogiri (1.4.4)
|
17
|
+
shoulda (2.11.3)
|
18
|
+
test-belt (0.2.1)
|
19
|
+
kelredd-useful (~> 0.4.0)
|
20
|
+
leftright (~> 0.9.0)
|
21
|
+
shoulda (~> 2.11)
|
22
|
+
xmlss (0.0.2)
|
23
|
+
nokogiri (~> 1.4.0)
|
24
|
+
|
25
|
+
PLATFORMS
|
26
|
+
ruby
|
27
|
+
|
28
|
+
DEPENDENCIES
|
29
|
+
bundler (~> 1.0)
|
30
|
+
enumeration (~> 1.1.0)
|
31
|
+
osheet!
|
32
|
+
test-belt (= 0.2.1)
|
33
|
+
xmlss (~> 0.0.2)
|
data/README.rdoc
CHANGED
@@ -9,72 +9,114 @@ Pronounced 'oh-sheeeeeet!' - this gem is a DSL wrapper to the spreadsheet gem th
|
|
9
9
|
|
10
10
|
$ gem install osheet
|
11
11
|
|
12
|
-
== Basic
|
12
|
+
== Basic Example
|
13
|
+
fields = ['Sex', 'Age', 'Height', 'Weight']
|
14
|
+
data = {
|
15
|
+
'Tom' => ['M', 52, "6'2\"", '220 lbs.'],
|
16
|
+
'Dick' => ['M', 33, "6'5\"", '243 lbs.'],
|
17
|
+
'Sally' => ['F', 29, "5'3\"", '132 lbs.']
|
18
|
+
}
|
19
|
+
|
20
|
+
# this will dump the above data to a single-sheet workbook w/ no styles
|
13
21
|
|
14
22
|
require 'osheet'
|
15
|
-
|
16
|
-
Osheet::Workbook do |wb|
|
17
|
-
wb.worksheet "Users" do |sheet|
|
18
|
-
sheet.column
|
19
|
-
sheet.column
|
20
|
-
sheet.column
|
21
|
-
|
22
|
-
sheet.row do |r|
|
23
|
-
r.cell "Characters on \"Friends\"", :colspan => 3
|
24
|
-
end
|
25
|
-
sheet.row do |r|
|
26
|
-
r.cell "man, that show was awesome...", :colspan => 3
|
27
|
-
end
|
28
23
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
r.cell 2
|
48
|
-
r.cell "Rachel"
|
49
|
-
r.cell "the hot one, dated and impregnated by Ross, generally spoiled"
|
50
|
-
end
|
51
|
-
|
52
|
-
sheet.row do |r|
|
53
|
-
r.cell 3
|
54
|
-
r.cell "Chandler"
|
55
|
-
r.cell "the responsible one, husband of Monica, insecure about everything"
|
56
|
-
end
|
57
|
-
|
58
|
-
sheet.row do |r|
|
59
|
-
r.cell 4
|
60
|
-
r.cell "Monica"
|
61
|
-
r.cell "the smart one, wife of Chandler, sister of Ross, OCD about cleaning and controlling"
|
62
|
-
end
|
63
|
-
|
64
|
-
sheet.row do |r|
|
65
|
-
r.cell 5
|
66
|
-
r.cell "Joey"
|
67
|
-
r.cell "the man-whore one, best-friend of Chandler, generally dumb, can't sustain sitcom on own"
|
24
|
+
wb = Osheet::Workbook.new {
|
25
|
+
worksheet {
|
26
|
+
name "Stats: #{fields.join(', ')}"
|
27
|
+
|
28
|
+
column {
|
29
|
+
width 200
|
30
|
+
meta(
|
31
|
+
:label => "Name"
|
32
|
+
)
|
33
|
+
}
|
34
|
+
fields.each_with_index do |f, i|
|
35
|
+
column {
|
36
|
+
width 80
|
37
|
+
meta(
|
38
|
+
:label => f.to_s,
|
39
|
+
:index => i
|
40
|
+
)
|
41
|
+
}
|
68
42
|
end
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
43
|
+
|
44
|
+
row { # title row
|
45
|
+
cell {
|
46
|
+
colspan columns.count
|
47
|
+
data worksheet.name
|
48
|
+
}
|
49
|
+
}
|
50
|
+
row { # empty row
|
51
|
+
cell {
|
52
|
+
colspan columns.count
|
53
|
+
data ''
|
54
|
+
}
|
55
|
+
}
|
56
|
+
row { # header row
|
57
|
+
columns.each do |column|
|
58
|
+
cell {
|
59
|
+
data column.meta[:label]
|
60
|
+
}
|
61
|
+
end
|
62
|
+
}
|
63
|
+
|
64
|
+
data.each do |name, stats|
|
65
|
+
row { # data row
|
66
|
+
cell {
|
67
|
+
data name
|
68
|
+
}
|
69
|
+
stats.each do |stat|
|
70
|
+
cell {
|
71
|
+
data stat
|
72
|
+
}
|
73
|
+
end
|
74
|
+
}
|
74
75
|
end
|
75
|
-
|
76
|
-
|
77
|
-
|
76
|
+
} # worksheet
|
77
|
+
} # workbook
|
78
|
+
|
79
|
+
file = wb.to_file('stats') # => <spreadsheet written to ./stats.xls>
|
80
|
+
|
81
|
+
== API
|
82
|
+
|
83
|
+
These classes define how a spreadsheet is constructed.
|
84
|
+
=== Osheet::Workbook
|
85
|
+
* *style(selector, &block)*: define a style for the workbook
|
86
|
+
* *template(for, named, &block)*: define a named template for the workbook
|
87
|
+
* *worksheet(&block)*: define a worksheet for the workbook
|
88
|
+
# TODO: *use(module)*
|
89
|
+
# TODO: *use(file)*
|
90
|
+
|
91
|
+
=== Osheet::Worksheet
|
92
|
+
* *name(value)*: set the name for this worksheet
|
93
|
+
* *column(&block)*: define a column for the worksheet
|
94
|
+
* *column(:template, *args): define a templated column for the worksheet
|
95
|
+
* *row(&block)*: define a row for the worksheet
|
96
|
+
* *row(:template, *args): define a templated row for the worksheet
|
97
|
+
|
98
|
+
=== Xmlss::Column
|
99
|
+
* *style_class(value)*: (string) the styles selectors should match against
|
100
|
+
* *width(value)*: (numeric) set the explicit width for the column
|
101
|
+
* *auto_fit_width(value)*: (bool) set whether the column should auto fit it's width, default: false
|
102
|
+
* *hidden(value)*: (bool) set whether the column is hidden, default: false
|
103
|
+
* *meta(data)*: (anything) a generic way to associate meta-data with the column
|
104
|
+
|
105
|
+
=== Xmlss::Row
|
106
|
+
* *style_class(value)*: (string) the styles selectors should match against
|
107
|
+
* *height(value)*: (numeric) set the explicit width for the column
|
108
|
+
* *auto_fit_height(value)*: (bool) set whether the row should auto fit it's height, default: false
|
109
|
+
* *hidden(value)*: (bool) set whether the row is hidden, default: false
|
110
|
+
* *cell(&block)*: define a cell for the row
|
111
|
+
* *cell(:template, *args): define a templated cell for the row
|
112
|
+
|
113
|
+
=== Xmlss::Cell
|
114
|
+
* *style_class(value)*: (string) the styles selectors should match against
|
115
|
+
* *data(value)*: (anything), data the cell should contain. if not a string, numeric, or date, will cast data to sting using 'inspect'.
|
116
|
+
* format(value)*: (anything), optional, custom formatting string for the data (see driver documentation for options)
|
117
|
+
* *colspan(value)*: (int) the number of columns (l to r) the cell should occupy, default: 1
|
118
|
+
* *rowspan(value)*: (int) the number of rows (t to b) the cell should occupy, default: 1
|
119
|
+
* *href(value)*: (string) set the href the data should link to
|
78
120
|
|
79
121
|
== Links
|
80
122
|
|
data/Rakefile
CHANGED
@@ -1,58 +1,7 @@
|
|
1
|
-
require '
|
2
|
-
|
3
|
-
require 'rake/testtask'
|
1
|
+
require 'bundler'
|
2
|
+
Bundler::GemHelper.install_tasks
|
4
3
|
|
5
|
-
require '
|
4
|
+
require 'test_belt/rake_tasks'
|
5
|
+
TestBelt::RakeTasks.for :test
|
6
6
|
|
7
|
-
|
8
|
-
s.name = 'osheet'
|
9
|
-
s.version = Osheet::Version.to_s
|
10
|
-
s.has_rdoc = true
|
11
|
-
s.extra_rdoc_files = %w(README.rdoc)
|
12
|
-
s.rdoc_options = %w(--main README.rdoc)
|
13
|
-
s.summary = "A DSL for generating spreadsheets that doesn't totally suck - pronounced 'Oh sheeeeeet!'"
|
14
|
-
s.author = 'Kelly Redding'
|
15
|
-
s.email = 'kelly@kelredd.com'
|
16
|
-
s.homepage = 'http://github.com/kelredd/osheet'
|
17
|
-
s.files = %w(README.rdoc Rakefile) + Dir.glob("{lib}/**/*")
|
18
|
-
# s.executables = ['osheet']
|
19
|
-
|
20
|
-
s.add_development_dependency("shoulda", [">= 2.10.0"])
|
21
|
-
s.add_development_dependency("kelredd-useful", [">= 0.3.0"])
|
22
|
-
|
23
|
-
s.add_dependency("spreadsheet", [">= 0.6.4"])
|
24
|
-
end
|
25
|
-
|
26
|
-
Rake::GemPackageTask.new(spec) do |pkg|
|
27
|
-
pkg.gem_spec = spec
|
28
|
-
end
|
29
|
-
|
30
|
-
Rake::TestTask.new do |t|
|
31
|
-
t.libs << 'test'
|
32
|
-
t.test_files = FileList["test/**/*_test.rb"]
|
33
|
-
t.verbose = true
|
34
|
-
end
|
35
|
-
|
36
|
-
begin
|
37
|
-
require 'rcov/rcovtask'
|
38
|
-
|
39
|
-
Rcov::RcovTask.new(:coverage) do |t|
|
40
|
-
t.libs = ['test']
|
41
|
-
t.test_files = FileList["test/**/*_test.rb"]
|
42
|
-
t.verbose = true
|
43
|
-
t.rcov_opts = ['--text-report', "-x #{Gem.path}", '-x /Library/Ruby', '-x /usr/lib/ruby']
|
44
|
-
end
|
45
|
-
|
46
|
-
task :default => :coverage
|
47
|
-
|
48
|
-
rescue LoadError
|
49
|
-
warn "\n**** Install rcov (sudo gem install relevance-rcov) to get coverage stats ****\n"
|
50
|
-
task :default => :test
|
51
|
-
end
|
52
|
-
|
53
|
-
desc 'Generate the gemspec to serve this gem'
|
54
|
-
task :gemspec do
|
55
|
-
file = File.dirname(__FILE__) + "/#{spec.name}.gemspec"
|
56
|
-
File.open(file, 'w') {|f| f << spec.to_ruby }
|
57
|
-
puts "Created gemspec: #{file}"
|
58
|
-
end
|
7
|
+
task :default => :build
|
data/examples/basic.rb
ADDED
@@ -0,0 +1,73 @@
|
|
1
|
+
# To run:
|
2
|
+
# $ bundle install
|
3
|
+
# $ bundle exec ruby examples/basic.rb
|
4
|
+
# $ open examples/basic.xls
|
5
|
+
|
6
|
+
require 'rubygems'
|
7
|
+
require 'osheet'
|
8
|
+
|
9
|
+
fields = ['Sex', 'Age', 'Height', 'Weight']
|
10
|
+
data = {
|
11
|
+
'Tom' => ['M', 52, "6'2\"", '220 lbs.'],
|
12
|
+
'Dick' => ['M', 33, "6'5\"", '243 lbs.'],
|
13
|
+
'Sally' => ['F', 29, "5'3\"", '132 lbs.']
|
14
|
+
}
|
15
|
+
|
16
|
+
# this will dump the above data to a single-sheet workbook w/ no styles
|
17
|
+
|
18
|
+
|
19
|
+
Osheet::Workbook.new {
|
20
|
+
title "basic"
|
21
|
+
worksheet {
|
22
|
+
name "Stats: #{fields.join(', ')}"
|
23
|
+
|
24
|
+
column {
|
25
|
+
width 200
|
26
|
+
meta(
|
27
|
+
:label => "Name"
|
28
|
+
)
|
29
|
+
}
|
30
|
+
fields.each_with_index do |f, i|
|
31
|
+
column {
|
32
|
+
width 80
|
33
|
+
meta(
|
34
|
+
:label => f.to_s,
|
35
|
+
:index => i
|
36
|
+
)
|
37
|
+
}
|
38
|
+
end
|
39
|
+
|
40
|
+
row { # title row
|
41
|
+
cell {
|
42
|
+
colspan columns.count
|
43
|
+
data worksheet.name
|
44
|
+
}
|
45
|
+
}
|
46
|
+
row { # empty row
|
47
|
+
cell {
|
48
|
+
colspan columns.count
|
49
|
+
data ''
|
50
|
+
}
|
51
|
+
}
|
52
|
+
row { # header row
|
53
|
+
columns.each do |column|
|
54
|
+
cell {
|
55
|
+
data column.meta[:label]
|
56
|
+
}
|
57
|
+
end
|
58
|
+
}
|
59
|
+
|
60
|
+
data.each do |name, stats|
|
61
|
+
row { # data row
|
62
|
+
cell {
|
63
|
+
data name
|
64
|
+
}
|
65
|
+
stats.each do |stat|
|
66
|
+
cell {
|
67
|
+
data stat
|
68
|
+
}
|
69
|
+
end
|
70
|
+
}
|
71
|
+
end
|
72
|
+
}
|
73
|
+
}.to_file('examples/basic.xls')
|