Created
February 6, 2012 08:03
-
-
Save brikis98/1750650 to your computer and use it in GitHub Desktop.
Seven Languages in Seven Weeks: Io, Day 3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
OperatorTable addAssignOperator(":", "atParseHash") | |
Builder := Object clone do ( | |
indent := "" | |
atParseHash := method( | |
key := call evalArgAt(0) asMutable removePrefix("\"") removeSuffix("\"") | |
value := call evalArgAt(1) | |
" #{key}=\"#{value}\"" interpolate | |
) | |
curlyBrackets := method( | |
call message arguments map(arg, self doMessage(arg)) join("") | |
) | |
forward := method( | |
arguments := call message arguments | |
name := call message name | |
attrs := "" | |
if(arguments size > 0 and arguments at(0) name == "curlyBrackets", | |
attrs = doMessage(arguments removeFirst) | |
) | |
writeln(indent, "<", name, attrs, ">") | |
arguments foreach(index, arg, | |
indent = indent .. " " | |
content := self doMessage(arg) | |
if (content type == "Sequence", writeln(indent, content)) | |
indent = indent exclusiveSlice(2) | |
) | |
writeln(indent, "</", name, ">") | |
) | |
) | |
doFile("BuilderNewTest.io") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
<title> | |
Test webpage | |
</title> | |
</head> | |
<body> | |
<h1> | |
Welcome to my test webpage! | |
</h1> | |
<div class="content" id="main"> | |
<p> | |
Lots of fun to be had! | |
</p> | |
<p> | |
Don't forget to sign the guest book | |
</p> | |
</div> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Builder html( | |
head( | |
title("Test webpage") | |
), | |
body( | |
h1("Welcome to my test webpage!"), | |
div({"class": "content", "id": "main"}, | |
p("Lots of fun to be had!"), | |
p("Don't forget to sign the guest book") | |
) | |
) | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Builder := Object clone do ( | |
forward := method( | |
writeln("<", call message name, ">") | |
call message arguments foreach(arg, | |
content := self doMessage(arg) | |
if (content type == "Sequence", writeln(content)) | |
) | |
writeln("</", call message name, ">") | |
) | |
) | |
doFile("BuilderOriginalTest.io") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
<title> | |
Test webpage | |
</title> | |
</head> | |
<body> | |
<h1> | |
Welcome to my test webpage! | |
</h1> | |
<div> | |
<p> | |
Lots of fun to be had! | |
</p> | |
<p> | |
Don't forget to sign the guest book | |
</p> | |
</div> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Builder html( | |
head( | |
title("Test webpage") | |
), | |
body( | |
h1("Welcome to my test webpage!"), | |
div( | |
p("Lots of fun to be had!"), | |
p("Don't forget to sign the guest book") | |
) | |
) | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
squareBrackets := method( | |
call message arguments | |
) | |
test := [1, 2, 3, 4] | |
test println // list(1, 2, 3, 4) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
doInTransaction := Object clone do( | |
curlyBrackets := method( | |
"Starting transaction" println | |
call evalArgs | |
"Ending transaction" println | |
) | |
) | |
doInTransaction { | |
"do some first thing" println | |
"do some second thing" println | |
"do a third thing" println | |
} | |
/* | |
Starting transaction | |
do some first thing | |
do some second thing | |
do a third thing | |
Ending transaction | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
See Seven Languages in Seven Weeks: Io, Day 3 for more information.