Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Carson Gross
committed
Jul 24, 2011
0 parents
commit e6665d6
Showing
4 changed files
with
72 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
classpath "../src" | ||
|
||
uses html.Example | ||
|
||
var x = new Example() | ||
print( x.generateHtml() ) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package html | ||
|
||
class Example implements HtmlUtils { | ||
|
||
function generateHtml() : String { | ||
return html( | ||
:head = head( | ||
:title = "XML encoding with Gosu" | ||
), | ||
:body = { | ||
h1( "XML encoding with Gosu" ), | ||
p( "this format can be used as an alternative markup to XML" ), | ||
/* an element with attributes and text content */ | ||
ahref( 'http://gosu-lang.org', "Gosu"), | ||
/* mixed content */ | ||
p({ | ||
"This is some", | ||
b("mixed"), | ||
"text. For more see the", | ||
ahref('http://gosu-lang.org', "Gosu"), | ||
"project" | ||
}), | ||
p( "some text" ) | ||
} | ||
) | ||
} | ||
|
||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
package html | ||
|
||
interface HtmlUtils { | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package html | ||
|
||
enhancement HtmlUtilsEnhancement : HtmlUtils { | ||
|
||
function html( head : String = "", body : List<String> = null) : String { | ||
var bodyContent = body == null ? "" : body.join( "\n" ) | ||
return "<html><head>\n${head}</head>\n<body>${bodyContent}</body>\n</html>" | ||
} | ||
|
||
function head( title : String = "" ) : String { | ||
return "<title>${title}</title>" | ||
} | ||
|
||
function h1( content : String ) : String { | ||
return "<h1>${content}</h1>" | ||
} | ||
|
||
function p( content : String ) : String { | ||
return "<p>${content}</p>" | ||
} | ||
|
||
function p( content : List<String> ) : String { | ||
var bodyContent = content == null ? "" : content.join( "\n" ) | ||
return "<p>${bodyContent}</p>" | ||
} | ||
|
||
function b( content : String ) : String { | ||
return "<b>${content}</b>" | ||
} | ||
|
||
function ahref( url : String, content : String ) : String { | ||
return "<a href='${url}'>${content}</b>" | ||
} | ||
} |