nanoc-weasyprint.rb 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: 754742e20e7029fec88fcbd708ab45504935f37f283eb78f6a91722be7a79119
4
+ data.tar.gz: d88b791fd6247156b2b607c5ae331307933883ae64ec8f6a4a8db02aade2bab2
5
+ SHA512:
6
+ metadata.gz: d3a95584be1306e396284692bb0dd893774386918fdf342bb884dcad0c7e75063fa5f2d8806983ab5759d4eed0256929dc63c1175b0c357ec0bd9d80b339e84f
7
+ data.tar.gz: 9daefce2312c4e6d8887c81836263d340c6d0f71115696ce6332fb6960e0f0628dcc3c68bac8f1f166475f4d17dcb42d8a161bb23b334c17aa946c8e49c7e5ff
data/LICENSE ADDED
@@ -0,0 +1,15 @@
1
+ Copyright (C) 2023 by 0x1eef <0x1eef@protonmail.com>
2
+
3
+ Permission to use, copy, modify, and/or distribute this
4
+ software for any purpose with or without fee is hereby
5
+ granted.
6
+
7
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS
8
+ ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
9
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO
10
+ EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
11
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
12
+ RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13
+ ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
14
+ ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
15
+ OF THIS SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,66 @@
1
+ ## About
2
+
3
+ nanoc-weasyprint.rb is a
4
+ [nanoc](https://nanoc.app)
5
+ filter that integrates
6
+ [weasyprint](https://github.com/Kozea/WeasyPrint)
7
+ into nanoc.
8
+ The filter can create PDF documents from markdown
9
+ and other markup languages during the
10
+ [nanoc](https://nanoc.app)
11
+ build process.
12
+
13
+ ## Examples
14
+
15
+ __Defaults__
16
+
17
+ The following example uses the
18
+ [default command-line options](https://0x1eef.github.io/x/nanoc-weasyprint.rb/Nanoc/WeasyPrint/Filter#default_options-class_method):
19
+
20
+ ``` ruby
21
+ # Rules
22
+ require "nanoc-weasyprint"
23
+ compile "/example.md" do
24
+ layout("/default.*")
25
+ filter(:kramdown)
26
+ write("/example.html")
27
+ filter(:weasyprint)
28
+ write("/example.pdf")
29
+ end
30
+ ```
31
+
32
+ __Options__
33
+
34
+ The following example forwards command-line options to
35
+ [weasyprint](https://github.com/Kozea/WeasyPrint):
36
+
37
+ ```ruby
38
+ # Rules
39
+ require "nanoc-weasyprint"
40
+ compile "/example.md" do
41
+ layout("/default.*")
42
+ filter(:kramdown)
43
+ write("/example.html")
44
+ filter(:weasyprint, argv: ["--encoding", "UTF-8"])
45
+ write("/example.pdf")
46
+ end
47
+ ```
48
+
49
+ ## <a id='install'>Install</a>
50
+
51
+ **Rubygems.org**
52
+
53
+ nanoc-weasyprint.rb can be installed via rubygems.org.
54
+
55
+ gem install nanoc-weasyprint.rb
56
+
57
+ ## Sources
58
+
59
+ * [GitHub](https://github.com/0x1eef/nanoc-weasyprint.rb#readme)
60
+ * [GitLab](https://gitlab.com/0x1eef/nanoc-weasyprint.rb#about)
61
+
62
+ ## License
63
+
64
+ [BSD Zero Clause](https://choosealicense.com/licenses/0bsd/).
65
+ <br>
66
+ See [LICENSE](./LICENSE).
@@ -0,0 +1,49 @@
1
+ module Nanoc::WeasyPrint
2
+ class Filter < Nanoc::Filter
3
+ require "fileutils"
4
+ require_relative "spawn"
5
+ include Spawn
6
+ include FileUtils
7
+
8
+ identifier :weasyprint
9
+ type text: :binary
10
+
11
+ ##
12
+ # @return [Array<String>]
13
+ # The default command line options forwarded to weasyprint.
14
+ def self.default_argv
15
+ []
16
+ end
17
+
18
+ ##
19
+ # @param [String] content
20
+ # HTML contnet.
21
+ #
22
+ # @param [Hash] options
23
+ # Filter options.
24
+ #
25
+ # @return [void]
26
+ def run(content, options = {})
27
+ spawn "weasyprint",
28
+ [*default_argv, *(options[:argv] || []), temporary_file(content).path, output_filename],
29
+ log: File.join(tmpdir, "weasyprint.log")
30
+ end
31
+
32
+ private
33
+
34
+ def default_argv
35
+ self.class.default_argv
36
+ end
37
+
38
+ def temporary_file(content)
39
+ mkdir_p(tmpdir)
40
+ file = Tempfile.new(File.basename(item.identifier.to_s), tmpdir)
41
+ file.write(content)
42
+ file.tap(&:flush)
43
+ end
44
+
45
+ def tmpdir
46
+ File.join(Dir.getwd, "tmp", "weasyprint")
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,19 @@
1
+ module Nanoc::WeasyPrint
2
+ module Spawn
3
+ Error = Class.new(RuntimeError)
4
+ def spawn(exe, argv, log:)
5
+ Kernel.spawn(
6
+ exe, *argv, { STDOUT => log, STDERR => log }
7
+ )
8
+ Process.wait
9
+ unless $?.success?
10
+ raise Error,
11
+ "#{File.basename(exe)} exited unsuccessfully " \
12
+ "(exit code: #{$?.exitstatus}, " \
13
+ "item: #{item.identifier}, " \
14
+ "log: #{log.gsub(Dir.getwd, '')[1..]})",
15
+ []
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,5 @@
1
+ module Nanoc
2
+ module WeasyPrint
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
@@ -0,0 +1,15 @@
1
+ ##
2
+ # nanoc-weasyprint.rb is a [nanoc](https://nanoc.app)
3
+ # filter that integrates [weasyprint](https://github.com/Kozea/WeasyPrint)
4
+ # into nanoc. The filter can create PDF documents
5
+ # from markdown and other markup languages during the
6
+ # [nanoc](https://nanoc.app) build process.
7
+ module Nanoc::WeasyPrint
8
+ require_relative "weasyprint/filter"
9
+
10
+ ##
11
+ # @return (see Nanoc::WeasyPrint::Filter.default_argv)
12
+ def self.default_argv
13
+ Filter.default_argv
14
+ end
15
+ end
@@ -0,0 +1,2 @@
1
+ require "nanoc"
2
+ require_relative "nanoc/weasyprint"
metadata ADDED
@@ -0,0 +1,148 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: nanoc-weasyprint.rb
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - '0x1eef'
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2024-03-29 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: yard
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.9'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0.9'
27
+ - !ruby/object:Gem::Dependency
28
+ name: redcarpet
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '3.5'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '3.5'
41
+ - !ruby/object:Gem::Dependency
42
+ name: test-unit
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.6'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.6'
55
+ - !ruby/object:Gem::Dependency
56
+ name: standard
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.13'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.13'
69
+ - !ruby/object:Gem::Dependency
70
+ name: nanoc
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '4.12'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '4.12'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rack
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '3.0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '3.0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rackup
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '2.1'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '2.1'
111
+ description: nanoc-weasyprint.rb integrates weasyprint into nanoc.
112
+ email:
113
+ - 0x1eef@protonmail.com
114
+ executables: []
115
+ extensions: []
116
+ extra_rdoc_files: []
117
+ files:
118
+ - LICENSE
119
+ - README.md
120
+ - lib/nanoc-weasyprint.rb
121
+ - lib/nanoc/weasyprint.rb
122
+ - lib/nanoc/weasyprint/filter.rb
123
+ - lib/nanoc/weasyprint/spawn.rb
124
+ - lib/nanoc/weasyprint/version.rb
125
+ homepage: https://github.com/0x1eef/nanoc-weasyprint.rb#readme
126
+ licenses:
127
+ - 0BSD
128
+ metadata: {}
129
+ post_install_message:
130
+ rdoc_options: []
131
+ require_paths:
132
+ - lib
133
+ required_ruby_version: !ruby/object:Gem::Requirement
134
+ requirements:
135
+ - - ">="
136
+ - !ruby/object:Gem::Version
137
+ version: '0'
138
+ required_rubygems_version: !ruby/object:Gem::Requirement
139
+ requirements:
140
+ - - ">="
141
+ - !ruby/object:Gem::Version
142
+ version: '0'
143
+ requirements: []
144
+ rubygems_version: 3.5.3
145
+ signing_key:
146
+ specification_version: 4
147
+ summary: nanoc-weasyprint.rb integrates weasyprint into nanoc.
148
+ test_files: []