osheet 0.4.0 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile.lock +24 -4
- data/examples/basic_with_templates.rb +1 -1
- data/examples/formats.rb +1 -1
- data/examples/styles.rb +1 -1
- data/examples/trivial.rb +1 -1
- data/lib/osheet/associations.rb +5 -9
- data/lib/osheet/cell.rb +24 -20
- data/lib/osheet/column.rb +19 -15
- data/lib/osheet/instance.rb +32 -0
- data/lib/osheet/railtie.rb +9 -0
- data/lib/osheet/row.rb +19 -15
- data/lib/osheet/style.rb +13 -8
- data/lib/osheet/styled_element.rb +1 -1
- data/lib/osheet/template.rb +13 -4
- data/lib/osheet/template_handler/rails.rb +44 -0
- data/lib/osheet/template_handler/tilt.rb +42 -0
- data/lib/osheet/template_handler.rb +2 -0
- data/lib/osheet/version.rb +1 -1
- data/lib/osheet/workbook.rb +22 -11
- data/lib/osheet/workbook_element.rb +10 -14
- data/lib/osheet/worksheet.rb +10 -6
- data/lib/osheet/worksheet_element.rb +3 -4
- data/lib/osheet/xmlss_writer/base.rb +5 -5
- data/lib/osheet.rb +16 -1
- data/osheet.gemspec +6 -1
- data/test/app_helper.rb +66 -0
- data/test/cell_test.rb +30 -14
- data/test/column_test.rb +24 -8
- data/test/helper.rb +4 -3
- data/test/mixin_test.rb +1 -2
- data/test/mixins.rb +1 -1
- data/test/osheet_test.rb +4 -2
- data/test/rails/three/.gitignore +4 -0
- data/test/rails/three/Gemfile +5 -0
- data/test/rails/three/Gemfile.lock +88 -0
- data/test/rails/three/app/controllers/application_controller.rb +3 -0
- data/test/rails/three/app/controllers/things_controller.rb +10 -0
- data/test/rails/three/app/helpers/application_helper.rb +2 -0
- data/test/rails/three/app/views/layouts/application.html.erb +14 -0
- data/test/rails/three/app/views/things/index.xls.osheet +15 -0
- data/test/rails/three/config/application.rb +42 -0
- data/test/rails/three/config/boot.rb +13 -0
- data/test/rails/three/config/database.yml +22 -0
- data/test/rails/three/config/environment.rb +5 -0
- data/test/rails/three/config/environments/development.rb +26 -0
- data/test/rails/three/config/environments/production.rb +49 -0
- data/test/rails/three/config/environments/test.rb +35 -0
- data/test/rails/three/config/initializers/app.rb +0 -0
- data/test/rails/three/config/initializers/backtrace_silencers.rb +7 -0
- data/test/rails/three/config/initializers/inflections.rb +10 -0
- data/test/rails/three/config/initializers/mime_types.rb +5 -0
- data/test/rails/three/config/initializers/secret_token.rb +7 -0
- data/test/rails/three/config/initializers/session_store.rb +8 -0
- data/test/rails/three/config/locales/en.yml +5 -0
- data/test/rails/three/config/routes.rb +3 -0
- data/test/rails/three/config.ru +4 -0
- data/test/rails/three/db/seeds.rb +7 -0
- data/test/rails/three/doc/README_FOR_APP +2 -0
- data/test/rails/three/lib/tasks/.gitkeep +0 -0
- data/test/rails/three/script/rails +6 -0
- data/test/rails/two/.bundle/config +2 -0
- data/test/rails/two/Booting +0 -0
- data/test/rails/two/Gemfile +5 -0
- data/test/rails/two/Gemfile.lock +45 -0
- data/test/rails/two/Rails +0 -0
- data/test/rails/two/app/controllers/application_controller.rb +20 -0
- data/test/rails/two/app/controllers/things_controller.rb +10 -0
- data/test/rails/two/app/helpers/application_helper.rb +3 -0
- data/test/rails/two/app/views/things/index.xls.osheet +15 -0
- data/test/rails/two/config/boot.rb +128 -0
- data/test/rails/two/config/database.yml +22 -0
- data/test/rails/two/config/environment.rb +41 -0
- data/test/rails/two/config/environments/development.rb +17 -0
- data/test/rails/two/config/environments/production.rb +28 -0
- data/test/rails/two/config/environments/test.rb +28 -0
- data/test/rails/two/config/initializers/app.rb +2 -0
- data/test/rails/two/config/initializers/backtrace_silencers.rb +7 -0
- data/test/rails/two/config/initializers/cookie_verification_secret.rb +7 -0
- data/test/rails/two/config/initializers/inflections.rb +10 -0
- data/test/rails/two/config/initializers/mime_types.rb +5 -0
- data/test/rails/two/config/initializers/new_rails_defaults.rb +21 -0
- data/test/rails/two/config/initializers/session_store.rb +15 -0
- data/test/rails/two/config/locales/en.yml +5 -0
- data/test/rails/two/config/routes.rb +3 -0
- data/test/rails/two/db/development.sqlite3 +0 -0
- data/test/rails/two/db/seeds.rb +7 -0
- data/test/rails/two/script/about +4 -0
- data/test/rails/two/script/console +3 -0
- data/test/rails/two/script/dbconsole +3 -0
- data/test/rails/two/script/destroy +3 -0
- data/test/rails/two/script/generate +3 -0
- data/test/rails/two/script/performance/benchmarker +3 -0
- data/test/rails/two/script/performance/profiler +3 -0
- data/test/rails/two/script/plugin +3 -0
- data/test/rails/two/script/runner +3 -0
- data/test/rails/two/script/server +3 -0
- data/test/rails/two/tmp/pids/server.pid +1 -0
- data/test/rails_test.rb +38 -0
- data/test/row_test.rb +24 -8
- data/test/sinatra/app.rb +16 -0
- data/test/sinatra/views/index.osheet +13 -0
- data/test/sinatra_test.rb +19 -0
- data/test/style_test.rb +19 -3
- data/test/template_test.rb +19 -0
- data/test/workbook_test.rb +18 -3
- data/test/worksheet_test.rb +18 -2
- metadata +232 -11
data/Gemfile.lock
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
osheet (0.
|
4
|
+
osheet (0.5.0)
|
5
5
|
enumeration (~> 1.1.0)
|
6
|
-
xmlss (~> 0.
|
6
|
+
xmlss (~> 0.2.0)
|
7
7
|
|
8
8
|
GEM
|
9
9
|
remote: http://rubygems.org/
|
@@ -13,13 +13,28 @@ GEM
|
|
13
13
|
kelredd-useful (0.4.1)
|
14
14
|
json
|
15
15
|
leftright (0.9.0)
|
16
|
+
mime-types (1.16)
|
16
17
|
nokogiri (1.4.4)
|
18
|
+
open4 (1.0.1)
|
19
|
+
rack (1.2.2)
|
20
|
+
rack-test (0.5.7)
|
21
|
+
rack (>= 1.0)
|
22
|
+
rest-client (1.6.1)
|
23
|
+
mime-types (>= 1.16)
|
17
24
|
shoulda (2.11.3)
|
25
|
+
sinatra (1.2.1)
|
26
|
+
rack (~> 1.1)
|
27
|
+
tilt (>= 1.2.2, < 2.0)
|
18
28
|
test-belt (0.2.1)
|
19
29
|
kelredd-useful (~> 0.4.0)
|
20
30
|
leftright (~> 0.9.0)
|
21
31
|
shoulda (~> 2.11)
|
22
|
-
|
32
|
+
tilt (1.2.2)
|
33
|
+
webrat (0.7.3)
|
34
|
+
nokogiri (>= 1.2.0)
|
35
|
+
rack (>= 1.0)
|
36
|
+
rack-test (>= 0.5.3)
|
37
|
+
xmlss (0.2.0)
|
23
38
|
enumeration (~> 1.1.0)
|
24
39
|
nokogiri (~> 1.4.0)
|
25
40
|
|
@@ -29,6 +44,11 @@ PLATFORMS
|
|
29
44
|
DEPENDENCIES
|
30
45
|
bundler (~> 1.0)
|
31
46
|
enumeration (~> 1.1.0)
|
47
|
+
open4
|
32
48
|
osheet!
|
49
|
+
rack-test (>= 0.5.3)
|
50
|
+
rest-client
|
51
|
+
sinatra (>= 0.9.4)
|
33
52
|
test-belt (= 0.2.1)
|
34
|
-
|
53
|
+
webrat (>= 0.6.0)
|
54
|
+
xmlss (~> 0.2.0)
|
data/examples/formats.rb
CHANGED
data/examples/styles.rb
CHANGED
data/examples/trivial.rb
CHANGED
data/lib/osheet/associations.rb
CHANGED
@@ -20,18 +20,14 @@ module Osheet::Associations
|
|
20
20
|
|
21
21
|
# define collection reader
|
22
22
|
self.send(:define_method, plural, Proc.new do
|
23
|
-
if
|
24
|
-
|
25
|
-
end
|
26
|
-
instance_variable_get("@#{plural}")
|
23
|
+
set_ivar(plural, []) if get_ivar(plural).nil?
|
24
|
+
get_ivar(plural)
|
27
25
|
end)
|
28
26
|
|
29
27
|
# define collection item writer
|
30
28
|
self.send(:define_method, singular) do |*args, &block|
|
31
|
-
if
|
32
|
-
|
33
|
-
end
|
34
|
-
instance_variable_get("@#{plural}") << if self.respond_to?(:workbook)
|
29
|
+
set_ivar(plural, []) if get_ivar(plural).nil?
|
30
|
+
push_ivar(plural, if self.respond_to?(:workbook)
|
35
31
|
# on: worksheet, column, row
|
36
32
|
# creating: column, row, cell
|
37
33
|
worksheet = self.respond_to?(:worksheet) ? self.worksheet : self
|
@@ -52,7 +48,7 @@ module Osheet::Associations
|
|
52
48
|
# add by block
|
53
49
|
klass.new(self, &block)
|
54
50
|
end
|
55
|
-
end
|
51
|
+
end)
|
56
52
|
end
|
57
53
|
|
58
54
|
end
|
data/lib/osheet/cell.rb
CHANGED
@@ -3,48 +3,52 @@ require 'osheet/format'
|
|
3
3
|
|
4
4
|
module Osheet
|
5
5
|
class Cell
|
6
|
+
include Instance
|
6
7
|
include WorkbookElement
|
7
8
|
include WorksheetElement
|
8
9
|
include StyledElement
|
9
10
|
|
10
11
|
def initialize(workbook=nil, worksheet=nil, *args, &block)
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
12
|
+
set_ivar(:workbook, workbook)
|
13
|
+
set_ivar(:worksheet, worksheet)
|
14
|
+
set_ivar(:data, nil)
|
15
|
+
set_ivar(:format, Format.new(:general))
|
16
|
+
set_ivar(:rowspan, 1)
|
17
|
+
set_ivar(:colspan, 1)
|
18
|
+
set_ivar(:href, nil)
|
19
|
+
if block_given?
|
20
|
+
set_binding_ivars(block.binding)
|
21
|
+
instance_exec(*args, &block)
|
22
|
+
end
|
19
23
|
end
|
20
24
|
|
21
25
|
def data(value)
|
22
|
-
|
26
|
+
set_ivar(:data, case value
|
23
27
|
when ::String, ::Numeric, ::Date, ::Time, ::DateTime
|
24
28
|
value
|
25
29
|
when ::Symbol
|
26
30
|
value.to_s
|
27
31
|
else
|
28
32
|
value.inspect.to_s
|
29
|
-
end
|
33
|
+
end)
|
30
34
|
end
|
31
35
|
|
32
36
|
def format(type, opts={})
|
33
|
-
|
37
|
+
set_ivar(:format, Format.new(type, opts))
|
34
38
|
end
|
35
39
|
|
36
|
-
def rowspan(value);
|
37
|
-
def colspan(value);
|
38
|
-
def href(value);
|
40
|
+
def rowspan(value); set_ivar(:rowspan, value); end
|
41
|
+
def colspan(value); set_ivar(:colspan, value); end
|
42
|
+
def href(value); set_ivar(:href, value); end
|
39
43
|
|
40
44
|
def attributes
|
41
45
|
{
|
42
|
-
:style_class =>
|
43
|
-
:data =>
|
44
|
-
:format =>
|
45
|
-
:colspan =>
|
46
|
-
:rowspan =>
|
47
|
-
:href =>
|
46
|
+
:style_class => get_ivar(:style_class),
|
47
|
+
:data => get_ivar(:data),
|
48
|
+
:format => get_ivar(:format),
|
49
|
+
:colspan => get_ivar(:colspan),
|
50
|
+
:rowspan => get_ivar(:rowspan),
|
51
|
+
:href => get_ivar(:href)
|
48
52
|
}
|
49
53
|
end
|
50
54
|
|
data/lib/osheet/column.rb
CHANGED
@@ -1,33 +1,37 @@
|
|
1
1
|
module Osheet
|
2
2
|
class Column
|
3
|
+
include Instance
|
3
4
|
include WorkbookElement
|
4
5
|
include WorksheetElement
|
5
6
|
include StyledElement
|
6
7
|
include MetaElement
|
7
8
|
|
8
9
|
def initialize(workbook=nil, worksheet=nil, *args, &block)
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
10
|
+
set_ivar(:workbook, workbook)
|
11
|
+
set_ivar(:worksheet, worksheet)
|
12
|
+
set_ivar(:width, nil)
|
13
|
+
set_ivar(:autofit, false)
|
14
|
+
set_ivar(:hidden, false)
|
15
|
+
if block_given?
|
16
|
+
set_binding_ivars(block.binding)
|
17
|
+
instance_exec(*args, &block)
|
18
|
+
end
|
15
19
|
end
|
16
20
|
|
17
21
|
def width(value=nil)
|
18
|
-
!value.nil? ?
|
22
|
+
!value.nil? ? set_ivar(:width, value) : get_ivar(:width)
|
19
23
|
end
|
20
|
-
def autofit(value);
|
21
|
-
def autofit?;
|
22
|
-
def hidden(value);
|
23
|
-
def hidden?;
|
24
|
+
def autofit(value); set_ivar(:autofit, !!value); end
|
25
|
+
def autofit?; get_ivar(:autofit); end
|
26
|
+
def hidden(value); set_ivar(:hidden, !!value); end
|
27
|
+
def hidden?; get_ivar(:hidden); end
|
24
28
|
|
25
29
|
def attributes
|
26
30
|
{
|
27
|
-
:style_class =>
|
28
|
-
:width =>
|
29
|
-
:autofit =>
|
30
|
-
:hidden =>
|
31
|
+
:style_class => get_ivar(:style_class),
|
32
|
+
:width => get_ivar(:width),
|
33
|
+
:autofit => get_ivar(:autofit),
|
34
|
+
:hidden => get_ivar(:hidden)
|
31
35
|
}
|
32
36
|
end
|
33
37
|
|
@@ -0,0 +1,32 @@
|
|
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
|
+
# puts "binding #{ivar}: "+binding.eval(ivar).object_id.to_s
|
28
|
+
instance_variable_set(ivar, binding.eval(ivar))
|
29
|
+
# puts "inst #{ivar}: "+ instance_variable_get(ivar).object_id.to_s
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
data/lib/osheet/row.rb
CHANGED
@@ -2,6 +2,7 @@ require 'osheet/cell'
|
|
2
2
|
|
3
3
|
module Osheet
|
4
4
|
class Row
|
5
|
+
include Instance
|
5
6
|
include Associations
|
6
7
|
include WorkbookElement
|
7
8
|
include WorksheetElement
|
@@ -11,28 +12,31 @@ module Osheet
|
|
11
12
|
hm :cells
|
12
13
|
|
13
14
|
def initialize(workbook=nil, worksheet=nil, *args, &block)
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
15
|
+
set_ivar(:workbook, workbook)
|
16
|
+
set_ivar(:worksheet, worksheet)
|
17
|
+
set_ivar(:height, nil)
|
18
|
+
set_ivar(:autofit, false)
|
19
|
+
set_ivar(:hidden, false)
|
20
|
+
if block_given?
|
21
|
+
set_binding_ivars(block.binding)
|
22
|
+
instance_exec(*args, &block)
|
23
|
+
end
|
20
24
|
end
|
21
25
|
|
22
26
|
def height(value=nil)
|
23
|
-
!value.nil? ?
|
27
|
+
!value.nil? ? set_ivar(:height, value) : get_ivar(:height)
|
24
28
|
end
|
25
|
-
def autofit(value);
|
26
|
-
def autofit?;
|
27
|
-
def hidden(value);
|
28
|
-
def hidden?;
|
29
|
+
def autofit(value); set_ivar(:autofit, !!value); end
|
30
|
+
def autofit?; get_ivar(:autofit); end
|
31
|
+
def hidden(value); set_ivar(:hidden, !!value); end
|
32
|
+
def hidden?; get_ivar(:hidden); end
|
29
33
|
|
30
34
|
def attributes
|
31
35
|
{
|
32
|
-
:style_class =>
|
33
|
-
:height =>
|
34
|
-
:autofit =>
|
35
|
-
:hidden =>
|
36
|
+
:style_class => get_ivar(:style_class),
|
37
|
+
:height => get_ivar(:height),
|
38
|
+
:autofit => get_ivar(:autofit),
|
39
|
+
:hidden => get_ivar(:hidden)
|
36
40
|
}
|
37
41
|
end
|
38
42
|
|
data/lib/osheet/style.rb
CHANGED
@@ -5,23 +5,28 @@ module Osheet
|
|
5
5
|
# each setting collects any arguments passed to it and
|
6
6
|
# it is up to the drivers to determine how to use the settings
|
7
7
|
|
8
|
+
include Instance
|
9
|
+
|
8
10
|
BORDER_POSITIONS = [:top, :right, :bottom, :left]
|
9
11
|
BORDERS = BORDER_POSITIONS.collect{|p| "border_#{p}".to_sym}
|
10
12
|
SETTINGS = [:align, :font, :bg] + BORDERS
|
11
13
|
|
12
|
-
attr_reader :selectors
|
13
|
-
|
14
14
|
def initialize(*selectors, &block)
|
15
|
-
|
16
|
-
SETTINGS.each
|
17
|
-
|
15
|
+
set_ivar(:selectors, verify(selectors))
|
16
|
+
SETTINGS.each {|setting| set_ivar(setting, [])}
|
17
|
+
if block_given?
|
18
|
+
set_binding_ivars(block.binding)
|
19
|
+
instance_eval(&block)
|
18
20
|
end
|
19
|
-
|
21
|
+
end
|
22
|
+
|
23
|
+
def selectors
|
24
|
+
get_ivar(:selectors)
|
20
25
|
end
|
21
26
|
|
22
27
|
SETTINGS.each do |setting|
|
23
28
|
define_method(setting) do |*args|
|
24
|
-
|
29
|
+
set_ivar(setting, get_ivar(setting) + args)
|
25
30
|
end
|
26
31
|
end
|
27
32
|
|
@@ -33,7 +38,7 @@ module Osheet
|
|
33
38
|
|
34
39
|
def attributes
|
35
40
|
SETTINGS.inject({}) do |attrs, s|
|
36
|
-
attrs[s] =
|
41
|
+
attrs[s] = get_ivar(s)
|
37
42
|
attrs
|
38
43
|
end
|
39
44
|
end
|
data/lib/osheet/template.rb
CHANGED
@@ -6,17 +6,26 @@ module Osheet
|
|
6
6
|
# if an element is initialized from a template, the template
|
7
7
|
# block will be instance_eval'd for the element being initialized
|
8
8
|
|
9
|
-
|
9
|
+
include Instance
|
10
10
|
|
11
|
-
|
11
|
+
ELEMENTS = ['worksheet', 'column', 'row', 'cell']
|
12
12
|
|
13
13
|
def initialize(element, name)
|
14
14
|
verify(element, name)
|
15
|
-
|
16
|
-
|
15
|
+
set_ivar(:element, element.to_s)
|
16
|
+
set_ivar(:name, name.to_s)
|
17
17
|
super()
|
18
18
|
end
|
19
19
|
|
20
|
+
[:element, :name].each do |meth|
|
21
|
+
define_method(meth) do
|
22
|
+
get_ivar(meth)
|
23
|
+
end
|
24
|
+
define_method("#{meth}=") do |value|
|
25
|
+
set_ivar(meth, value)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
20
29
|
private
|
21
30
|
|
22
31
|
def verify(element, name)
|
@@ -0,0 +1,44 @@
|
|
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
|
@@ -0,0 +1,42 @@
|
|
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/version.rb
CHANGED
data/lib/osheet/workbook.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
require 'osheet/instance'
|
1
2
|
require 'osheet/style_set'
|
2
3
|
require 'osheet/template_set'
|
3
4
|
require 'osheet/worksheet'
|
@@ -5,31 +6,41 @@ require 'osheet/xmlss_writer'
|
|
5
6
|
|
6
7
|
module Osheet
|
7
8
|
class Workbook
|
9
|
+
include Instance
|
8
10
|
include Associations
|
9
11
|
|
10
12
|
hm :worksheets
|
11
|
-
attr_reader :styles, :templates
|
12
13
|
|
13
14
|
def initialize(&block)
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
15
|
+
set_ivar(:title, nil)
|
16
|
+
set_ivar(:styles, StyleSet.new)
|
17
|
+
set_ivar(:templates, TemplateSet.new)
|
18
|
+
if block_given?
|
19
|
+
set_binding_ivars(block.binding)
|
20
|
+
instance_eval(&block)
|
21
|
+
end
|
18
22
|
end
|
19
23
|
|
20
24
|
def title(value=nil)
|
21
|
-
!value.nil? ?
|
25
|
+
!value.nil? ? set_ivar(:title, value) : get_ivar(:title)
|
26
|
+
end
|
27
|
+
|
28
|
+
def style(*selectors, &block); push_ivar(:styles, Style.new(*selectors, &block)); end
|
29
|
+
def styles
|
30
|
+
get_ivar(:styles)
|
31
|
+
end
|
32
|
+
def template(element, name, &block); push_ivar(:templates, Template.new(element, name, &block)); end
|
33
|
+
def templates
|
34
|
+
get_ivar(:templates)
|
22
35
|
end
|
23
|
-
def style(*selectors, &block); @styles << Style.new(*selectors, &block); end
|
24
|
-
def template(element, name, &block); @templates << Template.new(element, name, &block); end
|
25
36
|
|
26
37
|
def attributes
|
27
|
-
{ :title =>
|
38
|
+
{ :title => get_ivar(:title) }
|
28
39
|
end
|
29
40
|
|
30
41
|
def use(mixin)
|
31
|
-
(mixin.styles || []).each{ |s|
|
32
|
-
(mixin.templates || []).each{ |t|
|
42
|
+
(mixin.styles || []).each{ |s| push_ivar(:styles, s) }
|
43
|
+
(mixin.templates || []).each{ |t| push_ivar(:templates, t) }
|
33
44
|
end
|
34
45
|
|
35
46
|
def writer
|
@@ -1,21 +1,17 @@
|
|
1
1
|
module Osheet::WorkbookElement
|
2
|
-
class << self
|
3
2
|
|
4
|
-
|
5
|
-
|
6
|
-
|
3
|
+
def workbook
|
4
|
+
get_ivar(:workbook)
|
5
|
+
end
|
7
6
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
end
|
15
|
-
end
|
7
|
+
[:styles, :templates].each do |thing|
|
8
|
+
define_method(thing) do
|
9
|
+
if workbook && workbook.respond_to?(thing)
|
10
|
+
workbook.send(thing)
|
11
|
+
else
|
12
|
+
nil
|
16
13
|
end
|
17
|
-
|
18
14
|
end
|
19
|
-
|
20
15
|
end
|
16
|
+
|
21
17
|
end
|
data/lib/osheet/worksheet.rb
CHANGED
@@ -3,6 +3,7 @@ require 'osheet/row'
|
|
3
3
|
|
4
4
|
module Osheet
|
5
5
|
class Worksheet
|
6
|
+
include Instance
|
6
7
|
include Associations
|
7
8
|
include WorkbookElement
|
8
9
|
include MetaElement
|
@@ -11,23 +12,26 @@ module Osheet
|
|
11
12
|
hm :rows
|
12
13
|
|
13
14
|
def initialize(workbook=nil, *args, &block)
|
14
|
-
|
15
|
-
|
16
|
-
|
15
|
+
set_ivar(:workbook, workbook)
|
16
|
+
set_ivar(:name, nil)
|
17
|
+
if block_given?
|
18
|
+
set_binding_ivars(block.binding)
|
19
|
+
instance_exec(*args, &block)
|
20
|
+
end
|
17
21
|
end
|
18
22
|
|
19
23
|
def name(value=nil)
|
20
|
-
!value.nil? ?
|
24
|
+
!value.nil? ? set_ivar(:name, sanitized_name(value)) : get_ivar(:name)
|
21
25
|
end
|
22
26
|
|
23
27
|
def attributes
|
24
|
-
{ :name =>
|
28
|
+
{ :name => get_ivar(:name) }
|
25
29
|
end
|
26
30
|
|
27
31
|
private
|
28
32
|
|
29
33
|
def sanitized_name(name_value)
|
30
|
-
if
|
34
|
+
if get_ivar(:workbook) && get_ivar(:workbook).worksheets.collect{|ws| ws.name}.include?(name_value)
|
31
35
|
raise ArgumentError, "the sheet name '#{name_value}' is already in use. choose a sheet name that is not used by another sheet"
|
32
36
|
end
|
33
37
|
name_value
|