osheet 1.0.0 → 1.1.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.md CHANGED
@@ -110,7 +110,7 @@ I've added a few examples to ./examples. Please refer first to the API then to
110
110
 
111
111
  Add this line to your application's Gemfile:
112
112
 
113
- gem 'whysoslow'
113
+ gem 'osheet'
114
114
 
115
115
  And then execute:
116
116
 
@@ -118,7 +118,7 @@ And then execute:
118
118
 
119
119
  Or install it yourself as:
120
120
 
121
- $ gem install whysoslow
121
+ $ gem install osheet
122
122
 
123
123
  ## Contributing
124
124
 
@@ -0,0 +1,33 @@
1
+ module Osheet
2
+
3
+ module AssertTestHelpers
4
+
5
+ def assert_style(style, selectors)
6
+ with_backtrace(caller) do
7
+ assert_equal selectors, style.selectors, 'unexpected style selectors'
8
+ end
9
+ end
10
+
11
+ def assert_partial(workbook_partials, name)
12
+ with_backtrace(caller) do
13
+ partial = workbook_partials[name.to_s]
14
+ assert_not_nil partial, "could not find a partial named `#{name}`"
15
+ assert_equal name.to_s, partial.name, 'wrong partial name'
16
+ end
17
+ end
18
+
19
+ def assert_template(workbook_templates, element, name)
20
+ with_backtrace(caller) do
21
+ elem_templates = workbook_templates[element.to_s]
22
+ assert_not_nil elem_templates, "could not find any `#{element}` templates"
23
+ template = elem_templates[name.to_s]
24
+ assert_not_nil template, "could not find a `#{element}` template named `#{name}`"
25
+ assert_equal element.to_s, template.element, 'wrong template element'
26
+ assert_equal name.to_s, template.name, 'wrong template name'
27
+ end
28
+
29
+ end
30
+
31
+ end
32
+
33
+ end
@@ -5,6 +5,7 @@ module Osheet
5
5
  # block with arguments. If the partial is added to an element,
6
6
  # any markup in it's definition block is applied to the element.
7
7
  # ie. the definition block will be instance_eval'd on workbook.
8
+ attr_reader :name
8
9
 
9
10
  def initialize(name)
10
11
  unless name.kind_of?(::String) || name.kind_of?(::Symbol)
@@ -9,6 +9,8 @@ module Osheet
9
9
 
10
10
  ELEMENTS = ['worksheet', 'column', 'row', 'cell']
11
11
 
12
+ attr_reader :element
13
+
12
14
  def initialize(element, name)
13
15
  unless element.respond_to?(:to_s) && ELEMENTS.include?(element.to_s)
14
16
  raise ArgumentError, "you can only define a template for #{ELEMENTS.join(', ')} elements."
@@ -1,3 +1,3 @@
1
1
  module Osheet
2
- VERSION = "1.0.0"
2
+ VERSION = "1.1.0"
3
3
  end
@@ -1,6 +1,8 @@
1
1
  require "assert"
2
2
  require 'osheet/mixin'
3
3
 
4
+ require "osheet/assert_test_helpers"
5
+ require 'osheet/workbook'
4
6
  require "test/support/mixins"
5
7
 
6
8
  module Osheet::Mixin
@@ -47,6 +49,8 @@ module Osheet::Mixin
47
49
  end
48
50
 
49
51
  class MixinStyleTests < Assert::Context
52
+ include Osheet::AssertTestHelpers
53
+
50
54
  desc "that defines styles"
51
55
  subject { StyledMixin }
52
56
 
@@ -54,9 +58,22 @@ module Osheet::Mixin
54
58
  assert_equal 2, subject.styles.size
55
59
  assert_kind_of Osheet::Mixin::Args, subject.styles.first
56
60
  end
61
+
62
+ should "apply to a workbook" do
63
+ workbook = Osheet::Workbook.new{ use StyledMixin }
64
+
65
+ assert_equal 2, workbook.styles.size
66
+ test, test_awesome = workbook.styles
67
+
68
+ assert_style test, ['.test']
69
+ assert_style test_awesome, ['.test.awesome']
70
+ end
71
+
57
72
  end
58
73
 
59
74
  class MixinTemplateTests < Assert::Context
75
+ include Osheet::AssertTestHelpers
76
+
60
77
  desc "that defines templates"
61
78
  subject { TemplatedMixin }
62
79
 
@@ -65,9 +82,22 @@ module Osheet::Mixin
65
82
  assert_equal 3, subject.templates.size
66
83
  assert_kind_of Osheet::Mixin::Args, subject.templates.first
67
84
  end
85
+
86
+ should "apply to a workbook" do
87
+ workbook = Osheet::Workbook.new{ use TemplatedMixin }
88
+
89
+ assert_equal 3, workbook.templates.size
90
+
91
+ assert_template workbook.templates, :column, :yo
92
+ assert_template workbook.templates, :row, :yo_yo
93
+ assert_template workbook.templates, :worksheet, :go
94
+ end
95
+
68
96
  end
69
97
 
70
98
  class MixinPartialTests < Assert::Context
99
+ include Osheet::AssertTestHelpers
100
+
71
101
  desc "that defines partials"
72
102
  subject { PartialedMixin }
73
103
 
@@ -76,6 +106,16 @@ module Osheet::Mixin
76
106
  assert_equal 2, subject.partials.size
77
107
  assert_kind_of Osheet::Mixin::Args, subject.partials.first
78
108
  end
109
+
110
+ should "apply to a workbook" do
111
+ workbook = Osheet::Workbook.new{ use PartialedMixin }
112
+
113
+ assert_equal 2, workbook.partials.size
114
+
115
+ assert_partial workbook.partials, :three_empty_rows
116
+ assert_partial workbook.partials, :two_cells_in_a_row
117
+ end
118
+
79
119
  end
80
120
 
81
121
  end
@@ -8,6 +8,8 @@ class Osheet::Partial
8
8
  before{ @p = Osheet::Partial.new(:thing) {} }
9
9
  subject{ @p }
10
10
 
11
+ should have_reader :name
12
+
11
13
  should "be a Proc" do
12
14
  assert_kind_of ::Proc, subject
13
15
  end
@@ -12,6 +12,8 @@ class Osheet::Template
12
12
  end
13
13
  subject { @tmpl }
14
14
 
15
+ should have_reader :element
16
+
15
17
  should "define what elements it is valid for" do
16
18
  assert_equal ['worksheet', 'column', 'row', 'cell'], Osheet::Template::ELEMENTS
17
19
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: osheet
3
3
  version: !ruby/object:Gem::Version
4
- hash: 23
4
+ hash: 19
5
5
  prerelease:
6
6
  segments:
7
7
  - 1
8
+ - 1
8
9
  - 0
9
- - 0
10
- version: 1.0.0
10
+ version: 1.1.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Kelly Redding
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2013-07-21 00:00:00 Z
18
+ date: 2013-10-28 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: assert
@@ -63,6 +63,7 @@ files:
63
63
  - README.md
64
64
  - Rakefile
65
65
  - lib/osheet.rb
66
+ - lib/osheet/assert_test_helpers.rb
66
67
  - lib/osheet/cell.rb
67
68
  - lib/osheet/column.rb
68
69
  - lib/osheet/format.rb