osheet 0.10.0 → 1.0.0.rc.1
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +0 -1
- data/Gemfile.lock +9 -6
- data/Rakefile +35 -19
- data/bench/bench_runner.rb +91 -0
- data/bench/profiler_runner.rb +1 -0
- data/examples/basic.rb +1 -1
- data/examples/basic.xls +2 -1
- data/examples/basic_with_templates.rb +2 -2
- data/examples/basic_with_templates.xls +3 -3
- data/examples/formats.rb +2 -2
- data/examples/formats.xls +46 -46
- data/examples/formula.rb +2 -2
- data/examples/styles.rb +2 -2
- data/examples/styles.xls +5 -5
- data/examples/trivial.rb +2 -2
- data/lib/osheet/cell.rb +48 -46
- data/lib/osheet/column.rb +23 -29
- data/lib/osheet/format.rb +3 -3
- data/lib/osheet/meta_element.rb +2 -1
- data/lib/osheet/mixin.rb +21 -9
- data/lib/osheet/partial.rb +5 -9
- data/lib/osheet/row.rb +28 -32
- data/lib/osheet/style.rb +11 -25
- data/lib/osheet/styled_element.rb +9 -1
- data/lib/osheet/template.rb +3 -8
- data/lib/osheet/version.rb +1 -1
- data/lib/osheet/workbook.rb +135 -43
- data/lib/osheet/workbook_api.rb +208 -0
- data/lib/osheet/workbook_element.rb +225 -8
- data/lib/osheet/worksheet.rb +22 -28
- data/lib/osheet/xmlss_writer/style_cache.rb +64 -0
- data/lib/osheet/xmlss_writer/style_settings.rb +148 -0
- data/lib/osheet/xmlss_writer.rb +143 -1
- data/lib/osheet.rb +3 -29
- data/osheet.gemspec +4 -1
- data/test/cell_test.rb +33 -98
- data/test/column_test.rb +20 -88
- data/test/{mixins.rb → fixtures/mixins.rb} +6 -4
- data/test/fixtures/test_writer.rb +68 -0
- data/test/format_test.rb +2 -2
- data/test/helper.rb +34 -68
- data/test/mixin_test.rb +37 -43
- data/test/partial_test.rb +3 -26
- data/test/row_test.rb +32 -85
- data/test/style_test.rb +9 -26
- data/test/template_test.rb +5 -6
- data/test/workbook_element_test.rb +231 -0
- data/test/workbook_test.rb +225 -116
- data/test/worksheet_test.rb +51 -98
- data/test/xmlss_writer/api_test.rb +139 -0
- data/test/xmlss_writer/style_cache_test.rb +65 -0
- data/test/xmlss_writer/style_settings_test.rb +263 -0
- data/test/xmlss_writer/styles_test.rb +121 -153
- data/test/xmlss_writer_test.rb +91 -0
- metadata +75 -50
- data/lib/osheet/associations.rb +0 -58
- data/lib/osheet/instance.rb +0 -30
- data/lib/osheet/markup_element.rb +0 -22
- data/lib/osheet/partial_set.rb +0 -57
- data/lib/osheet/railtie.rb +0 -9
- data/lib/osheet/style_set.rb +0 -39
- data/lib/osheet/template_set.rb +0 -51
- data/lib/osheet/view_handler/rails.rb +0 -44
- data/lib/osheet/view_handler/tilt.rb +0 -42
- data/lib/osheet/view_handler.rb +0 -2
- data/lib/osheet/worksheet_element.rb +0 -17
- data/lib/osheet/xmlss_writer/base.rb +0 -49
- data/lib/osheet/xmlss_writer/elements.rb +0 -56
- data/lib/osheet/xmlss_writer/styles.rb +0 -216
- data/test/osheet_test.rb +0 -13
- data/test/partial_set_test.rb +0 -64
- data/test/style_set_test.rb +0 -47
- data/test/template_set_test.rb +0 -74
- data/test/xmlss_writer/base_test.rb +0 -103
- data/test/xmlss_writer/elements_test.rb +0 -172
metadata
CHANGED
@@ -1,13 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: osheet
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
5
|
-
prerelease:
|
4
|
+
hash: 15424055
|
5
|
+
prerelease: 6
|
6
6
|
segments:
|
7
|
+
- 1
|
7
8
|
- 0
|
8
|
-
- 10
|
9
9
|
- 0
|
10
|
-
|
10
|
+
- rc
|
11
|
+
- 1
|
12
|
+
version: 1.0.0.rc.1
|
11
13
|
platform: ruby
|
12
14
|
authors:
|
13
15
|
- Kelly Redding
|
@@ -15,11 +17,10 @@ autorequire:
|
|
15
17
|
bindir: bin
|
16
18
|
cert_chain: []
|
17
19
|
|
18
|
-
date: 2012-
|
20
|
+
date: 2012-03-15 00:00:00 Z
|
19
21
|
dependencies:
|
20
22
|
- !ruby/object:Gem::Dependency
|
21
23
|
type: :development
|
22
|
-
prerelease: false
|
23
24
|
requirement: &id001 !ruby/object:Gem::Requirement
|
24
25
|
none: false
|
25
26
|
requirements:
|
@@ -30,11 +31,11 @@ dependencies:
|
|
30
31
|
- 1
|
31
32
|
- 0
|
32
33
|
version: "1.0"
|
33
|
-
version_requirements: *id001
|
34
34
|
name: bundler
|
35
|
+
version_requirements: *id001
|
36
|
+
prerelease: false
|
35
37
|
- !ruby/object:Gem::Dependency
|
36
38
|
type: :development
|
37
|
-
prerelease: false
|
38
39
|
requirement: &id002 !ruby/object:Gem::Requirement
|
39
40
|
none: false
|
40
41
|
requirements:
|
@@ -45,12 +46,41 @@ dependencies:
|
|
45
46
|
- 0
|
46
47
|
- 3
|
47
48
|
version: "0.3"
|
48
|
-
version_requirements: *id002
|
49
49
|
name: assert
|
50
|
-
|
51
|
-
type: :runtime
|
50
|
+
version_requirements: *id002
|
52
51
|
prerelease: false
|
52
|
+
- !ruby/object:Gem::Dependency
|
53
|
+
type: :development
|
53
54
|
requirement: &id003 !ruby/object:Gem::Requirement
|
55
|
+
none: false
|
56
|
+
requirements:
|
57
|
+
- - ~>
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
hash: 11
|
60
|
+
segments:
|
61
|
+
- 0
|
62
|
+
- 0
|
63
|
+
version: "0.0"
|
64
|
+
name: whysoslow
|
65
|
+
version_requirements: *id003
|
66
|
+
prerelease: false
|
67
|
+
- !ruby/object:Gem::Dependency
|
68
|
+
type: :development
|
69
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
70
|
+
none: false
|
71
|
+
requirements:
|
72
|
+
- - ">="
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
hash: 3
|
75
|
+
segments:
|
76
|
+
- 0
|
77
|
+
version: "0"
|
78
|
+
name: ruby-prof
|
79
|
+
version_requirements: *id004
|
80
|
+
prerelease: false
|
81
|
+
- !ruby/object:Gem::Dependency
|
82
|
+
type: :runtime
|
83
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
54
84
|
none: false
|
55
85
|
requirements:
|
56
86
|
- - ~>
|
@@ -60,23 +90,26 @@ dependencies:
|
|
60
90
|
- 1
|
61
91
|
- 3
|
62
92
|
version: "1.3"
|
63
|
-
version_requirements: *id003
|
64
93
|
name: enumeration
|
94
|
+
version_requirements: *id005
|
95
|
+
prerelease: false
|
65
96
|
- !ruby/object:Gem::Dependency
|
66
97
|
type: :runtime
|
67
|
-
|
68
|
-
requirement: &id004 !ruby/object:Gem::Requirement
|
98
|
+
requirement: &id006 !ruby/object:Gem::Requirement
|
69
99
|
none: false
|
70
100
|
requirements:
|
71
101
|
- - ~>
|
72
102
|
- !ruby/object:Gem::Version
|
73
|
-
hash:
|
103
|
+
hash: 7712010
|
74
104
|
segments:
|
105
|
+
- 1
|
75
106
|
- 0
|
76
|
-
-
|
77
|
-
|
78
|
-
|
107
|
+
- 0
|
108
|
+
- rc
|
109
|
+
version: 1.0.0.rc
|
79
110
|
name: xmlss
|
111
|
+
version_requirements: *id006
|
112
|
+
prerelease: false
|
80
113
|
description: A DSL for specifying and generating spreadsheets using Ruby
|
81
114
|
email:
|
82
115
|
- kelly@kellyredding.com
|
@@ -92,6 +125,7 @@ files:
|
|
92
125
|
- Gemfile.lock
|
93
126
|
- README.rdoc
|
94
127
|
- Rakefile
|
128
|
+
- bench/bench_runner.rb
|
95
129
|
- bench/profiler.rb
|
96
130
|
- bench/profiler_1000.xls
|
97
131
|
- bench/profiler_runner.rb
|
@@ -108,7 +142,6 @@ files:
|
|
108
142
|
- examples/trivial.rb
|
109
143
|
- examples/trivial.xls
|
110
144
|
- lib/osheet.rb
|
111
|
-
- lib/osheet/associations.rb
|
112
145
|
- lib/osheet/cell.rb
|
113
146
|
- lib/osheet/column.rb
|
114
147
|
- lib/osheet/format.rb
|
@@ -124,34 +157,26 @@ files:
|
|
124
157
|
- lib/osheet/format/scientific.rb
|
125
158
|
- lib/osheet/format/special.rb
|
126
159
|
- lib/osheet/format/text.rb
|
127
|
-
- lib/osheet/instance.rb
|
128
|
-
- lib/osheet/markup_element.rb
|
129
160
|
- lib/osheet/meta_element.rb
|
130
161
|
- lib/osheet/mixin.rb
|
131
162
|
- lib/osheet/partial.rb
|
132
|
-
- lib/osheet/partial_set.rb
|
133
|
-
- lib/osheet/railtie.rb
|
134
163
|
- lib/osheet/row.rb
|
135
164
|
- lib/osheet/style.rb
|
136
|
-
- lib/osheet/style_set.rb
|
137
165
|
- lib/osheet/styled_element.rb
|
138
166
|
- lib/osheet/template.rb
|
139
|
-
- lib/osheet/template_set.rb
|
140
167
|
- lib/osheet/version.rb
|
141
|
-
- lib/osheet/view_handler.rb
|
142
|
-
- lib/osheet/view_handler/rails.rb
|
143
|
-
- lib/osheet/view_handler/tilt.rb
|
144
168
|
- lib/osheet/workbook.rb
|
169
|
+
- lib/osheet/workbook_api.rb
|
145
170
|
- lib/osheet/workbook_element.rb
|
146
171
|
- lib/osheet/worksheet.rb
|
147
|
-
- lib/osheet/worksheet_element.rb
|
148
172
|
- lib/osheet/xmlss_writer.rb
|
149
|
-
- lib/osheet/xmlss_writer/
|
150
|
-
- lib/osheet/xmlss_writer/
|
151
|
-
- lib/osheet/xmlss_writer/styles.rb
|
173
|
+
- lib/osheet/xmlss_writer/style_cache.rb
|
174
|
+
- lib/osheet/xmlss_writer/style_settings.rb
|
152
175
|
- osheet.gemspec
|
153
176
|
- test/cell_test.rb
|
154
177
|
- test/column_test.rb
|
178
|
+
- test/fixtures/mixins.rb
|
179
|
+
- test/fixtures/test_writer.rb
|
155
180
|
- test/format/accounting_test.rb
|
156
181
|
- test/format/currency_test.rb
|
157
182
|
- test/format/custom_test.rb
|
@@ -167,20 +192,18 @@ files:
|
|
167
192
|
- test/helper.rb
|
168
193
|
- test/irb.rb
|
169
194
|
- test/mixin_test.rb
|
170
|
-
- test/mixins.rb
|
171
|
-
- test/osheet_test.rb
|
172
|
-
- test/partial_set_test.rb
|
173
195
|
- test/partial_test.rb
|
174
196
|
- test/row_test.rb
|
175
|
-
- test/style_set_test.rb
|
176
197
|
- test/style_test.rb
|
177
|
-
- test/template_set_test.rb
|
178
198
|
- test/template_test.rb
|
199
|
+
- test/workbook_element_test.rb
|
179
200
|
- test/workbook_test.rb
|
180
201
|
- test/worksheet_test.rb
|
181
|
-
- test/xmlss_writer/
|
182
|
-
- test/xmlss_writer/
|
202
|
+
- test/xmlss_writer/api_test.rb
|
203
|
+
- test/xmlss_writer/style_cache_test.rb
|
204
|
+
- test/xmlss_writer/style_settings_test.rb
|
183
205
|
- test/xmlss_writer/styles_test.rb
|
206
|
+
- test/xmlss_writer_test.rb
|
184
207
|
homepage: http://github.com/kellyredding/osheet
|
185
208
|
licenses: []
|
186
209
|
|
@@ -201,12 +224,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
201
224
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
202
225
|
none: false
|
203
226
|
requirements:
|
204
|
-
- - "
|
227
|
+
- - ">"
|
205
228
|
- !ruby/object:Gem::Version
|
206
|
-
hash:
|
229
|
+
hash: 25
|
207
230
|
segments:
|
208
|
-
-
|
209
|
-
|
231
|
+
- 1
|
232
|
+
- 3
|
233
|
+
- 1
|
234
|
+
version: 1.3.1
|
210
235
|
requirements: []
|
211
236
|
|
212
237
|
rubyforge_project:
|
@@ -217,6 +242,8 @@ summary: A DSL for specifying and generating spreadsheets using Ruby
|
|
217
242
|
test_files:
|
218
243
|
- test/cell_test.rb
|
219
244
|
- test/column_test.rb
|
245
|
+
- test/fixtures/mixins.rb
|
246
|
+
- test/fixtures/test_writer.rb
|
220
247
|
- test/format/accounting_test.rb
|
221
248
|
- test/format/currency_test.rb
|
222
249
|
- test/format/custom_test.rb
|
@@ -232,17 +259,15 @@ test_files:
|
|
232
259
|
- test/helper.rb
|
233
260
|
- test/irb.rb
|
234
261
|
- test/mixin_test.rb
|
235
|
-
- test/mixins.rb
|
236
|
-
- test/osheet_test.rb
|
237
|
-
- test/partial_set_test.rb
|
238
262
|
- test/partial_test.rb
|
239
263
|
- test/row_test.rb
|
240
|
-
- test/style_set_test.rb
|
241
264
|
- test/style_test.rb
|
242
|
-
- test/template_set_test.rb
|
243
265
|
- test/template_test.rb
|
266
|
+
- test/workbook_element_test.rb
|
244
267
|
- test/workbook_test.rb
|
245
268
|
- test/worksheet_test.rb
|
246
|
-
- test/xmlss_writer/
|
247
|
-
- test/xmlss_writer/
|
269
|
+
- test/xmlss_writer/api_test.rb
|
270
|
+
- test/xmlss_writer/style_cache_test.rb
|
271
|
+
- test/xmlss_writer/style_settings_test.rb
|
248
272
|
- test/xmlss_writer/styles_test.rb
|
273
|
+
- test/xmlss_writer_test.rb
|
data/lib/osheet/associations.rb
DELETED
@@ -1,58 +0,0 @@
|
|
1
|
-
module Osheet::Associations
|
2
|
-
|
3
|
-
def self.included(receiver)
|
4
|
-
receiver.send(:extend, ClassMethods)
|
5
|
-
end
|
6
|
-
|
7
|
-
module ClassMethods
|
8
|
-
|
9
|
-
# A has many esque association helper
|
10
|
-
# - will provide a collection reader
|
11
|
-
# - will define a 'singular' item method for adding to the collection
|
12
|
-
# - will support adding to the collection both by black and template
|
13
|
-
def hm(collection)
|
14
|
-
unless collection.to_s =~ /s$/
|
15
|
-
raise ArgumentError, "association item names must end in 's'"
|
16
|
-
end
|
17
|
-
plural = collection.to_s
|
18
|
-
singular = plural.to_s.sub(/s$/, '')
|
19
|
-
klass = Osheet.const_get(singular.capitalize)
|
20
|
-
|
21
|
-
# define collection reader
|
22
|
-
self.send(:define_method, plural, Proc.new do
|
23
|
-
set_ivar(plural, []) if get_ivar(plural).nil?
|
24
|
-
get_ivar(plural)
|
25
|
-
end)
|
26
|
-
|
27
|
-
# define collection item writer
|
28
|
-
self.send(:define_method, singular) do |*args, &block|
|
29
|
-
set_ivar(plural, []) if get_ivar(plural).nil?
|
30
|
-
push_ivar(plural, if self.respond_to?(:workbook)
|
31
|
-
# on: worksheet, column, row
|
32
|
-
# creating: column, row, cell
|
33
|
-
worksheet = self.respond_to?(:worksheet) ? self.worksheet : self
|
34
|
-
if self.workbook && (template = self.workbook.templates.get(singular, args.first))
|
35
|
-
# add by template
|
36
|
-
klass.new(self.workbook, worksheet, *args[1..-1], &template)
|
37
|
-
else
|
38
|
-
# add by block
|
39
|
-
klass.new(self.workbook, worksheet, &block)
|
40
|
-
end
|
41
|
-
else
|
42
|
-
# on: workbook
|
43
|
-
# creating: worksheet
|
44
|
-
if (template = self.templates.get(singular, args.first))
|
45
|
-
# add by template
|
46
|
-
klass.new(self, *args[1..-1], &template)
|
47
|
-
else
|
48
|
-
# add by block
|
49
|
-
klass.new(self, &block)
|
50
|
-
end
|
51
|
-
end)
|
52
|
-
end
|
53
|
-
|
54
|
-
end
|
55
|
-
|
56
|
-
end
|
57
|
-
|
58
|
-
end
|
data/lib/osheet/instance.rb
DELETED
@@ -1,30 +0,0 @@
|
|
1
|
-
module Osheet::Instance
|
2
|
-
|
3
|
-
private
|
4
|
-
|
5
|
-
OSHEET_IVAR_NS = "_osheet_"
|
6
|
-
|
7
|
-
def get_ivar(name)
|
8
|
-
instance_variable_get(ivar_name(name))
|
9
|
-
end
|
10
|
-
|
11
|
-
def set_ivar(name, value)
|
12
|
-
instance_variable_set(ivar_name(name), value)
|
13
|
-
end
|
14
|
-
|
15
|
-
def push_ivar(name, value)
|
16
|
-
get_ivar(name) << value
|
17
|
-
end
|
18
|
-
|
19
|
-
def ivar_name(name)
|
20
|
-
"@#{OSHEET_IVAR_NS}#{name}"
|
21
|
-
end
|
22
|
-
|
23
|
-
def set_binding_ivars(binding)
|
24
|
-
binding.eval('instance_variables').
|
25
|
-
reject{|ivar| ivar =~ /^@#{OSHEET_IVAR_NS}/}.
|
26
|
-
each do |ivar|
|
27
|
-
instance_variable_set(ivar, binding.eval(ivar.to_s))
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
@@ -1,22 +0,0 @@
|
|
1
|
-
module Osheet
|
2
|
-
module MarkupElement
|
3
|
-
|
4
|
-
# markup elements can add partial markup to themselves
|
5
|
-
def add(partial_name, *args)
|
6
|
-
if self.kind_of?(Workbook)
|
7
|
-
# on: workbook
|
8
|
-
if (partial = self.partials.get(partial_name))
|
9
|
-
# add partial
|
10
|
-
instance_exec(*args, &partial)
|
11
|
-
end
|
12
|
-
else
|
13
|
-
# on: worksheet, column, row
|
14
|
-
if self.workbook && (partial = self.workbook.partials.get(partial_name))
|
15
|
-
# add partial
|
16
|
-
instance_exec(*args, &partial)
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
end
|
22
|
-
end
|
data/lib/osheet/partial_set.rb
DELETED
@@ -1,57 +0,0 @@
|
|
1
|
-
require 'osheet/partial'
|
2
|
-
|
3
|
-
module Osheet
|
4
|
-
class PartialSet < ::Hash
|
5
|
-
|
6
|
-
# this class is a Hash that behaves kinda like a set. I want to
|
7
|
-
# push partials into the set using the '<<' operator, only allow
|
8
|
-
# Osheet::Partial objs to be pushed, and then be able to reference
|
9
|
-
# a particular partial using a key
|
10
|
-
|
11
|
-
def initialize
|
12
|
-
super
|
13
|
-
end
|
14
|
-
|
15
|
-
def <<(partial)
|
16
|
-
if (key = verify(partial))
|
17
|
-
push(key, partial)
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
# return the named partial
|
22
|
-
def get(name)
|
23
|
-
lookup(key(name.to_s))
|
24
|
-
end
|
25
|
-
|
26
|
-
private
|
27
|
-
|
28
|
-
def lookup(key)
|
29
|
-
self[key]
|
30
|
-
end
|
31
|
-
|
32
|
-
# push the partial onto the key
|
33
|
-
def push(key, partial)
|
34
|
-
self[key] = partial
|
35
|
-
end
|
36
|
-
|
37
|
-
# verify the partial, init and return the key
|
38
|
-
# otherwise ArgumentError it up
|
39
|
-
def verify(partial)
|
40
|
-
unless partial.kind_of?(Partial)
|
41
|
-
raise ArgumentError, 'you can only push Osheet::Partial objs to the partial set'
|
42
|
-
end
|
43
|
-
pkey = partial_key(partial)
|
44
|
-
self[pkey] ||= nil
|
45
|
-
pkey
|
46
|
-
end
|
47
|
-
|
48
|
-
def partial_key(partial)
|
49
|
-
key(partial.name)
|
50
|
-
end
|
51
|
-
|
52
|
-
def key(name)
|
53
|
-
name.to_s
|
54
|
-
end
|
55
|
-
|
56
|
-
end
|
57
|
-
end
|
data/lib/osheet/railtie.rb
DELETED
data/lib/osheet/style_set.rb
DELETED
@@ -1,39 +0,0 @@
|
|
1
|
-
require 'osheet/style'
|
2
|
-
|
3
|
-
module Osheet
|
4
|
-
class StyleSet < ::Array
|
5
|
-
|
6
|
-
# this class is an Array has some helper methods. I want to
|
7
|
-
# push styles into the set using the '<<' operator, only allow
|
8
|
-
# Osheet::Style objs to be pushed, and then be able to reference
|
9
|
-
# a particular set of styles using a style class.
|
10
|
-
|
11
|
-
def initialize
|
12
|
-
super
|
13
|
-
end
|
14
|
-
|
15
|
-
def <<(value)
|
16
|
-
super if verify(value)
|
17
|
-
end
|
18
|
-
|
19
|
-
# return the style set for the style class
|
20
|
-
def for(style_class)
|
21
|
-
self.select{|s| s.match?(style_class)}
|
22
|
-
end
|
23
|
-
|
24
|
-
private
|
25
|
-
|
26
|
-
def styles(class_str)
|
27
|
-
end
|
28
|
-
|
29
|
-
# verify the style, otherwise ArgumentError it up
|
30
|
-
def verify(style)
|
31
|
-
if style.kind_of?(Style)
|
32
|
-
true
|
33
|
-
else
|
34
|
-
raise ArgumentError, 'you can only push Osheet::Style objs to the style set'
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
end
|
39
|
-
end
|
data/lib/osheet/template_set.rb
DELETED
@@ -1,51 +0,0 @@
|
|
1
|
-
require 'osheet/partial_set'
|
2
|
-
require 'osheet/template'
|
3
|
-
|
4
|
-
module Osheet
|
5
|
-
class TemplateSet < PartialSet
|
6
|
-
|
7
|
-
# this class is a PartialSet that keys off of the template element
|
8
|
-
# and name. Only Osheet::Template objs can be pushed, and you reference
|
9
|
-
# a particular template using a key of
|
10
|
-
|
11
|
-
def initialize
|
12
|
-
super
|
13
|
-
end
|
14
|
-
|
15
|
-
# return the template set for the named element
|
16
|
-
def get(element, name)
|
17
|
-
lookup(key(element.to_s, name.to_s))
|
18
|
-
end
|
19
|
-
|
20
|
-
private
|
21
|
-
|
22
|
-
def lookup(key)
|
23
|
-
self[key.first][key.last] if self[key.first]
|
24
|
-
end
|
25
|
-
|
26
|
-
# push the template onto the key
|
27
|
-
def push(key, template)
|
28
|
-
self[key.first][key.last] = template
|
29
|
-
end
|
30
|
-
|
31
|
-
# verify the template, init the key set, and return the key string
|
32
|
-
# otherwise ArgumentError it up
|
33
|
-
def verify(template)
|
34
|
-
unless template.kind_of?(Template)
|
35
|
-
raise ArgumentError, 'you can only push Osheet::Template objs to the template set'
|
36
|
-
end
|
37
|
-
key = template_key(template)
|
38
|
-
self[key.first] ||= {}
|
39
|
-
self[key.first][key.last] ||= nil
|
40
|
-
key
|
41
|
-
end
|
42
|
-
|
43
|
-
def template_key(template)
|
44
|
-
key(template.element, template.name)
|
45
|
-
end
|
46
|
-
|
47
|
-
def key(element, name)
|
48
|
-
[element.to_s, name.to_s]
|
49
|
-
end
|
50
|
-
end
|
51
|
-
end
|
@@ -1,44 +0,0 @@
|
|
1
|
-
# Rails 2.X Template
|
2
|
-
if Rails.version =~ /^2/
|
3
|
-
require 'action_view/base'
|
4
|
-
require 'action_view/template'
|
5
|
-
|
6
|
-
module ActionView
|
7
|
-
module TemplateHandlers
|
8
|
-
class OsheetHandler < TemplateHandler
|
9
|
-
include Compilable
|
10
|
-
|
11
|
-
def compile(template)
|
12
|
-
# template.format => 'xls' (or xlsx or whatever they specify)
|
13
|
-
%{::Osheet::Workbook.new {#{template.source}\n }.to_data}
|
14
|
-
end
|
15
|
-
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
::ActionView::Template.register_template_handler :osheet, ActionView::TemplateHandlers::OsheetHandler
|
21
|
-
end
|
22
|
-
|
23
|
-
# Rails 3.X Template
|
24
|
-
if Rails.version =~ /^3/
|
25
|
-
require 'action_view/base'
|
26
|
-
require 'action_view/template'
|
27
|
-
|
28
|
-
module ActionView
|
29
|
-
module Template::Handlers
|
30
|
-
class OsheetHandler < Template::Handler
|
31
|
-
include Compilable
|
32
|
-
|
33
|
-
self.default_format = Osheet::MIME_TYPE
|
34
|
-
def compile(template)
|
35
|
-
# template.format => 'xls' (or xlsx or whatever they specify)
|
36
|
-
%{::Osheet::Workbook.new {\n#{template.source}\n }.to_data}
|
37
|
-
end
|
38
|
-
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
::ActionView::Template.register_template_handler :osheet, ActionView::Template::Handlers::OsheetHandler
|
44
|
-
end
|
@@ -1,42 +0,0 @@
|
|
1
|
-
# TILT/Sinatra template engine
|
2
|
-
module Osheet
|
3
|
-
class TiltHandler < Tilt::Template
|
4
|
-
|
5
|
-
def self.engine_initialized?
|
6
|
-
defined? ::Osheet::Workbook
|
7
|
-
end
|
8
|
-
|
9
|
-
def initialize_engine
|
10
|
-
require_template_library 'osheet'
|
11
|
-
end
|
12
|
-
|
13
|
-
def prepare; end
|
14
|
-
|
15
|
-
def precompiled_preamble(locals)
|
16
|
-
"::Osheet::Workbook.new {\n#{super}"
|
17
|
-
end
|
18
|
-
|
19
|
-
def precompiled_template(locals)
|
20
|
-
data.to_str
|
21
|
-
end
|
22
|
-
def precompiled_postamble(locals)
|
23
|
-
"}.to_data"
|
24
|
-
end
|
25
|
-
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
Tilt.register 'osheet', Osheet::TiltHandler
|
30
|
-
|
31
|
-
if defined?(::Sinatra::Base)
|
32
|
-
class ::Sinatra::Base
|
33
|
-
|
34
|
-
# use this helper method to render Osheet views in Sinatra
|
35
|
-
# => view files should be named: "#{template}.osheet"
|
36
|
-
def osheet(template, options={}, locals={})
|
37
|
-
options.merge! :layout => false, :default_content_type => ::Osheet::MIME_TYPE
|
38
|
-
render :osheet, template, options, locals
|
39
|
-
end
|
40
|
-
|
41
|
-
end
|
42
|
-
end
|
data/lib/osheet/view_handler.rb
DELETED
@@ -1,17 +0,0 @@
|
|
1
|
-
module Osheet::WorksheetElement
|
2
|
-
|
3
|
-
def worksheet
|
4
|
-
get_ivar(:worksheet)
|
5
|
-
end
|
6
|
-
|
7
|
-
[:columns, :rows].each do |meth|
|
8
|
-
define_method(meth) do
|
9
|
-
if worksheet && worksheet.respond_to?(meth)
|
10
|
-
worksheet.send(meth)
|
11
|
-
else
|
12
|
-
nil
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
end
|
@@ -1,49 +0,0 @@
|
|
1
|
-
require 'fileutils'
|
2
|
-
module Osheet::XmlssWriter; end
|
3
|
-
require 'xmlss'
|
4
|
-
require 'osheet/xmlss_writer/elements'
|
5
|
-
require 'osheet/xmlss_writer/styles'
|
6
|
-
|
7
|
-
module Osheet::XmlssWriter
|
8
|
-
class Base
|
9
|
-
include Elements
|
10
|
-
include Styles
|
11
|
-
|
12
|
-
attr_reader :used_xstyles
|
13
|
-
|
14
|
-
def initialize(opts={})
|
15
|
-
@used_xstyles = []
|
16
|
-
self.oworkbook = if opts.has_key?(:workbook)
|
17
|
-
opts[:workbook]
|
18
|
-
else
|
19
|
-
::Osheet::Workbook.new
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
def to_data(xmlss_output_opts={})
|
24
|
-
self.xworkbook(xmlss_output_opts).to_s
|
25
|
-
end
|
26
|
-
|
27
|
-
def to_file(file_path, xmlss_output_opts={})
|
28
|
-
self.xworkbook(xmlss_output_opts).to_file(file_path)
|
29
|
-
end
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
def oworkbook=(value)
|
35
|
-
unless value.kind_of?(::Osheet::Workbook)
|
36
|
-
raise ArgumentError, "'#{value.inspect}' is not an Osheet::Workbook"
|
37
|
-
end
|
38
|
-
@oworkbook = value
|
39
|
-
end
|
40
|
-
|
41
|
-
def xworkbook(xmlss_output_opts={})
|
42
|
-
@used_xstyles = []
|
43
|
-
::Xmlss::Workbook.new(:output => xmlss_output_opts).tap do |xwkbk|
|
44
|
-
@oworkbook.worksheets.each { |sheet| worksheet(xwkbk, sheet) }
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
end
|
49
|
-
end
|