sbfaulkner-sinatra-prawn 0.9.1 → 0.9.2
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +20 -0
- data/README.rdoc +15 -11
- data/Rakefile +45 -0
- data/VERSION.yml +1 -1
- data/lib/sinatra/prawn.rb +8 -7
- data/test/sinatra_prawn_test.rb +3 -3
- metadata +10 -9
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 unwwwired.net
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
CHANGED
@@ -3,23 +3,27 @@
|
|
3
3
|
sinatra-prawn is an extension for sinatra to enable rendering of pdf files
|
4
4
|
using prawn templates.
|
5
5
|
|
6
|
+
== Installation
|
7
|
+
|
8
|
+
sudo gem install sbfaulkner-sinatra-prawn -s http://gems.github.com
|
9
|
+
|
6
10
|
== Example
|
7
11
|
|
8
|
-
|
9
|
-
|
10
|
-
|
12
|
+
require 'rubygems'
|
13
|
+
require 'sinatra'
|
14
|
+
require 'sinatra/prawn'
|
11
15
|
|
12
|
-
|
16
|
+
set :prawn, { :page_layout => :landscape }
|
13
17
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
+
get '/' do
|
19
|
+
content_type 'application/pdf'
|
20
|
+
prawn :pdf
|
21
|
+
end
|
18
22
|
|
19
|
-
|
23
|
+
__END__
|
20
24
|
|
21
|
-
|
22
|
-
|
25
|
+
@@ pdf
|
26
|
+
pdf.text "Hello world!!!!!"
|
23
27
|
|
24
28
|
== Legal
|
25
29
|
|
data/Rakefile
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
require 'rake'
|
2
|
+
|
3
|
+
begin
|
4
|
+
require 'jeweler'
|
5
|
+
Jeweler::Tasks.new do |s|
|
6
|
+
s.name = "sinatra-prawn"
|
7
|
+
s.summary = %Q{Sinatra extension to add support for pdf rendering with Prawn templates.}
|
8
|
+
s.email = "brentf@unwwwired.net"
|
9
|
+
s.homepage = "http://github.com/sbfaulkner/sinatra-prawn"
|
10
|
+
s.description = "Sinatra extension to add support for pdf rendering with Prawn templates."
|
11
|
+
s.authors = ["S. Brent Faulkner"]
|
12
|
+
s.add_dependency "prawn"
|
13
|
+
end
|
14
|
+
rescue LoadError
|
15
|
+
puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
|
16
|
+
end
|
17
|
+
|
18
|
+
require 'rake/rdoctask'
|
19
|
+
Rake::RDocTask.new do |rdoc|
|
20
|
+
rdoc.rdoc_dir = 'rdoc'
|
21
|
+
rdoc.title = 'sinatra-prawn'
|
22
|
+
rdoc.options << '--line-numbers' << '--inline-source'
|
23
|
+
rdoc.rdoc_files.include('README*')
|
24
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
25
|
+
end
|
26
|
+
|
27
|
+
require 'rake/testtask'
|
28
|
+
Rake::TestTask.new(:test) do |t|
|
29
|
+
t.libs << 'lib' << 'test'
|
30
|
+
t.pattern = 'test/**/*_test.rb'
|
31
|
+
t.verbose = false
|
32
|
+
end
|
33
|
+
|
34
|
+
begin
|
35
|
+
require 'rcov/rcovtask'
|
36
|
+
Rcov::RcovTask.new do |t|
|
37
|
+
t.libs << 'test'
|
38
|
+
t.test_files = FileList['test/**/*_test.rb']
|
39
|
+
t.verbose = true
|
40
|
+
end
|
41
|
+
rescue LoadError
|
42
|
+
puts "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
|
43
|
+
end
|
44
|
+
|
45
|
+
task :default => :test
|
data/VERSION.yml
CHANGED
data/lib/sinatra/prawn.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'sinatra/base'
|
2
|
+
require 'prawn'
|
2
3
|
|
3
4
|
module Sinatra
|
4
5
|
module Prawn
|
@@ -6,20 +7,20 @@ module Sinatra
|
|
6
7
|
# Takes the name of a template to render as a Symbol and returns a String with the rendered output.
|
7
8
|
#
|
8
9
|
# Options for prawn may be specified in Sinatra using set :prawn, { ... }
|
9
|
-
def prawn(template=nil, options={}, &block)
|
10
|
-
require 'prawn' unless defined? ::Prawn
|
10
|
+
def prawn(template=nil, options={}, locals = {}, &block)
|
11
11
|
options, template = template, nil if template.is_a?(Hash)
|
12
12
|
template = lambda { block } if template.nil?
|
13
13
|
options[:layout] = false
|
14
|
-
|
15
|
-
render :prawn, template, options
|
14
|
+
render :prawn, template, options, locals
|
16
15
|
end
|
17
16
|
|
18
17
|
protected
|
19
|
-
def render_prawn(template, data, options, &block)
|
20
|
-
|
18
|
+
def render_prawn(template, data, options, locals, &block)
|
19
|
+
filename = options.delete(:filename) || '<PRAWN>'
|
20
|
+
line = options.delete(:line) || 1
|
21
|
+
pdf = ::Prawn::Document.new(options)
|
21
22
|
if data.respond_to?(:to_str)
|
22
|
-
eval data.to_str, binding,
|
23
|
+
eval data.to_str, binding, filename, line
|
23
24
|
elsif data.kind_of?(Proc)
|
24
25
|
data.call(pdf)
|
25
26
|
end
|
data/test/sinatra_prawn_test.rb
CHANGED
@@ -1,8 +1,6 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/test_helper'
|
2
2
|
|
3
3
|
class SinatraPrawnTest < Test::Unit::TestCase
|
4
|
-
include Sinatra::Test
|
5
|
-
|
6
4
|
def prawn_app(&block)
|
7
5
|
mock_app {
|
8
6
|
helpers Sinatra::Prawn
|
@@ -44,8 +42,10 @@ class SinatraPrawnTest < Test::Unit::TestCase
|
|
44
42
|
def test_raises_error_if_template_not_found
|
45
43
|
mock_app {
|
46
44
|
helpers Sinatra::Prawn
|
45
|
+
set :environment, :test
|
46
|
+
set :raise_errors, true
|
47
47
|
get('/') { prawn :no_such_template }
|
48
48
|
}
|
49
|
-
|
49
|
+
assert_raises(Errno::ENOENT) { get('/') }
|
50
50
|
end
|
51
51
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sbfaulkner-sinatra-prawn
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.9.
|
4
|
+
version: 0.9.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- S. Brent Faulkner
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-
|
12
|
+
date: 2009-04-28 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -28,22 +28,22 @@ executables: []
|
|
28
28
|
|
29
29
|
extensions: []
|
30
30
|
|
31
|
-
extra_rdoc_files:
|
32
|
-
|
31
|
+
extra_rdoc_files:
|
32
|
+
- LICENSE
|
33
|
+
- README.rdoc
|
33
34
|
files:
|
35
|
+
- LICENSE
|
34
36
|
- README.rdoc
|
37
|
+
- Rakefile
|
35
38
|
- VERSION.yml
|
36
|
-
- lib/sinatra
|
37
39
|
- lib/sinatra/prawn.rb
|
38
40
|
- test/sinatra_prawn_test.rb
|
39
41
|
- test/test_helper.rb
|
40
|
-
- test/views
|
41
42
|
- test/views/hello.prawn
|
42
43
|
has_rdoc: true
|
43
44
|
homepage: http://github.com/sbfaulkner/sinatra-prawn
|
44
45
|
post_install_message:
|
45
46
|
rdoc_options:
|
46
|
-
- --inline-source
|
47
47
|
- --charset=UTF-8
|
48
48
|
require_paths:
|
49
49
|
- lib
|
@@ -66,5 +66,6 @@ rubygems_version: 1.2.0
|
|
66
66
|
signing_key:
|
67
67
|
specification_version: 2
|
68
68
|
summary: Sinatra extension to add support for pdf rendering with Prawn templates.
|
69
|
-
test_files:
|
70
|
-
|
69
|
+
test_files:
|
70
|
+
- test/sinatra_prawn_test.rb
|
71
|
+
- test/test_helper.rb
|