isodoc 1.2.7 → 1.4.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/rake.yml +14 -9
- data/README.adoc +1 -3
- data/isodoc.gemspec +1 -1
- data/lib/isodoc-yaml/i18n-en.yaml +56 -0
- data/lib/isodoc-yaml/i18n-fr.yaml +64 -7
- data/lib/isodoc-yaml/i18n-zh-Hans.yaml +1 -0
- data/lib/isodoc/base_style/blocks.scss +2 -2
- data/lib/isodoc/base_style/typography.scss +1 -1
- data/lib/isodoc/convert.rb +13 -85
- data/lib/isodoc/css.rb +95 -0
- data/lib/isodoc/function/inline.rb +0 -33
- data/lib/isodoc/function/inline_simple.rb +10 -1
- data/lib/isodoc/function/lists.rb +2 -1
- data/lib/isodoc/function/references.rb +8 -13
- data/lib/isodoc/function/section.rb +1 -1
- data/lib/isodoc/function/table.rb +10 -0
- data/lib/isodoc/function/to_word_html.rb +2 -2
- data/lib/isodoc/gem_tasks.rb +4 -0
- data/lib/isodoc/html_function/html.rb +7 -0
- data/lib/isodoc/html_function/mathvariant_to_plain.rb +82 -0
- data/lib/isodoc/html_function/postprocess.rb +41 -20
- data/lib/isodoc/i18n.rb +15 -2
- data/lib/isodoc/metadata_contributor.rb +4 -3
- data/lib/isodoc/presentation_function/bibdata.rb +3 -3
- data/lib/isodoc/presentation_function/block.rb +14 -9
- data/lib/isodoc/presentation_function/inline.rb +126 -22
- data/lib/isodoc/presentation_function/section.rb +9 -0
- data/lib/isodoc/presentation_xml_convert.rb +5 -0
- data/lib/isodoc/version.rb +1 -1
- data/lib/isodoc/word_convert.rb +0 -20
- data/lib/isodoc/word_function/body.rb +12 -0
- data/lib/isodoc/word_function/postprocess.rb +38 -80
- data/lib/isodoc/word_function/postprocess_cover.rb +55 -0
- data/lib/isodoc/word_function/table.rb +10 -0
- data/lib/isodoc/xref.rb +1 -0
- data/lib/isodoc/xref/xref_counter.rb +20 -9
- data/lib/isodoc/xref/xref_gen.rb +20 -2
- data/lib/isodoc/xref/xref_sect_gen.rb +1 -1
- data/spec/assets/html.scss +14 -0
- data/spec/assets/i18n.yaml +7 -6
- data/spec/isodoc/blocks_spec.rb +2 -1
- data/spec/isodoc/cleanup_spec.rb +0 -1
- data/spec/isodoc/footnotes_spec.rb +4 -5
- data/spec/isodoc/i18n_spec.rb +23 -2
- data/spec/isodoc/inline_spec.rb +182 -202
- data/spec/isodoc/lists_spec.rb +1 -1
- data/spec/isodoc/metadata_spec.rb +3 -1
- data/spec/isodoc/postproc_spec.rb +472 -11
- data/spec/isodoc/presentation_xml_spec.rb +584 -1
- data/spec/isodoc/ref_spec.rb +325 -7
- data/spec/isodoc/table_spec.rb +28 -0
- data/spec/isodoc/xref_spec.rb +162 -17
- metadata +18 -16
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 81eb17e1804dbdda88651d40a5263f265a39f3c5c3eee536ddbb409ee1c206f5
|
4
|
+
data.tar.gz: 62551af56891b80367034f70fd90b909f13b58717999dd0109e67f6974aa9adb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3a933d2ec1665a9853a8ad29a340d718726b9f37c1b8f843feca20bd4ced4f38b89a7b862912e7154e63acd126b58b930b35c57f3ddea9896c52d8517139928d
|
7
|
+
data.tar.gz: 611451fcf174a2594cf3ae73518b33ae2d251b783a8c633c6d571e977731ea1b4113b11492df99cfc879c9c26363fd4b8a8a4decc28f7ecddcd50a3d9d3428a2
|
data/.github/workflows/rake.yml
CHANGED
@@ -4,7 +4,8 @@ name: rake
|
|
4
4
|
|
5
5
|
on:
|
6
6
|
push:
|
7
|
-
branches: [ master ]
|
7
|
+
branches: [ master, main ]
|
8
|
+
tags: [ v* ]
|
8
9
|
pull_request:
|
9
10
|
|
10
11
|
jobs:
|
@@ -31,11 +32,19 @@ jobs:
|
|
31
32
|
steps:
|
32
33
|
- uses: actions/checkout@master
|
33
34
|
|
34
|
-
-
|
35
|
-
uses: ruby/setup-ruby@v1
|
35
|
+
- uses: ruby/setup-ruby@v1
|
36
36
|
with:
|
37
37
|
ruby-version: ${{ matrix.ruby }}
|
38
|
-
|
38
|
+
|
39
|
+
- uses: actions/cache@v2
|
40
|
+
with:
|
41
|
+
path: vendor/bundle
|
42
|
+
key: bundle-${{ matrix.os }}-${{ matrix.ruby }}-${{ hashFiles('**/*.gemspec') }}
|
43
|
+
restore-keys: bundle-${{ matrix.os }}-${{ matrix.ruby }}
|
44
|
+
|
45
|
+
- run: bundle config set path 'vendor/bundle'
|
46
|
+
|
47
|
+
- run: bundle install --jobs 4 --retry 3
|
39
48
|
|
40
49
|
- name: Install Inkscape macOS
|
41
50
|
if: matrix.os == 'macos-latest'
|
@@ -57,8 +66,4 @@ jobs:
|
|
57
66
|
choco install --no-progress -y inkscape
|
58
67
|
inkscape --version
|
59
68
|
|
60
|
-
-
|
61
|
-
run: bundle install --jobs 4 --retry 3
|
62
|
-
|
63
|
-
- name: Run specs
|
64
|
-
run: bundle exec rake
|
69
|
+
- run: bundle exec rake
|
data/README.adoc
CHANGED
@@ -1,9 +1,7 @@
|
|
1
1
|
= isodoc: Processor to generate HTML/Word from Metanorma XML
|
2
2
|
|
3
3
|
image:https://img.shields.io/gem/v/isodoc.svg["Gem Version", link="https://rubygems.org/gems/isodoc"]
|
4
|
-
image:https://github.com/metanorma/isodoc/workflows/
|
5
|
-
image:https://github.com/metanorma/isodoc/workflows/macos/badge.svg["OSX Build Status", link="https://github.com/metanorma/isodoc/actions?query=workflow%3Amacos"]
|
6
|
-
image:https://github.com/metanorma/isodoc/workflows/windows/badge.svg["Windows Build Status", link="https://github.com/metanorma/isodoc/actions?query=workflow%3Awindows"]
|
4
|
+
image:https://github.com/metanorma/isodoc/workflows/rake/badge.svg["Build Status", link="https://github.com/metanorma/isodoc/actions?query=workflow%3Arake"]
|
7
5
|
image:https://codeclimate.com/github/metanorma/isodoc/badges/gpa.svg["Code Climate", link="https://codeclimate.com/github/metanorma/isodoc"]
|
8
6
|
image:https://img.shields.io/github/issues-pr-raw/metanorma/isodoc.svg["Pull Requests", link="https://github.com/metanorma/isodoc/pulls"]
|
9
7
|
image:https://img.shields.io/github/commits-since/metanorma/isodoc/latest.svg["Commits since latest",link="https://github.com/metanorma/isodoc/releases"]
|
data/isodoc.gemspec
CHANGED
@@ -35,10 +35,10 @@ Gem::Specification.new do |spec|
|
|
35
35
|
spec.add_dependency "uuidtools"
|
36
36
|
spec.add_dependency "html2doc", "~> 1.0.0"
|
37
37
|
spec.add_dependency "liquid"
|
38
|
+
spec.add_dependency "twitter_cldr"
|
38
39
|
spec.add_dependency "roman-numerals"
|
39
40
|
spec.add_dependency "metanorma", "~> 1.2.0"
|
40
41
|
spec.add_dependency "relaton-cli"
|
41
|
-
spec.add_dependency "gyoku", "~> 1.3"
|
42
42
|
|
43
43
|
spec.add_development_dependency "rake", "~> 13.0"
|
44
44
|
spec.add_development_dependency "byebug", "~> 9.1"
|
@@ -36,6 +36,7 @@ external_terms_boilerplate: |
|
|
36
36
|
internal_external_terms_boilerplate: |
|
37
37
|
<p>For the purposes of this document, the terms and definitions
|
38
38
|
given in % and the following apply.</p>
|
39
|
+
term_defined_in: "[term defined in %]"
|
39
40
|
note: NOTE
|
40
41
|
note_xref: Note
|
41
42
|
termnote: Note % to entry
|
@@ -96,3 +97,58 @@ locality: {
|
|
96
97
|
note: Note,
|
97
98
|
formula: Formula
|
98
99
|
}
|
100
|
+
inflection:
|
101
|
+
Clause:
|
102
|
+
sg: Clause
|
103
|
+
pl: Clauses
|
104
|
+
Annex:
|
105
|
+
sg: Annex
|
106
|
+
pl: Annexes
|
107
|
+
Appendix:
|
108
|
+
sg: Appendix
|
109
|
+
pl: Appendixes
|
110
|
+
Note:
|
111
|
+
sg: Note
|
112
|
+
pl: Notes
|
113
|
+
"Note % to entry":
|
114
|
+
sg: Note % to entry
|
115
|
+
pl: Notes % to entry
|
116
|
+
List:
|
117
|
+
sg: List
|
118
|
+
pl: Lists
|
119
|
+
Figure:
|
120
|
+
sg: Figure
|
121
|
+
pl: Figures
|
122
|
+
Formula:
|
123
|
+
sg: Formula
|
124
|
+
pl: Formulas
|
125
|
+
Table:
|
126
|
+
sg: Table
|
127
|
+
pl: Tables
|
128
|
+
Requirement:
|
129
|
+
sg: Requirement
|
130
|
+
pl: Requirements
|
131
|
+
Recommendation:
|
132
|
+
sg: Recommendation
|
133
|
+
pl: Recommendations
|
134
|
+
Permission:
|
135
|
+
sg: Permission
|
136
|
+
pl: Permissions
|
137
|
+
Example:
|
138
|
+
sg: Example
|
139
|
+
pl: Examples
|
140
|
+
Part:
|
141
|
+
sg: Part
|
142
|
+
pl: Parts
|
143
|
+
Section:
|
144
|
+
sg: Section
|
145
|
+
pl: Sections
|
146
|
+
Paragraph:
|
147
|
+
sg: Paragraph
|
148
|
+
pl: Paragraphs
|
149
|
+
Chapter:
|
150
|
+
sg: Chapter
|
151
|
+
pl: Chapters
|
152
|
+
Page:
|
153
|
+
sg: Page
|
154
|
+
pl: Pages
|
@@ -1,5 +1,5 @@
|
|
1
1
|
term_def_boilerplate:
|
2
|
-
scope: Domaine d
|
2
|
+
scope: Domaine d’application
|
3
3
|
symbolsabbrev: Symboles et termes abrégés
|
4
4
|
abbrev: Termes abrégés
|
5
5
|
symbols: Symboles
|
@@ -18,20 +18,21 @@ clause: Article
|
|
18
18
|
annex: Annexe
|
19
19
|
appendix: Appendice
|
20
20
|
no_terms_boilerplate: |
|
21
|
-
<p>Aucun terme n
|
21
|
+
<p>Aucun terme n’est defini dans le présent document.</p>
|
22
22
|
internal_terms_boilerplate: |
|
23
|
-
<p>Pour les besoins du présent document, les termes et définitions suivants s
|
23
|
+
<p>Pour les besoins du présent document, les termes et définitions suivants s’appliquent.</p>
|
24
24
|
norm_with_refs_pref:
|
25
|
-
Les documents suivants
|
25
|
+
Les documents suivants cités dans le texte constituent, pour tout ou partie de leur contenu, des exigences du présent document. Pour les références datées, seule l’édition citée s’applique. Pour les références non datées, la dernière édition du document de référence s’applique (y compris les éventuels amendements).
|
26
26
|
norm_empty_pref:
|
27
27
|
Le présent document ne contient aucune référence normative.
|
28
28
|
external_terms_boilerplate: |
|
29
|
-
<p>Pour les besoins du présent document, les termes et définitions de % s
|
29
|
+
<p>Pour les besoins du présent document, les termes et définitions de % s’appliquent.</p>
|
30
30
|
internal_external_terms_boilerplate: |
|
31
|
-
<p>Pour les besoins du présent document, les termes et définitions de % ainsi que les suivants, s
|
31
|
+
<p>Pour les besoins du présent document, les termes et définitions de % ainsi que les suivants, s’appliquent.</p>
|
32
|
+
term_defined_in: "[terme défini dans %]"
|
32
33
|
note: NOTE
|
33
34
|
note_xref: Note
|
34
|
-
termnote: Note % à l
|
35
|
+
termnote: Note % à l’article
|
35
36
|
figure: Figure
|
36
37
|
formula: Formule
|
37
38
|
inequality: Formule
|
@@ -89,3 +90,59 @@ locality: {
|
|
89
90
|
note: Note,
|
90
91
|
formula: Formule
|
91
92
|
}
|
93
|
+
inflection:
|
94
|
+
Clause:
|
95
|
+
sg: Article
|
96
|
+
pl: Articles
|
97
|
+
Annex:
|
98
|
+
sg: Annexe
|
99
|
+
pl: Annexes
|
100
|
+
Appendix:
|
101
|
+
sg: Appendice
|
102
|
+
pl: Appendices
|
103
|
+
Note:
|
104
|
+
sg: Note
|
105
|
+
pl: Notes
|
106
|
+
"Note % à l’article":
|
107
|
+
sg: Note % à l’article
|
108
|
+
pl: Notes % à l’article
|
109
|
+
List:
|
110
|
+
sg: Liste
|
111
|
+
pl: Listes
|
112
|
+
Figure:
|
113
|
+
sg: Figure
|
114
|
+
pl: Figures
|
115
|
+
Formula:
|
116
|
+
sg: Formule
|
117
|
+
pl: Formules
|
118
|
+
Table:
|
119
|
+
sg: Tableau
|
120
|
+
pl: Tableaux
|
121
|
+
Requirement:
|
122
|
+
sg: Exigence
|
123
|
+
pl: Exigences
|
124
|
+
Recommendation:
|
125
|
+
sg: Recommandation
|
126
|
+
pl: Recommandations
|
127
|
+
Permission:
|
128
|
+
sg: Autorisation
|
129
|
+
pl: Autorisations
|
130
|
+
Example:
|
131
|
+
sg: Exemple
|
132
|
+
pl: Exemples
|
133
|
+
Part:
|
134
|
+
sg: Partie
|
135
|
+
pl: Parties
|
136
|
+
Section:
|
137
|
+
sg: Section
|
138
|
+
pl: Sections
|
139
|
+
Paragraph:
|
140
|
+
sg: Alinéa
|
141
|
+
pl: Alinéas
|
142
|
+
Chapter:
|
143
|
+
sg: Chapitre
|
144
|
+
pl: Chapitres
|
145
|
+
Page:
|
146
|
+
sg: Page
|
147
|
+
pl: Pages
|
148
|
+
|
@@ -50,7 +50,7 @@
|
|
50
50
|
}
|
51
51
|
|
52
52
|
background-color: $colorBg;
|
53
|
-
font-size:
|
53
|
+
font-size: $monospacefontsize;
|
54
54
|
line-height: 1.6em;
|
55
55
|
padding: 1.5em;
|
56
56
|
margin: 2em 0 1em 0;
|
@@ -68,7 +68,7 @@
|
|
68
68
|
}
|
69
69
|
|
70
70
|
background-color: $colorBg;
|
71
|
-
font-size:
|
71
|
+
font-size: $monospacefontsize;
|
72
72
|
line-height: 1.6em;
|
73
73
|
padding: 1.5em;
|
74
74
|
margin: 2em 0 1em 0;
|
data/lib/isodoc/convert.rb
CHANGED
@@ -3,6 +3,7 @@ require "isodoc/common"
|
|
3
3
|
require "fileutils"
|
4
4
|
require "tempfile"
|
5
5
|
require_relative "i18n"
|
6
|
+
require_relative "css"
|
6
7
|
|
7
8
|
module IsoDoc
|
8
9
|
class Convert < ::IsoDoc::Common
|
@@ -17,6 +18,10 @@ module IsoDoc
|
|
17
18
|
# wordcoverpage: Cover page for Word
|
18
19
|
# htmlintropage: Introductory page for HTML
|
19
20
|
# wordintropage: Introductory page for Word
|
21
|
+
# normalfontsize: Font size for body text
|
22
|
+
# smallerfontsize: Font size for smaller than body text
|
23
|
+
# monospacefontsize: Font size for monospace font
|
24
|
+
# footnotefontsize: Font size for footnotes
|
20
25
|
# i18nyaml: YAML file for internationalisation of text
|
21
26
|
# ulstyle: list style in Word CSS for unordered lists
|
22
27
|
# olstyle: list style in Word CSS for ordered lists
|
@@ -25,8 +30,10 @@ module IsoDoc
|
|
25
30
|
# monospace: font to use for monospace text
|
26
31
|
# suppressheadingnumbers: suppress heading numbers for clauses
|
27
32
|
# scripts: Scripts file for HTML
|
28
|
-
# scripts_pdf: Scripts file for PDF
|
33
|
+
# scripts_pdf: Scripts file for PDF (not used in XSLT PDF)
|
29
34
|
# datauriimage: Encode images in HTML output as data URIs
|
35
|
+
# break_up_urls_in_tables: whether to insert spaces in URLs in tables
|
36
|
+
# every 40-odd chars
|
30
37
|
def initialize(options)
|
31
38
|
@libdir ||= File.dirname(__FILE__)
|
32
39
|
options.merge!(default_fonts(options)) do |_, old, new|
|
@@ -46,6 +53,10 @@ module IsoDoc
|
|
46
53
|
@wordcoverpage = options[:wordcoverpage]
|
47
54
|
@htmlintropage = options[:htmlintropage]
|
48
55
|
@wordintropage = options[:wordintropage]
|
56
|
+
@normalfontsize = options[:normalfontsize]
|
57
|
+
@smallerfontsize = options[:smallerfontsize]
|
58
|
+
@monospacefontsize = options[:monospacefontsize]
|
59
|
+
@footnotefontsize = options[:footnotefontsize]
|
49
60
|
@scripts = options[:scripts]
|
50
61
|
@scripts_pdf = options[:scripts_pdf]
|
51
62
|
@i18nyaml = options[:i18nyaml]
|
@@ -80,62 +91,10 @@ module IsoDoc
|
|
80
91
|
@fn_bookmarks = {}
|
81
92
|
end
|
82
93
|
|
83
|
-
# Check if already compiled version(.css) exists,
|
84
|
-
# if not, return original scss file. During release
|
85
|
-
# we compile scss into css files in order to not depend on scss
|
86
|
-
def precompiled_style_or_original(stylesheet_path)
|
87
|
-
# Already have compiled stylesheet, use it
|
88
|
-
return stylesheet_path if stylesheet_path.nil? ||
|
89
|
-
File.extname(stylesheet_path) == '.css'
|
90
|
-
|
91
|
-
basename = File.basename(stylesheet_path, '.*')
|
92
|
-
compiled_path = File.join(File.dirname(stylesheet_path),
|
93
|
-
"#{basename}.css")
|
94
|
-
return stylesheet_path unless File.file?(compiled_path)
|
95
|
-
|
96
|
-
compiled_path
|
97
|
-
end
|
98
|
-
|
99
|
-
# run this after @meta is populated
|
100
|
-
def populate_css
|
101
|
-
@htmlstylesheet = generate_css(@htmlstylesheet_name, true)
|
102
|
-
@wordstylesheet = generate_css(@wordstylesheet_name, false)
|
103
|
-
@standardstylesheet = generate_css(@standardstylesheet_name, false)
|
104
|
-
end
|
105
|
-
|
106
94
|
def tmpimagedir_suffix
|
107
95
|
'_images'
|
108
96
|
end
|
109
97
|
|
110
|
-
def default_fonts(_options)
|
111
|
-
{
|
112
|
-
bodyfont: 'Arial',
|
113
|
-
headerfont: 'Arial',
|
114
|
-
monospacefont: 'Courier'
|
115
|
-
}
|
116
|
-
end
|
117
|
-
|
118
|
-
# none for this parent gem, but will be populated in child gems
|
119
|
-
# which have access to stylesheets &c
|
120
|
-
def default_file_locations(_options)
|
121
|
-
{}
|
122
|
-
end
|
123
|
-
|
124
|
-
def fonts_options
|
125
|
-
{
|
126
|
-
'bodyfont' => options[:bodyfont] || 'Arial',
|
127
|
-
'headerfont' => options[:headerfont] || 'Arial',
|
128
|
-
'monospacefont' => options[:monospacefont] || 'Courier'
|
129
|
-
}
|
130
|
-
end
|
131
|
-
|
132
|
-
def scss_fontheader
|
133
|
-
b = options[:bodyfont] || 'Arial'
|
134
|
-
h = options[:headerfont] || 'Arial'
|
135
|
-
m = options[:monospacefont] || 'Courier'
|
136
|
-
"$bodyfont: #{b};\n$headerfont: #{h};\n$monospacefont: #{m};\n"
|
137
|
-
end
|
138
|
-
|
139
98
|
def html_doc_path(*file)
|
140
99
|
file.each do |f|
|
141
100
|
ret = File.join(@libdir, File.join('html', f))
|
@@ -144,37 +103,6 @@ module IsoDoc
|
|
144
103
|
nil
|
145
104
|
end
|
146
105
|
|
147
|
-
def convert_scss(filename, stylesheet)
|
148
|
-
require 'sassc'
|
149
|
-
require 'isodoc/sassc_importer'
|
150
|
-
|
151
|
-
[File.join(Gem.loaded_specs['isodoc'].full_gem_path,
|
152
|
-
'lib', 'isodoc'),
|
153
|
-
File.dirname(filename)].each do |name|
|
154
|
-
SassC.load_paths << name
|
155
|
-
end
|
156
|
-
SassC::Engine.new(scss_fontheader + stylesheet, syntax: :scss,
|
157
|
-
importer: SasscImporter)
|
158
|
-
.render
|
159
|
-
end
|
160
|
-
|
161
|
-
def generate_css(filename, stripwordcss)
|
162
|
-
return nil if filename.nil?
|
163
|
-
|
164
|
-
filename = precompiled_style_or_original(filename)
|
165
|
-
stylesheet = File.read(filename, encoding: 'UTF-8')
|
166
|
-
stylesheet = populate_template(stylesheet, :word)
|
167
|
-
stylesheet.gsub!(/(\s|\{)mso-[^:]+:[^;]+;/m, '\\1') if stripwordcss
|
168
|
-
if File.extname(filename) == '.scss'
|
169
|
-
stylesheet = convert_scss(filename, stylesheet)
|
170
|
-
end
|
171
|
-
Tempfile.open([File.basename(filename, '.*'), 'css'],
|
172
|
-
encoding: 'utf-8') do |f|
|
173
|
-
f.write(stylesheet)
|
174
|
-
f
|
175
|
-
end
|
176
|
-
end
|
177
|
-
|
178
106
|
def convert1(docxml, filename, dir)
|
179
107
|
@xrefs.parse docxml
|
180
108
|
noko do |xml|
|
@@ -229,7 +157,7 @@ module IsoDoc
|
|
229
157
|
FileUtils.rm_rf dir
|
230
158
|
end
|
231
159
|
|
232
|
-
def middle_clause
|
160
|
+
def middle_clause(docxml = nil)
|
233
161
|
"//clause[parent::sections][not(@type = 'scope')]"\
|
234
162
|
'[not(descendant::terms)]'
|
235
163
|
end
|
data/lib/isodoc/css.rb
ADDED
@@ -0,0 +1,95 @@
|
|
1
|
+
module IsoDoc
|
2
|
+
class Convert < ::IsoDoc::Common
|
3
|
+
# Check if already compiled version(.css) exists,
|
4
|
+
# if not, return original scss file. During release
|
5
|
+
# we compile scss into css files in order to not depend on scss
|
6
|
+
def precompiled_style_or_original(stylesheet_path)
|
7
|
+
# Already have compiled stylesheet, use it
|
8
|
+
return stylesheet_path if stylesheet_path.nil? ||
|
9
|
+
File.extname(stylesheet_path) == '.css'
|
10
|
+
basename = File.basename(stylesheet_path, '.*')
|
11
|
+
compiled_path = File.join(File.dirname(stylesheet_path),
|
12
|
+
"#{basename}.css")
|
13
|
+
return stylesheet_path unless File.file?(compiled_path)
|
14
|
+
compiled_path
|
15
|
+
end
|
16
|
+
|
17
|
+
# run this after @meta is populated
|
18
|
+
def populate_css
|
19
|
+
@htmlstylesheet = generate_css(@htmlstylesheet_name, true)
|
20
|
+
@wordstylesheet = generate_css(@wordstylesheet_name, false)
|
21
|
+
@standardstylesheet = generate_css(@standardstylesheet_name, false)
|
22
|
+
end
|
23
|
+
|
24
|
+
def default_fonts(_options)
|
25
|
+
{
|
26
|
+
bodyfont: 'Arial',
|
27
|
+
headerfont: 'Arial',
|
28
|
+
monospacefont: 'Courier',
|
29
|
+
}
|
30
|
+
end
|
31
|
+
|
32
|
+
# none for this parent gem, but will be populated in child gems
|
33
|
+
# which have access to stylesheets &c
|
34
|
+
def default_file_locations(_options)
|
35
|
+
{}
|
36
|
+
end
|
37
|
+
|
38
|
+
def fonts_options
|
39
|
+
{
|
40
|
+
'bodyfont' => options[:bodyfont] || 'Arial',
|
41
|
+
'headerfont' => options[:headerfont] || 'Arial',
|
42
|
+
'monospacefont' => options[:monospacefont] || 'Courier',
|
43
|
+
"normalfontsize" => options[:normalfontsize],
|
44
|
+
"monospacefontsize" => options[:monospacefontsize],
|
45
|
+
"smallerfontsize" => options[:smallerfontsize],
|
46
|
+
"footnotefontsize" => options[:footnotefontsize]
|
47
|
+
}
|
48
|
+
end
|
49
|
+
|
50
|
+
def scss_fontheader(is_html_css)
|
51
|
+
b = options[:bodyfont] || 'Arial'
|
52
|
+
h = options[:headerfont] || 'Arial'
|
53
|
+
m = options[:monospacefont] || 'Courier'
|
54
|
+
ns = options[:normalfontsize] || (is_html_css ? "1.0em" : '12.0pt')
|
55
|
+
ms = options[:monospacefontsize] || (is_html_css ? "0.8em" : '11.0pt')
|
56
|
+
ss = options[:smallerfontsize] || (is_html_css ? "0.9em" : '10.0pt')
|
57
|
+
fs = options[:footnotefontsize] || (is_html_css ? "0.9em" : '9.0pt')
|
58
|
+
"$bodyfont: #{b};\n$headerfont: #{h};\n$monospacefont: #{m};\n"\
|
59
|
+
"$normalfontsize: #{ns};\n$monospacefontsize: #{ms};\n"\
|
60
|
+
"$smallerfontsize: #{ss};\n$footnotefontsize: #{fs};\n"
|
61
|
+
end
|
62
|
+
|
63
|
+
def convert_scss(filename, stylesheet, stripwordcss)
|
64
|
+
require 'sassc'
|
65
|
+
require 'isodoc/sassc_importer'
|
66
|
+
|
67
|
+
[File.join(Gem.loaded_specs['isodoc'].full_gem_path,
|
68
|
+
'lib', 'isodoc'),
|
69
|
+
File.dirname(filename)].each do |name|
|
70
|
+
SassC.load_paths << name
|
71
|
+
end
|
72
|
+
SassC::Engine.new(scss_fontheader(stripwordcss) + stylesheet,
|
73
|
+
syntax: :scss, importer: SasscImporter)
|
74
|
+
.render
|
75
|
+
end
|
76
|
+
|
77
|
+
# stripwordcss if HTML stylesheet, !stripwordcss if DOC stylesheet
|
78
|
+
def generate_css(filename, stripwordcss)
|
79
|
+
return nil if filename.nil?
|
80
|
+
|
81
|
+
filename = precompiled_style_or_original(filename)
|
82
|
+
stylesheet = File.read(filename, encoding: 'UTF-8')
|
83
|
+
stylesheet = populate_template(stylesheet, :word)
|
84
|
+
stylesheet.gsub!(/(\s|\{)mso-[^:]+:[^;]+;/m, '\\1') if stripwordcss
|
85
|
+
if File.extname(filename) == '.scss'
|
86
|
+
stylesheet = convert_scss(filename, stylesheet, stripwordcss)
|
87
|
+
end
|
88
|
+
Tempfile.open([File.basename(filename, '.*'), 'css'],
|
89
|
+
encoding: 'utf-8') do |f|
|
90
|
+
f.write(stylesheet)
|
91
|
+
f
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|