module ReDuxml
Public Instance Methods
resolve(path=nil)
click to toggle source
generates new doc from current doc, resolving parameter values and instantiating Instance objects, and pruning filtered objonents.
# File lib/re_dux.rb, line 62 def resolve(path=nil) io = File.open path saxer = ResolverClass.new(Duxml::Doc.new) Ox.sax_parse(saxer, io, {convert_special: true, symbolize: false}) saxer.cursor end
Private Instance Methods
find_close_parens_index(str)
click to toggle source
finds index of close parentheses corresponding to first open parentheses found in given str
# File lib/re_dux.rb, line 72 def find_close_parens_index(str) levels = 0 index = 0 str.each_char do |char| case char when '(' then levels += 1 when ')' then levels -= 1 else end return index if levels == 0 index += 1 end raise Exception, "cannot find end of parameter expression!" end
find_expr(str)
click to toggle source
finds macro expression within given string e.g. find_expr
'asdf @(param) asdf' => 'param'
# File lib/re_dux.rb, line 102 def find_expr(str) expr_start_index = str.index('@(') return nil if expr_start_index.nil? expr_end_index = find_close_parens_index str[expr_start_index+1..-1] str[expr_start_index+2, expr_end_index-1] end
find_non_inst_ancestor(node)
click to toggle source
returns first ancestor that is NOT an Instance
# File lib/re_dux.rb, line 110 def find_non_inst_ancestor(node) cur = node.parent return if cur.nil? if cur.respond_to?(:params) && cur.simple_class != 'design' find_non_inst_ancestor cur else cur end end
resolve_str(content_str, param_hash)
click to toggle source
takes given potentially parameterized string, applies given param_hash's values, then resolves parameter expressions returning resolved result
# File lib/re_dux.rb, line 91 def resolve_str(content_str, param_hash) question = find_expr content_str return content_str if question.nil? reply = Macro.new e.evaluate(question, param_hash) replacement_str = reply.parameterized? ? reply : reply.demacro macro_string = Macro.new(question) content_str.gsub(macro_string, replacement_str) end