def preprocess_conditional_inclusion directive, target, delimiter, text
if ((directive == 'ifdef' || directive == 'ifndef') && target.empty?) ||
(directive == 'endif' && text)
return false
end
target = target.downcase
if directive == 'endif'
stack_size = @conditional_stack.size
if stack_size > 0
pair = @conditional_stack[-1]
if target.empty? || target == pair[:target]
@conditional_stack.pop
@skipping = @conditional_stack.empty? ? false : @conditional_stack[-1][:skipping]
else
warn %(asciidoctor: ERROR: #{line_info}: mismatched macro: endif::#{target}[], expected endif::#{pair[:target]}[])
end
else
warn %(asciidoctor: ERROR: #{line_info}: unmatched macro: endif::#{target}[])
end
return true
end
skip = false
unless @skipping
case directive
when 'ifdef'
case delimiter
when nil
skip = !@document.attributes.has_key?(target)
when ','
skip = !target.split(',').detect {|name| @document.attributes.has_key? name }
when '+'
skip = target.split('+').detect {|name| !@document.attributes.has_key? name }
end
when 'ifndef'
case delimiter
when nil
skip = @document.attributes.has_key?(target)
when ','
skip = !target.split(',').detect {|name| !@document.attributes.has_key? name }
when '+'
skip = target.split('+').detect {|name| @document.attributes.has_key? name }
end
when 'ifeval'
if !target.empty? || !(expr_match = EvalExpressionRx.match(text.strip))
return false
end
lhs = resolve_expr_val expr_match[1]
rhs = resolve_expr_val expr_match[3]
if (op = expr_match[2]) == '!='
skip = lhs.send :==, rhs
else
skip = !(lhs.send op.to_sym, rhs)
end
end
end
if directive == 'ifeval' || !text
@skipping = true if skip
@conditional_stack << {:target => target, :skip => skip, :skipping => @skipping}
else
unless @skipping || skip
conditional_line = peek_line true
replace_next_line text.rstrip
unshift conditional_line
return true
end
end
true
end