#!/usr/bin/env python

import os
import robot
from robot.result.jsparser import create_datamodel_from

BASEDIR = os.path.dirname(__file__)
TESTDATA = os.path.join(BASEDIR, 'dir.suite')
OUTPUT = os.path.join(BASEDIR, 'output.xml')
TARGET = os.path.join(BASEDIR, 'data.js')

if __name__ == '__main__':
    robot.run(TESTDATA, log='NONE', report='NONE',
              tagstatlink=['force:http://google.com:<kuukkeli&gt;',
                           'i*:http://%1/:Title of i%1'],
              tagdoc=['test:this_is_*my_bold*_test',
                      'IX:*Combined* & escaped <&lt; tag doc'],
              tagstatcombine=['fooANDi*:zap', 'i?:IX'],
              critical=['i?'], noncritical=['*kek*kone*'], outputdir=BASEDIR)
    model = create_datamodel_from(OUTPUT)
    model.set_settings({'logURL': 'log.html',
                        'reportURL': 'report.html',
                        'background': {'fail': 'DeepPink'}})
    with open(TARGET, 'w') as output:
        model.write_to(output)


@@ -270,33 +270,48 @@
 ')%0A%0A
-if __name__ == '__main__'
+def run_robot(outputdirectory, testdata)
 :%0A  
@@ -322,24 +322,24 @@
 bot.run(
-TESTDATA
+testdata
 , log='N
@@ -731,16 +731,70 @@
 dir=
-BASEDIR)
+outputdirectory)%0A%0A%0Adef create_jsdata(output_xml_file, target):
 %0A   
@@ -824,22 +824,31 @@
 el_from(
-OUTPUT
+output_xml_file
 )%0A    mo
@@ -1014,22 +1014,22 @@
 th open(
-TARGET
+target
 , 'w') a
@@ -1070,8 +1070,103 @@
 utput)%0A%0A
+if __name__ == '__main__':%0A    run_robot(BASEDIR, TESTDATA)%0A    create_jsdata(OUTPUT, TARGET)%0A%0A

refactor create_jsdata -- preparation for jasmine spec data generator