Skip to content
Browse files

Commit code

  • Loading branch information...
0 parents commit e6665d6cdb5f446a922afb6875b6b66ca0e0d23c @carsongross committed Jul 24, 2011
Showing with 72 additions and 0 deletions.
  1. +6 −0 bin/run.gsp
  2. +28 −0 src/html/Example.gs
  3. +4 −0 src/html/HtmlUtils.gs
  4. +34 −0 src/html/HtmlUtilsEnhancement.gsx
6 bin/run.gsp
@@ -0,0 +1,6 @@
+classpath "../src"
+
+uses html.Example
+
+var x = new Example()
+print( x.generateHtml() )
28 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 src/html/HtmlUtils.gs
@@ -0,0 +1,4 @@
+package html
+
+interface HtmlUtils {
+}
34 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.
Something went wrong with that request. Please try again.