slim2pdf 0.0.2 → 0.0.3
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/.travis.yml +4 -0
- data/README.md +59 -36
- data/lib/slim2pdf/version.rb +1 -1
- data/lib/slim2pdf/writer.rb +3 -2
- data/test/writer_test.rb +7 -2
- metadata +5 -4
data/.travis.yml
ADDED
data/README.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# Slim2pdf [](https://codeclimate.com/github/macuk/slim2pdf)
|
|
1
|
+
# Slim2pdf [](https://codeclimate.com/github/macuk/slim2pdf) [](https://travis-ci.org/macuk/slim2pdf)
|
|
2
2
|
|
|
3
3
|
Slim2pdf renders [slim template](http://slim-lang.com/) with data hash and saves the results as pdf file.
|
|
4
4
|
|
|
@@ -18,30 +18,49 @@ Or install it yourself as:
|
|
|
18
18
|
|
|
19
19
|
## Usage
|
|
20
20
|
|
|
21
|
-
|
|
21
|
+
```ruby
|
|
22
|
+
require 'slim2pdf'
|
|
23
|
+
```
|
|
22
24
|
|
|
23
25
|
### Create writer object
|
|
24
26
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
27
|
+
```ruby
|
|
28
|
+
writer = Slim2pdf::Writer.new
|
|
29
|
+
writer.template = 'template.slim'
|
|
30
|
+
writer.data = {name: 'John', surname: 'Doe'}
|
|
31
|
+
```
|
|
28
32
|
|
|
29
33
|
### Set parameters in initializer
|
|
30
34
|
|
|
31
|
-
|
|
35
|
+
```ruby
|
|
36
|
+
writer = Slim2pdf::Writer.new('template.slim', {name: 'John', surname: 'Doe'})
|
|
37
|
+
```
|
|
32
38
|
|
|
33
39
|
### Possible actions
|
|
34
40
|
|
|
35
|
-
|
|
41
|
+
```ruby
|
|
42
|
+
writer.render_to_html # return rendered html as string
|
|
36
43
|
|
|
37
|
-
|
|
44
|
+
writer.save_to_html('output.html') # saves rendered html to file
|
|
38
45
|
|
|
39
|
-
|
|
46
|
+
writer.save_to_pdf('output.pdf') # saves rendered html as pdf file
|
|
47
|
+
```
|
|
40
48
|
|
|
41
|
-
### Changing default wkhtmltopdf
|
|
49
|
+
### Changing default wkhtmltopdf path
|
|
42
50
|
|
|
43
|
-
|
|
44
|
-
|
|
51
|
+
```ruby
|
|
52
|
+
writer = Slim2pdf::Writer.new
|
|
53
|
+
writer.wkhtmltopdf_path = '/your/path/to/wkhtmltopdf'
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
Wkhtmltopdf params will be generated automatically.
|
|
57
|
+
|
|
58
|
+
### Changing default wkhtmltopdf command with params
|
|
59
|
+
|
|
60
|
+
```ruby
|
|
61
|
+
writer = Slim2pdf::Writer.new
|
|
62
|
+
writer.wkhtmltopdf_command = '/bin/some_wrapper /your/path/to/wkhtmltopdf --your --params'
|
|
63
|
+
```
|
|
45
64
|
|
|
46
65
|
Input (html) and output (pdf) files will be added automatically.
|
|
47
66
|
|
|
@@ -49,38 +68,40 @@ Input (html) and output (pdf) files will be added automatically.
|
|
|
49
68
|
|
|
50
69
|
### Save simple slim template without data to pdf file
|
|
51
70
|
|
|
52
|
-
|
|
71
|
+
```ruby
|
|
72
|
+
require 'slim2pdf'
|
|
53
73
|
|
|
54
|
-
|
|
55
|
-
|
|
74
|
+
writer = Slim2pdf::Writer.new('simple.slim')
|
|
75
|
+
writer.save_to_pdf('simple.pdf')
|
|
76
|
+
```
|
|
56
77
|
|
|
57
78
|
See: [doc/examples/simple](https://github.com/macuk/slim2pdf/tree/master/doc/examples/simple)
|
|
58
79
|
|
|
59
80
|
### Generate agreement with footer
|
|
60
81
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
82
|
+
```ruby
|
|
83
|
+
writer = Slim2pdf::Writer.new('agreement.slim')
|
|
84
|
+
writer.data = {date: '2014-01-14', part1: 'Google', part2: 'Microsoft'}
|
|
85
|
+
writer.footer_text = 'Agreement footer'
|
|
86
|
+
writer.save_to_pdf('agreement.pdf')
|
|
87
|
+
```
|
|
67
88
|
|
|
68
89
|
See: [doc/examples/agreement](https://github.com/macuk/slim2pdf/tree/master/doc/examples/agreement)
|
|
69
90
|
|
|
70
91
|
### Generate bulk invoices
|
|
71
92
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
93
|
+
```ruby
|
|
94
|
+
writer = Slim2pdf::Writer.new('invoice.slim')
|
|
95
|
+
buyers = ['Buyer A', 'Buyer B', 'Buyer C', 'Buyer D']
|
|
96
|
+
buyers.each_with_index do |buyer, index|
|
|
97
|
+
number = index + 1
|
|
98
|
+
writer.data = {
|
|
99
|
+
seller: 'Seller', buyer: buyer, number: "#{number}/2014",
|
|
100
|
+
item_name: 'Service', price: '$100', date: '2014-01-14'
|
|
101
|
+
}
|
|
102
|
+
writer.save_to_pdf("invoice-#{number}.pdf")
|
|
103
|
+
end
|
|
104
|
+
```
|
|
84
105
|
|
|
85
106
|
See: [doc/examples/invoices](https://github.com/macuk/slim2pdf/tree/master/doc/examples/invoices)
|
|
86
107
|
|
|
@@ -88,10 +109,12 @@ See: [doc/examples/invoices](https://github.com/macuk/slim2pdf/tree/master/doc/e
|
|
|
88
109
|
|
|
89
110
|
### Setting logger
|
|
90
111
|
|
|
91
|
-
|
|
112
|
+
```ruby
|
|
113
|
+
require 'logger'
|
|
92
114
|
|
|
93
|
-
|
|
94
|
-
|
|
115
|
+
writer = Slim2pdf::Writer.new
|
|
116
|
+
writer.logger = Logger.new(STDERR)
|
|
117
|
+
```
|
|
95
118
|
|
|
96
119
|
If you use Slim2pdf with Rails, the Rails.logger will be set automatically.
|
|
97
120
|
|
data/lib/slim2pdf/version.rb
CHANGED
data/lib/slim2pdf/writer.rb
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
module Slim2pdf
|
|
2
2
|
class Writer
|
|
3
3
|
attr_accessor :template, :data
|
|
4
|
-
attr_accessor :wkhtmltopdf_command
|
|
4
|
+
attr_accessor :wkhtmltopdf_path, :wkhtmltopdf_command
|
|
5
5
|
attr_accessor :footer_text, :footer_font, :footer_font_size
|
|
6
6
|
attr_accessor :logger
|
|
7
7
|
|
|
@@ -32,7 +32,8 @@ module Slim2pdf
|
|
|
32
32
|
|
|
33
33
|
# wkhtmltopdf command without html and pdf file params
|
|
34
34
|
def wkhtmltopdf_command
|
|
35
|
-
@
|
|
35
|
+
path = @wkhtmltopdf_path || 'wkhtmltopdf'
|
|
36
|
+
@wkhtmltopdf_command || "#{path} #{footer_params} -q"
|
|
36
37
|
end
|
|
37
38
|
|
|
38
39
|
def logger
|
data/test/writer_test.rb
CHANGED
|
@@ -61,9 +61,14 @@ module Slim2pdf
|
|
|
61
61
|
assert_equal false, File.exists?(path)
|
|
62
62
|
end
|
|
63
63
|
|
|
64
|
+
def test_wkhtmltopdf_path
|
|
65
|
+
assert_equal 'wkhtmltopdf -q', @writer.wkhtmltopdf_command
|
|
66
|
+
@writer.wkhtmltopdf_path = '/test/path/to/wkhtmltopdf'
|
|
67
|
+
assert_equal '/test/path/to/wkhtmltopdf -q', @writer.wkhtmltopdf_command
|
|
68
|
+
end
|
|
69
|
+
|
|
64
70
|
def test_wkhtmltopdf_command
|
|
65
|
-
|
|
66
|
-
assert_match /-q/, @writer.wkhtmltopdf_command
|
|
71
|
+
assert_equal 'wkhtmltopdf -q', @writer.wkhtmltopdf_command
|
|
67
72
|
@writer.wkhtmltopdf_command = 'test -a -b -c'
|
|
68
73
|
assert_equal 'test -a -b -c', @writer.wkhtmltopdf_command
|
|
69
74
|
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: slim2pdf
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.0.
|
|
4
|
+
version: 0.0.3
|
|
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: 2014-01-
|
|
12
|
+
date: 2014-01-21 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
|
14
14
|
- !ruby/object:Gem::Dependency
|
|
15
15
|
name: bundler
|
|
@@ -100,6 +100,7 @@ extensions: []
|
|
|
100
100
|
extra_rdoc_files: []
|
|
101
101
|
files:
|
|
102
102
|
- .gitignore
|
|
103
|
+
- .travis.yml
|
|
103
104
|
- Gemfile
|
|
104
105
|
- LICENSE.txt
|
|
105
106
|
- README.md
|
|
@@ -138,7 +139,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
138
139
|
version: '0'
|
|
139
140
|
segments:
|
|
140
141
|
- 0
|
|
141
|
-
hash:
|
|
142
|
+
hash: 3380417682014750478
|
|
142
143
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
143
144
|
none: false
|
|
144
145
|
requirements:
|
|
@@ -147,7 +148,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
147
148
|
version: '0'
|
|
148
149
|
segments:
|
|
149
150
|
- 0
|
|
150
|
-
hash:
|
|
151
|
+
hash: 3380417682014750478
|
|
151
152
|
requirements: []
|
|
152
153
|
rubyforge_project:
|
|
153
154
|
rubygems_version: 1.8.25
|