isodoc 1.6.0 → 1.6.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/rspec +1 -2
- data/lib/isodoc/convert.rb +2 -2
- data/lib/isodoc/css.rb +30 -26
- data/lib/isodoc/function/blocks.rb +11 -4
- data/lib/isodoc/function/blocks_example_note.rb +2 -2
- data/lib/isodoc/function/cleanup.rb +1 -2
- data/lib/isodoc/function/utils.rb +41 -39
- data/lib/isodoc/gem_tasks.rb +30 -31
- data/lib/isodoc/html_convert.rb +4 -4
- data/lib/isodoc/html_function/postprocess.rb +27 -71
- data/lib/isodoc/html_function/postprocess_footnotes.rb +59 -0
- data/lib/isodoc/i18n.rb +20 -20
- data/lib/isodoc/presentation_function/block.rb +17 -8
- data/lib/isodoc/presentation_function/inline.rb +2 -0
- data/lib/isodoc/version.rb +1 -1
- data/lib/isodoc/word_function/footnotes.rb +22 -15
- data/lib/isodoc/xref.rb +9 -10
- data/lib/isodoc/xref/xref_counter.rb +31 -15
- data/lib/isodoc/xref/xref_gen.rb +12 -7
- data/lib/isodoc/xref/xref_sect_gen.rb +22 -20
- data/spec/isodoc/blocks_spec.rb +2585 -2576
- data/spec/isodoc/cleanup_spec.rb +1107 -1109
- data/spec/isodoc/i18n_spec.rb +984 -972
- data/spec/isodoc/lists_spec.rb +316 -315
- data/spec/isodoc/postproc_spec.rb +1636 -1530
- data/spec/isodoc/ref_spec.rb +718 -723
- data/spec/isodoc/xref_spec.rb +52 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 75ecf3fa764d00da20d4334b09534a204da5937eaef686dc341789b90d12a5a7
|
4
|
+
data.tar.gz: 8e4ed1c6fa123a51507ea403be8ea462d272ca19c0107d0c30cf87a6c842f68a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dbca0780e09eca6364b99cb71b66799d9440a25df70c13c4e54bed3c884e19437f4d84e916816bb34234323ccf98c0589586bffb024b428ff0fef37334c8068c
|
7
|
+
data.tar.gz: 8bc973b97d542a380822f66900ef1208fec7308ebb396e7a6588022578ee7e6af59cf91bb6ff7634ca675d4e8a2fcbd2379c061eb2498f29398d1166bf71d1a5
|
data/bin/rspec
CHANGED
data/lib/isodoc/convert.rb
CHANGED
@@ -163,9 +163,9 @@ module IsoDoc
|
|
163
163
|
FileUtils.rm_rf dir
|
164
164
|
end
|
165
165
|
|
166
|
-
def middle_clause(
|
166
|
+
def middle_clause(_docxml = nil)
|
167
167
|
"//clause[parent::sections][not(@type = 'scope')]"\
|
168
|
-
|
168
|
+
"[not(descendant::terms)]"
|
169
169
|
end
|
170
170
|
|
171
171
|
def target_pdf(node)
|
data/lib/isodoc/css.rb
CHANGED
@@ -6,17 +6,20 @@ module IsoDoc
|
|
6
6
|
def precompiled_style_or_original(stylesheet_path)
|
7
7
|
# Already have compiled stylesheet, use it
|
8
8
|
return stylesheet_path if stylesheet_path.nil? ||
|
9
|
-
File.extname(stylesheet_path) ==
|
10
|
-
|
9
|
+
File.extname(stylesheet_path) == ".css"
|
10
|
+
|
11
|
+
basename = File.basename(stylesheet_path, ".*")
|
11
12
|
compiled_path = File.join(File.dirname(stylesheet_path),
|
12
13
|
"#{basename}.css")
|
13
14
|
return stylesheet_path unless File.file?(compiled_path)
|
15
|
+
|
14
16
|
compiled_path
|
15
17
|
end
|
16
18
|
|
17
19
|
def localpath(path)
|
18
|
-
return path if %r{^[A-Z]:|^/|^file:/}.match(path)
|
20
|
+
return path if %r{^[A-Z]:|^/|^file:/}.match?(path)
|
19
21
|
return path unless (@sourcedir || @localdir) && path
|
22
|
+
|
20
23
|
File.expand_path(File.join((@sourcedir || @localdir), path))
|
21
24
|
end
|
22
25
|
|
@@ -34,9 +37,9 @@ module IsoDoc
|
|
34
37
|
|
35
38
|
def default_fonts(_options)
|
36
39
|
{
|
37
|
-
bodyfont:
|
38
|
-
headerfont:
|
39
|
-
monospacefont:
|
40
|
+
bodyfont: "Arial",
|
41
|
+
headerfont: "Arial",
|
42
|
+
monospacefont: "Courier",
|
40
43
|
}
|
41
44
|
end
|
42
45
|
|
@@ -48,35 +51,35 @@ module IsoDoc
|
|
48
51
|
|
49
52
|
def fonts_options
|
50
53
|
{
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
+
"bodyfont" => options[:bodyfont] || "Arial",
|
55
|
+
"headerfont" => options[:headerfont] || "Arial",
|
56
|
+
"monospacefont" => options[:monospacefont] || "Courier",
|
54
57
|
"normalfontsize" => options[:normalfontsize],
|
55
58
|
"monospacefontsize" => options[:monospacefontsize],
|
56
59
|
"smallerfontsize" => options[:smallerfontsize],
|
57
|
-
"footnotefontsize" => options[:footnotefontsize]
|
60
|
+
"footnotefontsize" => options[:footnotefontsize],
|
58
61
|
}
|
59
62
|
end
|
60
63
|
|
61
64
|
def scss_fontheader(is_html_css)
|
62
|
-
b = options[:bodyfont] ||
|
63
|
-
h = options[:headerfont] ||
|
64
|
-
m = options[:monospacefont] ||
|
65
|
-
ns = options[:normalfontsize] || (is_html_css ? "1.0em" :
|
66
|
-
ms = options[:monospacefontsize] || (is_html_css ? "0.8em" :
|
67
|
-
ss = options[:smallerfontsize] || (is_html_css ? "0.9em" :
|
68
|
-
fs = options[:footnotefontsize] || (is_html_css ? "0.9em" :
|
65
|
+
b = options[:bodyfont] || "Arial"
|
66
|
+
h = options[:headerfont] || "Arial"
|
67
|
+
m = options[:monospacefont] || "Courier"
|
68
|
+
ns = options[:normalfontsize] || (is_html_css ? "1.0em" : "12.0pt")
|
69
|
+
ms = options[:monospacefontsize] || (is_html_css ? "0.8em" : "11.0pt")
|
70
|
+
ss = options[:smallerfontsize] || (is_html_css ? "0.9em" : "10.0pt")
|
71
|
+
fs = options[:footnotefontsize] || (is_html_css ? "0.9em" : "9.0pt")
|
69
72
|
"$bodyfont: #{b};\n$headerfont: #{h};\n$monospacefont: #{m};\n"\
|
70
73
|
"$normalfontsize: #{ns};\n$monospacefontsize: #{ms};\n"\
|
71
74
|
"$smallerfontsize: #{ss};\n$footnotefontsize: #{fs};\n"
|
72
75
|
end
|
73
76
|
|
74
77
|
def convert_scss(filename, stylesheet, stripwordcss)
|
75
|
-
require
|
76
|
-
require
|
78
|
+
require "sassc"
|
79
|
+
require "isodoc/sassc_importer"
|
77
80
|
|
78
|
-
[File.join(Gem.loaded_specs[
|
79
|
-
|
81
|
+
[File.join(Gem.loaded_specs["isodoc"].full_gem_path,
|
82
|
+
"lib", "isodoc"),
|
80
83
|
File.dirname(filename)].each do |name|
|
81
84
|
SassC.load_paths << name
|
82
85
|
end
|
@@ -88,15 +91,16 @@ module IsoDoc
|
|
88
91
|
# stripwordcss if HTML stylesheet, !stripwordcss if DOC stylesheet
|
89
92
|
def generate_css(filename, stripwordcss)
|
90
93
|
return nil if filename.nil?
|
94
|
+
|
91
95
|
filename = precompiled_style_or_original(filename)
|
92
|
-
stylesheet = File.read(filename, encoding:
|
96
|
+
stylesheet = File.read(filename, encoding: "UTF-8")
|
93
97
|
stylesheet = populate_template(stylesheet, :word)
|
94
|
-
stylesheet.gsub!(/(\s|\{)mso-[^:]+:[^;]+;/m,
|
95
|
-
if File.extname(filename) ==
|
98
|
+
stylesheet.gsub!(/(\s|\{)mso-[^:]+:[^;]+;/m, "\\1") if stripwordcss
|
99
|
+
if File.extname(filename) == ".scss"
|
96
100
|
stylesheet = convert_scss(filename, stylesheet, stripwordcss)
|
97
101
|
end
|
98
|
-
Tempfile.open([File.basename(filename,
|
99
|
-
encoding:
|
102
|
+
Tempfile.open([File.basename(filename, ".*"), "css"],
|
103
|
+
encoding: "utf-8") do |f|
|
100
104
|
f.write(stylesheet)
|
101
105
|
f
|
102
106
|
end
|
@@ -24,6 +24,7 @@ module IsoDoc::Function
|
|
24
24
|
def figure_parse(node, out)
|
25
25
|
return pseudocode_parse(node, out) if node["class"] == "pseudocode" ||
|
26
26
|
node["type"] == "pseudocode"
|
27
|
+
|
27
28
|
@in_figure = true
|
28
29
|
out.div **figure_attrs(node) do |div|
|
29
30
|
node.children.each do |n|
|
@@ -51,6 +52,7 @@ module IsoDoc::Function
|
|
51
52
|
|
52
53
|
def sourcecode_name_parse(node, div, name)
|
53
54
|
return if name.nil?
|
55
|
+
|
54
56
|
div.p **{ class: "SourceTitle", style: "text-align:center;" } do |p|
|
55
57
|
name.children.each { |n| parse(n, p) }
|
56
58
|
end
|
@@ -91,14 +93,15 @@ module IsoDoc::Function
|
|
91
93
|
@annotation = false
|
92
94
|
end
|
93
95
|
|
94
|
-
def admonition_class(
|
96
|
+
def admonition_class(_node)
|
95
97
|
"Admonition"
|
96
98
|
end
|
97
99
|
|
98
100
|
def admonition_name(node, type)
|
99
101
|
name = node&.at(ns("./name")) and return name
|
100
|
-
name = Nokogiri::XML::Node.new(
|
102
|
+
name = Nokogiri::XML::Node.new("name", node.document)
|
101
103
|
return unless type && @i18n.admonition[type]
|
104
|
+
|
102
105
|
name << @i18n.admonition[type]&.upcase
|
103
106
|
name
|
104
107
|
end
|
@@ -119,7 +122,8 @@ module IsoDoc::Function
|
|
119
122
|
|
120
123
|
def formula_where(dl, out)
|
121
124
|
return unless dl
|
122
|
-
|
125
|
+
|
126
|
+
out.p **{ style: "page-break-after:avoid;" } do |p|
|
123
127
|
p << @i18n.where
|
124
128
|
end
|
125
129
|
parse(dl, out)
|
@@ -148,6 +152,7 @@ module IsoDoc::Function
|
|
148
152
|
formula_where(node.at(ns("./dl")), div)
|
149
153
|
node.children.each do |n|
|
150
154
|
next if %w(stem dl name).include? n.name
|
155
|
+
|
151
156
|
parse(n, div)
|
152
157
|
end
|
153
158
|
end
|
@@ -182,6 +187,7 @@ module IsoDoc::Function
|
|
182
187
|
author = node.at(ns("./author"))
|
183
188
|
source = node.at(ns("./source"))
|
184
189
|
return if author.nil? && source.nil?
|
190
|
+
|
185
191
|
out.p **{ class: "QuoteAttribution" } do |p|
|
186
192
|
p << "— #{author.text}" if author
|
187
193
|
p << ", " if author && source
|
@@ -201,8 +207,9 @@ module IsoDoc::Function
|
|
201
207
|
end
|
202
208
|
|
203
209
|
def passthrough_parse(node, out)
|
204
|
-
return if node["format"]
|
210
|
+
return if node["format"] &&
|
205
211
|
!(node["format"].split(/,/).include? @format.to_s)
|
212
|
+
|
206
213
|
out.passthrough node.text
|
207
214
|
end
|
208
215
|
|
@@ -59,7 +59,7 @@ module IsoDoc::Function
|
|
59
59
|
name = node&.at(ns("./name"))&.remove
|
60
60
|
div.p do |p|
|
61
61
|
name and p.span **{ class: "note_label" } do |s|
|
62
|
-
name
|
62
|
+
name.children.each { |n| parse(n, s) }
|
63
63
|
s << note_delim
|
64
64
|
end
|
65
65
|
insert_tab(p, 1)
|
@@ -98,7 +98,7 @@ module IsoDoc::Function
|
|
98
98
|
@note = true
|
99
99
|
out.div **note_attrs(node) do |div|
|
100
100
|
node&.at(ns("./*[local-name() != 'name'][1]"))&.name == "p" ?
|
101
|
-
#node.first_element_child.name == "p" ?
|
101
|
+
# node.first_element_child.name == "p" ?
|
102
102
|
note_p_parse(node, div) : note_parse1(node, div)
|
103
103
|
end
|
104
104
|
@note = false
|
@@ -28,10 +28,10 @@ module IsoDoc::Function
|
|
28
28
|
# to allow for HTMLentities
|
29
29
|
def noko(&block)
|
30
30
|
doc = ::Nokogiri::XML.parse(NOKOHEAD)
|
31
|
-
fragment = doc.fragment(
|
31
|
+
fragment = doc.fragment("")
|
32
32
|
::Nokogiri::XML::Builder.with fragment, &block
|
33
|
-
fragment.to_xml(encoding:
|
34
|
-
l.gsub(/\s*\n/,
|
33
|
+
fragment.to_xml(encoding: "US-ASCII").lines.map do |l|
|
34
|
+
l.gsub(/\s*\n/, "")
|
35
35
|
end
|
36
36
|
end
|
37
37
|
|
@@ -46,17 +46,18 @@ module IsoDoc::Function
|
|
46
46
|
'"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">'
|
47
47
|
|
48
48
|
def to_xhtml(xml)
|
49
|
-
xml.gsub!(/<\?xml[^>]*>/,
|
49
|
+
xml.gsub!(/<\?xml[^>]*>/, "")
|
50
50
|
/<!DOCTYPE /.match(xml) || (xml = DOCTYPE_HDR + xml)
|
51
51
|
xml = xml.split(/(\&[^ \r\n\t#;]+;)/).map do |t|
|
52
52
|
/^(\&[^ \t\r\n#;]+;)/.match?(t) ?
|
53
53
|
HTMLEntities.new.encode(HTMLEntities.new.decode(t), :hexadecimal) : t
|
54
|
-
end.join(
|
54
|
+
end.join("")
|
55
55
|
begin
|
56
56
|
Nokogiri::XML.parse(xml, &:strict)
|
57
57
|
rescue Nokogiri::XML::SyntaxError => e
|
58
|
-
File.open("#{@filename}.#{@format}.err",
|
59
|
-
abort "Malformed Output XML for #{@format}: #{e}
|
58
|
+
File.open("#{@filename}.#{@format}.err", "w:UTF-8") { |f| f.write xml }
|
59
|
+
abort "Malformed Output XML for #{@format}: #{e} "\
|
60
|
+
"(see #{@filename}.#{@format}.err)"
|
60
61
|
end
|
61
62
|
end
|
62
63
|
|
@@ -67,11 +68,12 @@ module IsoDoc::Function
|
|
67
68
|
end
|
68
69
|
|
69
70
|
def from_xhtml(xml)
|
70
|
-
xml.to_xml.sub(%r{ xmlns="http://www.w3.org/1999/xhtml"},
|
71
|
+
xml.to_xml.sub(%r{ xmlns="http://www.w3.org/1999/xhtml"}, "")
|
71
72
|
end
|
72
73
|
|
73
74
|
CLAUSE_ANCESTOR =
|
74
75
|
".//ancestor::*[local-name() = 'annex' or "\
|
76
|
+
"local-name() = 'definitions' or "\
|
75
77
|
"local-name() = 'acknowledgements' or local-name() = 'term' or "\
|
76
78
|
"local-name() = 'appendix' or local-name() = 'foreword' or "\
|
77
79
|
"local-name() = 'introduction' or local-name() = 'terms' or "\
|
@@ -102,32 +104,32 @@ module IsoDoc::Function
|
|
102
104
|
else
|
103
105
|
@i18n.l10n("#{array[0..-2].join(', ')} "\
|
104
106
|
"#{@i18n.and} #{array.last}",
|
105
|
-
|
107
|
+
@lang, @script)
|
106
108
|
end
|
107
109
|
end
|
108
110
|
|
109
111
|
# avoid `; avoid {{ (Liquid Templates); avoid [[ (Javascript)
|
110
112
|
def extract_delims(text)
|
111
|
-
@openmathdelim =
|
112
|
-
@closemathdelim =
|
113
|
+
@openmathdelim = "(#("
|
114
|
+
@closemathdelim = ")#)"
|
113
115
|
while text.include?(@openmathdelim) || text.include?(@closemathdelim)
|
114
|
-
@openmathdelim +=
|
115
|
-
@closemathdelim +=
|
116
|
+
@openmathdelim += "("
|
117
|
+
@closemathdelim += ")"
|
116
118
|
end
|
117
119
|
[@openmathdelim, @closemathdelim]
|
118
120
|
end
|
119
121
|
|
120
122
|
def header_strip(h)
|
121
|
-
h = h.to_s.gsub(%r{<br\s*/>},
|
122
|
-
|
123
|
+
h = h.to_s.gsub(%r{<br\s*/>}, " ").gsub(/<\/?h[123456][^>]*>/, "")
|
124
|
+
.gsub(/<\/?b[^>]*>/, "")
|
123
125
|
h1 = to_xhtml_fragment(h.dup)
|
124
126
|
h1.traverse do |x|
|
125
|
-
x.replace(
|
126
|
-
x.remove if x.name ==
|
127
|
-
x.remove if x.name ==
|
128
|
-
x.remove if x.name ==
|
129
|
-
x.remove if x.name ==
|
130
|
-
x.replace(x.children) if x.name ==
|
127
|
+
x.replace(" ") if x.name == "span" && /mso-tab-count/.match(x["style"])
|
128
|
+
x.remove if x.name == "img"
|
129
|
+
x.remove if x.name == "span" && x["class"] == "MsoCommentReference"
|
130
|
+
x.remove if x.name == "a" && x["class"] == "FootnoteRef"
|
131
|
+
x.remove if x.name == "span" && /mso-bookmark/.match(x["style"])
|
132
|
+
x.replace(x.children) if x.name == "a"
|
131
133
|
end
|
132
134
|
from_xhtml(h1)
|
133
135
|
end
|
@@ -139,9 +141,9 @@ module IsoDoc::Function
|
|
139
141
|
def liquid(doc)
|
140
142
|
# unescape HTML escapes in doc
|
141
143
|
doc = doc.split(%r<(\{%|%\})>).each_slice(4).map do |a|
|
142
|
-
a[2] = a[2].gsub(/\</,
|
143
|
-
a.join(
|
144
|
-
end.join(
|
144
|
+
a[2] = a[2].gsub(/\</, "<").gsub(/\>/, ">") if a.size > 2
|
145
|
+
a.join("")
|
146
|
+
end.join("")
|
145
147
|
Liquid::Template.parse(doc)
|
146
148
|
end
|
147
149
|
|
@@ -152,20 +154,20 @@ module IsoDoc::Function
|
|
152
154
|
|
153
155
|
def populate_template(docxml, _format = nil)
|
154
156
|
meta = @meta
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
157
|
+
.get
|
158
|
+
.merge(@labels ? {labels: @labels} : {})
|
159
|
+
.merge(@meta.labels ? {labels: @meta.labels} : {})
|
160
|
+
.merge(fonts_options || {})
|
159
161
|
template = liquid(docxml)
|
160
162
|
template.render(meta.map { |k, v| [k.to_s, empty2nil(v)] }.to_h)
|
161
|
-
|
163
|
+
.gsub("<", "<").gsub(">", ">").gsub("&", "&")
|
162
164
|
end
|
163
165
|
|
164
166
|
def save_dataimage(uri, _relative_dir = true)
|
165
167
|
%r{^data:(image|application)/(?<imgtype>[^;]+);base64,(?<imgdata>.+)$} =~ uri
|
166
|
-
imgtype.sub!(/\+[a-z0-9]+$/,
|
167
|
-
imgtype =
|
168
|
-
Tempfile.open([
|
168
|
+
imgtype.sub!(/\+[a-z0-9]+$/, "") # svg+xml
|
169
|
+
imgtype = "png" unless /^[a-z0-9]+$/.match imgtype
|
170
|
+
Tempfile.open(["image", ".#{imgtype}"]) do |f|
|
169
171
|
f.binmode
|
170
172
|
f.write(Base64.strict_decode64(imgdata))
|
171
173
|
@tempfile_cache << f # persist to the end
|
@@ -174,18 +176,18 @@ module IsoDoc::Function
|
|
174
176
|
end
|
175
177
|
|
176
178
|
def image_localfile(i)
|
177
|
-
if /^data:/.match? i[
|
178
|
-
save_dataimage(i[
|
179
|
-
elsif %r{^([A-Z]:)?/}.match? i[
|
180
|
-
i[
|
179
|
+
if /^data:/.match? i["src"]
|
180
|
+
save_dataimage(i["src"], false)
|
181
|
+
elsif %r{^([A-Z]:)?/}.match? i["src"]
|
182
|
+
i["src"]
|
181
183
|
else
|
182
|
-
File.join(@localdir, i[
|
184
|
+
File.join(@localdir, i["src"])
|
183
185
|
end
|
184
186
|
end
|
185
187
|
|
186
188
|
def labelled_ancestor(node)
|
187
|
-
!node.ancestors(
|
188
|
-
|
189
|
+
!node.ancestors("example, requirement, recommendation, permission, "\
|
190
|
+
"note, table, figure, sourcecode").empty?
|
189
191
|
end
|
190
192
|
end
|
191
193
|
end
|
data/lib/isodoc/gem_tasks.rb
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require
|
3
|
+
require "sassc"
|
4
|
+
require "isodoc/sassc_importer"
|
5
|
+
require "rake/clean"
|
6
6
|
|
7
7
|
module IsoDoc
|
8
8
|
module GemTasks
|
@@ -11,7 +11,7 @@ module IsoDoc
|
|
11
11
|
module_function
|
12
12
|
|
13
13
|
def install
|
14
|
-
rule
|
14
|
+
rule ".css" => [proc { |tn| tn.sub(/\.css$/, ".scss") }] do |current_task|
|
15
15
|
begin
|
16
16
|
puts(current_task)
|
17
17
|
compile_scss_task(current_task)
|
@@ -20,23 +20,23 @@ module IsoDoc
|
|
20
20
|
end
|
21
21
|
end
|
22
22
|
|
23
|
-
scss_files = Rake::FileList[
|
24
|
-
source_files = scss_files.ext(
|
23
|
+
scss_files = Rake::FileList["lib/**/*.scss"]
|
24
|
+
source_files = scss_files.ext(".css")
|
25
25
|
|
26
26
|
task :comment_out_liquid do
|
27
27
|
process_css_files(scss_files) do |file_name|
|
28
|
-
comment_out_liquid(File.read(file_name, encoding:
|
28
|
+
comment_out_liquid(File.read(file_name, encoding: "UTF-8"))
|
29
29
|
end
|
30
30
|
end
|
31
31
|
|
32
32
|
task build_scss: [:comment_out_liquid].push(*source_files) do
|
33
33
|
process_css_files(scss_files) do |file_name|
|
34
|
-
uncomment_out_liquid(File.read(file_name, encoding:
|
34
|
+
uncomment_out_liquid(File.read(file_name, encoding: "UTF-8"))
|
35
35
|
end
|
36
|
-
git_cache_compiled_files && puts(
|
36
|
+
git_cache_compiled_files && puts("Built scss!")
|
37
37
|
end
|
38
38
|
|
39
|
-
Rake::Task[
|
39
|
+
Rake::Task["build"].enhance [:build_scss] do
|
40
40
|
git_rm_compiled_files
|
41
41
|
Rake::Task[:clean].invoke
|
42
42
|
end
|
@@ -44,7 +44,7 @@ module IsoDoc
|
|
44
44
|
|
45
45
|
def notify_borken_compilation(error, current_task)
|
46
46
|
puts("Cannot compile #{current_task} because of #{error.message}")
|
47
|
-
puts(
|
47
|
+
puts("continue anyway[y|n]?")
|
48
48
|
answer = STDIN.gets.strip
|
49
49
|
if %w[y yes].include?(answer.strip.downcase)
|
50
50
|
puts("Cannot compile #{current_task} because of #{error.message}")
|
@@ -68,7 +68,7 @@ module IsoDoc
|
|
68
68
|
def process_css_files(scss_files)
|
69
69
|
scss_files.each do |file_name|
|
70
70
|
result = yield(file_name)
|
71
|
-
File.open(file_name,
|
71
|
+
File.open(file_name, "w", encoding: "UTF-8") do |file|
|
72
72
|
file.puts(result)
|
73
73
|
end
|
74
74
|
end
|
@@ -81,42 +81,41 @@ module IsoDoc
|
|
81
81
|
else
|
82
82
|
line
|
83
83
|
end
|
84
|
-
end
|
85
|
-
.join("\n")
|
84
|
+
end.join("\n")
|
86
85
|
end
|
87
86
|
|
88
87
|
def uncomment_out_liquid(text)
|
89
88
|
text
|
90
|
-
.gsub(
|
91
|
-
.gsub(
|
92
|
-
.gsub('"{{', '{{').gsub('}}"',
|
89
|
+
.gsub("/* LIQUID_COMMENT", "")
|
90
|
+
.gsub("LIQUID_COMMENT */", "")
|
91
|
+
.gsub('"{{', '{{').gsub('}}"', "}}")
|
93
92
|
end
|
94
93
|
|
95
94
|
def fonts_placeholder
|
96
95
|
<<~TEXT
|
97
|
-
$bodyfont:
|
98
|
-
$headerfont:
|
99
|
-
$monospacefont:
|
100
|
-
$normalfontsize:
|
101
|
-
$smallerfontsize:
|
102
|
-
$footnotefontsize:
|
103
|
-
$monospacefontsize:
|
96
|
+
$bodyfont: "{{bodyfont}}";
|
97
|
+
$headerfont: "{{headerfont}}";
|
98
|
+
$monospacefont: "{{monospacefont}}";
|
99
|
+
$normalfontsize: "{{normalfontsize}}";
|
100
|
+
$smallerfontsize: "{{smallerfontsize}}";
|
101
|
+
$footnotefontsize: "{{footnotefontsize}}";
|
102
|
+
$monospacefontsize: "{{monospacefontsize}}";
|
104
103
|
TEXT
|
105
104
|
end
|
106
105
|
|
107
106
|
def compile_scss(filename)
|
108
|
-
require
|
107
|
+
require "sassc"
|
109
108
|
|
110
|
-
isodoc_path = if Gem.loaded_specs[
|
111
|
-
File.join(Gem.loaded_specs[
|
109
|
+
isodoc_path = if Gem.loaded_specs["isodoc"]
|
110
|
+
File.join(Gem.loaded_specs["isodoc"].full_gem_path, "lib", "isodoc")
|
112
111
|
else
|
113
|
-
File.join(
|
112
|
+
File.join("lib", "isodoc")
|
114
113
|
end
|
115
114
|
[isodoc_path,
|
116
115
|
File.dirname(filename)].each do |name|
|
117
116
|
SassC.load_paths << name
|
118
117
|
end
|
119
|
-
sheet_content = File.read(filename, encoding:
|
118
|
+
sheet_content = File.read(filename, encoding: "UTF-8")
|
120
119
|
SassC::Engine.new(fonts_placeholder + sheet_content,
|
121
120
|
syntax: :scss,
|
122
121
|
importer: SasscImporter)
|
@@ -125,10 +124,10 @@ module IsoDoc
|
|
125
124
|
|
126
125
|
def compile_scss_task(current_task)
|
127
126
|
filename = current_task.source
|
128
|
-
basename = File.basename(filename,
|
127
|
+
basename = File.basename(filename, ".*")
|
129
128
|
compiled_path = File.join(File.dirname(filename), "#{basename}.css")
|
130
129
|
content = uncomment_out_liquid(compile_scss(filename))
|
131
|
-
File.open(compiled_path,
|
130
|
+
File.open(compiled_path, "w:UTF-8") do |f|
|
132
131
|
f.write(content)
|
133
132
|
end
|
134
133
|
CLEAN << compiled_path
|