prawndown 0.1.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
+ SHA256:
3
+ metadata.gz: 15f1c566a5138e7e6e6116a153a5322a37b82fdb95b3e6b729bf7b0e8911a782
4
+ data.tar.gz: 4fa94d709d3c05059c07690f76f1211519723c838b066336f78cd8162da5743e
5
+ SHA512:
6
+ metadata.gz: a49b17d69baa959894f0457e91659007f868a61ad1dc54d9b8ffd1938b07adbf9263263f0ae4fd387236bc7014048ad161cd3031d8caceb3d593d582725a6c75
7
+ data.tar.gz: ba7ff76b1d419a9e69a86a563a432c82a5b3259079e0596ddfb2a001f23ac5739ee69050c057eeea398d64145b347bce5c1eb4fede190dc0d96647a30b166bb7
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+ coverage
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.5.0
5
+ before_install: gem install bundler -v 1.16.1
data/CHANGELOG.md ADDED
@@ -0,0 +1,23 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ For more information about changelogs, check
6
+ [Keep a Changelog](http://keepachangelog.com) and
7
+ [Vandamme](http://tech-angels.github.io/vandamme).
8
+
9
+ ## 0.1.1 - 2018.03.29
10
+
11
+ * [ENHANCEMENT] Add generatable examples
12
+
13
+ ## 0.1.0 - 2018.03.29
14
+
15
+ * [FEATURE] Add `#markdown` extension to `Prawn::Document`
16
+
17
+ ## 0.0.2 - 2018.03.16
18
+
19
+ * [FEATURE] Add support for additional header sizes (header 4-6)
20
+
21
+ ## 0.0.1 - 2018.03.16
22
+
23
+ * [FEATURE] Add basic support for parsing Markdown
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in prawndown.gemspec
6
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,49 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ prawndown (0.1.1)
5
+ prawn (~> 2.0)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ Ascii85 (1.0.3)
11
+ afm (0.2.2)
12
+ docile (1.3.0)
13
+ hashery (2.1.2)
14
+ json (2.1.0)
15
+ minitest (5.11.3)
16
+ pdf-core (0.7.0)
17
+ pdf-inspector (1.3.0)
18
+ pdf-reader (>= 1.0, < 3.0.a)
19
+ pdf-reader (2.1.0)
20
+ Ascii85 (~> 1.0.0)
21
+ afm (~> 0.2.1)
22
+ hashery (~> 2.0)
23
+ ruby-rc4
24
+ ttfunk
25
+ prawn (2.2.2)
26
+ pdf-core (~> 0.7.0)
27
+ ttfunk (~> 1.5)
28
+ rake (10.5.0)
29
+ ruby-rc4 (0.1.5)
30
+ simplecov (0.16.1)
31
+ docile (~> 1.1)
32
+ json (>= 1.8, < 3)
33
+ simplecov-html (~> 0.10.0)
34
+ simplecov-html (0.10.2)
35
+ ttfunk (1.5.1)
36
+
37
+ PLATFORMS
38
+ ruby
39
+
40
+ DEPENDENCIES
41
+ bundler (~> 1.16)
42
+ minitest (~> 5.0)
43
+ pdf-inspector (~> 1.3)
44
+ prawndown!
45
+ rake (~> 10.0)
46
+ simplecov (~> 0.16.1)
47
+
48
+ BUNDLED WITH
49
+ 1.16.1
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 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.
data/README.md ADDED
@@ -0,0 +1,55 @@
1
+ # Prawndown
2
+
3
+ A tiny Ruby gem to render a subset of Markdown in PDF files
4
+
5
+ Prawn is a Ruby library to generate PDF files. It supports text formatting trough its own HTML-esque language, which has tags for different formatting options like **bold**, _italic_ and [links](https://github.com/kaspermeyer/prawndown). Read more about the supported tags in the [Prawn documentation](http://prawnpdf.org/api-docs/2.0/Prawn/Text.html#text-instance_method).
6
+
7
+ ## Usage
8
+
9
+ Prawndown extends Prawn with the `markdown` method. Use it to render Markdown in the document:
10
+
11
+ ```ruby
12
+ Prawn::Document.generate('markdown.pdf') do
13
+ markdown '# Welcome to Prawndown!'
14
+ markdown '**Important:** We _hope_ you enjoy your stay!'
15
+ end
16
+ ```
17
+
18
+ It accepts the same options as [`Prawn::Document#text`](http://prawnpdf.org/api-docs/2.0/Prawn/Text.html#text-instance_method)
19
+
20
+ If you prefer, you can also use the parser directly:
21
+
22
+ ```ruby
23
+ Prawndown::Parser.new('_Welcome_ to **Prawndown**').to_prawn #=> '<i>Welcome</i> to <b>Prawndown</b>'
24
+ ```
25
+
26
+ More thorough examples can be found under the `examples` folder. Run `rake examples` to generate the examples PDF.
27
+
28
+ *Note: Prawdown can't output the tags `<sub>`, `<sup>`, `<font>` and `<color>` as they lack native support in Markdown.*
29
+
30
+ ## Installation
31
+
32
+ Add this line to your application's Gemfile:
33
+
34
+ ```ruby
35
+ gem 'prawndown'
36
+ ```
37
+
38
+ And then execute:
39
+
40
+ $ bundle
41
+
42
+ Or install it yourself as:
43
+
44
+ $ gem install prawndown
45
+
46
+ ## Development
47
+
48
+ 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.
49
+
50
+ To install this gem onto your local machine, run `bundle exec rake install`.
51
+
52
+ ## Credits
53
+
54
+ + [Henrik Ny](https://github.com/henrik) for the [idea and name](https://gist.github.com/henrik/2775319) of the project.
55
+ + [Johnny Broadway](https://github.com/jbroadway) for creating [Slimdown](https://gist.github.com/jbroadway/2836900) and coming up with great regular expressions to match Markdown tags with.
data/Rakefile ADDED
@@ -0,0 +1,17 @@
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
11
+
12
+ desc 'Generate the examples'
13
+ task :examples do
14
+ puts 'Building markdown.pdf'
15
+ require_relative 'examples/markdown'
16
+ puts 'Done'
17
+ end
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "prawndown"
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
@@ -0,0 +1,26 @@
1
+ require 'prawndown'
2
+
3
+ def sample_text
4
+ <<-HEREDOC
5
+ # Header 1
6
+ ## Header 2
7
+ ### Header 3
8
+ #### Header 4
9
+ ##### Header 5
10
+ ###### Header 6
11
+
12
+ It is __really__ **really** important that you _use_ this gem for something ~~useful~~ fun!
13
+ Visit the [Prawndown documentation](https://github.com/kaspermeyer/prawndown) *now*!
14
+
15
+ Remember that it also supports paragraphs.
16
+
17
+
18
+
19
+
20
+ It respects the number of new lines.
21
+ HEREDOC
22
+ end
23
+
24
+ Prawn::Document.generate('markdown.pdf') do
25
+ markdown sample_text
26
+ end
@@ -0,0 +1,32 @@
1
+ module Prawndown
2
+ # Markdown to Prawn parser
3
+ class Parser
4
+ MATCHERS = {
5
+ /^# (.+)/ => '<font size="26"><b>\1</b></font>', # Header 1
6
+ /^## (.+)/ => '<font size="24"><b>\1</b></font>', # Header 2
7
+ /^### (.+)/ => '<font size="22"><b>\1</b></font>', # Header 3
8
+ /^#### (.+)/ => '<font size="20"><b>\1</b></font>', # Header 4
9
+ /^##### (.+)/ => '<font size="18"><b>\1</b></font>', # Header 5
10
+ /^###### (.+)/ => '<font size="16"><b>\1</b></font>', # Header 6
11
+ /\[([^\[]+)\]\(([^\)]+)\)/ => '<link href="\2">\1</link>', # Link
12
+ /(\*\*|__)(.*?)\1/ => '<b>\2</b>', # Bold
13
+ /(\*|_)(.*?)\1/ => '<i>\2</i>', # Italic
14
+ /\~\~(.*?)\~\~/ => '<strikethrough>\1</strikethrough>' # Strikethrough
15
+ }
16
+
17
+ # Initialize a new +Prawndown::Parser+.
18
+ # +text+ must a a valid Markdown string that only contains supported tags.
19
+ #
20
+ # Supported tags are: Header 1-6, bold, italic, strikethrough and link.
21
+ def initialize(text)
22
+ @text = text.to_s
23
+ end
24
+
25
+ # Parses the Markdown text and outputs a Prawn compatible string
26
+ def to_prawn
27
+ MATCHERS.inject(@text) do |final_string, (markdown_matcher, prawn_tag)|
28
+ final_string.gsub(markdown_matcher, prawn_tag)
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,3 @@
1
+ module Prawndown
2
+ VERSION = "0.1.1"
3
+ end
data/lib/prawndown.rb ADDED
@@ -0,0 +1,22 @@
1
+ require 'prawn'
2
+ require "prawndown/version"
3
+ require "prawndown/parser"
4
+
5
+ module Prawndown
6
+ module Interface
7
+ # Renders Markdown in the current document
8
+ #
9
+ # It supports header 1-6, bold text, italic text, strikethrough and links
10
+ # It supports the same options as +Prawn::Document#text+
11
+ #
12
+ # Prawn::Document.generate('markdown.pdf') do
13
+ # markdown '# Welcome to Prawndown!'
14
+ # markdown '**Important:** We _hope_ you enjoy your stay!'
15
+ # end
16
+ def markdown(string, options = {})
17
+ text Prawndown::Parser.new(string).to_prawn, options.merge(inline_format: true)
18
+ end
19
+ end
20
+ end
21
+
22
+ Prawn::Document.extensions << Prawndown::Interface
data/prawndown.gemspec ADDED
@@ -0,0 +1,29 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "prawndown/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "prawndown"
8
+ spec.version = Prawndown::VERSION
9
+ spec.authors = ["Kasper Meyer"]
10
+ spec.email = ["hi@kaspermeyer.com"]
11
+
12
+ spec.summary = %q{A tiny Ruby gem to render a subset of Markdown in PDF files}
13
+ spec.homepage = "https://github.com/kaspermeyer/prawndown"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
17
+ f.match(%r{^(test|spec|features)/})
18
+ end
19
+ spec.bindir = "exe"
20
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
21
+ spec.require_paths = ["lib"]
22
+
23
+ spec.add_dependency "prawn", "~> 2.0"
24
+ spec.add_development_dependency "pdf-inspector", "~> 1.3"
25
+ spec.add_development_dependency "simplecov", "~> 0.16.1"
26
+ spec.add_development_dependency "bundler", "~> 1.16"
27
+ spec.add_development_dependency "rake", "~> 10.0"
28
+ spec.add_development_dependency "minitest", "~> 5.0"
29
+ end
metadata ADDED
@@ -0,0 +1,143 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: prawndown
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Kasper Meyer
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2018-03-29 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.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: pdf-inspector
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.3'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.3'
41
+ - !ruby/object:Gem::Dependency
42
+ name: simplecov
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 0.16.1
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 0.16.1
55
+ - !ruby/object:Gem::Dependency
56
+ name: bundler
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.16'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.16'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '10.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '10.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: minitest
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '5.0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '5.0'
97
+ description:
98
+ email:
99
+ - hi@kaspermeyer.com
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - ".gitignore"
105
+ - ".travis.yml"
106
+ - CHANGELOG.md
107
+ - Gemfile
108
+ - Gemfile.lock
109
+ - LICENSE.txt
110
+ - README.md
111
+ - Rakefile
112
+ - bin/console
113
+ - bin/setup
114
+ - examples/markdown.rb
115
+ - lib/prawndown.rb
116
+ - lib/prawndown/parser.rb
117
+ - lib/prawndown/version.rb
118
+ - prawndown.gemspec
119
+ homepage: https://github.com/kaspermeyer/prawndown
120
+ licenses:
121
+ - MIT
122
+ metadata: {}
123
+ post_install_message:
124
+ rdoc_options: []
125
+ require_paths:
126
+ - lib
127
+ required_ruby_version: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ required_rubygems_version: !ruby/object:Gem::Requirement
133
+ requirements:
134
+ - - ">="
135
+ - !ruby/object:Gem::Version
136
+ version: '0'
137
+ requirements: []
138
+ rubyforge_project:
139
+ rubygems_version: 2.7.3
140
+ signing_key:
141
+ specification_version: 4
142
+ summary: A tiny Ruby gem to render a subset of Markdown in PDF files
143
+ test_files: []