prawn-markup 0.1.0

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: 17db8afa6a062ac1cac8322276b7f013e2d9ba7c
4
+ data.tar.gz: 03a009820c6851a0d06ca2812487757e1a142056
5
+ SHA512:
6
+ metadata.gz: b9d20fb86722b5ade3804c648116b84e3d423b39a3ffcdeadd2340b6b5d886e1ba80a98fa0a570bf1b448d2e0f1a88058781ccf5330cb6f9c218e7c8467da770
7
+ data.tar.gz: 8fdce13e68ce84ccbace42d051ffc5d66f3888ad9094af6aa79abc62a0251e386088ccc81e627dc0a3be67ef746c5d6e82575af4455f14121cf50ec3d89a54f6
data/.gitignore ADDED
@@ -0,0 +1,12 @@
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 ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,64 @@
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/LineLength:
19
+ Max: 100
20
+ Severity: error
21
+
22
+ Metrics/MethodLength:
23
+ Max: 10
24
+ Severity: error
25
+
26
+ Metrics/ModuleLength:
27
+ Max: 150
28
+ Severity: error
29
+
30
+ Metrics/ParameterLists:
31
+ Max: 4
32
+ Severity: warning
33
+
34
+ # Keep for now, easier with superclass definitions
35
+ ClassAndModuleChildren:
36
+ Enabled: false
37
+
38
+ # The ones we use must exist for the entire class hierarchy.
39
+ ClassVars:
40
+ Enabled: false
41
+
42
+ # Well, well, well
43
+ Documentation:
44
+ Enabled: false
45
+
46
+ # Keep single line bodys for if and unless
47
+ IfUnlessModifier:
48
+ Enabled: false
49
+
50
+ # We thinks that's fine for specs
51
+ Layout/EmptyLinesAroundBlockBody:
52
+ Enabled: false
53
+
54
+ # We thinks that's fine
55
+ Layout/EmptyLinesAroundClassBody:
56
+ Enabled: false
57
+
58
+ # We thinks that's fine
59
+ Layout/EmptyLinesAroundModuleBody:
60
+ Enabled: false
61
+
62
+ # We think that's the developers choice
63
+ Style/GuardClause:
64
+ Enabled: false
data/.travis.yml ADDED
@@ -0,0 +1,25 @@
1
+ sudo: false
2
+
3
+ language: ruby
4
+
5
+ rvm:
6
+ - 2.5.1
7
+
8
+ env:
9
+ global:
10
+ - CC_TEST_REPORTER_ID=d70fe39ffb8f2f7c5f837f0133d10a3a1c6784d0dd189153111577b60f74c603
11
+
12
+ before_install: gem install bundler
13
+
14
+ before_script:
15
+ - curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
16
+ - chmod +x ./cc-test-reporter
17
+ - ./cc-test-reporter before-build
18
+
19
+ script:
20
+ - bundle exec rake
21
+ - bundle exec rubocop
22
+
23
+ after_script:
24
+ - ./cc-test-reporter format-coverage -t simplecov -o spec/coverage/codeclimate.json spec/coverage/.resultset.json
25
+ - if [[ "$TRAVIS_TEST_RESULT" == 0 ]]; then ./cc-test-reporter upload-coverage -i spec/coverage/codeclimate.json; fi
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at info@puzzle.ch. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in prawn-markup.gemspec
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,89 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ prawn-markup (0.1.0)
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 (10.0.2)
16
+ diff-lcs (1.3)
17
+ docile (1.3.1)
18
+ hashery (2.1.2)
19
+ jaro_winkler (1.5.1)
20
+ json (2.1.0)
21
+ mini_portile2 (2.3.0)
22
+ nokogiri (1.8.4)
23
+ mini_portile2 (~> 2.3.0)
24
+ parallel (1.12.1)
25
+ parser (2.5.1.2)
26
+ ast (~> 2.4.0)
27
+ pdf-core (0.7.0)
28
+ pdf-inspector (1.3.0)
29
+ pdf-reader (>= 1.0, < 3.0.a)
30
+ pdf-reader (2.1.0)
31
+ Ascii85 (~> 1.0.0)
32
+ afm (~> 0.2.1)
33
+ hashery (~> 2.0)
34
+ ruby-rc4
35
+ ttfunk
36
+ powerpack (0.1.2)
37
+ prawn (2.2.2)
38
+ pdf-core (~> 0.7.0)
39
+ ttfunk (~> 1.5)
40
+ prawn-table (0.2.2)
41
+ prawn (>= 1.3.0, < 3.0.0)
42
+ rainbow (3.0.0)
43
+ rake (12.3.1)
44
+ rspec (3.8.0)
45
+ rspec-core (~> 3.8.0)
46
+ rspec-expectations (~> 3.8.0)
47
+ rspec-mocks (~> 3.8.0)
48
+ rspec-core (3.8.0)
49
+ rspec-support (~> 3.8.0)
50
+ rspec-expectations (3.8.1)
51
+ diff-lcs (>= 1.2.0, < 2.0)
52
+ rspec-support (~> 3.8.0)
53
+ rspec-mocks (3.8.0)
54
+ diff-lcs (>= 1.2.0, < 2.0)
55
+ rspec-support (~> 3.8.0)
56
+ rspec-support (3.8.0)
57
+ rubocop (0.58.2)
58
+ jaro_winkler (~> 1.5.1)
59
+ parallel (~> 1.10)
60
+ parser (>= 2.5, != 2.5.1.1)
61
+ powerpack (~> 0.1)
62
+ rainbow (>= 2.2.2, < 4.0)
63
+ ruby-progressbar (~> 1.7)
64
+ unicode-display_width (~> 1.0, >= 1.0.1)
65
+ ruby-progressbar (1.10.0)
66
+ ruby-rc4 (0.1.5)
67
+ simplecov (0.16.1)
68
+ docile (~> 1.1)
69
+ json (>= 1.8, < 3)
70
+ simplecov-html (~> 0.10.0)
71
+ simplecov-html (0.10.2)
72
+ ttfunk (1.5.1)
73
+ unicode-display_width (1.4.0)
74
+
75
+ PLATFORMS
76
+ ruby
77
+
78
+ DEPENDENCIES
79
+ bundler
80
+ byebug
81
+ pdf-inspector
82
+ prawn-markup!
83
+ rake
84
+ rspec
85
+ rubocop
86
+ simplecov
87
+
88
+ BUNDLED WITH
89
+ 1.16.2
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 Puzzle ITC GmbH
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,106 @@
1
+ # Prawn::Markup
2
+
3
+ [![Build Status](https://travis-ci.org/puzzle/prawn-markup.svg?branch=master)](https://travis-ci.org/puzzle/prawn-markup)
4
+ [![Maintainability](https://api.codeclimate.com/v1/badges/52a462f9d65e33352d4e/maintainability)](https://codeclimate.com/github/puzzle/prawn-markup/maintainability)
5
+ [![Test Coverage](https://api.codeclimate.com/v1/badges/52a462f9d65e33352d4e/test_coverage)](https://codeclimate.com/github/puzzle/prawn-markup/test_coverage)
6
+
7
+ Adds simple HTML snippets into [Prawn](http://prawnpdf.org)-generated PDFs. All elements are layouted vertically using Prawn's formatting options. A major use case for this gem is to include WYSIWYG-generated HTML parts into server-generated PDF documents.
8
+
9
+ This gem does not and will never convert entire HTML + CSS pages to PDF. Use [wkhtmltopdf](https://wkhtmltopdf.org/) for that. Have a look at the details of the [Supported HTML](#supported-html).
10
+
11
+ ## Installation
12
+
13
+ Add this line to your application's Gemfile:
14
+
15
+ ```ruby
16
+ gem 'prawn-markup'
17
+ ```
18
+
19
+ And then execute:
20
+
21
+ $ bundle
22
+
23
+ Or install it yourself as:
24
+
25
+ $ gem install prawn-markup
26
+
27
+ ## Usage
28
+
29
+ In your prawn Document, add HTML like this:
30
+
31
+ ```ruby
32
+ doc = Prawn::Document.new
33
+ doc.markup('<p>Hello World</p><hr/><p>KTHXBYE</p>')
34
+ ```
35
+
36
+ To customize element formatting, do:
37
+
38
+ ```ruby
39
+ doc = Prawn::Document.new
40
+ # set options for the entire document
41
+ doc.markup_options = {
42
+ text: { font: 'Times' },
43
+ table: { header: { style: :bold, background_color: 'FFFFDD' } }
44
+ }
45
+ # set additional options for each single call
46
+ doc.markup('<p>Hello World</p><hr/><p>KTHXBYE</p>', text: { align: :center })
47
+ ```
48
+
49
+ Options may be set for `text`, `table` (`cell` and `header`) and `list` (`content` and `bullet`).
50
+
51
+ Text options include all keys from Prawns [#text](http://prawnpdf.org/api-docs/2.0/Prawn/Text.html#text-instance_method) method: `font`, `size`, `color`, `style`, `align`, `valign`, `leading`,`direction`, `character_spacing`, `indent_paragraphs`, `kerning`, `mode`.
52
+
53
+ Tables and lists are rendered with [prawn-table](https://github.com/prawnpdf/prawn-table) and have the following additional options: `padding`, `borders`, `border_width`, `border_color`, `background_color`, `border_lines`, `rotate`, `overflow`, `min_font_size`. Options from `text` may be overridden.
54
+
55
+ Beside these options handled by Prawn / prawn-table, the following values may be customized:
56
+
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 content: `p`, `div`, `ol`, `ul`, `li`, `hr`
78
+ * Text semantics: `b`, `strong`, `i`, `em`, `u`, `a`, `br`
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 are may be contained in the `src` attribute as base64 encoded data URIs. Prawn only supports `PNG` and `JPG`.
86
+
87
+
88
+ ## Development
89
+
90
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
91
+
92
+ 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).
93
+
94
+ ## Contributing
95
+
96
+ Bug reports and pull requests are welcome on GitHub at https://github.com/puzzle/prawn-markup. For pull requests, add specs, make sure all of them pass and fix all rubocop issues.
97
+
98
+ This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
99
+
100
+ ## License
101
+
102
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
103
+
104
+ ## Code of Conduct
105
+
106
+ Everyone interacting in the Prawn::Markup project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/puzzle/prawn-markup/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task default: :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'prawn/markup'
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
@@ -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