diff options
author | Guillermo Ramos | 2012-05-03 14:11:55 +0200 |
---|---|---|
committer | Guillermo Ramos | 2012-05-05 14:35:04 +0200 |
commit | a36e9e7221841ffee75a8b35c07f3929240a0e17 (patch) | |
tree | 196fa58fa6c38c0179510c7e57dd96d9a1f03733 /io/xmlGen.io | |
parent | 83054326eb51ea73a8078a1e7feefae88107c3db (diff) | |
download | 7l-a36e9e7221841ffee75a8b35c07f3929240a0e17.tar.gz |
[Io] Día 3
Diffstat (limited to 'io/xmlGen.io')
-rw-r--r-- | io/xmlGen.io | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/io/xmlGen.io b/io/xmlGen.io new file mode 100644 index 0000000..1fa4b50 --- /dev/null +++ b/io/xmlGen.io @@ -0,0 +1,75 @@ +OperatorTable addAssignOperator(":", "atPutNumber") + +curlyBrackets := method( + m := Map clone + call message arguments foreach(arg, m doMessage(arg)) + m +) + +Map atPutNumber := method( + self atPut( + call evalArgAt(0) asMutable removePrefix("\"") removeSuffix("\""), + call evalArgAt(1) + ) +) + +Map asString := method( + pairs := Sequence asMutable + foreach(k,v, + pairs appendSeq(" #{k}=\"#{v}\"" interpolate) + ) + pairs +) + +xmlGen := Object clone do( + tabs := 0 + + ind_print := method(s, + "\t" repeated(tabs) print + s println + self + ) + + etiq := method(str, + ind_print("<" .. str .. ">") + self + ) + + indent_up := method(tabs = tabs+1) + indent_down := method(tabs = tabs-1) + + forward = method( + msgName := call message name + args := call message arguments + + if (args isEmpty not and args first name == "curlyBrackets") then ( + m := doString(args first asString) + etiq(msgName .. m) + args removeFirst + ) else ( + etiq(msgName) + ) + + indent_up + args foreach(arg, + m := doMessage(arg) + if (m type == "Sequence", + ind_print(arg) + ) + ) + indent_down + + etiq("/" .. msgName) + ) +) + +xmlGen html( + head( + title("Mi pagina"), + meta("robots") + ), + body( + p("Hola"), + a({"href":"google.es", "alt":"Google!"}, "URL") + ) +) |