prawn-markup 0.2.2 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e2a68c2f0773fd3769437fcee6aed0cba929e95808c6618b8e36dc2f7624c8fe
4
- data.tar.gz: d379eb9ed4e28cbdbeca6048b06019d5dd4d8e741cb41ebd304a65a3a05be034
3
+ metadata.gz: 3e42ddd575822d3805d7edb1525124617db37098e35ad139a2fed48824d08790
4
+ data.tar.gz: feb4ae593f40ebb09875ff2e4e9158ee4de7856980cf90e602103855d9bb47ad
5
5
  SHA512:
6
- metadata.gz: 0da58a2bcd5b700753ae0f59f0c68c4014af194c74d2946e61e5028e29e8263fba91b255b023f2e9db5246a44a05cf5798b6808831309936091c7cdf53ff6c8f
7
- data.tar.gz: 9129eaba7c308464c68c501dab041e2e54f79618734b0fd29c53554320b12cb6b2c18c25aa02bd77108eb3c17728720f95dce3412a4664f5fcc1d9c37beefccf
6
+ metadata.gz: c13137a43fb81062dd27fcc0492d9d910f7244bf8841cda87c690bc36ad8a17434e783a864874e56cdeea90e7a4eff49b242c9f62d72a318a869110d2a393848
7
+ data.tar.gz: f43d2499d55744f2e973a11ea9add7c254b283eee5639d29aa043f2b600d40a00fc52b4087c7bf7012d9eba502d9ab36a4da6b5f10484bdc9eb91e703dd1a23f
data/README.md CHANGED
@@ -33,6 +33,27 @@ doc = Prawn::Document.new
33
33
  doc.markup('<p>Hello World</p><hr/><p>KTHXBYE</p>')
34
34
  ```
35
35
 
36
+ ## Supported HTML
37
+
38
+ This gem parses the given HTML and layouts the following elements in a vertical order:
39
+
40
+ * Text blocks: `p`, `div`, `ol`, `ul`, `li`, `hr`, `br`
41
+ * Text semantics: `a`, `b`, `strong`, `i`, `em`, `u`, `s`, `del`, `sub`, `sup`
42
+ * Headings: `h1`, `h2`, `h3`, `h4`, `h5`, `h6`
43
+ * Tables: `table`, `tr`, `td`, `th`
44
+ * Media: `img`, `iframe`
45
+ * Inputs: `type=checkbox`, `type=radio`
46
+
47
+ All other elements are ignored, their content is added to the parent element. With a few exceptions, no CSS is processed. One exception is the `width` property of `img`, `td` and `th`, which may contain values in `cm`, `mm`, `px`, `pt`, `%` or `auto`.
48
+
49
+ If no explicit loader is given (see above), images are loaded from `http(s)` addresses or may be contained in the `src` attribute as base64 encoded data URIs. Prawn only supports `PNG` and `JPG`.
50
+
51
+ ## Example
52
+
53
+ Have a look at [showcase.html](spec/fixtures/showcase.html), which is rendered by the corresponding [spec](spec/prawn/markup/showcase_spec.rb). Uncomment the `lookatit` call there to directly open the generated PDF when running the spec with `spec spec/prawn/markup/showcase_spec.rb`.
54
+
55
+ ## Formatting Options
56
+
36
57
  To customize element formatting, do:
37
58
 
38
59
  ```ruby
@@ -54,39 +75,40 @@ Tables and lists are rendered with [prawn-table](https://github.com/prawnpdf/pra
54
75
 
55
76
  Beside these options handled by Prawn / prawn-table, the following values may be customized:
56
77
 
57
- * `[:text][:preprocessor]`: A proc/callable that is called each time before a chunk of text is rendered.
58
- * `[:text][:margin_bottom]`: Margin after each `<p>`, `<ol>`, `<ul>` or `<table>`. Defaults to about half a line.
59
- * `[:heading1-6][:margin_top]`: Margin before a heading. Default is 0.
60
- * `[:heading1-6][:margin_bottom]`: Margin after a heading. Default is 0.
61
- * `[:table][:placeholder][:too_large]`: If the table content does not fit into the current bounding box, this text/callable is rendered instead. Defaults to '[table content too large]'.
62
- * `[:table][:placeholder][:subtable_too_large]`: If the content of a subtable cannot be fitted into the table, this text is rendered instead. Defaults to '[nested tables with automatic width are not supported]'.
63
- * `[:list][:vertical_margin]`: Margin at the top and the bottom of a list. Default is 5.
64
- * `[:list][:bullet][:char]`: The text used as bullet in unordered lists. Default is '•'.
65
- * `[:list][:bullet][:margin]`: Margin before the bullet. Default is 10.
66
- * `[:list][:content][:margin]`: Margin between the bullet and the content. Default is 10.
67
- * `[:list][:placeholder][:too_large]`: If the list content does not fit into the current bounding box, this text/callable is rendered instead. Defaults to '[list content too large]'.
68
- * `[:image][:loader]`: A callable that accepts the `src` attribute as an argument an returns a value understood by Prawn's `image` method. Loads `http(s)` URLs and base64 encoded data URIs by default.
69
- * `[:image][:placeholder]`: If an image is not supported, this text/callable is rendered instead. Defaults to '[unsupported image]'.
70
- * `[:iframe][:placeholder]`: If the HTML contains IFrames, this text/callable is rendered instead.
71
- A callable gets the URL of the IFrame as an argument. Defaults to ignore iframes.
72
-
73
- ## Supported HTML
74
-
75
- This gem parses the given HTML and layouts the following elements in a vertical order:
76
-
77
- * Text blocks: `p`, `div`, `ol`, `ul`, `li`, `hr`, `br`
78
- * Text semantics: `a`, `b`, `strong`, `i`, `em`, `u`, `s`, `del`, `sub`, `sup`
79
- * Headings: `h1`, `h2`, `h3`, `h4`, `h5`, `h6`
80
- * Tables: `table`, `tr`, `td`, `th`
81
- * Media: `img`, `iframe`
82
-
83
- All other elements are ignored, their content is added to the parent element. With a few exceptions, no CSS is processed. One exception is the `width` property of `img`, `td` and `th`, which may contain values in `cm`, `mm`, `px`, `pt`, `%` or `auto`.
84
-
85
- If no explicit loader is given (see above), images are loaded from `http(s)` addresses or may be contained in the `src` attribute as base64 encoded data URIs. Prawn only supports `PNG` and `JPG`.
86
-
87
- ## Example
88
-
89
- Have a look at [showcase.html](spec/fixtures/showcase.html), which is rendered by the corresponding [spec](spec/prawn/markup/showcase_spec.rb). Uncomment the `lookatit` call there to directly open the generated PDF when running the spec with `spec spec/prawn/markup/showcase_spec.rb`.
78
+ * `:text`
79
+ * `:preprocessor`: A proc/callable that is called each time before a chunk of text is rendered.
80
+ * `:margin_bottom`: Margin after each `<p>`, `<ol>`, `<ul>` or `<table>`. Defaults to about half a line.
81
+ * `:heading1-6`
82
+ * `:margin_top`: Margin before a heading. Default is 0.
83
+ * `:margin_bottom`: Margin after a heading. Default is 0.
84
+ * `:table`
85
+ * `:placeholder`
86
+ * `:too_large`: If the table content does not fit into the current bounding box, this text/callable is rendered instead. Defaults to '[table content too large]'.
87
+ * `:subtable_too_large`: If the content of a subtable cannot be fitted into the table, this text is rendered instead. Defaults to '[nested tables with automatic width are not supported]'.
88
+ * `:list`
89
+ * `:vertical_margin`: Margin at the top and the bottom of a list. Default is 5.
90
+ * `:bullet`
91
+ * `:char`: The text used as bullet in unordered lists. Default is '•'.
92
+ * `:margin`: Margin before the bullet. Default is 10.
93
+ * `:content`
94
+ * `:margin`: Margin between the bullet and the content. Default is 10.
95
+ * `:placeholder`
96
+ * `:too_large`: If the list content does not fit into the current bounding box, this text/callable is rendered instead. Defaults to '[list content too large]'.
97
+ * `:image`
98
+ * `:loader`: A callable that accepts the `src` attribute as an argument an returns a value understood by Prawn's `image` method. Loads `http(s)` URLs and base64 encoded data URIs by default.
99
+ * `:placeholder`: If an image is not supported, this text/callable is rendered instead. Defaults to '[unsupported image]'.
100
+ * `:iframe`
101
+ * `:placeholder`: If the HTML contains IFrames, this text/callable is rendered instead.
102
+ A callable gets the URL of the IFrame as an argument. Defaults to ignore iframes.
103
+ * `:input`
104
+ * `:symbol_font`: A special font to print checkboxes and radios. Prawn's standard fonts do not support special unicode characters. Do not forget to update the document's `font_families`.
105
+ * `:symbol_font_size`: The size of the special font to print checkboxes and radios.
106
+ * `:checkbox`
107
+ * `:checked`: The char to print for a checked checkbox. Default is '☑'.
108
+ * `:unchecked`: The char to print for an unchecked checkbox. Default is '☐'.
109
+ * `:radio`
110
+ * `:checked`: The char to print for a checked radio. Default is '◉'.
111
+ * `:unchecked`: The char to print for an unchecked radio. Default is '○'.
90
112
 
91
113
  ## Development
92
114
 
@@ -26,6 +26,7 @@ module Prawn
26
26
  require 'prawn/markup/processor/blocks'
27
27
  require 'prawn/markup/processor/headings'
28
28
  require 'prawn/markup/processor/images'
29
+ require 'prawn/markup/processor/inputs'
29
30
  require 'prawn/markup/processor/tables'
30
31
  require 'prawn/markup/processor/lists'
31
32
 
@@ -33,6 +34,7 @@ module Prawn
33
34
  prepend Prawn::Markup::Processor::Blocks
34
35
  prepend Prawn::Markup::Processor::Headings
35
36
  prepend Prawn::Markup::Processor::Images
37
+ prepend Prawn::Markup::Processor::Inputs
36
38
  prepend Prawn::Markup::Processor::Tables
37
39
  prepend Prawn::Markup::Processor::Lists
38
40
 
@@ -128,7 +130,7 @@ module Prawn
128
130
  end
129
131
 
130
132
  def placeholder_value(keys, *args)
131
- placeholder = dig_options(keys)
133
+ placeholder = dig_options(*keys)
132
134
  return if placeholder.nil?
133
135
 
134
136
  if placeholder.respond_to?(:call)
@@ -138,7 +140,7 @@ module Prawn
138
140
  end
139
141
  end
140
142
 
141
- def dig_options(keys)
143
+ def dig_options(*keys)
142
144
  keys.inject(options) { |opts, key| opts ? opts[key] : nil }
143
145
  end
144
146
 
@@ -0,0 +1,61 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Prawn
4
+ module Markup
5
+ module Processor::Inputs
6
+
7
+ DEFAULT_CHECKABLE_CHARS = {
8
+ checkbox: {
9
+ checked: '☑',
10
+ unchecked: '☐'
11
+ },
12
+ radio: {
13
+ checked: '◉',
14
+ unchecked: '○'
15
+ }
16
+ }.freeze
17
+
18
+ def self.prepended(base)
19
+ base.known_elements.push('input')
20
+ end
21
+
22
+ def start_input
23
+ type = current_attrs['type'].to_sym
24
+ if DEFAULT_CHECKABLE_CHARS.keys.include?(type)
25
+ append_checked_symbol(type)
26
+ end
27
+ end
28
+
29
+ private
30
+
31
+ def append_checked_symbol(type)
32
+ char = checkable_symbol(type)
33
+ append_text(build_font_tag(char))
34
+ end
35
+
36
+ def checkable_symbol(type)
37
+ state = current_attrs.key?('checked') ? :checked : :unchecked
38
+ dig_options(:input, type, state) || DEFAULT_CHECKABLE_CHARS[type][state]
39
+ end
40
+
41
+ def symbol_font_options
42
+ @symbol_font_options ||= {
43
+ name: dig_options(:input, :symbol_font),
44
+ size: dig_options(:input, :symbol_font_size)
45
+ }.compact
46
+ end
47
+
48
+ def build_font_tag(content)
49
+ return content if symbol_font_options.empty?
50
+
51
+ out = +'<font'
52
+ symbol_font_options.each do |key, value|
53
+ out << " #{key}=\"#{value}\""
54
+ end
55
+ out << '>'
56
+ out << content
57
+ out << '</font>'
58
+ end
59
+ end
60
+ end
61
+ end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Prawn
4
4
  module Markup
5
- VERSION = '0.2.2'
5
+ VERSION = '0.3.0'
6
6
  end
7
7
  end
@@ -17,7 +17,7 @@ Gem::Specification.new do |spec|
17
17
  spec.license = 'MIT'
18
18
 
19
19
  spec.files = `git ls-files -z`.split("\x0").reject do |f|
20
- f.match(%r{^(test|spec|features)/})
20
+ f.match(%r{^(((spec|bin)/)|\.|Gemfile|Rakefile)})
21
21
  end
22
22
  spec.bindir = 'exe'
23
23
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: prawn-markup
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pascal Zumkehr
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-03-16 00:00:00.000000000 Z
11
+ date: 2020-08-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nokogiri
@@ -159,18 +159,9 @@ executables: []
159
159
  extensions: []
160
160
  extra_rdoc_files: []
161
161
  files:
162
- - ".gitignore"
163
- - ".rspec"
164
- - ".rubocop.yml"
165
- - ".travis.yml"
166
162
  - CODE_OF_CONDUCT.md
167
- - Gemfile
168
- - Gemfile.lock
169
163
  - LICENSE.txt
170
164
  - README.md
171
- - Rakefile
172
- - bin/console
173
- - bin/setup
174
165
  - lib/prawn/markup.rb
175
166
  - lib/prawn/markup/builders/list_builder.rb
176
167
  - lib/prawn/markup/builders/nestable_builder.rb
@@ -183,6 +174,7 @@ files:
183
174
  - lib/prawn/markup/processor/blocks.rb
184
175
  - lib/prawn/markup/processor/headings.rb
185
176
  - lib/prawn/markup/processor/images.rb
177
+ - lib/prawn/markup/processor/inputs.rb
186
178
  - lib/prawn/markup/processor/lists.rb
187
179
  - lib/prawn/markup/processor/tables.rb
188
180
  - lib/prawn/markup/processor/text.rb
@@ -195,7 +187,7 @@ homepage: https://github.com/puzzle/prawn-markup
195
187
  licenses:
196
188
  - MIT
197
189
  metadata: {}
198
- post_install_message:
190
+ post_install_message:
199
191
  rdoc_options: []
200
192
  require_paths:
201
193
  - lib
@@ -210,8 +202,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
210
202
  - !ruby/object:Gem::Version
211
203
  version: '0'
212
204
  requirements: []
213
- rubygems_version: 3.1.2
214
- signing_key:
205
+ rubygems_version: 3.0.6
206
+ signing_key:
215
207
  specification_version: 4
216
208
  summary: Parse simple HTML markup to include in Prawn PDFs
217
209
  test_files: []
data/.gitignore DELETED
@@ -1,12 +0,0 @@
1
- /.bundle/
2
- /.yardoc
3
- /_yardoc/
4
- /coverage/
5
- /doc/
6
- /pkg/
7
- /spec/reports/
8
- /spec/coverage/
9
- /tmp/
10
-
11
- # rspec failure tracking
12
- .rspec_status
data/.rspec DELETED
@@ -1,3 +0,0 @@
1
- --format documentation
2
- --color
3
- --require spec_helper
@@ -1,68 +0,0 @@
1
- AllCops:
2
- DisplayCopNames: true
3
- Exclude:
4
- - '*.gemspec'
5
- - spec/**/*
6
- - vendor/**/*
7
-
8
- Metrics/AbcSize:
9
- Severity: error
10
-
11
- Metrics/ClassLength:
12
- Max: 250
13
- Severity: error
14
-
15
- Metrics/CyclomaticComplexity:
16
- Severity: error
17
-
18
- Metrics/MethodLength:
19
- Max: 10
20
- Severity: error
21
-
22
- Metrics/ModuleLength:
23
- Max: 150
24
- Severity: error
25
-
26
- Metrics/ParameterLists:
27
- Max: 4
28
- Severity: warning
29
-
30
- Layout/LineLength:
31
- Max: 100
32
- Severity: error
33
-
34
- # We thinks that's fine for specs
35
- Layout/EmptyLinesAroundBlockBody:
36
- Enabled: false
37
-
38
- # We thinks that's fine
39
- Layout/EmptyLinesAroundClassBody:
40
- Enabled: false
41
-
42
- # We thinks that's fine
43
- Layout/EmptyLinesAroundModuleBody:
44
- Enabled: false
45
-
46
- # Keep for now, easier with superclass definitions
47
- Style/ClassAndModuleChildren:
48
- Enabled: false
49
-
50
- # The ones we use must exist for the entire class hierarchy.
51
- Style/ClassVars:
52
- Enabled: false
53
-
54
- # Well, well, well
55
- Style/Documentation:
56
- Enabled: false
57
-
58
- # Keep single line bodys for if and unless
59
- Style/IfUnlessModifier:
60
- Enabled: false
61
-
62
- # We think that's the developers choice
63
- Style/GuardClause:
64
- Enabled: false
65
-
66
- # Backwards compatibility
67
- Style/SafeNavigation:
68
- Enabled: false
@@ -1,21 +0,0 @@
1
- language: ruby
2
-
3
- rvm:
4
- - 2.5.7
5
-
6
- env:
7
- global:
8
- - CC_TEST_REPORTER_ID=d70fe39ffb8f2f7c5f837f0133d10a3a1c6784d0dd189153111577b60f74c603
9
-
10
- before_script:
11
- - curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
12
- - chmod +x ./cc-test-reporter
13
- - ./cc-test-reporter before-build
14
-
15
- script:
16
- - bundle exec rake
17
- - bundle exec rubocop
18
-
19
- after_script:
20
- - ./cc-test-reporter format-coverage -t simplecov -o spec/coverage/codeclimate.json spec/coverage/.resultset.json
21
- - if [[ "$TRAVIS_TEST_RESULT" == 0 ]]; then ./cc-test-reporter upload-coverage -i spec/coverage/codeclimate.json; fi
data/Gemfile DELETED
@@ -1,6 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- source 'https://rubygems.org'
4
-
5
- # Specify your gem's dependencies in prawn-markup.gemspec
6
- gemspec
@@ -1,87 +0,0 @@
1
- PATH
2
- remote: .
3
- specs:
4
- prawn-markup (0.2.2)
5
- nokogiri
6
- prawn
7
- prawn-table
8
-
9
- GEM
10
- remote: https://rubygems.org/
11
- specs:
12
- Ascii85 (1.0.3)
13
- afm (0.2.2)
14
- ast (2.4.0)
15
- byebug (11.1.1)
16
- diff-lcs (1.3)
17
- docile (1.3.2)
18
- hashery (2.1.2)
19
- jaro_winkler (1.5.4)
20
- mini_portile2 (2.4.0)
21
- nokogiri (1.10.9)
22
- mini_portile2 (~> 2.4.0)
23
- parallel (1.19.1)
24
- parser (2.7.0.4)
25
- ast (~> 2.4.0)
26
- pdf-core (0.7.0)
27
- pdf-inspector (1.3.0)
28
- pdf-reader (>= 1.0, < 3.0.a)
29
- pdf-reader (2.4.0)
30
- Ascii85 (~> 1.0.0)
31
- afm (~> 0.2.1)
32
- hashery (~> 2.0)
33
- ruby-rc4
34
- ttfunk
35
- prawn (2.2.2)
36
- pdf-core (~> 0.7.0)
37
- ttfunk (~> 1.5)
38
- prawn-table (0.2.2)
39
- prawn (>= 1.3.0, < 3.0.0)
40
- rainbow (3.0.0)
41
- rake (13.0.1)
42
- rexml (3.2.4)
43
- rspec (3.9.0)
44
- rspec-core (~> 3.9.0)
45
- rspec-expectations (~> 3.9.0)
46
- rspec-mocks (~> 3.9.0)
47
- rspec-core (3.9.1)
48
- rspec-support (~> 3.9.1)
49
- rspec-expectations (3.9.1)
50
- diff-lcs (>= 1.2.0, < 2.0)
51
- rspec-support (~> 3.9.0)
52
- rspec-mocks (3.9.1)
53
- diff-lcs (>= 1.2.0, < 2.0)
54
- rspec-support (~> 3.9.0)
55
- rspec-support (3.9.2)
56
- rubocop (0.80.1)
57
- jaro_winkler (~> 1.5.1)
58
- parallel (~> 1.10)
59
- parser (>= 2.7.0.1)
60
- rainbow (>= 2.2.2, < 4.0)
61
- rexml
62
- ruby-progressbar (~> 1.7)
63
- unicode-display_width (>= 1.4.0, < 1.7)
64
- ruby-progressbar (1.10.1)
65
- ruby-rc4 (0.1.5)
66
- simplecov (0.18.5)
67
- docile (~> 1.1)
68
- simplecov-html (~> 0.11)
69
- simplecov-html (0.12.2)
70
- ttfunk (1.6.2.1)
71
- unicode-display_width (1.6.1)
72
-
73
- PLATFORMS
74
- ruby
75
-
76
- DEPENDENCIES
77
- bundler
78
- byebug
79
- pdf-inspector
80
- prawn-markup!
81
- rake
82
- rspec
83
- rubocop
84
- simplecov
85
-
86
- BUNDLED WITH
87
- 1.17.3
data/Rakefile DELETED
@@ -1,8 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'bundler/gem_tasks'
4
- require 'rspec/core/rake_task'
5
-
6
- RSpec::Core::RakeTask.new(:spec)
7
-
8
- task default: :spec
@@ -1,15 +0,0 @@
1
- #!/usr/bin/env ruby
2
- # frozen_string_literal: true
3
-
4
- require 'bundler/setup'
5
- require 'prawn/markup'
6
-
7
- # You can add fixtures and/or initialization code here to make experimenting
8
- # with your gem easier. You can also use a different console, if you like.
9
-
10
- # (If you use this, don't forget to add pry to your Gemfile!)
11
- # require "pry"
12
- # Pry.start
13
-
14
- require 'irb'
15
- IRB.start(__FILE__)
data/bin/setup DELETED
@@ -1,8 +0,0 @@
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