Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- OperatorTable addAssignOperator(":", "addEntry")
- Builder := Object clone
- Builder curlyBrackets := method(
- m := Map clone
- call message arguments foreach(arg, m doString(arg asString))
- m
- )
- Map addEntry := method(
- self atPut(
- call evalArgAt(0) asMutable removePrefix("\"") removeSuffix("\""),
- call evalArgAt(1))
- )
- Builder increaseLevel := method(
- if (self level == 0,
- self level = 4,
- self level := 4 + self level)
- )
- Builder decreaseLevel := method(
- if (self level == 0,
- 0, self level := self level - 4)
- )
- Builder printStringWithOffset := method(string,
- writeln(string alignRight(self level + string size))
- )
- Builder level := 0
- Builder forward := method(
- hasAttributes := (call message argAt(0) asString beginsWithSeq("curlyBrackets"))
- (hasAttributes) ifFalse(printStringWithOffset("<" .. (call message name) .. ">"))
- tagClosed := false
- call message arguments foreach(arg,
- self increaseLevel
- content := self doMessage(arg)
- self decreaseLevel
- if (content type == "Map",
- attributes := ""
- content foreach(key, val,
- attributes = attributes .. key .. "=\"" .. val .. "\" ")
- closingBracket := ">"
- if (call message arguments size == 1,
- closingBracket = "/>"
- tagClosed = true
- )
- printStringWithOffset("<" .. (call message name) .. " " .. attributes .. closingBracket)
- )
- if (content type == "Sequence",
- self increaseLevel
- printStringWithOffset(content)
- self decreaseLevel
- )
- )
- (tagClosed) ifFalse(printStringWithOffset("</" .. (call message name) .. ">"))
- )
- //Example
- Builder html(
- {"xmlns:c":"http://java.sun.com/jsp/jstl/core", "xmlns:fn":"http://java.sun.com/jsp/jstl/functions"},
- head(title("Hello")),
- body(
- {"bgcolor":"white"},
- img({"src":"duke.waving.gif"}),
- h2("My name is Duke. What is yours?")
- form(
- {"method":"get"},
- input({"type":"text", "name":"username", "size":"25"}),
- p(""),
- input({"type":"submit", "value":"Submit"}),
- input({"type":"reset", "value":"Reset"})
- ),
- jsp:useBean({"id":"userNameBean", "class":"hello.UserNameBean", "scope":"request"}),
- jsp:setProperty({"name":"userNameBean", "property":"name", "value":"${param.username}"}),
- c:if(
- {"test":"${fn:length(userBeanName.name) gt 0}"},
- jsp:directive.include({"file":"response.jsp"})
- )
- )
- )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement