asciidoctor-pdf 1.5.0.beta.1 → 1.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.adoc +277 -2
- data/LICENSE.adoc +1 -1
- data/NOTICE.adoc +1 -1
- data/README.adoc +486 -292
- data/asciidoctor-pdf.gemspec +12 -11
- data/bin/asciidoctor-pdf +2 -6
- data/bin/asciidoctor-pdf-optimize +20 -0
- data/data/fonts/ABOUT-mplus1mn-subset +26 -0
- data/data/fonts/ABOUT-mplus1p-subset +26 -0
- data/data/fonts/ABOUT-notoemoji-subset +3 -0
- data/data/fonts/ABOUT-notoserif-subset +26 -0
- data/data/fonts/{LICENSE-mplus-testflight-58 → LICENSE-mplus} +2 -2
- data/data/fonts/{LICENSE-noto-2015-06-05 → LICENSE-notoserif} +0 -0
- data/data/fonts/mplus1mn-bold-ascii.ttf +0 -0
- data/data/fonts/mplus1mn-bold-subset.ttf +0 -0
- data/data/fonts/mplus1mn-bold_italic-ascii.ttf +0 -0
- data/data/fonts/mplus1mn-bold_italic-subset.ttf +0 -0
- data/data/fonts/mplus1mn-italic-ascii.ttf +0 -0
- data/data/fonts/mplus1mn-italic-subset.ttf +0 -0
- data/data/fonts/mplus1mn-regular-ascii-conums.ttf +0 -0
- data/data/fonts/mplus1mn-regular-subset.ttf +0 -0
- data/data/fonts/mplus1p-regular-fallback.ttf +0 -0
- data/data/fonts/notoemoji-subset.ttf +0 -0
- data/data/fonts/notoserif-bold-subset.ttf +0 -0
- data/data/fonts/notoserif-bold_italic-subset.ttf +0 -0
- data/data/fonts/notoserif-italic-subset.ttf +0 -0
- data/data/fonts/notoserif-regular-subset.ttf +0 -0
- data/data/themes/base-theme.yml +22 -4
- data/data/themes/default-theme.yml +59 -29
- data/data/themes/default-with-fallback-font-theme.yml +4 -17
- data/docs/theming-guide.adoc +1647 -167
- data/lib/asciidoctor/pdf/converter.rb +4489 -0
- data/lib/{asciidoctor-pdf/asciidoctor_ext → asciidoctor/pdf/ext/asciidoctor}/abstract_block.rb +2 -0
- data/lib/asciidoctor/pdf/ext/asciidoctor/abstract_node.rb +7 -0
- data/lib/{asciidoctor-pdf/asciidoctor_ext → asciidoctor/pdf/ext/asciidoctor}/document.rb +2 -0
- data/lib/asciidoctor/pdf/ext/asciidoctor/image.rb +35 -0
- data/lib/{asciidoctor-pdf/asciidoctor_ext → asciidoctor/pdf/ext/asciidoctor}/list.rb +4 -2
- data/lib/{asciidoctor-pdf/asciidoctor_ext → asciidoctor/pdf/ext/asciidoctor}/list_item.rb +3 -1
- data/lib/asciidoctor/pdf/ext/asciidoctor/logging_shim.rb +33 -0
- data/lib/{asciidoctor-pdf/asciidoctor_ext → asciidoctor/pdf/ext/asciidoctor}/section.rb +9 -6
- data/lib/asciidoctor/pdf/ext/asciidoctor.rb +11 -0
- data/lib/{asciidoctor-pdf/core_ext → asciidoctor/pdf/ext/core}/array.rb +6 -0
- data/lib/asciidoctor/pdf/ext/core/file.rb +9 -0
- data/lib/{asciidoctor-pdf/core_ext → asciidoctor/pdf/ext/core}/hash.rb +2 -0
- data/lib/{asciidoctor-pdf/core_ext → asciidoctor/pdf/ext/core}/numeric.rb +5 -3
- data/lib/{asciidoctor-pdf/core_ext → asciidoctor/pdf/ext/core}/object.rb +3 -1
- data/lib/{asciidoctor-pdf/core_ext → asciidoctor/pdf/ext/core}/quantifiable_stdout.rb +9 -1
- data/lib/{asciidoctor-pdf/core_ext → asciidoctor/pdf/ext/core}/regexp.rb +2 -0
- data/lib/{asciidoctor-pdf/core_ext → asciidoctor/pdf/ext/core}/string.rb +9 -13
- data/lib/asciidoctor/pdf/ext/core.rb +10 -0
- data/lib/asciidoctor/pdf/ext/pdf-core/page.rb +54 -0
- data/lib/asciidoctor/pdf/ext/pdf-core/pdf_object.rb +8 -0
- data/lib/asciidoctor/pdf/ext/pdf-core.rb +4 -0
- data/lib/asciidoctor/pdf/ext/prawn/coderay_encoder.rb +117 -0
- data/lib/asciidoctor/pdf/ext/prawn/extensions.rb +922 -0
- data/lib/{asciidoctor-pdf/prawn_ext → asciidoctor/pdf/ext/prawn}/font/afm.rb +14 -10
- data/lib/asciidoctor/pdf/ext/prawn/font_metric_cache.rb +9 -0
- data/lib/asciidoctor/pdf/ext/prawn/formatted_text/box.rb +66 -0
- data/lib/{asciidoctor-pdf/prawn_ext → asciidoctor/pdf/ext/prawn}/formatted_text/fragment.rb +16 -12
- data/lib/asciidoctor/pdf/ext/prawn/images.rb +54 -0
- data/lib/asciidoctor/pdf/ext/prawn-svg/interface.rb +14 -0
- data/lib/{asciidoctor-pdf/prawn-svg_ext.rb → asciidoctor/pdf/ext/prawn-svg.rb} +3 -1
- data/lib/asciidoctor/pdf/ext/prawn-table/cell/asciidoc.rb +76 -0
- data/lib/{asciidoctor-pdf/prawn-table_ext → asciidoctor/pdf/ext/prawn-table}/cell/text.rb +6 -3
- data/lib/{asciidoctor-pdf/prawn-table_ext → asciidoctor/pdf/ext/prawn-table}/cell.rb +10 -10
- data/lib/asciidoctor/pdf/ext/prawn-table.rb +6 -0
- data/lib/{asciidoctor-pdf/prawn-templates_ext.rb → asciidoctor/pdf/ext/prawn-templates.rb} +2 -0
- data/lib/asciidoctor/pdf/ext/prawn.rb +9 -0
- data/lib/asciidoctor/pdf/ext/pygments.rb +34 -0
- data/lib/asciidoctor/pdf/ext/rouge/formatters/prawn.rb +208 -0
- data/lib/{asciidoctor-pdf/rouge_ext → asciidoctor/pdf/ext/rouge}/themes/asciidoctor_pdf_default.rb +2 -0
- data/lib/asciidoctor/pdf/ext/rouge.rb +5 -0
- data/lib/asciidoctor/pdf/ext.rb +9 -0
- data/lib/asciidoctor/pdf/formatted_text/formatter.rb +43 -0
- data/lib/asciidoctor/pdf/formatted_text/fragment_position_renderer.rb +14 -0
- data/lib/asciidoctor/pdf/formatted_text/inline_destination_marker.rb +21 -0
- data/lib/asciidoctor/pdf/formatted_text/inline_image_arranger.rb +134 -0
- data/lib/asciidoctor/pdf/formatted_text/inline_image_renderer.rb +51 -0
- data/lib/asciidoctor/pdf/formatted_text/inline_text_aligner.rb +22 -0
- data/lib/{asciidoctor-pdf → asciidoctor/pdf}/formatted_text/parser.rb +31 -7
- data/lib/{asciidoctor-pdf → asciidoctor/pdf}/formatted_text/parser.treetop +3 -4
- data/lib/asciidoctor/pdf/formatted_text/source_wrap.rb +43 -0
- data/lib/asciidoctor/pdf/formatted_text/text_background_and_border_renderer.rb +55 -0
- data/lib/asciidoctor/pdf/formatted_text/transform.rb +394 -0
- data/lib/{asciidoctor-pdf → asciidoctor/pdf}/formatted_text.rb +4 -0
- data/lib/asciidoctor/pdf/index_catalog.rb +133 -0
- data/lib/asciidoctor/pdf/measurements.rb +62 -0
- data/lib/asciidoctor/pdf/optimizer.rb +44 -0
- data/lib/asciidoctor/pdf/pdfmark.rb +41 -0
- data/lib/asciidoctor/pdf/roman_numeral.rb +128 -0
- data/lib/asciidoctor/pdf/sanitizer.rb +45 -0
- data/lib/asciidoctor/pdf/text_transformer.rb +116 -0
- data/lib/asciidoctor/pdf/theme_loader.rb +305 -0
- data/lib/asciidoctor/pdf/version.rb +8 -1
- data/lib/asciidoctor/pdf.rb +15 -1
- data/lib/asciidoctor-pdf/converter.rb +2 -3824
- data/lib/asciidoctor-pdf/version.rb +3 -6
- data/lib/asciidoctor-pdf.rb +3 -4
- metadata +130 -85
- data/lib/asciidoctor-pdf/asciidoctor_ext/image.rb +0 -24
- data/lib/asciidoctor-pdf/asciidoctor_ext/logging_shim.rb +0 -25
- data/lib/asciidoctor-pdf/asciidoctor_ext.rb +0 -8
- data/lib/asciidoctor-pdf/core_ext/ostruct.rb +0 -8
- data/lib/asciidoctor-pdf/core_ext.rb +0 -6
- data/lib/asciidoctor-pdf/formatted_text/formatter.rb +0 -40
- data/lib/asciidoctor-pdf/formatted_text/inline_destination_marker.rb +0 -21
- data/lib/asciidoctor-pdf/formatted_text/inline_image_arranger.rb +0 -160
- data/lib/asciidoctor-pdf/formatted_text/inline_image_renderer.rb +0 -46
- data/lib/asciidoctor-pdf/formatted_text/inline_text_aligner.rb +0 -20
- data/lib/asciidoctor-pdf/formatted_text/text_background_and_border_renderer.rb +0 -45
- data/lib/asciidoctor-pdf/formatted_text/transform.rb +0 -294
- data/lib/asciidoctor-pdf/implicit_header_processor.rb +0 -63
- data/lib/asciidoctor-pdf/index_catalog.rb +0 -127
- data/lib/asciidoctor-pdf/measurements.rb +0 -58
- data/lib/asciidoctor-pdf/pdf-core_ext/page.rb +0 -25
- data/lib/asciidoctor-pdf/pdf-core_ext/pdf_object.rb +0 -6
- data/lib/asciidoctor-pdf/pdf-core_ext.rb +0 -2
- data/lib/asciidoctor-pdf/pdfmark.rb +0 -33
- data/lib/asciidoctor-pdf/prawn-svg_ext/interface.rb +0 -10
- data/lib/asciidoctor-pdf/prawn-table_ext/cell/asciidoc.rb +0 -69
- data/lib/asciidoctor-pdf/prawn-table_ext.rb +0 -4
- data/lib/asciidoctor-pdf/prawn_ext/coderay_encoder.rb +0 -115
- data/lib/asciidoctor-pdf/prawn_ext/extensions.rb +0 -904
- data/lib/asciidoctor-pdf/prawn_ext/images.rb +0 -51
- data/lib/asciidoctor-pdf/prawn_ext.rb +0 -5
- data/lib/asciidoctor-pdf/roman_numeral.rb +0 -126
- data/lib/asciidoctor-pdf/rouge_ext/formatters/prawn.rb +0 -175
- data/lib/asciidoctor-pdf/rouge_ext/themes/bw.rb +0 -38
- data/lib/asciidoctor-pdf/rouge_ext.rb +0 -4
- data/lib/asciidoctor-pdf/sanitizer.rb +0 -101
- data/lib/asciidoctor-pdf/temporary_path.rb +0 -13
- data/lib/asciidoctor-pdf/theme_loader.rb +0 -280
- data/lib/asciidoctor-pdf/ttfunk_ext.rb +0 -8
@@ -1,280 +0,0 @@
|
|
1
|
-
require 'safe_yaml/load'
|
2
|
-
require 'ostruct'
|
3
|
-
require_relative 'core_ext/ostruct'
|
4
|
-
require_relative 'measurements'
|
5
|
-
|
6
|
-
module Asciidoctor
|
7
|
-
module PDF
|
8
|
-
class ThemeLoader
|
9
|
-
include ::Asciidoctor::PDF::Measurements
|
10
|
-
if defined? ::Asciidoctor::Logging
|
11
|
-
include ::Asciidoctor::Logging
|
12
|
-
else
|
13
|
-
include ::Asciidoctor::LoggingShim
|
14
|
-
end
|
15
|
-
|
16
|
-
DataDir = ::File.expand_path(::File.join(::File.dirname(__FILE__), '..', '..', 'data'))
|
17
|
-
ThemesDir = ::File.join DataDir, 'themes'
|
18
|
-
FontsDir = ::File.join DataDir, 'fonts'
|
19
|
-
DefaultThemePath = ::File.expand_path 'default-theme.yml', ThemesDir
|
20
|
-
BaseThemePath = ::File.expand_path 'base-theme.yml', ThemesDir
|
21
|
-
|
22
|
-
VariableRx = /\$([a-z0-9_-]+)/
|
23
|
-
LoneVariableRx = /^\$([a-z0-9_-]+)$/
|
24
|
-
HexColorEntryRx = /^(?<k> *\p{Graph}+): +(?!null$)(?<q>["']?)(?<h>#)?(?<v>[a-f0-9]{3,6})\k<q> *(?:#.*)?$/
|
25
|
-
MultiplyDivideOpRx = /(-?\d+(?:\.\d+)?) +([*\/]) +(-?\d+(?:\.\d+)?)/
|
26
|
-
AddSubtractOpRx = /(-?\d+(?:\.\d+)?) +([+\-]) +(-?\d+(?:\.\d+)?)/
|
27
|
-
PrecisionFuncRx = /^(round|floor|ceil)\(/
|
28
|
-
|
29
|
-
# TODO implement white? & black? methods
|
30
|
-
module ColorValue; end
|
31
|
-
|
32
|
-
class HexColorValue < String
|
33
|
-
include ColorValue
|
34
|
-
end
|
35
|
-
|
36
|
-
# A marker module for a normalized CMYK array
|
37
|
-
# Prevents normalizing CMYK value more than once
|
38
|
-
module CMYKColorValue
|
39
|
-
include ColorValue
|
40
|
-
def to_s
|
41
|
-
%([#{join ', '}])
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
def self.resolve_theme_file theme_name = nil, theme_path = nil
|
46
|
-
# if .yml extension is given, assume it's a path (don't append -theme.yml)
|
47
|
-
if ((theme_name ||= 'default').end_with? '.yml')
|
48
|
-
# FIXME restrict to jail!
|
49
|
-
theme_file = ::File.expand_path theme_name, theme_path
|
50
|
-
theme_path ||= ::File.dirname theme_file
|
51
|
-
else
|
52
|
-
theme_file = ::File.expand_path %(#{theme_name}-theme.yml), (theme_path || (theme_path = ThemesDir))
|
53
|
-
end
|
54
|
-
[theme_file, theme_path]
|
55
|
-
end
|
56
|
-
|
57
|
-
def self.resolve_theme_asset asset_path, theme_path
|
58
|
-
::File.expand_path asset_path, (theme_path || ThemesDir)
|
59
|
-
end
|
60
|
-
|
61
|
-
# NOTE base theme is loaded "as is" (no post-processing)
|
62
|
-
def self.load_base_theme
|
63
|
-
(::OpenStruct.new ::SafeYAML.load_file BaseThemePath).tap {|theme| theme.__dir__ = ThemesDir }
|
64
|
-
end
|
65
|
-
|
66
|
-
def self.load_theme theme_name = nil, theme_path = nil
|
67
|
-
theme_file, theme_path = resolve_theme_file theme_name, theme_path
|
68
|
-
if theme_file == BaseThemePath
|
69
|
-
load_base_theme
|
70
|
-
else
|
71
|
-
theme_data = load_file theme_file, nil, theme_path
|
72
|
-
unless theme_file == DefaultThemePath
|
73
|
-
# QUESTION should we enforce any other fallback values?
|
74
|
-
theme_data.base_align ||= 'left'
|
75
|
-
theme_data.code_font_family ||= (theme_data.literal_font_family || 'Courier')
|
76
|
-
theme_data.conum_font_family ||= (theme_data.literal_font_family || 'Courier')
|
77
|
-
end
|
78
|
-
theme_data.__dir__ = theme_path
|
79
|
-
theme_data
|
80
|
-
end
|
81
|
-
end
|
82
|
-
|
83
|
-
def self.load_file filename, theme_data = nil, theme_path = nil
|
84
|
-
data = ::File.read filename, encoding: ::Encoding::UTF_8
|
85
|
-
data = data.each_line.map {|l|
|
86
|
-
l.sub(HexColorEntryRx) { %(#{(m = $~)[:k]}: #{m[:h] || (m[:k].end_with? 'color') ? "'#{m[:v]}'" : m[:v]}) }
|
87
|
-
}.join unless filename == DefaultThemePath
|
88
|
-
yaml_data = ::SafeYAML.load data
|
89
|
-
if ::Hash === yaml_data && (yaml_data.key? 'extends')
|
90
|
-
if (extends = yaml_data.delete 'extends')
|
91
|
-
[*extends].each do |extend_file|
|
92
|
-
if extend_file == 'base'
|
93
|
-
theme_data = theme_data ? (::OpenStruct.new theme_data.to_h.merge load_base_theme.to_h) : load_base_theme
|
94
|
-
next
|
95
|
-
elsif extend_file == 'default' || extend_file == 'default-with-fallback-font'
|
96
|
-
extend_file, extend_theme_path = resolve_theme_file extend_file
|
97
|
-
elsif extend_file.start_with? './'
|
98
|
-
extend_file, extend_theme_path = resolve_theme_file extend_file, (::File.dirname filename)
|
99
|
-
else
|
100
|
-
extend_file, extend_theme_path = resolve_theme_file extend_file, theme_path
|
101
|
-
end
|
102
|
-
theme_data = load_file extend_file, theme_data, extend_theme_path
|
103
|
-
end
|
104
|
-
end
|
105
|
-
else
|
106
|
-
theme_data ||= (filename == DefaultThemePath ? nil : load_base_theme)
|
107
|
-
end
|
108
|
-
self.new.load yaml_data, theme_data, theme_path
|
109
|
-
end
|
110
|
-
|
111
|
-
def load hash, theme_data = nil, theme_path = nil
|
112
|
-
::Hash === hash ? hash.reduce(theme_data || ::OpenStruct.new) {|data, (key, val)| process_entry key, val, data } : (theme_data || ::OpenStruct.new)
|
113
|
-
end
|
114
|
-
|
115
|
-
private
|
116
|
-
|
117
|
-
def process_entry key, val, data
|
118
|
-
key = key.tr '-', '_' if key.include? '-'
|
119
|
-
if key == 'font_catalog' || key == 'font_fallbacks'
|
120
|
-
data[key] = val
|
121
|
-
elsif key.start_with? 'admonition_icon_'
|
122
|
-
data[key] = (val || {}).map do |(key2, val2)|
|
123
|
-
[key2.to_sym, (key2.end_with? '_color') ? to_color(evaluate val2, data) : (evaluate val2, data)]
|
124
|
-
end.to_h
|
125
|
-
elsif ::Hash === val
|
126
|
-
val.each {|subkey, subval| process_entry %(#{key}_#{subkey}), subval, data }
|
127
|
-
elsif key.end_with? '_color'
|
128
|
-
# QUESTION do we really need to evaluate_math in this case?
|
129
|
-
data[key] = to_color(evaluate val, data)
|
130
|
-
elsif %(#{key.chomp '_'}_).include? '_content_'
|
131
|
-
data[key] = (expand_vars val.to_s, data).to_s
|
132
|
-
else
|
133
|
-
data[key] = evaluate val, data
|
134
|
-
end
|
135
|
-
data
|
136
|
-
end
|
137
|
-
|
138
|
-
def evaluate expr, vars
|
139
|
-
case expr
|
140
|
-
when ::String
|
141
|
-
evaluate_math(expand_vars expr, vars)
|
142
|
-
when ::Array
|
143
|
-
expr.map {|e| evaluate e, vars }
|
144
|
-
else
|
145
|
-
expr
|
146
|
-
end
|
147
|
-
end
|
148
|
-
|
149
|
-
# NOTE we assume expr is a String
|
150
|
-
def expand_vars expr, vars
|
151
|
-
if (idx = (expr.index '$'))
|
152
|
-
if idx == 0 && expr =~ LoneVariableRx
|
153
|
-
if (key = $1).include? '-'
|
154
|
-
key = key.tr '-', '_'
|
155
|
-
end
|
156
|
-
if vars.respond_to? key
|
157
|
-
vars[key]
|
158
|
-
else
|
159
|
-
logger.warn %(unknown variable reference in PDF theme: $#{$1})
|
160
|
-
expr
|
161
|
-
end
|
162
|
-
else
|
163
|
-
expr.gsub(VariableRx) do
|
164
|
-
if (key = $1).include? '-'
|
165
|
-
key = key.tr '-', '_'
|
166
|
-
end
|
167
|
-
if vars.respond_to? key
|
168
|
-
vars[key]
|
169
|
-
else
|
170
|
-
logger.warn %(unknown variable reference in PDF theme: $#{$1})
|
171
|
-
$&
|
172
|
-
end
|
173
|
-
end
|
174
|
-
end
|
175
|
-
else
|
176
|
-
expr
|
177
|
-
end
|
178
|
-
end
|
179
|
-
|
180
|
-
def evaluate_math expr
|
181
|
-
return expr if !(::String === expr) || ColorValue === expr
|
182
|
-
# resolve measurement values (e.g., 0.5in => 36)
|
183
|
-
# QUESTION should we round the value? perhaps leave that to the precision functions
|
184
|
-
# NOTE leave % as a string; handled by converter for now
|
185
|
-
expr = resolve_measurement_values(original = expr)
|
186
|
-
while true
|
187
|
-
if (expr.count '*/') > 0
|
188
|
-
result = expr.gsub(MultiplyDivideOpRx) { $1.to_f.send $2.to_sym, $3.to_f }
|
189
|
-
unchanged = (result == expr)
|
190
|
-
expr = result
|
191
|
-
break if unchanged
|
192
|
-
else
|
193
|
-
break
|
194
|
-
end
|
195
|
-
end
|
196
|
-
while true
|
197
|
-
if (expr.count '+-') > 0
|
198
|
-
result = expr.gsub(AddSubtractOpRx) { $1.to_f.send $2.to_sym, $3.to_f }
|
199
|
-
unchanged = (result == expr)
|
200
|
-
expr = result
|
201
|
-
break if unchanged
|
202
|
-
else
|
203
|
-
break
|
204
|
-
end
|
205
|
-
end
|
206
|
-
if (expr.end_with? ')') && expr =~ PrecisionFuncRx
|
207
|
-
op = $1
|
208
|
-
offset = op.length + 1
|
209
|
-
expr = expr[offset...-1].to_f.send op.to_sym
|
210
|
-
end
|
211
|
-
if expr == original
|
212
|
-
original
|
213
|
-
else
|
214
|
-
(int_val = expr.to_i) == (flt_val = expr.to_f) ? int_val : flt_val
|
215
|
-
end
|
216
|
-
end
|
217
|
-
|
218
|
-
def to_color value
|
219
|
-
case value
|
220
|
-
when ColorValue
|
221
|
-
# already converted
|
222
|
-
return value
|
223
|
-
when ::Array
|
224
|
-
case value.length
|
225
|
-
# CMYK value
|
226
|
-
when 4
|
227
|
-
value = value.map do |e|
|
228
|
-
if ::Numeric === e
|
229
|
-
e = e * 100.0 unless e > 1
|
230
|
-
else
|
231
|
-
e = e.to_s.chomp('%').to_f
|
232
|
-
end
|
233
|
-
e == (int_e = e.to_i) ? int_e : e
|
234
|
-
end
|
235
|
-
case value
|
236
|
-
when [0, 0, 0, 0]
|
237
|
-
return HexColorValue.new 'FFFFFF'
|
238
|
-
when [100, 100, 100, 100]
|
239
|
-
return HexColorValue.new '000000'
|
240
|
-
else
|
241
|
-
value.extend CMYKColorValue
|
242
|
-
return value
|
243
|
-
end
|
244
|
-
# RGB value
|
245
|
-
when 3
|
246
|
-
return HexColorValue.new value.map {|e| '%02X' % e }.join
|
247
|
-
# Nonsense array value; flatten to string
|
248
|
-
else
|
249
|
-
value = value.join
|
250
|
-
end
|
251
|
-
when ::String
|
252
|
-
if value == 'transparent'
|
253
|
-
# FIXME should we have a TransparentColorValue class?
|
254
|
-
return HexColorValue.new value
|
255
|
-
elsif value.length == 6
|
256
|
-
return HexColorValue.new value.upcase
|
257
|
-
end
|
258
|
-
when ::NilClass
|
259
|
-
return nil
|
260
|
-
else
|
261
|
-
# Unknown type (usually Integer); coerce to String
|
262
|
-
if (value = value.to_s).length == 6
|
263
|
-
return HexColorValue.new value.upcase
|
264
|
-
end
|
265
|
-
end
|
266
|
-
value = case value.length
|
267
|
-
when 6
|
268
|
-
value
|
269
|
-
when 3
|
270
|
-
# expand hex shorthand (e.g., f00 -> ff0000)
|
271
|
-
value.each_char.map {|c| c * 2 }.join
|
272
|
-
else
|
273
|
-
# truncate or pad with leading zeros (e.g., ff -> 0000ff)
|
274
|
-
value[0..5].rjust 6, '0'
|
275
|
-
end
|
276
|
-
HexColorValue.new value.upcase
|
277
|
-
end
|
278
|
-
end
|
279
|
-
end
|
280
|
-
end
|