From e6665d6cdb5f446a922afb6875b6b66ca0e0d23c Mon Sep 17 00:00:00 2001 From: Carson Gross Date: Sun, 24 Jul 2011 14:34:02 -0700 Subject: [PATCH] Commit code --- bin/run.gsp | 6 ++++++ src/html/Example.gs | 28 +++++++++++++++++++++++++ src/html/HtmlUtils.gs | 4 ++++ src/html/HtmlUtilsEnhancement.gsx | 34 +++++++++++++++++++++++++++++++ 4 files changed, 72 insertions(+) create mode 100644 bin/run.gsp create mode 100644 src/html/Example.gs create mode 100644 src/html/HtmlUtils.gs create mode 100644 src/html/HtmlUtilsEnhancement.gsx diff --git a/bin/run.gsp b/bin/run.gsp new file mode 100644 index 0000000..cc8e13c --- /dev/null +++ b/bin/run.gsp @@ -0,0 +1,6 @@ +classpath "../src" + +uses html.Example + +var x = new Example() +print( x.generateHtml() ) \ No newline at end of file diff --git a/src/html/Example.gs b/src/html/Example.gs new file mode 100644 index 0000000..1d90e7a --- /dev/null +++ b/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" ) + } + ) + } + +} diff --git a/src/html/HtmlUtils.gs b/src/html/HtmlUtils.gs new file mode 100644 index 0000000..aec5527 --- /dev/null +++ b/src/html/HtmlUtils.gs @@ -0,0 +1,4 @@ +package html + +interface HtmlUtils { +} diff --git a/src/html/HtmlUtilsEnhancement.gsx b/src/html/HtmlUtilsEnhancement.gsx new file mode 100644 index 0000000..317c421 --- /dev/null +++ b/src/html/HtmlUtilsEnhancement.gsx @@ -0,0 +1,34 @@ +package html + +enhancement HtmlUtilsEnhancement : HtmlUtils { + + function html( head : String = "", body : List = null) : String { + var bodyContent = body == null ? "" : body.join( "\n" ) + return "\n${head}\n${bodyContent}\n" + } + + function head( title : String = "" ) : String { + return "${title}" + } + + function h1( content : String ) : String { + return "

${content}

" + } + + function p( content : String ) : String { + return "

${content}

" + } + + function p( content : List ) : String { + var bodyContent = content == null ? "" : content.join( "\n" ) + return "

${bodyContent}

" + } + + function b( content : String ) : String { + return "${content}" + } + + function ahref( url : String, content : String ) : String { + return "${content}" + } +}