prawn_cocktail_rails 0.1.0 → 0.3.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.github/workflows/ci.yml +26 -0
- data/.rubocop.yml +5 -0
- data/Gemfile +6 -1
- data/README.md +14 -7
- data/Rakefile +7 -0
- data/lib/prawn_cocktail_rails/controller.rb +4 -4
- data/lib/prawn_cocktail_rails/railtie.rb +4 -0
- data/lib/prawn_cocktail_rails/version.rb +1 -1
- data/lib/prawn_cocktail_rails.rb +0 -2
- data/prawn_cocktail_rails.gemspec +24 -0
- data/spec/dummy/.gitignore +1 -0
- data/spec/dummy/Rakefile +6 -0
- data/spec/dummy/app/controllers/application_controller.rb +3 -0
- data/spec/dummy/app/controllers/dummy_controller.rb +6 -0
- data/spec/dummy/app/documents/helpers/test_document_helper.rb +5 -0
- data/spec/dummy/app/documents/test_document.rb +17 -0
- data/spec/dummy/app/views/documents/test_document.pdf.rb +6 -0
- data/spec/dummy/config/application.rb +16 -0
- data/spec/dummy/config/boot.rb +10 -0
- data/spec/dummy/config/environment.rb +5 -0
- data/spec/dummy/config/environments/test.rb +37 -0
- data/spec/dummy/config/initializers/secret_token.rb +7 -0
- data/spec/dummy/config/initializers/session_store.rb +3 -0
- data/spec/dummy/config/locales/en.yml +5 -0
- data/spec/dummy/config/routes.rb +3 -0
- data/spec/dummy/config.ru +4 -0
- data/spec/dummy/lib/assets/.gitkeep +0 -0
- data/spec/dummy/script/rails +6 -0
- data/spec/integration_spec.rb +33 -0
- metadata +94 -23
- data/prawn_cocktail.gemspec +0 -21
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: ac39360c48b9d97535316933f2c27b9a6168ac4fdf2e35e49729f4d3bba1354e
|
4
|
+
data.tar.gz: d47baa4f5ce4a84d01012fd7cdaeab492571b0d64c35fca95bf825197765ea88
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: e8147b805f4d60e8c50f01ddfe7775a93bd33e693533baaaa5125bef2449e9dac1fcad88404c2fc4826bbf89bd098d0cb2b870c5918e78b6d02f2b2dd1a9feb8
|
7
|
+
data.tar.gz: 1b6dee0014c83d892682617994f3a1ee8340727369dc57b0e64d13b13a1190ed0cce1758b0c3618104524ef2aa6b53cb8dff969a7c320c6c42737e3fd5211217
|
@@ -0,0 +1,26 @@
|
|
1
|
+
name: Ruby CI
|
2
|
+
|
3
|
+
on:
|
4
|
+
push:
|
5
|
+
branches: [ master ]
|
6
|
+
pull_request:
|
7
|
+
branches: [ master ]
|
8
|
+
|
9
|
+
jobs:
|
10
|
+
test:
|
11
|
+
|
12
|
+
runs-on: ubuntu-latest
|
13
|
+
|
14
|
+
strategy:
|
15
|
+
matrix:
|
16
|
+
ruby-version: ["3.0", "2.7", "2.6", "2.5"]
|
17
|
+
|
18
|
+
steps:
|
19
|
+
- uses: actions/checkout@v2
|
20
|
+
- name: Set up Ruby ${{ matrix.ruby-version }}
|
21
|
+
uses: ruby/setup-ruby@ae9cb3b565e36682a2c6045e4f664388da4c73aa
|
22
|
+
with:
|
23
|
+
ruby-version: ${{ matrix.ruby-version }}
|
24
|
+
bundler-cache: true # runs 'bundle install' and caches installed gems automatically
|
25
|
+
- name: Run tests
|
26
|
+
run: bundle exec rake
|
data/.rubocop.yml
ADDED
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,12 +1,8 @@
|
|
1
1
|
# PrawnCocktailRails
|
2
2
|
|
3
|
-
Ruby
|
4
|
-
|
5
|
-
NOTE: Work in progress; well used but untested.
|
6
|
-
|
7
|
-
## TODO
|
3
|
+
[![Ruby CI](https://github.com/barsoom/prawn_cocktail_rails/actions/workflows/ci.yml/badge.svg)](https://github.com/barsoom/prawn_cocktail_rails/actions/workflows/ci.yml)
|
8
4
|
|
9
|
-
|
5
|
+
Ruby on Rails integration for [PrawnCocktail](http://github.com/barsoom/prawn_cocktail).
|
10
6
|
|
11
7
|
## Usage
|
12
8
|
|
@@ -24,8 +20,11 @@ class InvoicesController < ApplicationController
|
|
24
20
|
end
|
25
21
|
```
|
26
22
|
|
23
|
+
The default [disposition](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Disposition) is `"attachment"`, meaning it should be downloaded rather than opened inline in the browser.
|
24
|
+
|
25
|
+
You can change disposition to `"inline"` with `send_pdf(document, disposition: "inline")`.
|
27
26
|
|
28
|
-
|
27
|
+
PrawnCocktailRails configures PrawnCocktail to look for its views in `app/views/documents`.
|
29
28
|
|
30
29
|
It also adds `app/documents/helpers` to the Rails autoload path so you can put your PrawnCocktail helpers there.
|
31
30
|
|
@@ -45,6 +44,14 @@ And then execute:
|
|
45
44
|
|
46
45
|
As this library depends on `prawn_cocktail`, you only need to list this one to get both.
|
47
46
|
|
47
|
+
### Mime types
|
48
|
+
|
49
|
+
You may need to register the pdf mimetype in `config/initializers/mime_types.rb`, for older versions of rails.
|
50
|
+
|
51
|
+
```ruby
|
52
|
+
Mime::Type.register "application/pdf", :pdf
|
53
|
+
```
|
54
|
+
|
48
55
|
## License
|
49
56
|
|
50
57
|
Copyright (c) 2013 [Barsoom AB](http://barsoom.se)
|
data/Rakefile
CHANGED
@@ -2,12 +2,12 @@ module PrawnCocktailRails
|
|
2
2
|
module Controller
|
3
3
|
private
|
4
4
|
|
5
|
-
def send_pdf(document)
|
5
|
+
def send_pdf(document, disposition: "attachment")
|
6
6
|
send_data(
|
7
7
|
document.render,
|
8
|
-
type:
|
9
|
-
disposition:
|
10
|
-
filename: document.filename
|
8
|
+
type: :pdf,
|
9
|
+
disposition: disposition,
|
10
|
+
filename: document.filename,
|
11
11
|
)
|
12
12
|
end
|
13
13
|
end
|
@@ -5,5 +5,9 @@ module PrawnCocktailRails
|
|
5
5
|
initializer "prawn_cocktail.autoload", before: :set_autoload_paths do |app|
|
6
6
|
app.config.autoload_paths << "#{app.config.root}/app/documents/helpers"
|
7
7
|
end
|
8
|
+
|
9
|
+
initializer "prawn_cocktail.set_template_root" do |app|
|
10
|
+
PrawnCocktail.template_root = app.config.root.join("app/views/documents")
|
11
|
+
end
|
8
12
|
end
|
9
13
|
end
|
data/lib/prawn_cocktail_rails.rb
CHANGED
@@ -0,0 +1,24 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "prawn_cocktail_rails/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = "prawn_cocktail_rails"
|
8
|
+
gem.version = PrawnCocktailRails::VERSION
|
9
|
+
gem.authors = [ "Henrik Nyh" ]
|
10
|
+
gem.email = [ "henrik@barsoom.se" ]
|
11
|
+
gem.summary = "Simple documents, templates and helpers on top of Prawn. In Ruby on Rails."
|
12
|
+
gem.homepage = ""
|
13
|
+
gem.metadata = { "rubygems_mfa_required" => "true" }
|
14
|
+
|
15
|
+
gem.files = `git ls-files`.split($/)
|
16
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
17
|
+
gem.require_paths = [ "lib" ]
|
18
|
+
|
19
|
+
gem.add_dependency "prawn_cocktail", ">=0.4.0"
|
20
|
+
gem.add_dependency "rails"
|
21
|
+
|
22
|
+
gem.add_development_dependency "rake" # For Travis CI.
|
23
|
+
gem.add_development_dependency "pdf-inspector"
|
24
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
log/*
|
data/spec/dummy/Rakefile
ADDED
@@ -0,0 +1,6 @@
|
|
1
|
+
#!/usr/bin/env rake
|
2
|
+
# Add your own tasks in files placed in lib/tasks ending in .rake,
|
3
|
+
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
|
4
|
+
|
5
|
+
require File.expand_path("../config/application", __FILE__)
|
6
|
+
Dummy::Application.load_tasks
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require File.expand_path("../boot", __FILE__)
|
2
|
+
|
3
|
+
# Pick the frameworks you want:
|
4
|
+
require "action_controller/railtie"
|
5
|
+
#require "action_mailer/railtie"
|
6
|
+
#require "active_resource/railtie"
|
7
|
+
#require "sprockets/railtie"
|
8
|
+
#require "rails/test_unit/railtie"
|
9
|
+
|
10
|
+
Bundler.require
|
11
|
+
require "prawn_cocktail_rails"
|
12
|
+
|
13
|
+
module Dummy
|
14
|
+
class Application < Rails::Application
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
Dummy::Application.configure do
|
2
|
+
# Settings specified here will take precedence over those in config/application.rb
|
3
|
+
|
4
|
+
# The test environment is used exclusively to run your application's
|
5
|
+
# test suite. You never need to work with it otherwise. Remember that
|
6
|
+
# your test database is "scratch space" for the test suite and is wiped
|
7
|
+
# and recreated between test runs. Don't rely on the data there!
|
8
|
+
config.cache_classes = true
|
9
|
+
|
10
|
+
# Configure static asset server for tests with Cache-Control for performance
|
11
|
+
config.serve_static_assets = true
|
12
|
+
config.static_cache_control = "public, max-age=3600"
|
13
|
+
|
14
|
+
# Log error messages when you accidentally call methods on nil
|
15
|
+
config.whiny_nils = true
|
16
|
+
|
17
|
+
# Show full error reports and disable caching
|
18
|
+
config.consider_all_requests_local = true
|
19
|
+
config.action_controller.perform_caching = false
|
20
|
+
|
21
|
+
# Raise exceptions instead of rendering exception templates
|
22
|
+
config.action_dispatch.show_exceptions = false
|
23
|
+
|
24
|
+
# Disable request forgery protection in test environment
|
25
|
+
config.action_controller.allow_forgery_protection = false
|
26
|
+
|
27
|
+
# Tell Action Mailer not to deliver emails to the real world.
|
28
|
+
# The :test delivery method accumulates sent emails in the
|
29
|
+
# ActionMailer::Base.deliveries array.
|
30
|
+
#config.action_mailer.delivery_method = :test
|
31
|
+
|
32
|
+
# Raise exception on mass assignment protection for Active Record models
|
33
|
+
#config.active_record.mass_assignment_sanitizer = :strict
|
34
|
+
|
35
|
+
# Print deprecation notices to the stderr
|
36
|
+
config.active_support.deprecation = :stderr
|
37
|
+
end
|
@@ -0,0 +1,7 @@
|
|
1
|
+
# Be sure to restart your server when you modify this file.
|
2
|
+
|
3
|
+
# Your secret key for verifying the integrity of signed cookies.
|
4
|
+
# If you change this key, all old signed cookies will become invalid!
|
5
|
+
# Make sure the secret is at least 30 characters and all random,
|
6
|
+
# no regular words or you'll be exposed to dictionary attacks.
|
7
|
+
Dummy::Application.config.secret_token = "ecc1e4d2f3688465864a194ce713e2a958d94741c8a39741775b5fd5c001fcf279c2f32540d95139f3cb814718a25d36b23de65d8c7d8d5643e5da61ba86e5a9"
|
File without changes
|
@@ -0,0 +1,6 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.
|
3
|
+
|
4
|
+
APP_PATH = File.expand_path("../../config/application", __FILE__)
|
5
|
+
require File.expand_path("../../config/boot", __FILE__)
|
6
|
+
require "rails/commands"
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# Load dummy Rails app.
|
2
|
+
ENV["RAILS_ENV"] ||= "test"
|
3
|
+
require_relative "dummy/config/environment.rb"
|
4
|
+
require "rails/test_help"
|
5
|
+
|
6
|
+
require "pdf/inspector"
|
7
|
+
require "minitest/pride"
|
8
|
+
|
9
|
+
class IntegrationTest < ActionController::TestCase
|
10
|
+
tests DummyController
|
11
|
+
|
12
|
+
def test_integration
|
13
|
+
get :show
|
14
|
+
assert_header "Content-Type", "application/pdf"
|
15
|
+
assert_match %r{attachment; filename="test\.pdf"}, response.headers["Content-Disposition"]
|
16
|
+
assert_pdf_strings [
|
17
|
+
"Helper works.",
|
18
|
+
"Message: test.",
|
19
|
+
]
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def assert_header(name, value)
|
24
|
+
assert_equal value, response.headers[name]
|
25
|
+
end
|
26
|
+
|
27
|
+
def assert_pdf_strings(strings)
|
28
|
+
assert_equal strings, parse_strings(response.body)
|
29
|
+
end
|
30
|
+
|
31
|
+
def parse_strings(pdf_data)
|
32
|
+
PDF::Inspector::Text.analyze(pdf_data).strings
|
33
|
+
end
|
metadata
CHANGED
@@ -1,38 +1,71 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: prawn_cocktail_rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
5
|
-
prerelease:
|
4
|
+
version: 0.3.2
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Henrik Nyh
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 2021-11-19 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: prawn_cocktail
|
16
|
-
requirement:
|
17
|
-
none: false
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
18
16
|
requirements:
|
19
|
-
- -
|
17
|
+
- - ">="
|
20
18
|
- !ruby/object:Gem::Version
|
21
19
|
version: 0.4.0
|
22
20
|
type: :runtime
|
23
21
|
prerelease: false
|
24
|
-
version_requirements:
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.4.0
|
25
27
|
- !ruby/object:Gem::Dependency
|
26
28
|
name: rails
|
27
|
-
requirement:
|
28
|
-
none: false
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
29
30
|
requirements:
|
30
|
-
- -
|
31
|
+
- - ">="
|
31
32
|
- !ruby/object:Gem::Version
|
32
33
|
version: '0'
|
33
34
|
type: :runtime
|
34
35
|
prerelease: false
|
35
|
-
version_requirements:
|
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: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: pdf-inspector
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
36
69
|
description:
|
37
70
|
email:
|
38
71
|
- henrik@barsoom.se
|
@@ -40,7 +73,9 @@ executables: []
|
|
40
73
|
extensions: []
|
41
74
|
extra_rdoc_files: []
|
42
75
|
files:
|
43
|
-
- .
|
76
|
+
- ".github/workflows/ci.yml"
|
77
|
+
- ".gitignore"
|
78
|
+
- ".rubocop.yml"
|
44
79
|
- Gemfile
|
45
80
|
- README.md
|
46
81
|
- Rakefile
|
@@ -48,30 +83,66 @@ files:
|
|
48
83
|
- lib/prawn_cocktail_rails/controller.rb
|
49
84
|
- lib/prawn_cocktail_rails/railtie.rb
|
50
85
|
- lib/prawn_cocktail_rails/version.rb
|
51
|
-
-
|
86
|
+
- prawn_cocktail_rails.gemspec
|
87
|
+
- spec/dummy/.gitignore
|
88
|
+
- spec/dummy/Rakefile
|
89
|
+
- spec/dummy/app/controllers/application_controller.rb
|
90
|
+
- spec/dummy/app/controllers/dummy_controller.rb
|
91
|
+
- spec/dummy/app/documents/helpers/test_document_helper.rb
|
92
|
+
- spec/dummy/app/documents/test_document.rb
|
93
|
+
- spec/dummy/app/views/documents/test_document.pdf.rb
|
94
|
+
- spec/dummy/config.ru
|
95
|
+
- spec/dummy/config/application.rb
|
96
|
+
- spec/dummy/config/boot.rb
|
97
|
+
- spec/dummy/config/environment.rb
|
98
|
+
- spec/dummy/config/environments/test.rb
|
99
|
+
- spec/dummy/config/initializers/secret_token.rb
|
100
|
+
- spec/dummy/config/initializers/session_store.rb
|
101
|
+
- spec/dummy/config/locales/en.yml
|
102
|
+
- spec/dummy/config/routes.rb
|
103
|
+
- spec/dummy/lib/assets/.gitkeep
|
104
|
+
- spec/dummy/script/rails
|
105
|
+
- spec/integration_spec.rb
|
52
106
|
homepage: ''
|
53
107
|
licenses: []
|
108
|
+
metadata:
|
109
|
+
rubygems_mfa_required: 'true'
|
54
110
|
post_install_message:
|
55
111
|
rdoc_options: []
|
56
112
|
require_paths:
|
57
113
|
- lib
|
58
114
|
required_ruby_version: !ruby/object:Gem::Requirement
|
59
|
-
none: false
|
60
115
|
requirements:
|
61
|
-
- -
|
116
|
+
- - ">="
|
62
117
|
- !ruby/object:Gem::Version
|
63
118
|
version: '0'
|
64
119
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
65
|
-
none: false
|
66
120
|
requirements:
|
67
|
-
- -
|
121
|
+
- - ">="
|
68
122
|
- !ruby/object:Gem::Version
|
69
123
|
version: '0'
|
70
124
|
requirements: []
|
71
|
-
|
72
|
-
rubygems_version: 1.8.5
|
125
|
+
rubygems_version: 3.2.31
|
73
126
|
signing_key:
|
74
|
-
specification_version:
|
75
|
-
summary:
|
76
|
-
test_files:
|
77
|
-
|
127
|
+
specification_version: 4
|
128
|
+
summary: Simple documents, templates and helpers on top of Prawn. In Ruby on Rails.
|
129
|
+
test_files:
|
130
|
+
- spec/dummy/.gitignore
|
131
|
+
- spec/dummy/Rakefile
|
132
|
+
- spec/dummy/app/controllers/application_controller.rb
|
133
|
+
- spec/dummy/app/controllers/dummy_controller.rb
|
134
|
+
- spec/dummy/app/documents/helpers/test_document_helper.rb
|
135
|
+
- spec/dummy/app/documents/test_document.rb
|
136
|
+
- spec/dummy/app/views/documents/test_document.pdf.rb
|
137
|
+
- spec/dummy/config.ru
|
138
|
+
- spec/dummy/config/application.rb
|
139
|
+
- spec/dummy/config/boot.rb
|
140
|
+
- spec/dummy/config/environment.rb
|
141
|
+
- spec/dummy/config/environments/test.rb
|
142
|
+
- spec/dummy/config/initializers/secret_token.rb
|
143
|
+
- spec/dummy/config/initializers/session_store.rb
|
144
|
+
- spec/dummy/config/locales/en.yml
|
145
|
+
- spec/dummy/config/routes.rb
|
146
|
+
- spec/dummy/lib/assets/.gitkeep
|
147
|
+
- spec/dummy/script/rails
|
148
|
+
- spec/integration_spec.rb
|
data/prawn_cocktail.gemspec
DELETED
@@ -1,21 +0,0 @@
|
|
1
|
-
# -*- encoding: utf-8 -*-
|
2
|
-
lib = File.expand_path('../lib', __FILE__)
|
3
|
-
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
-
require 'prawn_cocktail_rails/version'
|
5
|
-
|
6
|
-
Gem::Specification.new do |gem|
|
7
|
-
gem.name = "prawn_cocktail_rails"
|
8
|
-
gem.version = PrawnCocktailRails::VERSION
|
9
|
-
gem.authors = ["Henrik Nyh"]
|
10
|
-
gem.email = ["henrik@barsoom.se"]
|
11
|
-
gem.summary = "PrawnCocktail on Rails."
|
12
|
-
gem.homepage = ""
|
13
|
-
|
14
|
-
gem.files = `git ls-files`.split($/)
|
15
|
-
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
16
|
-
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
17
|
-
gem.require_paths = ["lib"]
|
18
|
-
|
19
|
-
gem.add_dependency "prawn_cocktail", ">=0.4.0"
|
20
|
-
gem.add_dependency "rails"
|
21
|
-
end
|