sugpoko 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +11 -0
- data/.rspec +3 -0
- data/.travis.yml +7 -0
- data/Gemfile +4 -0
- data/README.md +68 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/sugpoko.rb +9 -0
- data/lib/sugpoko/base.rb +32 -0
- data/lib/sugpoko/component.rb +16 -0
- data/lib/sugpoko/version.rb +3 -0
- data/sugpoko.gemspec +41 -0
- metadata +98 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 88e84036fab620a72d223e6b63b24e1aaca2f057
|
4
|
+
data.tar.gz: 5112051bf8f3054a66aed7a1545f9d58a46abcb7
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 699cf988d09c49bd0e7e71bf997d2d7786b56721d3d6de22c2d19bffee0c321abb33fb24d199a07ad002b6eeba2c05714829b7f1b137154ed5d0f74b3c21786e
|
7
|
+
data.tar.gz: f46bc4dd1388ec612f9b86fd3bb3894516c7438166fda47a692d0c1aabaa87138e9d4c4e5a785926a9902a2018cbe69f71316ce32bdcfbda759d29f24def890d
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
# Sugpoko
|
2
|
+
|
3
|
+
Modularize your pdf code with this gem
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'prawn'
|
11
|
+
gem 'sugpoko'
|
12
|
+
```
|
13
|
+
|
14
|
+
And then execute:
|
15
|
+
|
16
|
+
$ bundle
|
17
|
+
|
18
|
+
Or install it yourself as:
|
19
|
+
|
20
|
+
$ gem install sugpoko
|
21
|
+
|
22
|
+
## Usage
|
23
|
+
|
24
|
+
Create a class that inherits `Sugpoko::Base`. This class is the main pdf component
|
25
|
+
where the pdf generation is triggered. It includes `Prawn::View` module.
|
26
|
+
|
27
|
+
``` ruby
|
28
|
+
class PdfDocument < Sugpoko::Base
|
29
|
+
def generate
|
30
|
+
pdf.text 'Hello World'
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
PdfDocument.new.generate
|
35
|
+
# Hello world
|
36
|
+
```
|
37
|
+
|
38
|
+
A component can also be created using `Sugpoko::Component`
|
39
|
+
|
40
|
+
``` ruby
|
41
|
+
class Header < Sugpoko::Component
|
42
|
+
def generate
|
43
|
+
pdf.text 'This is a header'
|
44
|
+
end
|
45
|
+
end
|
46
|
+
```
|
47
|
+
|
48
|
+
To add `Header` on our previous base document, use `draw` method. It accepts a
|
49
|
+
class that inherits from either `Sugpoko::Base` or `Sugpoko::Component`.
|
50
|
+
``` ruby
|
51
|
+
class PdfDocument < Sugpoko::Base
|
52
|
+
def generate
|
53
|
+
draw Header
|
54
|
+
pdf.text 'Hello World'
|
55
|
+
draw ...
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
PdfDocument.new.generate
|
60
|
+
# This is a Header
|
61
|
+
# Hello World
|
62
|
+
```
|
63
|
+
|
64
|
+
`Sugpoko::Component` can also use `draw` method
|
65
|
+
|
66
|
+
|
67
|
+
|
68
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/neume/sugpoko.
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "sugpoko"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/lib/sugpoko.rb
ADDED
data/lib/sugpoko/base.rb
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
module Sugpoko
|
2
|
+
class Base
|
3
|
+
attr_reader :pdf, :data
|
4
|
+
|
5
|
+
include Prawn::View
|
6
|
+
|
7
|
+
def generate
|
8
|
+
raise '#generate not defined'
|
9
|
+
end
|
10
|
+
|
11
|
+
def draw(klass, options = {})
|
12
|
+
klass.new(options.merge(pdf: pdf)).generate
|
13
|
+
end
|
14
|
+
|
15
|
+
def initialize(options = {})
|
16
|
+
@data = options[:data]
|
17
|
+
@pdf = self
|
18
|
+
end
|
19
|
+
|
20
|
+
def document
|
21
|
+
@document ||= Prawn::Document.new(default_options)
|
22
|
+
end
|
23
|
+
|
24
|
+
def default_options
|
25
|
+
@default_options ||= {
|
26
|
+
page_size: [8.5.in, 11.in],
|
27
|
+
page_layout: :portrait
|
28
|
+
}
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
class Sugpoko::Component
|
2
|
+
attr_reader :pdf, :cursor_origin
|
3
|
+
|
4
|
+
def generate
|
5
|
+
raise '#generate not defined'
|
6
|
+
end
|
7
|
+
|
8
|
+
def draw(klass, options = {})
|
9
|
+
klass.new(options.merge(pdf: pdf)).generate
|
10
|
+
end
|
11
|
+
|
12
|
+
def initialize(options = {})
|
13
|
+
@pdf = options.fetch(:pdf)
|
14
|
+
@cursor_origin = pdf.cursor
|
15
|
+
end
|
16
|
+
end
|
data/sugpoko.gemspec
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "sugpoko/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "sugpoko"
|
8
|
+
spec.version = Sugpoko::VERSION
|
9
|
+
spec.authors = ["Joseph Nelson Valeros"]
|
10
|
+
spec.email = ["valerosjoseph@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{A prawnpdf wrapper }
|
13
|
+
spec.description = %q{Modularize your prawnpdf code }
|
14
|
+
spec.homepage = "https://github.com/neume/sugpoko"
|
15
|
+
|
16
|
+
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
17
|
+
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
18
|
+
# if spec.respond_to?(:metadata)
|
19
|
+
# spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"
|
20
|
+
#
|
21
|
+
# spec.metadata["homepage_uri"] = spec.homepage
|
22
|
+
# spec.metadata["source_code_uri"] = "TODO: Put your gem's public repo URL here."
|
23
|
+
# spec.metadata["changelog_uri"] = "TODO: Put your gem's CHANGELOG.md URL here."
|
24
|
+
# else
|
25
|
+
# raise "RubyGems 2.0 or newer is required to protect against " \
|
26
|
+
# "public gem pushes."
|
27
|
+
# end
|
28
|
+
|
29
|
+
# Specify which files should be added to the gem when it is released.
|
30
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
31
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
32
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
33
|
+
end
|
34
|
+
spec.bindir = "exe"
|
35
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
36
|
+
spec.require_paths = ["lib"]
|
37
|
+
|
38
|
+
spec.add_development_dependency "bundler", "~> 2.0"
|
39
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
40
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
41
|
+
end
|
metadata
ADDED
@@ -0,0 +1,98 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: sugpoko
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Joseph Nelson Valeros
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-08-21 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: '2.0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '2.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.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: '3.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
description: 'Modularize your prawnpdf code '
|
56
|
+
email:
|
57
|
+
- valerosjoseph@gmail.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- ".gitignore"
|
63
|
+
- ".rspec"
|
64
|
+
- ".travis.yml"
|
65
|
+
- Gemfile
|
66
|
+
- README.md
|
67
|
+
- Rakefile
|
68
|
+
- bin/console
|
69
|
+
- bin/setup
|
70
|
+
- lib/sugpoko.rb
|
71
|
+
- lib/sugpoko/base.rb
|
72
|
+
- lib/sugpoko/component.rb
|
73
|
+
- lib/sugpoko/version.rb
|
74
|
+
- sugpoko.gemspec
|
75
|
+
homepage: https://github.com/neume/sugpoko
|
76
|
+
licenses: []
|
77
|
+
metadata: {}
|
78
|
+
post_install_message:
|
79
|
+
rdoc_options: []
|
80
|
+
require_paths:
|
81
|
+
- lib
|
82
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
83
|
+
requirements:
|
84
|
+
- - ">="
|
85
|
+
- !ruby/object:Gem::Version
|
86
|
+
version: '0'
|
87
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
88
|
+
requirements:
|
89
|
+
- - ">="
|
90
|
+
- !ruby/object:Gem::Version
|
91
|
+
version: '0'
|
92
|
+
requirements: []
|
93
|
+
rubyforge_project:
|
94
|
+
rubygems_version: 2.6.14
|
95
|
+
signing_key:
|
96
|
+
specification_version: 4
|
97
|
+
summary: A prawnpdf wrapper
|
98
|
+
test_files: []
|