Skip to content

Commit

Permalink
resolves #429 require space on either side of math operator (PR #433)
Browse files Browse the repository at this point in the history
- don't evaluate math in theme keys used for content
- short-circuit keys for font catalog and fallbacks earlier
- minor optimizations
  • Loading branch information
mojavelinux committed May 2, 2016
1 parent 27b2cf6 commit f014b17
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions lib/asciidoctor-pdf/theme_loader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ class ThemeLoader
LoneVariableRx = /^\$([a-z0-9_]+)$/
HexColorEntryRx = /^(?<k>[[:blank:]]*[[:graph:]]+): +(?<q>["']?)#?(?<v>\w{3,6})\k<q> *(?:#.*)?$/
MeasurementValueRx = /(?<=^| |\()(-?\d+(?:\.\d+)?)(in|mm|cm|pt)(?=$| |\))/
MultiplyDivideOpRx = /(-?\d+(?:\.\d+)?) *([*\/]) *(-?\d+(?:\.\d+)?)/
AddSubtractOpRx = /(-?\d+(?:\.\d+)?) *([+\-]) *(-?\d+(?:\.\d+)?)/
MultiplyDivideOpRx = /(-?\d+(?:\.\d+)?) +([*\/]) +(-?\d+(?:\.\d+)?)/
AddSubtractOpRx = /(-?\d+(?:\.\d+)?) +([+\-]) +(-?\d+(?:\.\d+)?)/
PrecisionFuncRx = /^(round|floor|ceil)\(/

# TODO implement white? & black? methods
Expand Down Expand Up @@ -86,17 +86,23 @@ def load hash, theme_data = nil
private

def process_entry key, val, data
if key.start_with? 'admonition_icon_'
if key.start_with? 'font_'
data[key] = val
elsif key.start_with? 'admonition_icon_'
data[key] = (val || {}).map do |(key2, val2)|
static_val2 = evaluate val2, data
[key2.to_sym, (key2.end_with? '_color') ? to_color(static_val2) : static_val2]
[key2.to_sym, (key2.end_with? '_color') ? to_color(evaluate val2, data) : (evaluate val2, data)]
end.to_h
elsif key != 'font_catalog' && ::Hash === val
elsif ::Hash === val
val.each do |key2, val2|
process_entry %(#{key}_#{key2.tr '-', '_'}), val2, data
end
elsif key.end_with? '_color'
# QUESTION do we need to evaluate_math in this case?
data[key] = to_color(evaluate val, data)
elsif %(#{key.chomp '_'}_).include? '_content_'
data[key] = expand_vars val, data
else
data[key] = (key.end_with? '_color') ? to_color(evaluate val, data) : (evaluate val, data)
data[key] = evaluate val, data
end
data
end
Expand Down

0 comments on commit f014b17

Please sign in to comment.