entable 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README.md +24 -3
- data/lib/entable/html_builder.rb +1 -1
- data/lib/entable/version.rb +1 -1
- data/spec/entable/entable_spec.rb +11 -10
- data/spec/spec_helper.rb +6 -6
- metadata +12 -16
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 609673674c17a5213a7a6d95c459d59b677c50fd
|
4
|
+
data.tar.gz: 51d597be22a0c96111c3c484b977f71da253d1f8
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: ca52a7d6598679effea65ed57e911dbdacd8549aebf94caa0440059fe2324c37fc3b119da8174f11c234fb374328ec09840298769207b4aa05dfbfb8d1c4653a
|
7
|
+
data.tar.gz: 1386e92b1dc23c1be2e5937a4dc6ae1536fedde71489b612d5c50cb5c32c01dd1af3c322348b216016ca1d0e37e92957b24c6c7ffbab79fd9d4aa63cbed65d33
|
data/README.md
CHANGED
@@ -78,6 +78,22 @@ Or, similarly,
|
|
78
78
|
collection.order("full_name ASC")
|
79
79
|
end
|
80
80
|
|
81
|
+
You can pass any object that responds to #call:
|
82
|
+
|
83
|
+
Entable.add_transformer :sort_by_full_name, OrderApplication("full_name ASC")
|
84
|
+
|
85
|
+
where
|
86
|
+
|
87
|
+
class OrderApplication
|
88
|
+
def initialize(expr)
|
89
|
+
@expr = expr
|
90
|
+
end
|
91
|
+
|
92
|
+
def call(collection)
|
93
|
+
collection.order(@expr)
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
81
97
|
|
82
98
|
Wrappers are not strictly necessary; you could apply a wrapper inside a transformer.
|
83
99
|
Separating the two frees you to apply each independently.
|
@@ -93,11 +109,16 @@ dates.
|
|
93
109
|
|
94
110
|
To install a wrapper, call Entable#add_wrapper
|
95
111
|
|
96
|
-
Entable.add_wrapper :contact_export do |
|
97
|
-
ContactTable.new
|
112
|
+
Entable.add_wrapper :contact_export do |contact, *args|
|
113
|
+
ContactTable.new contact, *args
|
98
114
|
end
|
99
115
|
|
100
|
-
In this example, the
|
116
|
+
In this example, the _contact_ is the object to be wrapped, and _*args_ are the arguments passed to #to_xls earlier. This allows you pass any extra parameters to your wrapper that you might need in order to render each item as a row in a spreadsheet.
|
117
|
+
|
118
|
+
You can also supply a Class directly - this example is equivalent to the example above:
|
119
|
+
|
120
|
+
Entable.add_wrapper :contact_export, ContactTable
|
121
|
+
|
101
122
|
|
102
123
|
|
103
124
|
|
data/lib/entable/html_builder.rb
CHANGED
@@ -6,7 +6,7 @@ module Entable::HtmlBuilder
|
|
6
6
|
|
7
7
|
str = str.strip.gsub(/%\{[^}]*\}/) { |match|
|
8
8
|
attr = match.gsub(/^%\{/, '').gsub(/\}$/, '').gsub(/-/, '_').strip
|
9
|
-
if attr.match(/^[a-zA-Z_][a-zA-Z0-9_]*$/)
|
9
|
+
if attr.match(/^[a-zA-Z_][a-zA-Z0-9_\.]*$/)
|
10
10
|
"%{item.#{attr}}"
|
11
11
|
else
|
12
12
|
errors << "prohibited attribute #{match}"
|
data/lib/entable/version.rb
CHANGED
@@ -7,18 +7,19 @@ describe Entable do
|
|
7
7
|
it "should generate a very simple table with one row per item" do
|
8
8
|
config = {
|
9
9
|
"columns" => [
|
10
|
-
{ "title" => "First", "content" => "%{firstname}"
|
11
|
-
{ "title" => "Last", "content" => "%{lastname}"
|
12
|
-
{ "title" => "Phone", "content" => "%{phone}"
|
13
|
-
{ "title" => "Postcode", "content" => "%{postcode}"
|
10
|
+
{ "title" => "First", "content" => "%{firstname}" },
|
11
|
+
{ "title" => "Last", "content" => "%{lastname}" },
|
12
|
+
{ "title" => "Phone", "content" => "%{phone}" },
|
13
|
+
{ "title" => "Postcode", "content" => "%{postcode}" },
|
14
|
+
{ "title" => "Org", "content" => "%{org.name}" },
|
14
15
|
]
|
15
16
|
}
|
16
17
|
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>
|
17
|
-
<tr><td>First</td> <td>Last</td> <td>Phone</td> <td>Postcode</td></tr>
|
18
|
-
<tr><td>Conan</td> <td>Dalton</td> <td>01234567</td> <td>75020</td></tr>
|
19
|
-
<tr><td>Zed</td> <td>Zenumbra</td> <td>999999</td> <td>99999</td></tr>
|
20
|
-
<tr><td>Abraham</td> <td>Aardvark</td> <td>0000000</td> <td>0</td></tr>
|
21
|
-
<tr><td>James</td> <td>Joyce</td> <td>3647583</td> <td>75001</td></tr>
|
18
|
+
<tr><td>First</td> <td>Last</td> <td>Phone</td> <td>Postcode</td> <td>Org</td></tr>
|
19
|
+
<tr><td>Conan</td> <td>Dalton</td> <td>01234567</td> <td>75020</td> <td>Softify</td></tr>
|
20
|
+
<tr><td>Zed</td> <td>Zenumbra</td> <td>999999</td> <td>99999</td> <td>Ericsson</td></tr>
|
21
|
+
<tr><td>Abraham</td> <td>Aardvark</td> <td>0000000</td> <td>0</td> <td>Nokia</td></tr>
|
22
|
+
<tr><td>James</td> <td>Joyce</td> <td>3647583</td> <td>75001</td> <td>Nortel</td></tr>
|
22
23
|
</table></body></html>}
|
23
24
|
end
|
24
25
|
|
@@ -175,7 +176,7 @@ describe Entable do
|
|
175
176
|
Proc.new { Exporter.new(config).to_xls(CONTACTS) }.should raise_error(StandardError, "Unknown wrapper name :not_configured")
|
176
177
|
end
|
177
178
|
|
178
|
-
it "should generate an error for a nonexistent
|
179
|
+
it "should generate an error for a nonexistent transform" do
|
179
180
|
config = {
|
180
181
|
"preprocess" => {
|
181
182
|
"transform" => "not_configured"
|
data/spec/spec_helper.rb
CHANGED
@@ -18,13 +18,14 @@ RSpec.configure do |config|
|
|
18
18
|
config.order = 'random'
|
19
19
|
end
|
20
20
|
|
21
|
-
|
21
|
+
Org = Struct.new :name
|
22
|
+
Contact = Struct.new :firstname, :lastname, :phone, :postcode, :org
|
22
23
|
|
23
24
|
CONTACTS = []
|
24
|
-
CONTACTS << Contact.new("Conan",
|
25
|
-
CONTACTS << Contact.new("Zed",
|
26
|
-
CONTACTS << Contact.new("Abraham", "Aardvark", "0000000",
|
27
|
-
CONTACTS << Contact.new("James",
|
25
|
+
CONTACTS << Contact.new("Conan", "Dalton", "01234567", "75020", Org.new("Softify"))
|
26
|
+
CONTACTS << Contact.new("Zed", "Zenumbra", "999999", "99999", Org.new("Ericsson"))
|
27
|
+
CONTACTS << Contact.new("Abraham", "Aardvark", "0000000", "0", Org.new("Nokia"))
|
28
|
+
CONTACTS << Contact.new("James", "Joyce", "3647583", "75001", Org.new("Nortel"))
|
28
29
|
|
29
30
|
class ContactUpper
|
30
31
|
def firstname; contact.firstname.upcase; end
|
@@ -113,4 +114,3 @@ class Exporter
|
|
113
114
|
build_interpreter(config).to_xls items, *args
|
114
115
|
end
|
115
116
|
end
|
116
|
-
|
metadata
CHANGED
@@ -1,33 +1,30 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: entable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
5
|
-
prerelease:
|
4
|
+
version: 0.0.6
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Conan Dalton
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 2014-09-10 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: rspec
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
16
|
requirements:
|
19
|
-
- - ~>
|
17
|
+
- - "~>"
|
20
18
|
- !ruby/object:Gem::Version
|
21
19
|
version: '2.9'
|
22
20
|
type: :development
|
23
21
|
prerelease: false
|
24
22
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
23
|
requirements:
|
27
|
-
- - ~>
|
24
|
+
- - "~>"
|
28
25
|
- !ruby/object:Gem::Version
|
29
26
|
version: '2.9'
|
30
|
-
description:
|
27
|
+
description: 'Generate HTML tables which popular spreadsheet software packages know
|
31
28
|
how to read '
|
32
29
|
email:
|
33
30
|
- conan@conandalton.net
|
@@ -35,8 +32,8 @@ executables: []
|
|
35
32
|
extensions: []
|
36
33
|
extra_rdoc_files: []
|
37
34
|
files:
|
38
|
-
- .gitignore
|
39
|
-
- .rspec
|
35
|
+
- ".gitignore"
|
36
|
+
- ".rspec"
|
40
37
|
- Gemfile
|
41
38
|
- LICENSE.txt
|
42
39
|
- README.md
|
@@ -52,27 +49,26 @@ files:
|
|
52
49
|
- spec/spec_helper.rb
|
53
50
|
homepage: https://github.com/conanite/entable
|
54
51
|
licenses: []
|
52
|
+
metadata: {}
|
55
53
|
post_install_message:
|
56
54
|
rdoc_options: []
|
57
55
|
require_paths:
|
58
56
|
- lib
|
59
57
|
required_ruby_version: !ruby/object:Gem::Requirement
|
60
|
-
none: false
|
61
58
|
requirements:
|
62
|
-
- -
|
59
|
+
- - ">="
|
63
60
|
- !ruby/object:Gem::Version
|
64
61
|
version: '0'
|
65
62
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
66
|
-
none: false
|
67
63
|
requirements:
|
68
|
-
- -
|
64
|
+
- - ">="
|
69
65
|
- !ruby/object:Gem::Version
|
70
66
|
version: '0'
|
71
67
|
requirements: []
|
72
68
|
rubyforge_project:
|
73
|
-
rubygems_version:
|
69
|
+
rubygems_version: 2.2.2
|
74
70
|
signing_key:
|
75
|
-
specification_version:
|
71
|
+
specification_version: 4
|
76
72
|
summary: LibreOffice and Microsoft Office are both able to open a HTML file and interpret
|
77
73
|
the contents of the <table> element as a worksheet. This gem generates such a HTML
|
78
74
|
file, given a collection and a configuration. For each column, the configuration
|