prawn-component 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: b7cb7530aaae6e8a12b14d4c36e12007fa984cf4
4
+ data.tar.gz: 59b18c2861e462bf302f7a3fd83d09bcfa98d789
5
+ SHA512:
6
+ metadata.gz: a4a64195c3ca0be9529125dbbf5b2541ef077079fd3b6d1142608a9d28f9fa3c6fe1d75f1772cef2046f666a6b9018614286e53165b3a0052f3a243073ad059f
7
+ data.tar.gz: b18626a3a6bbc49e6e59c2c9303e2b4d5c497c7479eb2669f26d1e96be3110a95c1fda2aa8f30b746e4e92eb9da8662ee9110553e48cf9b7b0bf6206c8562226
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ # A sample Gemfile
2
+ source "https://rubygems.org"
3
+
4
+ gemspec
5
+
6
+ # gem "rails"
data/Gemfile.lock ADDED
@@ -0,0 +1,25 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ prawn-component (0.0.1)
5
+ prawn (~> 1.3.0)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ minitest (5.4.2)
11
+ pdf-core (0.4.0)
12
+ prawn (1.3.0)
13
+ pdf-core (~> 0.4.0)
14
+ ttfunk (~> 1.4.0)
15
+ rake (10.3.2)
16
+ ttfunk (1.4.0)
17
+
18
+ PLATFORMS
19
+ ruby
20
+
21
+ DEPENDENCIES
22
+ bundler (~> 1.7)
23
+ minitest (>= 0.0)
24
+ prawn-component!
25
+ rake (~> 10.0)
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2014 Gregory Brown and PrawnPDF contributors
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.
22
+
@@ -0,0 +1,3 @@
1
+ require "prawn"
2
+
3
+ require_relative "../lib/prawn/component"
data/example/simple.rb ADDED
@@ -0,0 +1,9 @@
1
+ require_relative "example_helper"
2
+
3
+ Prawn::Component.define(:greetings) do
4
+ text "Seasons greetings, #{params[:name]}!", :size => 24
5
+ end
6
+
7
+ Prawn::Document.generate("x.pdf") do
8
+ draw :greetings, :name => "Matz"
9
+ end
@@ -0,0 +1,29 @@
1
+ module Prawn
2
+ module Component
3
+ def self.definitions
4
+ @definitions ||= {}
5
+ end
6
+
7
+ def self.define(name, component_class=nil,&block)
8
+ if component_class
9
+ definitions[name] =component_class
10
+ else
11
+ definitions[name] = Class.new
12
+ definitions[name].send(:include, Prawn::Component)
13
+ definitions[name].send(:define_method, :draw, &block)
14
+ end
15
+ end
16
+
17
+ include Prawn::View
18
+
19
+ attr_reader :document, :params
20
+
21
+ def initialize(document, params={})
22
+ @document = document
23
+ @params = params
24
+ end
25
+ end
26
+ end
27
+
28
+ require_relative "component/document_extensions"
29
+ Prawn::Document.extensions << Prawn::Component::DocumentExtensions
@@ -0,0 +1,51 @@
1
+ module Prawn
2
+ module Component
3
+ module DocumentExtensions
4
+ def data_source(name)
5
+ define_singleton_method(name) do
6
+ @data_source ||= {}
7
+ @data_source[name] ||= yield
8
+ end
9
+ end
10
+
11
+ # consider adding support for padding
12
+ # and if we ever allow dynamic rendering, margins
13
+ def draw(component, params={})
14
+ if Symbol === component
15
+ component = Prawn::Component.definitions[component]
16
+ end
17
+
18
+ box = params.delete(:box)
19
+ border = params.delete(:border)
20
+
21
+ if box.nil?
22
+ component.new(self, params).draw
23
+ stroke_bounds if border
24
+ elsif box.kind_of?(Prawn::Document::GridBox) # FIXME: Massive duplication + explicit type check
25
+ box.bounding_box do
26
+ bounds.define_singleton_method(:move_past_bottom) do
27
+ raise Prawn::Errors::CannotFit
28
+ end
29
+
30
+ component.new(self, params).draw
31
+ stroke_bounds if border
32
+ end
33
+ else
34
+ left, top, width, height = box
35
+
36
+ top = top >= 0 ? bounds.top - top : top*-1
37
+ left = left >= 0 ? left : bounds.right - left*-1
38
+
39
+ bounding_box([left, top], :width => width, :height => height) do
40
+ bounds.define_singleton_method(:move_past_bottom) do
41
+ raise Prawn::Errors::CannotFit
42
+ end
43
+
44
+ component.new(self, params).draw
45
+ stroke_bounds if border
46
+ end
47
+ end
48
+ end
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,5 @@
1
+ module Prawn
2
+ class Component
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ require "#{lib}/prawn/component/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "prawn-component"
7
+ spec.version = Prawn::Component::VERSION
8
+ spec.authors = ["Gregory Brown"]
9
+ spec.email = ["gregory.t.brown@gmail.com"]
10
+ spec.summary = "Prawn::Component"
11
+ spec.description = "A system for building reusable chunks of Prawn code"
12
+ spec.license = "MIT"
13
+
14
+ spec.files = `git ls-files -z`.split("\x0")
15
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
16
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
17
+ spec.require_paths = ["lib"]
18
+
19
+ spec.add_dependency "prawn", "~> 1.3.0"
20
+ spec.add_development_dependency "bundler", "~> 1.7"
21
+ spec.add_development_dependency "rake", "~> 10.0"
22
+ spec.add_development_dependency "minitest", ">= 0.0"
23
+ end
metadata ADDED
@@ -0,0 +1,110 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: prawn-component
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Gregory Brown
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-10-12 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: 1.3.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 1.3.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.7'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.7'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: minitest
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0.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.0'
69
+ description: A system for building reusable chunks of Prawn code
70
+ email:
71
+ - gregory.t.brown@gmail.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - Gemfile
77
+ - Gemfile.lock
78
+ - LICENSE
79
+ - example/example_helper.rb
80
+ - example/simple.rb
81
+ - lib/prawn/component.rb
82
+ - lib/prawn/component/document_extensions.rb
83
+ - lib/prawn/component/version.rb
84
+ - prawn-component.gemspec
85
+ homepage:
86
+ licenses:
87
+ - MIT
88
+ metadata: {}
89
+ post_install_message:
90
+ rdoc_options: []
91
+ require_paths:
92
+ - lib
93
+ required_ruby_version: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - ">="
96
+ - !ruby/object:Gem::Version
97
+ version: '0'
98
+ required_rubygems_version: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ version: '0'
103
+ requirements: []
104
+ rubyforge_project:
105
+ rubygems_version: 2.2.2
106
+ signing_key:
107
+ specification_version: 4
108
+ summary: Prawn::Component
109
+ test_files: []
110
+ has_rdoc: