table2png 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/Gemfile +3 -0
- data/LICENSE.txt +22 -0
- data/README.md +32 -0
- data/Rakefile +1 -0
- data/lib/table2png/bin/wkhtmltoimage +0 -0
- data/lib/table2png/bin/wkhtmltoimage-amd64 +0 -0
- data/lib/table2png/converter.rb +43 -0
- data/lib/table2png/table.css +30 -0
- data/lib/table2png.rb +7 -0
- data/spec/converter_spec.rb +32 -0
- data/spec/fixtures/big.png +0 -0
- data/spec/fixtures/big_table.html +1 -0
- data/spec/fixtures/small.png +0 -0
- data/spec/fixtures/small_table.html +12 -0
- data/spec/spec_helper.rb +6 -0
- data/table.css +30 -0
- data/table2png.gemspec +27 -0
- metadata +138 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 02e6568f4b2c9ce82355096ce6ffe9fccd96c657
|
4
|
+
data.tar.gz: 0f895421bad382c9abe42c77dcbf2ca956b16e5f
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 89fce77bd35d1ce4cdd294ebd6cb44e3ac36dba81b5441f8260c4ba25325e0670546549694deae837a7e45d5e7348c37b2558f836321e0a7cc974755d851869a
|
7
|
+
data.tar.gz: 49e8617bbab0ee9ee5f9c99f76f9ede714bd3955554b127f2c559698bb11359016e03878fc095183abd2866e2c117701c5c5003d046512354dcc9532008ab0a9
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Maiz Lulkin
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
# Table2PNG
|
2
|
+
|
3
|
+
A simple PNG generator based on an HTML table.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'table2png'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install table2png
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
```ruby
|
22
|
+
# e.g. Table2PNG table_html, max_width
|
23
|
+
Table2PNG "<table><tr><td>HEY</td></tr></table>", 300
|
24
|
+
```
|
25
|
+
|
26
|
+
## Contributing
|
27
|
+
|
28
|
+
1. Fork it
|
29
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
30
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
31
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
32
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
Binary file
|
Binary file
|
@@ -0,0 +1,43 @@
|
|
1
|
+
module Table2PNG
|
2
|
+
IMGKit.configure do |config|
|
3
|
+
binary_path = ENV['HEROKU'] ?
|
4
|
+
'bin/wkhtmltoimage-amd64' :
|
5
|
+
'bin/wkhtmltoimage'
|
6
|
+
|
7
|
+
config.wkhtmltoimage = File.join(File.dirname(__FILE__), binary_path)
|
8
|
+
config.default_options = { quality: 100, "disable-javascript" => true }
|
9
|
+
end
|
10
|
+
|
11
|
+
Converter = Struct.new(:html, :new_width) do
|
12
|
+
def save path
|
13
|
+
process
|
14
|
+
png.save path
|
15
|
+
end
|
16
|
+
|
17
|
+
def width
|
18
|
+
png.width
|
19
|
+
end
|
20
|
+
|
21
|
+
def height
|
22
|
+
png.height
|
23
|
+
end
|
24
|
+
|
25
|
+
def process
|
26
|
+
png.trim!
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
def png
|
31
|
+
@png ||= ChunkyPNG::Image.from_blob png_from_table
|
32
|
+
end
|
33
|
+
|
34
|
+
def png_from_table
|
35
|
+
return @png_from_table if defined?(@png_from_table)
|
36
|
+
|
37
|
+
image_from_table = IMGKit.new(html)
|
38
|
+
image_from_table.stylesheets << "#{Dir.pwd}/table.css"
|
39
|
+
|
40
|
+
@png_from_table = image_from_table.to_img(:png)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
table{
|
2
|
+
border: 0;
|
3
|
+
border-collapse: collapse;
|
4
|
+
border-spacing: 0;
|
5
|
+
font-family: "Helvetica Neue", Arial;
|
6
|
+
}
|
7
|
+
table tr:first-child{
|
8
|
+
background: #f5f5f5;
|
9
|
+
}
|
10
|
+
tr{
|
11
|
+
border: 0;
|
12
|
+
}
|
13
|
+
td{
|
14
|
+
border: 1px solid #ccc;
|
15
|
+
padding: 8px;
|
16
|
+
color: #555 !important;
|
17
|
+
}
|
18
|
+
th{
|
19
|
+
color: #000;
|
20
|
+
}
|
21
|
+
tr td:first-child p{
|
22
|
+
color: #444 !important;
|
23
|
+
}
|
24
|
+
|
25
|
+
p{
|
26
|
+
color: #777 !important;
|
27
|
+
}
|
28
|
+
strong{
|
29
|
+
color: #444 !important;
|
30
|
+
}
|
data/lib/table2png.rb
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
require_relative 'spec_helper'
|
2
|
+
|
3
|
+
include Table2PNG
|
4
|
+
|
5
|
+
describe Converter do
|
6
|
+
|
7
|
+
subject(:png) { Converter.new(table).process }
|
8
|
+
|
9
|
+
describe '#process' do
|
10
|
+
context 'given a small table' do
|
11
|
+
let(:table) { File.read(Dir.pwd + "/spec/fixtures/small_table.html") }
|
12
|
+
let(:result) { File.read(Dir.pwd + "/spec/fixtures/small.png") }
|
13
|
+
|
14
|
+
it 'converts table to trimmed png' do
|
15
|
+
expect(png.to_blob).to eq(result)
|
16
|
+
expect(png.width).to eq(300)
|
17
|
+
expect(png.height).to eq(73)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
context 'given a big table' do
|
22
|
+
let(:table) { File.read(Dir.pwd + "/spec/fixtures/big_table.html") }
|
23
|
+
let(:result) { File.read(Dir.pwd + "/spec/fixtures/big.png") }
|
24
|
+
|
25
|
+
it 'converts table to trimmed png' do
|
26
|
+
expect(png.to_blob).to eq(result)
|
27
|
+
expect(png.width).to eq(845)
|
28
|
+
expect(png.height).to eq(414)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
Binary file
|
@@ -0,0 +1 @@
|
|
1
|
+
<table border="1" cellpadding="0"><colgroup><col><col><col><col><col><col><col></colgroup> <tbody><tr><td> </td><td><p><strong>Q4 2014</strong></p></td><td><p><strong>Q4 2013</strong></p></td><td><p><strong>Y/Y Change</strong></p></td><td><p><strong>2014</strong></p></td><td><p><strong>2013</strong></p></td><td><p><strong>Y/Y Change</strong></p></td></tr> <tr><td><p>Revenue</p></td><td><p>$6,723,934</p></td><td><p>$5,295,318</p></td><td><p>26.98%</p></td><td><p>$26,108,607</p></td><td><p>$23,569,475</p></td><td><p>10.77%</p></td></tr> <tr><td><p>Cost of Goods Sold</p></td><td><p>($6,336,746)</p></td><td><p>($4,981,024)</p></td><td><p>27.22%</p></td><td><p>($24,603,198)</p></td><td><p>($22,182,230)</p></td><td><p>10.91%</p></td></tr> <tr><td><p>Gross Profit</p></td><td><p>$387,188</p></td><td><p>$314,294</p></td><td><p>23.19%</p></td><td><p>$1,505,409</p></td><td><p>$1,387,245</p></td><td><p>8.52%</p></td></tr> <tr><td><p><em>Gross Margin</em></p></td><td><p><em>5.76%</em></p></td><td><p><em>5.94%</em></p></td><td><p>-2.98%</p></td><td><p><em>5.77%</em></p></td><td><p><em>5.89%</em></p></td><td><p>-2.04%</p></td></tr> <tr><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td></tr> <tr><td><p>SG&A</p></td><td><p>$205,235</p></td><td><p>$208,781</p></td><td><p>-1.70%</p></td><td><p>$840,897</p></td><td><p>$775,869</p></td><td><p>8.38%</p></td></tr> <tr><td><p><em>As a % of Revenue</em></p></td><td><p><em>3.05%</em></p></td><td><p><em>3.94%</em></p></td><td><p>-22.58%</p></td><td><p><em>3.22%</em></p></td><td><p><em>3.29%</em></p></td><td><p>-2.16%</p></td></tr> <tr><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td></tr> <tr><td><p>Operating Income (Loss)</p></td><td><p>$181,953</p></td><td><p>$105,513</p></td><td><p>72.45%</p></td><td><p>$664,512</p></td><td><p>$611,376</p></td><td><p>8.69%</p></td></tr> <tr><td><p><em>Operating Margin</em></p></td><td><p><em>2.71%</em></p></td><td><p><em>1.99%</em></p></td><td><p>35.81%</p></td><td><p><em>2.55%</em></p></td><td><p><em>2.59%</em></p></td><td><p>-1.88%</p></td></tr> <tr><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td></tr> <tr><td><p><strong>EPS</strong></p></td><td><p><strong>$0.24</strong></p></td><td><p><strong>$0.13</strong></p></td><td><p><strong>84.62%</strong></p></td><td><p><strong>$0.89</strong></p></td><td><p><strong>$0.84</strong></p></td><td><p><strong>5.95%</strong></p></td></tr></tbody></table>
|
Binary file
|
data/spec/spec_helper.rb
ADDED
data/table.css
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
table{
|
2
|
+
border: 0;
|
3
|
+
border-collapse: collapse;
|
4
|
+
border-spacing: 0;
|
5
|
+
font-family: "Helvetica Neue", Arial;
|
6
|
+
}
|
7
|
+
table tr:first-child{
|
8
|
+
background: #f5f5f5;
|
9
|
+
}
|
10
|
+
tr{
|
11
|
+
border: 0;
|
12
|
+
}
|
13
|
+
td{
|
14
|
+
border: 1px solid #ccc;
|
15
|
+
padding: 8px;
|
16
|
+
color: #555 !important;
|
17
|
+
}
|
18
|
+
th{
|
19
|
+
color: #000;
|
20
|
+
}
|
21
|
+
tr td:first-child p{
|
22
|
+
color: #444 !important;
|
23
|
+
}
|
24
|
+
|
25
|
+
p{
|
26
|
+
color: #777 !important;
|
27
|
+
}
|
28
|
+
strong{
|
29
|
+
color: #444 !important;
|
30
|
+
}
|
data/table2png.gemspec
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "table2png"
|
7
|
+
spec.version = '0.0.1'
|
8
|
+
spec.authors = ["Maiz Lulkin"]
|
9
|
+
spec.email = ["maiz@lulk.in"]
|
10
|
+
spec.description = %q{Generates a png based on an HTML table}
|
11
|
+
spec.summary = %q{Generates a png based on an HTML table}
|
12
|
+
spec.homepage = ""
|
13
|
+
spec.license = "MIT"
|
14
|
+
|
15
|
+
spec.files = `git ls-files`.split($/)
|
16
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
17
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
18
|
+
spec.require_paths = ["lib"]
|
19
|
+
|
20
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
21
|
+
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
spec.add_development_dependency "rspec", "~>2.14"
|
24
|
+
|
25
|
+
spec.add_dependency 'chunky_png'
|
26
|
+
spec.add_dependency 'imgkit', '1.4.1'
|
27
|
+
end
|
metadata
ADDED
@@ -0,0 +1,138 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: table2png
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Maiz Lulkin
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-05-19 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.3'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ~>
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '2.14'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '2.14'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: chunky_png
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: imgkit
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - '='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 1.4.1
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - '='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 1.4.1
|
83
|
+
description: Generates a png based on an HTML table
|
84
|
+
email:
|
85
|
+
- maiz@lulk.in
|
86
|
+
executables: []
|
87
|
+
extensions: []
|
88
|
+
extra_rdoc_files: []
|
89
|
+
files:
|
90
|
+
- .gitignore
|
91
|
+
- Gemfile
|
92
|
+
- LICENSE.txt
|
93
|
+
- README.md
|
94
|
+
- Rakefile
|
95
|
+
- lib/table2png.rb
|
96
|
+
- lib/table2png/bin/wkhtmltoimage
|
97
|
+
- lib/table2png/bin/wkhtmltoimage-amd64
|
98
|
+
- lib/table2png/converter.rb
|
99
|
+
- lib/table2png/table.css
|
100
|
+
- spec/converter_spec.rb
|
101
|
+
- spec/fixtures/big.png
|
102
|
+
- spec/fixtures/big_table.html
|
103
|
+
- spec/fixtures/small.png
|
104
|
+
- spec/fixtures/small_table.html
|
105
|
+
- spec/spec_helper.rb
|
106
|
+
- table.css
|
107
|
+
- table2png.gemspec
|
108
|
+
homepage: ''
|
109
|
+
licenses:
|
110
|
+
- MIT
|
111
|
+
metadata: {}
|
112
|
+
post_install_message:
|
113
|
+
rdoc_options: []
|
114
|
+
require_paths:
|
115
|
+
- lib
|
116
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
117
|
+
requirements:
|
118
|
+
- - '>='
|
119
|
+
- !ruby/object:Gem::Version
|
120
|
+
version: '0'
|
121
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
122
|
+
requirements:
|
123
|
+
- - '>='
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
version: '0'
|
126
|
+
requirements: []
|
127
|
+
rubyforge_project:
|
128
|
+
rubygems_version: 2.0.6
|
129
|
+
signing_key:
|
130
|
+
specification_version: 4
|
131
|
+
summary: Generates a png based on an HTML table
|
132
|
+
test_files:
|
133
|
+
- spec/converter_spec.rb
|
134
|
+
- spec/fixtures/big.png
|
135
|
+
- spec/fixtures/big_table.html
|
136
|
+
- spec/fixtures/small.png
|
137
|
+
- spec/fixtures/small_table.html
|
138
|
+
- spec/spec_helper.rb
|