fourmi-prawn-utils 0.1.0

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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 5ea58138a0f9fd6da9db87d1bb929f962d85a9ff3a3a5e6a7f46991e179d401d
4
+ data.tar.gz: 3a3402195f5fa623959b51038f03144a94a612a52ef58aa7183206fa44ee1087
5
+ SHA512:
6
+ metadata.gz: 48c9de9298d9c4d52dfedf9e187e09c900db0c27120513f475c5cab7c4e624ed1158331f413dae1b3815df9242cf4c353ff25870c274db81193ff85eda0b591b
7
+ data.tar.gz: 5ae9ada9f8c253fe376e6bf1622443755e946768afb842e9ee2048f16d36a50fc384339d5139ec4fb72a086e81b2fb4cb2d976fac705f42c09982aee4e403016
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0] - 2022-10-14
4
+
5
+ - Initial release
data/Gemfile ADDED
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in fourmi-prawn-utils.gemspec
6
+ gemspec
7
+
8
+ gem "rake", "~> 13.0"
9
+
10
+ gem "minitest", "~> 5.0"
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2022 Guillaume Dott
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.
data/README.md ADDED
@@ -0,0 +1,33 @@
1
+ # Fourmi::Prawn::Utils
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/fourmi/prawn/utils`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Install the gem and add to the application's Gemfile by executing:
10
+
11
+ $ bundle add fourmi-prawn-utils
12
+
13
+ If bundler is not being used to manage dependencies, install the gem by executing:
14
+
15
+ $ gem install fourmi-prawn-utils
16
+
17
+ ## Usage
18
+
19
+ TODO: Write usage instructions here
20
+
21
+ ## Development
22
+
23
+ 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.
24
+
25
+ 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 the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
26
+
27
+ ## Contributing
28
+
29
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/fourmi-prawn-utils.
30
+
31
+ ## License
32
+
33
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rake/testtask"
5
+
6
+ Rake::TestTask.new(:test) do |t|
7
+ t.libs << "test"
8
+ t.libs << "lib"
9
+ t.test_files = FileList["test/**/test_*.rb"]
10
+ end
11
+
12
+ task default: :test
@@ -0,0 +1,14 @@
1
+ module Fourmi::Prawn::Utils
2
+ module Callbacks
3
+ class BorderCallback
4
+ def initialize(document)
5
+ @document = document
6
+ end
7
+
8
+ def render_in_front(fragment)
9
+ @document.stroke_polygon(fragment.top_left, fragment.top_right,
10
+ fragment.bottom_right, fragment.bottom_left)
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,19 @@
1
+ module Fourmi::Prawn::Utils
2
+ module Callbacks
3
+ class HighlightCallback
4
+ def initialize(color, document, padding_top = 0, padding_left = 0)
5
+ @color = color
6
+ @document = document
7
+ @padding_top = padding_top
8
+ @padding_left = padding_left
9
+ end
10
+
11
+ def render_behind(fragment)
12
+ original_color = @document.fill_color
13
+ @document.fill_color = @color
14
+ @document.fill_rectangle([fragment.left - @padding_left, fragment.top + @padding_top], fragment.width + 2 * @padding_left, fragment.height + 2 * @padding_top)
15
+ @document.fill_color = original_color
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,53 @@
1
+ require 'fourmi/prawn/utils/extensions/text_align'
2
+
3
+ module Fourmi::Prawn::Utils
4
+ module Extensions
5
+ module Box
6
+ def textbox(content = nil, height = 40)
7
+ bounding_box([0, cursor], height: content.blank? && !block_given? ? height : nil, width: bounds.width) do
8
+ pad(5) do
9
+ indent(5) do
10
+ text content unless content.blank?
11
+ yield if block_given?
12
+ end
13
+ end
14
+ stroke_bounds
15
+ end
16
+ end
17
+
18
+ def padded_box(position, padding, **options, &block)
19
+ rounded = options.delete(:rounded)
20
+ rounded = true if rounded.nil?
21
+
22
+ bounding_box position, options do
23
+ bounding_box [padding, bounds.top - padding], width: bounds.width - 2 * padding, height: bounds.height > 2 * padding ? bounds.height - 2 * padding : nil do
24
+ yield block
25
+ move_down padding
26
+ end
27
+ if rounded
28
+ stroke_rounded_bounds
29
+ else
30
+ stroke_bounds
31
+ end
32
+ end
33
+ end
34
+
35
+ def filled_box(color, x: 0, y: cursor, width: bounds.width, height: 150, &block)
36
+ fill_color(color) do
37
+ fill_rectangle [x, y], width, height
38
+ end
39
+ bounding_box([x, y], width: width, height: height, &block)
40
+ end
41
+
42
+ def list(text, options = {})
43
+ float { indent(5) { text '- ' } }
44
+ indent 15 do
45
+ textj text, options
46
+ end
47
+ end
48
+ end
49
+ end
50
+ end
51
+
52
+ require 'prawn/document'
53
+ Prawn::Document.extensions << Fourmi::Prawn::Utils::Extensions::Box
@@ -0,0 +1,12 @@
1
+ module Fourmi::Prawn::Utils
2
+ module Extensions
3
+ module StrokeRoundedBounds
4
+ def stroke_rounded_bounds(radius = 2)
5
+ stroke_rounded_rectangle [0, bounds.top], bounds.width, bounds.height, radius
6
+ end
7
+ end
8
+ end
9
+ end
10
+
11
+ require 'prawn/document'
12
+ Prawn::Document.extensions << Fourmi::Prawn::Utils::Extensions::StrokeRoundedBounds
@@ -0,0 +1,30 @@
1
+ module Fourmi::Prawn::Utils
2
+ module Extensions
3
+ module StrokesAndColors
4
+ def with_fill_color(color)
5
+ original_color = fill_color
6
+ self.fill_color = color
7
+
8
+ yield if block_given?
9
+ ensure
10
+ self.fill_color = original_color
11
+ end
12
+
13
+ def with_stroke_properties(color: nil, width: nil)
14
+ original_color = stroke_color
15
+ original_width = line_width
16
+
17
+ self.stroke_color = color unless color.nil?
18
+ self.line_width = width unless width.nil?
19
+
20
+ yield if block_given?
21
+ ensure
22
+ self.stroke_color = original_color
23
+ self.line_width = original_width
24
+ end
25
+ end
26
+ end
27
+ end
28
+
29
+ require 'prawn/document'
30
+ Prawn::Document.extensions << Fourmi::Prawn::Utils::Extensions::StrokesAndColors
@@ -0,0 +1,21 @@
1
+ module Fourmi::Prawn::Utils
2
+ module Extensions
3
+ module TextAlign
4
+ def paragraph(string, options = {})
5
+ textj string, options
6
+ move_down 4
7
+ end
8
+
9
+ def textc(string, options = {})
10
+ text string, {align: :center}.merge(options)
11
+ end
12
+
13
+ def textj(string, options = {})
14
+ text string, {align: :justify}.merge(options)
15
+ end
16
+ end
17
+ end
18
+ end
19
+
20
+ require 'prawn/document'
21
+ Prawn::Document.extensions << Fourmi::Prawn::Utils::Extensions::TextAlign
@@ -0,0 +1,32 @@
1
+ require 'fourmi/prawn/utils/extensions/strokes_and_colors'
2
+ require 'prawn/blank'
3
+
4
+ module Fourmi::Prawn::Utils
5
+ module Extensions
6
+ module VisualForm
7
+ def visual_checkbox(name, checked = false, size: 8, white: false, form: false)
8
+ bounding_box([0, cursor], width: bounds.width) do
9
+ float do
10
+ bounding_box([0, cursor], width: size, height: size) do
11
+ if form
12
+ checkbox name: name, at: [0, bounds.top], checked: checked, width: bounds.width, height: bounds.height
13
+ else
14
+ with_fill_color 'FFFFFF' do
15
+ fill_rectangle [0, bounds.top], bounds.width, bounds.height if white
16
+ end
17
+ fill_rectangle [2, bounds.height - 2], bounds.width - 4, bounds.height - 4 if checked
18
+ end
19
+ stroke_bounds
20
+ end
21
+ end
22
+ indent(size + 7) do
23
+ yield
24
+ end if block_given?
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
30
+
31
+ require 'prawn/document'
32
+ Prawn::Document.extensions << Fourmi::Prawn::Utils::Extensions::VisualForm
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Fourmi
4
+ module Prawn
5
+ module Utils
6
+ VERSION = "0.1.0"
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "utils/version"
4
+
5
+ module Fourmi
6
+ module Prawn
7
+ module Utils
8
+ class Error < StandardError; end
9
+ # Your code goes here...
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,8 @@
1
+ module Fourmi
2
+ module Prawn
3
+ module Utils
4
+ VERSION: String
5
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
6
+ end
7
+ end
8
+ end
metadata ADDED
@@ -0,0 +1,88 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fourmi-prawn-utils
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Guillaume Dott
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2022-10-14 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: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: prawn-blank
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: Some methods to simplify PDF creation with Prawn
42
+ email:
43
+ - guillaume+github@dott.fr
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - CHANGELOG.md
49
+ - Gemfile
50
+ - LICENSE.txt
51
+ - README.md
52
+ - Rakefile
53
+ - lib/fourmi/prawn/utils.rb
54
+ - lib/fourmi/prawn/utils/callbacks/border_callback.rb
55
+ - lib/fourmi/prawn/utils/callbacks/highlight_callback.rb
56
+ - lib/fourmi/prawn/utils/extensions/box.rb
57
+ - lib/fourmi/prawn/utils/extensions/stroke_rounded_bounds.rb
58
+ - lib/fourmi/prawn/utils/extensions/strokes_and_colors.rb
59
+ - lib/fourmi/prawn/utils/extensions/text_align.rb
60
+ - lib/fourmi/prawn/utils/extensions/visual_form.rb
61
+ - lib/fourmi/prawn/utils/version.rb
62
+ - sig/fourmi/prawn/utils.rbs
63
+ homepage: https://code.lafourmi-immo.com/lafourmi-immo/prawn-utils
64
+ licenses:
65
+ - MIT
66
+ metadata:
67
+ homepage_uri: https://code.lafourmi-immo.com/lafourmi-immo/prawn-utils
68
+ source_code_uri: https://code.lafourmi-immo.com/lafourmi-immo/prawn-utils
69
+ post_install_message:
70
+ rdoc_options: []
71
+ require_paths:
72
+ - lib
73
+ required_ruby_version: !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - ">="
76
+ - !ruby/object:Gem::Version
77
+ version: 2.6.0
78
+ required_rubygems_version: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ requirements: []
84
+ rubygems_version: 3.3.21
85
+ signing_key:
86
+ specification_version: 4
87
+ summary: Some methods to simplify PDF creation with Prawn
88
+ test_files: []