lib/openwfe/expressions/fe_fqv.rb in openwferu-0.9.10.653 vs lib/openwfe/expressions/fe_fqv.rb in openwferu-0.9.11

- old
+ new

@@ -37,16 +37,19 @@ # "made in Japan" # # John Mettraux at openwfe.org # +require 'openwfe/rest/xmlcodec' require 'openwfe/expressions/flowexpression' # # 'f', 'q' and 'v' expressions # +# 'a' as well +# module OpenWFE # # This expression implementation gathers the 'f', 'q' and 'v' expressions, @@ -111,9 +114,64 @@ end def variable (text, workitem) self.lookup_variable(text) end + end + + # + # The 'a' or 'attribute' expression. Directly describing some + # variable or list content in XML or in YAML. + # + # _set :field => "list" do + # _a """ + # <list> + # <string>a</string> + # <string>b</string> + # <string>c</string> + # </list> + # """ + # end + # + # or + # + # _set :field => "list" do + # _attribute """ + # --- + # - a + # - b + # - c + # """ + # end + # + # Note that it's actually easier to write : + # + # _set :filed => "list" do + # reval "[ 'a', 'b', 'c' ]" + # end + # + # but it's less secure. + # + class AttributeExpression < FlowExpression + + names :a, :attribute + + def apply workitem + + text = fetch_text_content workitem + text = text.strip + + result = if text[0, 3] == "---" + YAML.load text + else + d = REXML::Document.new text + XmlCodec::decode_attribute d.root + end + + workitem.set_result(result) if result != nil + + reply_to_parent workitem + end end end