Skip to content

Commit

Permalink
Commit code
Browse files Browse the repository at this point in the history
  • Loading branch information
Carson Gross committed Jul 24, 2011
0 parents commit e6665d6
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 0 deletions.
6 changes: 6 additions & 0 deletions bin/run.gsp
@@ -0,0 +1,6 @@
classpath "../src"

uses html.Example

var x = new Example()
print( x.generateHtml() )
28 changes: 28 additions & 0 deletions src/html/Example.gs
@@ -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" )
}
)
}

}
4 changes: 4 additions & 0 deletions src/html/HtmlUtils.gs
@@ -0,0 +1,4 @@
package html

interface HtmlUtils {
}
34 changes: 34 additions & 0 deletions src/html/HtmlUtilsEnhancement.gsx
@@ -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>"
}
}

0 comments on commit e6665d6

Please sign in to comment.