tilt-prawn 0.0.1 → 0.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.
- checksums.yaml +4 -4
- data/README.md +79 -0
- data/lib/tilt/prawn/version.rb +1 -1
- data/lib/tilt/prawn.rb +34 -26
- metadata +4 -17
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: f0a35a8cd9c83e420dc8cc7826d9ef8aa962efe9
|
|
4
|
+
data.tar.gz: d7356ebc81a1f6887557e9cc1e757d3a2be0d8d4
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: f934330b71be18b75aa39c950baa417aedc680b42553807dfe5e8aa69455bb581a02d8d876daf18a1912c66f1ca996d8d48c033485ce867d5e7fd740d2b6ad4b
|
|
7
|
+
data.tar.gz: 015f05a5d2744d51ed5e521fff3e298703be71fe9843d21ed02c3e3312a841955c7fb5b776f18f359e39ec5ddb625944dcff05a0b8973f719cfa7163cb58fa8d
|
data/README.md
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
# tilt-prawn [](https://travis-ci.org/fengb/tilt-prawn)
|
|
2
|
+
|
|
3
|
+
Adds support for rendering [Prawn](http://prawn.majesticseacreature.com/) templates using [Tilt](https://github.com/rtomayko/tilt).
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
Add this line to your application's Gemfile:
|
|
8
|
+
|
|
9
|
+
gem 'tilt-prawn'
|
|
10
|
+
|
|
11
|
+
And then execute:
|
|
12
|
+
|
|
13
|
+
$ bundle
|
|
14
|
+
|
|
15
|
+
Or install it yourself as:
|
|
16
|
+
|
|
17
|
+
$ gem install tilt-prawn
|
|
18
|
+
|
|
19
|
+
## Usage
|
|
20
|
+
|
|
21
|
+
Create a Prawn template file with a `.prawn` extension
|
|
22
|
+
|
|
23
|
+
Example, in `hello.prawn`:
|
|
24
|
+
|
|
25
|
+
```ruby
|
|
26
|
+
pdf.text "Hello #{name}"
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
Then, render the template with Ruby:
|
|
30
|
+
|
|
31
|
+
```ruby
|
|
32
|
+
require 'tilt/prawn'
|
|
33
|
+
|
|
34
|
+
template = Tilt.new('hello.prawn')
|
|
35
|
+
puts template.render(nil, name: 'Bob')
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
## Customization
|
|
39
|
+
|
|
40
|
+
Additional convenience methods may be added to the rendering engine:
|
|
41
|
+
|
|
42
|
+
```ruby
|
|
43
|
+
Tilt::PrawnTemplate.extend_engine do
|
|
44
|
+
def date_text(date)
|
|
45
|
+
text date.strftime('%b %d, %Y')
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
`date_text` is now available as an instance method on the renderer:
|
|
51
|
+
|
|
52
|
+
```ruby
|
|
53
|
+
pdf.date_text(Date.today)
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
If you defined an external class as a base template, you may use it instead of
|
|
57
|
+
the default class:
|
|
58
|
+
|
|
59
|
+
```ruby
|
|
60
|
+
class CustomEngine < Prawn::Document
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
Tilt::PrawnTemplate.engine = CustomEngine
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
Alternatively, may be passed in as an argument to the template constructor:
|
|
67
|
+
|
|
68
|
+
```ruby
|
|
69
|
+
template = Tilt.new('hello.prawn', engine: CustomEngine)
|
|
70
|
+
puts template.render
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
## Contributing
|
|
74
|
+
|
|
75
|
+
1. Fork it
|
|
76
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
|
77
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
|
78
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
|
79
|
+
5. Create new Pull Request
|
data/lib/tilt/prawn/version.rb
CHANGED
data/lib/tilt/prawn.rb
CHANGED
|
@@ -4,43 +4,51 @@ require 'tilt/prawn/version'
|
|
|
4
4
|
|
|
5
5
|
module Tilt
|
|
6
6
|
class PrawnTemplate < Template
|
|
7
|
-
|
|
7
|
+
class Engine < ::Prawn::Document
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
class << self
|
|
11
|
+
attr_accessor :engine
|
|
8
12
|
|
|
9
|
-
|
|
10
|
-
|
|
13
|
+
def reset_engine!
|
|
14
|
+
self.engine = Engine
|
|
15
|
+
Engine.instance_methods(false).each do |method|
|
|
16
|
+
Engine.send(:undef_method, method)
|
|
17
|
+
end
|
|
18
|
+
end
|
|
11
19
|
end
|
|
12
20
|
|
|
13
|
-
|
|
14
|
-
|
|
21
|
+
self.default_mime_type = 'application/pdf'
|
|
22
|
+
self.reset_engine!
|
|
23
|
+
|
|
24
|
+
def self.extend_engine(&block)
|
|
25
|
+
Engine.class_eval(&block)
|
|
15
26
|
end
|
|
16
27
|
|
|
17
28
|
def prepare
|
|
18
29
|
end
|
|
19
30
|
|
|
31
|
+
def engine
|
|
32
|
+
@options[:engine] || self.class.engine
|
|
33
|
+
end
|
|
34
|
+
|
|
20
35
|
def evaluate(scope, locals, &block)
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
end
|
|
27
|
-
scope.instance_exec(pdf, &data)
|
|
28
|
-
else
|
|
29
|
-
context = scope.instance_eval { binding }
|
|
30
|
-
if context.respond_to?(:local_variable_set)
|
|
31
|
-
locals.each do |key, val|
|
|
32
|
-
context.local_variable_set(key, val)
|
|
33
|
-
end
|
|
34
|
-
else
|
|
35
|
-
locals.each do |key, val|
|
|
36
|
-
# Wow, what a hack
|
|
37
|
-
context.eval("#{key} = #{val.inspect}")
|
|
38
|
-
end
|
|
39
|
-
end
|
|
40
|
-
context.eval(data)
|
|
36
|
+
scope = scope ? scope.dup : Object.new
|
|
37
|
+
pdf = engine.new
|
|
38
|
+
if data.respond_to?(:call)
|
|
39
|
+
locals.each do |key, val|
|
|
40
|
+
scope.define_singleton_method(key) { val }
|
|
41
41
|
end
|
|
42
|
+
scope.instance_exec(pdf, &data)
|
|
43
|
+
else
|
|
44
|
+
locals[:pdf] = pdf
|
|
45
|
+
super(scope, locals, &block)
|
|
42
46
|
end
|
|
43
|
-
|
|
47
|
+
pdf.render
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def precompiled_template(local_keys)
|
|
51
|
+
data
|
|
44
52
|
end
|
|
45
53
|
end
|
|
46
54
|
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: tilt-prawn
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.0
|
|
4
|
+
version: 0.1.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Benjamin Feng
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2014-07-
|
|
11
|
+
date: 2014-07-10 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: tilt
|
|
@@ -66,20 +66,6 @@ dependencies:
|
|
|
66
66
|
- - "~>"
|
|
67
67
|
- !ruby/object:Gem::Version
|
|
68
68
|
version: '1.3'
|
|
69
|
-
- !ruby/object:Gem::Dependency
|
|
70
|
-
name: pry
|
|
71
|
-
requirement: !ruby/object:Gem::Requirement
|
|
72
|
-
requirements:
|
|
73
|
-
- - "~>"
|
|
74
|
-
- !ruby/object:Gem::Version
|
|
75
|
-
version: '0.10'
|
|
76
|
-
type: :development
|
|
77
|
-
prerelease: false
|
|
78
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
79
|
-
requirements:
|
|
80
|
-
- - "~>"
|
|
81
|
-
- !ruby/object:Gem::Version
|
|
82
|
-
version: '0.10'
|
|
83
69
|
description: tilt-prawn integrates prawn with tilt
|
|
84
70
|
email: contact@fengb.info
|
|
85
71
|
executables: []
|
|
@@ -87,10 +73,11 @@ extensions: []
|
|
|
87
73
|
extra_rdoc_files: []
|
|
88
74
|
files:
|
|
89
75
|
- LICENSE
|
|
76
|
+
- README.md
|
|
90
77
|
- lib/tilt-prawn.rb
|
|
91
78
|
- lib/tilt/prawn.rb
|
|
92
79
|
- lib/tilt/prawn/version.rb
|
|
93
|
-
homepage:
|
|
80
|
+
homepage: https://github.com/fengb/tilt-prawn
|
|
94
81
|
licenses:
|
|
95
82
|
- MIT
|
|
96
83
|
metadata: {}
|