entable 0.0.3 → 0.0.4

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.
@@ -1,8 +1,8 @@
1
1
  require "entable/version"
2
2
 
3
3
  module Entable
4
- def self.add_transformer name, &block
5
- Entable::Transformer.add_transformer name, &block
4
+ def self.add_transformer name, transformer=nil, &block
5
+ Entable::Transformer.add_transformer name, transformer, &block
6
6
  end
7
7
 
8
8
  def self.add_wrapper name, &block
@@ -1,7 +1,7 @@
1
1
  module Entable::Transformer
2
- def self.add_transformer name, &block
2
+ def self.add_transformer name, transformer=nil, &block
3
3
  @@transformers ||= { }
4
- @@transformers[name.to_sym] = block
4
+ @@transformers[name.to_sym] = transformer || block
5
5
  end
6
6
 
7
7
  def self.apply_transform collection, transform_name
@@ -1,3 +1,3 @@
1
1
  module Entable
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
@@ -62,6 +62,29 @@ describe Entable do
62
62
  </table></body></html>}
63
63
  end
64
64
 
65
+ it "should generate a simple table, with two of each item" do
66
+ config = {
67
+ "preprocess" => {
68
+ "transform" => "double_each_item"
69
+ },
70
+ "columns" => [
71
+ { "title" => "First", "content" => "%{firstname}" },
72
+ { "title" => "Last", "content" => "%{lastname}" }
73
+ ]
74
+ }
75
+ Exporter.new(config).to_xls(CONTACTS).should == %{<html><head><meta content='application/vnd.ms-excel;charset=UTF-8' http-equiv='Content-Type'><meta content='UTF-8' http-equiv='Encoding'></head><body><table>
76
+ <tr><td>First</td> <td>Last</td></tr>
77
+ <tr><td>Conan</td> <td>Dalton</td></tr>
78
+ <tr><td>Conan</td> <td>Dalton</td></tr>
79
+ <tr><td>Zed</td> <td>Zenumbra</td></tr>
80
+ <tr><td>Zed</td> <td>Zenumbra</td></tr>
81
+ <tr><td>Abraham</td> <td>Aardvark</td></tr>
82
+ <tr><td>Abraham</td> <td>Aardvark</td></tr>
83
+ <tr><td>James</td> <td>Joyce</td></tr>
84
+ <tr><td>James</td> <td>Joyce</td></tr>
85
+ </table></body></html>}
86
+ end
87
+
65
88
 
66
89
  it "should generate a table with two rows per item, applying #colspan attribute " do
67
90
  config = {
@@ -39,10 +39,22 @@ class ContactUpper
39
39
  end
40
40
  end
41
41
 
42
+ class TwiceEverything
43
+ def call collection
44
+ collection.inject([]) { |result, item|
45
+ result << item
46
+ result << item
47
+ result
48
+ }
49
+ end
50
+ end
51
+
42
52
  Entable.add_transformer :sort_by_last_name do |collection|
43
53
  collection.sort_by &:lastname
44
54
  end
45
55
 
56
+ Entable.add_transformer :double_each_item, TwiceEverything.new
57
+
46
58
  Entable.add_wrapper :uppercase do |item|
47
59
  ContactUpper.new item
48
60
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: entable
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-06-11 00:00:00.000000000 Z
12
+ date: 2013-06-23 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec