htmlbook 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- checksums.yaml.gz.sig +5 -0
- data.tar.gz.sig +0 -0
- data/lib/htmlbook.rb +147 -0
- metadata +90 -0
- metadata.gz.sig +0 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 10f3f8845485c92b7a57f88b8590e52d24d7725cb9ec455666f96151c175b5dc
|
4
|
+
data.tar.gz: 0c306002be7f38ec4c10dad2c3e1471ecea5df015ff89d2a5c9356f004595fc8
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 1ba7edfed7e6258889739411a15e3641913ae7af599eaaba186f01e1f787db115060d7ef3fe5adaf4449d5f46fa6e00134cfca5cc0b58241e0d4311a4bad393d
|
7
|
+
data.tar.gz: a91da212f1c25dfd0b2815ca5fdb60ecf8e00ab79ce05e15edb759802054e258d25210fe66d62427943bb797d7e399278e0c21dc5a22bba95e53a87fe59de21c
|
checksums.yaml.gz.sig
ADDED
@@ -0,0 +1,5 @@
|
|
1
|
+
��s�AB茇��Hr|��
|
2
|
+
c���cb;��t� y��F6��7�
|
3
|
+
0���r`P�A"� �*Xua�Tc��s���cPC%������[��;���o��4>h�̍�Aܕo�
|
4
|
+
��!�䫖���W�ѵT+9�RO�ma��z�CҊJ���'��4wH���u����t�qT��
|
5
|
+
��j��>�r�Kt��]HU@�V�7�(��i�'��Em8��!����}{�����>�?�X״�>83V�T�yVmT��C����R�9��u,��Z��r2w�,\T���\e�x��yu��o���~��}�_���>�ڗ_f���G����!$��̆%��T~
|
data.tar.gz.sig
ADDED
Binary file
|
data/lib/htmlbook.rb
ADDED
@@ -0,0 +1,147 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
# file: htmlbook.rb
|
4
|
+
|
5
|
+
|
6
|
+
require 'rexle-builder'
|
7
|
+
require 'qnd_html2page'
|
8
|
+
|
9
|
+
|
10
|
+
|
11
|
+
class HtmlBook
|
12
|
+
|
13
|
+
attr_reader :to_html
|
14
|
+
attr_accessor :pages
|
15
|
+
|
16
|
+
|
17
|
+
def initialize(filename='page.html', pg_height: 740, width: '700px',
|
18
|
+
debug: false)
|
19
|
+
|
20
|
+
@filename, @pg_height, @width, @debug = filename, pg_height, width, debug
|
21
|
+
@doc = build()
|
22
|
+
@to_html = @doc.root.xml pretty: true
|
23
|
+
|
24
|
+
end
|
25
|
+
|
26
|
+
def build()
|
27
|
+
|
28
|
+
doc = Rexle.new(RXFHelper.read(@filename).first)
|
29
|
+
|
30
|
+
style = Rexle::Element.new('style').add_text css
|
31
|
+
style.attributes[:id] = 'tmpcss'
|
32
|
+
doc.root.element('head').add style
|
33
|
+
puts 'doc: ' + doc.xml.inspect if @debug
|
34
|
+
|
35
|
+
pages = QndHtml2Page.new(doc, pg_height: @pg_height, debug: @debug).to_pages
|
36
|
+
doc.at_css('#tmpcss').delete
|
37
|
+
build_html doc, collate(pages)
|
38
|
+
|
39
|
+
end
|
40
|
+
|
41
|
+
def save(filename=@filename.sub(/\.\w+$/,'2\0'))
|
42
|
+
|
43
|
+
css_filename = filename.sub(/\.html$/, '.css')
|
44
|
+
@doc.root.element('head/link').attributes[:href] = css_filename
|
45
|
+
File.write css_filename, css()
|
46
|
+
File.write filename, @doc.xml(pretty: true)
|
47
|
+
|
48
|
+
end
|
49
|
+
|
50
|
+
protected
|
51
|
+
|
52
|
+
def collate(pages)
|
53
|
+
pages.map.with_index {|pg, pg_no| [pg, pg_no+1]}
|
54
|
+
end
|
55
|
+
|
56
|
+
|
57
|
+
def build_html(doc, pages)
|
58
|
+
|
59
|
+
xml = RexleBuilder.new
|
60
|
+
|
61
|
+
a = xml.body do
|
62
|
+
|
63
|
+
pages.each do |page, pg_no|
|
64
|
+
|
65
|
+
puts 'page: ' + page.inspect if @debug
|
66
|
+
|
67
|
+
xml.div({class: 'page '}) do
|
68
|
+
xml.article page.children.join
|
69
|
+
xml.footer do
|
70
|
+
xml.p({class: 'n'+ (pg_no.odd? ? 'odd' : 'even')},
|
71
|
+
'pg ' + pg_no.to_s)
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
end
|
76
|
+
|
77
|
+
end
|
78
|
+
|
79
|
+
body = Rexle.new(a).root
|
80
|
+
puts 'after body' if @debug
|
81
|
+
doc.root.element('body').delete
|
82
|
+
doc.root.add body
|
83
|
+
|
84
|
+
attr = Attributes.new( { rel: "stylesheet", type: "text/css", \
|
85
|
+
href: @filename.sub(/\.html$/, '.css'), media: \
|
86
|
+
"screen, projection, tv, print" })
|
87
|
+
link = Rexle::Element.new('link', attributes: attr)
|
88
|
+
|
89
|
+
doc.root.element('head').add link
|
90
|
+
puts 'returning the doc' if @debug
|
91
|
+
return doc
|
92
|
+
|
93
|
+
end
|
94
|
+
|
95
|
+
def css()
|
96
|
+
<<CSS
|
97
|
+
html,
|
98
|
+
body {
|
99
|
+
height: 100%;
|
100
|
+
margin: 0;
|
101
|
+
padding: 0;
|
102
|
+
max-width: 700px;
|
103
|
+
}
|
104
|
+
|
105
|
+
span {font-size: 0.01em; margin: 0; padding: 0;}
|
106
|
+
|
107
|
+
.page {
|
108
|
+
display: flex;
|
109
|
+
flex-direction: column;
|
110
|
+
min-height: 100%;
|
111
|
+
}
|
112
|
+
|
113
|
+
article {
|
114
|
+
flex: 1;
|
115
|
+
}
|
116
|
+
|
117
|
+
@media print {
|
118
|
+
.page {page-break-after: always;}
|
119
|
+
}
|
120
|
+
|
121
|
+
.page {
|
122
|
+
|
123
|
+
margin: 0; padding: 0;
|
124
|
+
border: 1px solid black;
|
125
|
+
/* height: 98vh; */
|
126
|
+
|
127
|
+
display: -webkit-box;
|
128
|
+
display: -ms-flexbox;
|
129
|
+
display: flex;
|
130
|
+
-webkit-box-orient: vertical;
|
131
|
+
-webkit-box-direction: normal;
|
132
|
+
-ms-flex-direction: column;
|
133
|
+
flex-direction: column;
|
134
|
+
min-height: 88%;
|
135
|
+
}
|
136
|
+
article {
|
137
|
+
-webkit-box-flex: 1;
|
138
|
+
-ms-flex: 1;
|
139
|
+
flex: 1;
|
140
|
+
}
|
141
|
+
|
142
|
+
|
143
|
+
footer p.nodd {text-align: right;}
|
144
|
+
CSS
|
145
|
+
end
|
146
|
+
|
147
|
+
end
|
metadata
ADDED
@@ -0,0 +1,90 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: htmlbook
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- James Robertson
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain:
|
11
|
+
- |
|
12
|
+
-----BEGIN CERTIFICATE-----
|
13
|
+
MIIEXjCCAsagAwIBAgIBATANBgkqhkiG9w0BAQsFADAsMSowKAYDVQQDDCFnZW1t
|
14
|
+
YXN0ZXIvREM9amFtZXNyb2JlcnRzb24vREM9ZXUwHhcNMTkxMTE2MTUyMjAyWhcN
|
15
|
+
MjAxMTE1MTUyMjAyWjAsMSowKAYDVQQDDCFnZW1tYXN0ZXIvREM9amFtZXNyb2Jl
|
16
|
+
cnRzb24vREM9ZXUwggGiMA0GCSqGSIb3DQEBAQUAA4IBjwAwggGKAoIBgQDi9Sru
|
17
|
+
HD3vHQ+YTPitbpUhw/tAZMnq1G1lVUuLajG/ik/15c5kTSBVAxuWU4dHQzyNXX0U
|
18
|
+
2DLZz91jwOxNJ0MIIlJH+Xq+OU2RSYOBeAntLYvjEBtoI+zmfu2U/hfaF/RKc7tl
|
19
|
+
4huuaYuQv/IqHCGkfI5F9j6mrCKQ1GSqx38dUHsBn/DDdQuTZRRrj2Yw5ZL+jsEX
|
20
|
+
tqPAYuaTi4EyXTrn+IluwX0xDFKWv6dGZMWJN8ffQrc91SiTNlxtPYF/l7/NgL3b
|
21
|
+
igHrpgFVz+absPuoyBQkXCvsTB3PqT77bqF4eyxAnv7lvR9JrVZM6w9Oi9wiRj00
|
22
|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+
-----END CERTIFICATE-----
|
38
|
+
date: 2019-11-16 00:00:00.000000000 Z
|
39
|
+
dependencies:
|
40
|
+
- !ruby/object:Gem::Dependency
|
41
|
+
name: qnd_html2page
|
42
|
+
requirement: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - ">="
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: 0.2.0
|
47
|
+
- - "~>"
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: '0.2'
|
50
|
+
type: :runtime
|
51
|
+
prerelease: false
|
52
|
+
version_requirements: !ruby/object:Gem::Requirement
|
53
|
+
requirements:
|
54
|
+
- - ">="
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: 0.2.0
|
57
|
+
- - "~>"
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
version: '0.2'
|
60
|
+
description:
|
61
|
+
email: james@jamesrobertson.eu
|
62
|
+
executables: []
|
63
|
+
extensions: []
|
64
|
+
extra_rdoc_files: []
|
65
|
+
files:
|
66
|
+
- lib/htmlbook.rb
|
67
|
+
homepage: https://github.com/jrobertson/htmlbook
|
68
|
+
licenses:
|
69
|
+
- MIT
|
70
|
+
metadata: {}
|
71
|
+
post_install_message:
|
72
|
+
rdoc_options: []
|
73
|
+
require_paths:
|
74
|
+
- lib
|
75
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
76
|
+
requirements:
|
77
|
+
- - ">="
|
78
|
+
- !ruby/object:Gem::Version
|
79
|
+
version: '0'
|
80
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
81
|
+
requirements:
|
82
|
+
- - ">="
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
version: '0'
|
85
|
+
requirements: []
|
86
|
+
rubygems_version: 3.0.3
|
87
|
+
signing_key:
|
88
|
+
specification_version: 4
|
89
|
+
summary: Splits HTML content into pages suitable for printing.
|
90
|
+
test_files: []
|
metadata.gz.sig
ADDED
Binary file
|