canned_tuna 0.0.6

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: ae4cf59776aa39002650fa4497ab9af9207a545b83c1f601b9c4f46fb61477e8
4
+ data.tar.gz: d0953722529d21d5381b242745bdf5080f619ed894f2ecc0e1d64ab2364c485d
5
+ SHA512:
6
+ metadata.gz: 6b9273d8db95cd502a7542c1972edaff57b7aca1c13f2582f48359eb8f256e36cf20abc9e792d75a8f04c84a192868cff91c6faaf3b6ef1e677bae8d81e9faed
7
+ data.tar.gz: 8a231d9d12802a515ba49627c78dd237fc4fb28473cee240cd4574cb796d4ccd63d3b6e3b2c12210fcd7baccd6ffc3dae9d88f4f05820482dc2a0f48ab4ba93e
@@ -0,0 +1,8 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
@@ -0,0 +1 @@
1
+ 2.6.4
@@ -0,0 +1,7 @@
1
+ ---
2
+ sudo: false
3
+ language: ruby
4
+ cache: bundler
5
+ rvm:
6
+ - 2.6.3
7
+ before_install: gem install bundler -v 2.0.2
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in prawn-component.gemspec
4
+ gemspec
@@ -0,0 +1,65 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ canned_tuna (0.0.6)
5
+ prawn (~> 2.2)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ Ascii85 (1.0.3)
11
+ afm (0.2.2)
12
+ ast (2.4.0)
13
+ hashery (2.1.2)
14
+ jaro_winkler (1.5.3)
15
+ minitest (5.11.3)
16
+ minitest-focus (1.2.0)
17
+ minitest (>= 4, < 6)
18
+ parallel (1.17.0)
19
+ parser (2.6.4.1)
20
+ ast (~> 2.4.0)
21
+ pdf-core (0.7.0)
22
+ pdf-inspector (1.3.0)
23
+ pdf-reader (>= 1.0, < 3.0.a)
24
+ pdf-reader (2.2.1)
25
+ Ascii85 (~> 1.0.0)
26
+ afm (~> 0.2.1)
27
+ hashery (~> 2.0)
28
+ ruby-rc4
29
+ ttfunk
30
+ prawn (2.2.2)
31
+ pdf-core (~> 0.7.0)
32
+ ttfunk (~> 1.5)
33
+ rainbow (3.0.0)
34
+ rake (13.0.1)
35
+ rubocop (0.72.0)
36
+ jaro_winkler (~> 1.5.1)
37
+ parallel (~> 1.10)
38
+ parser (>= 2.6)
39
+ rainbow (>= 2.2.2, < 4.0)
40
+ ruby-progressbar (~> 1.7)
41
+ unicode-display_width (>= 1.4.0, < 1.7)
42
+ rubocop-performance (1.4.1)
43
+ rubocop (>= 0.71.0)
44
+ ruby-progressbar (1.10.1)
45
+ ruby-rc4 (0.1.5)
46
+ standard (0.1.4)
47
+ rubocop (~> 0.72.0)
48
+ rubocop-performance (~> 1.4.0)
49
+ ttfunk (1.5.1)
50
+ unicode-display_width (1.6.0)
51
+
52
+ PLATFORMS
53
+ ruby
54
+
55
+ DEPENDENCIES
56
+ bundler (~> 2.0)
57
+ canned_tuna!
58
+ minitest (~> 5.0)
59
+ minitest-focus (~> 1.2)
60
+ pdf-inspector (~> 1.3)
61
+ rake (~> 13.0)
62
+ standard (~> 0.1.4)
63
+
64
+ BUNDLED WITH
65
+ 2.0.2
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2019 Kasper Meyer
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,132 @@
1
+ # Canned Tuna
2
+
3
+ > 🚧 Under construction. Expect unstable API on versions less than 0.1.0 🚧
4
+
5
+ Organizing content in Prawn gets notoriously difficult as the size and complexity of the document increases. This often leads to a junk drawer of helper methods and mixins that is hard to maintain.
6
+
7
+ Components are an antidote to this approach. They encapsulate a self-contained piece of content which can be drawn in any document. This makes them easy to test and reuse.
8
+
9
+ ## Example
10
+ ```ruby
11
+ class Box < CannedTuna::Component
12
+ template do
13
+ bounding_box([0, cursor - 100], width: width, height: height) do
14
+ outlet
15
+ draw_border
16
+ end
17
+ end
18
+
19
+ attr_reader :width, :height
20
+
21
+ def initialize(width: 100, height: 100)
22
+ @width, @height = width, height
23
+ end
24
+
25
+ def draw_border
26
+ transparent(0.5) { stroke_bounds }
27
+ end
28
+ end
29
+
30
+ Prawn::Document.generate("box.pdf") do
31
+ draw Box, width: 200, height: 100 do
32
+ text "Inside the box"
33
+ end
34
+ end
35
+ ```
36
+
37
+ ## Outlets
38
+
39
+ ### Default outlet
40
+ Components can define a single content outlet using the short-hand syntax.
41
+
42
+ ```ruby
43
+ class Box < CannedTuna::Component
44
+ template do
45
+ outlet
46
+ end
47
+ end
48
+
49
+ Prawn::Document.generate("box.pdf") do
50
+ draw Box do
51
+ text "Inside the box"
52
+ end
53
+ end
54
+ ```
55
+
56
+ ### Named outlets
57
+ Components can define multiple content outlets by yielding a content object that provides hooks for naming and defining multiple outlets.
58
+
59
+ ```ruby
60
+ class Box < CannedTuna::Component
61
+ template do
62
+ outlet(:header)
63
+ outlet(:body)
64
+ outlet(:footer)
65
+ end
66
+ end
67
+
68
+ Prawn::Document.generate("outlets.pdf") do
69
+ draw Box do |content|
70
+ content.outlet(:header) do
71
+ text "I am the header"
72
+ end
73
+ content.outlet(:body) do
74
+ text "I am the body"
75
+ end
76
+ content.outlet(:footer) do
77
+ text "I am the footer"
78
+ end
79
+ end
80
+ end
81
+ ```
82
+
83
+ ### Default content
84
+ Components can define default content for their outlets
85
+
86
+ ```ruby
87
+ class Box < CannedTuna::Component
88
+ template do
89
+ outlet(:header) { text "I am the header" }
90
+ outlet(:body)
91
+ outlet(:footer) { text "I am the footer" }
92
+ end
93
+ end
94
+
95
+ Prawn::Document.generate("outlets.pdf") do
96
+ draw Box do |content|
97
+ content.outlet(:body) do
98
+ text "I am the body"
99
+ end
100
+ end
101
+ end
102
+ ```
103
+
104
+ ## Installation
105
+
106
+ Add this line to your application's Gemfile:
107
+
108
+ ```ruby
109
+ gem 'canned_tuna'
110
+ ```
111
+
112
+ And then execute:
113
+
114
+ $ bundle
115
+
116
+ Or install it yourself as:
117
+
118
+ $ gem install canned_tuna
119
+
120
+ ## Development
121
+
122
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
123
+
124
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
125
+
126
+ ## Contributing
127
+
128
+ Bug reports and pull requests are welcome on GitHub at https://github.com/kaspermeyer/canned_tuna.
129
+
130
+ ## License
131
+
132
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.libs << "lib"
7
+ t.test_files = FileList["test/**/*_test.rb"]
8
+ end
9
+
10
+ task default: :test
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "canned_tuna"
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__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,35 @@
1
+ lib = File.expand_path("lib", __dir__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require "canned_tuna/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "canned_tuna"
7
+ spec.version = CannedTuna::VERSION
8
+ spec.authors = ["Kasper Meyer"]
9
+ spec.email = ["hi@kaspermeyer.com"]
10
+
11
+ spec.summary = "Components for Prawn"
12
+ spec.description = "Modular components to encapsulate data and markup in Prawn"
13
+ spec.homepage = "https://github.com/kaspermeyer/canned_tuna"
14
+ spec.license = "MIT"
15
+
16
+ spec.metadata["homepage_uri"] = spec.homepage
17
+ spec.metadata["source_code_uri"] = spec.homepage
18
+
19
+ # Specify which files should be added to the gem when it is released.
20
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
21
+ spec.files = Dir.chdir(File.expand_path("..", __FILE__)) do
22
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
23
+ end
24
+ spec.bindir = "exe"
25
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
26
+ spec.require_paths = ["lib"]
27
+
28
+ spec.add_dependency "prawn", "~> 2.2"
29
+ spec.add_development_dependency "bundler", "~> 2.0"
30
+ spec.add_development_dependency "minitest", "~> 5.0"
31
+ spec.add_development_dependency "minitest-focus", "~> 1.2"
32
+ spec.add_development_dependency "pdf-inspector", "~> 1.3"
33
+ spec.add_development_dependency "rake", "~> 13.0"
34
+ spec.add_development_dependency "standard", "~> 0.1.4"
35
+ end
@@ -0,0 +1,36 @@
1
+ require_relative "../lib/canned_tuna"
2
+
3
+ class Box < CannedTuna::Component
4
+ template do
5
+ bounding_box([0, cursor - 100], width: width, height: height) do
6
+ outlet(:header)
7
+ outlet(:body)
8
+ outlet(:footer)
9
+ draw_border
10
+ end
11
+ end
12
+
13
+ attr_reader :width, :height
14
+
15
+ def initialize(width: 100, height: 100)
16
+ @width, @height = width, height
17
+ end
18
+
19
+ def draw_border
20
+ transparent(0.5) { stroke_bounds }
21
+ end
22
+ end
23
+
24
+ Prawn::Document.generate("outlets.pdf") do
25
+ draw Box, width: 200, height: 100 do |content|
26
+ content.outlet(:header) do
27
+ text "I am the header"
28
+ end
29
+ content.outlet(:body) do
30
+ text "I am the body"
31
+ end
32
+ content.outlet(:footer) do
33
+ text "I am the footer"
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,26 @@
1
+ require_relative "../lib/canned_tuna"
2
+
3
+ class Box < CannedTuna::Component
4
+ template do
5
+ bounding_box([0, cursor - 100], width: width, height: height) do
6
+ outlet
7
+ draw_border
8
+ end
9
+ end
10
+
11
+ attr_reader :width, :height
12
+
13
+ def initialize(width: 100, height: 100)
14
+ @width, @height = width, height
15
+ end
16
+
17
+ def draw_border
18
+ transparent(0.5) { stroke_bounds }
19
+ end
20
+ end
21
+
22
+ Prawn::Document.generate("simple.pdf") do
23
+ draw Box, width: 200, height: 100 do
24
+ text "Inside the box"
25
+ end
26
+ end
@@ -0,0 +1,8 @@
1
+ require "prawn"
2
+ require_relative "canned_tuna/version"
3
+ require_relative "canned_tuna/interface"
4
+ require_relative "canned_tuna/component"
5
+ require_relative "canned_tuna/content_proxy"
6
+
7
+ module CannedTuna
8
+ end
@@ -0,0 +1,49 @@
1
+ module CannedTuna
2
+ class Component
3
+ include Prawn::View
4
+
5
+ def self.template &block
6
+ if block_given?
7
+ @template = block
8
+ else
9
+ @template || proc {}
10
+ end
11
+ end
12
+
13
+ def draw_in pdf, &block
14
+ register_outlets(&block)
15
+
16
+ with_temporary_document(pdf) do
17
+ instance_exec(&self.class.template)
18
+ end
19
+ end
20
+
21
+ private
22
+
23
+ def content
24
+ @content ||= ContentProxy.new
25
+ end
26
+
27
+ def outlet name = :default, &default_content
28
+ content.outlet_for(name, &default_content).call
29
+ end
30
+
31
+ def with_temporary_document pdf
32
+ @document = pdf
33
+ yield
34
+ @document = nil
35
+ end
36
+
37
+ def register_outlets &block
38
+ return unless block_given?
39
+
40
+ # Multiple content outlets
41
+ if block.arity > 0
42
+ instance_exec(content, &block)
43
+ # Default content outlet (short-hand syntax)
44
+ else
45
+ content.outlet(:default, &block)
46
+ end
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,15 @@
1
+ module CannedTuna
2
+ class ContentProxy
3
+ def initialize
4
+ @outlets = {}
5
+ end
6
+
7
+ def outlet_for name, &default_content
8
+ @outlets[name] || default_content || proc {}
9
+ end
10
+
11
+ def outlet name = :default, &block
12
+ @outlets[name] = block
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,9 @@
1
+ module CannedTuna
2
+ module Interface
3
+ def draw component, *args, &block
4
+ component.new(*args).draw_in(self, &block)
5
+ end
6
+ end
7
+ end
8
+
9
+ Prawn::Document.extensions << CannedTuna::Interface
@@ -0,0 +1,3 @@
1
+ module CannedTuna
2
+ VERSION = "0.0.6"
3
+ end
metadata ADDED
@@ -0,0 +1,161 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: canned_tuna
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.6
5
+ platform: ruby
6
+ authors:
7
+ - Kasper Meyer
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2020-06-03 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: prawn
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.2'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.2'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '2.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '2.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: minitest
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '5.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '5.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: minitest-focus
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.2'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.2'
69
+ - !ruby/object:Gem::Dependency
70
+ name: pdf-inspector
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '1.3'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '1.3'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rake
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '13.0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '13.0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: standard
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: 0.1.4
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: 0.1.4
111
+ description: Modular components to encapsulate data and markup in Prawn
112
+ email:
113
+ - hi@kaspermeyer.com
114
+ executables: []
115
+ extensions: []
116
+ extra_rdoc_files: []
117
+ files:
118
+ - ".gitignore"
119
+ - ".ruby-version"
120
+ - ".travis.yml"
121
+ - Gemfile
122
+ - Gemfile.lock
123
+ - LICENSE.txt
124
+ - README.md
125
+ - Rakefile
126
+ - bin/console
127
+ - bin/setup
128
+ - canned_tuna.gemspec
129
+ - example/outlets.rb
130
+ - example/simple.rb
131
+ - lib/canned_tuna.rb
132
+ - lib/canned_tuna/component.rb
133
+ - lib/canned_tuna/content_proxy.rb
134
+ - lib/canned_tuna/interface.rb
135
+ - lib/canned_tuna/version.rb
136
+ homepage: https://github.com/kaspermeyer/canned_tuna
137
+ licenses:
138
+ - MIT
139
+ metadata:
140
+ homepage_uri: https://github.com/kaspermeyer/canned_tuna
141
+ source_code_uri: https://github.com/kaspermeyer/canned_tuna
142
+ post_install_message:
143
+ rdoc_options: []
144
+ require_paths:
145
+ - lib
146
+ required_ruby_version: !ruby/object:Gem::Requirement
147
+ requirements:
148
+ - - ">="
149
+ - !ruby/object:Gem::Version
150
+ version: '0'
151
+ required_rubygems_version: !ruby/object:Gem::Requirement
152
+ requirements:
153
+ - - ">="
154
+ - !ruby/object:Gem::Version
155
+ version: '0'
156
+ requirements: []
157
+ rubygems_version: 3.0.3
158
+ signing_key:
159
+ specification_version: 4
160
+ summary: Components for Prawn
161
+ test_files: []