[ANN] GWK - Version 0.6a Released

217 views
Skip to first unread message

buzzlight

unread,
Jun 5, 2013, 3:28:15 AM6/5/13
to golan...@googlegroups.com
- add viewengine, support temlate layout & partial template, you can find examples at ./test/views and ./demo/basic/views
- design new UI of demo project with bootstrap  
- add compressResponseWriter to compress response  
- route can use regexp to match request 
- bugs fix  and some new demo  

How to run demo

cd ./demo/basic  
go run main.go  



Mateusz Czapliński

unread,
Jun 5, 2013, 7:28:30 AM6/5/13
to golan...@googlegroups.com
Would Thou Fancy Issuing Textual Summary? (helps interpret details)

buzzlight

unread,
Jun 5, 2013, 10:02:10 PM6/5/13
to golan...@googlegroups.com
sorry for my bad English

1: view engine

add Temlate Func
---
eq //equal
eqs //format to string then compare
gt //greater than
le //less than
set //// set a map[string]interface{}
raw //unescaped html
selected //output "selected" or ""
checked // output "checked" or ""
nl2br // replace \n to <br/>
jsvar // convert data to javascript variable, like var name = {...}
import // import a layout file
incl // slice include

a example
---

{{set . "title" "title demo" }}
{{import "_layout.html" }}

{{define "head" }}
<script type="text/javascript">
</script>
<style>
div{padding: 10px;}
</style>
{{end}}

{{define "body" }}

<h1>hello gwk!</h1>

{{raw  "<!-- <script><style><html>  -->"}}

<div>
<lable for="selected">selected</lable>
<select id="selected">
<option value="" ></option>
<option value="selected" {{selected true}}>selected</option>
</select>
<lable for="notselected">not selected</lable>
<select id="notselected">
<option value="" ></option>
<option value="notselected" {{selected false}}>not selected</option>
</select>
</div>

<div>
<input id="checked" type="checkbox" {{checked true}}>checked</input>
<input id="notchecked" type="checkbox" {{checked false}}>not checked</input>
</div>

<ul>
<li id="eq">eq 123 123 = {{eq 123 123}}</li>
<li id="eq">eqs "123" 123 = {{eqs "123" 123}}</li>
<li id="gt">gt 3.14 3 = {{gt 3.14 3}}</li>
<li id="le">le 1.1 2 = {{le 1.1 2}}</li>
</ul>

<div>{{nl2br "a\nb\nc" }}</div>

<div id="settest-before">settest-before = {{.settest}}</div>
{{set . "settest" "true"}}
<div id="settest-after">settest-after = {{.settest}}</div>

{{partial "user.html" .user}}

{{end}}

{{define "script" }}

<script>
{{jsvar "user" .user}}
</script>

{{end}}


the output is 

2
redesign demo project, all demo & document will be integrated in this demo project, run main.go can see all changes

3
add compressResponseWriter to compress response  
// compressResponseWriter wrap gzip/deflate and ResponseWriter
type compressResponseWriter struct {
rw            http.ResponseWriter
writer        compresser
contentType   string
format        string
headerWritten bool
}

in previous version, gwk use CompressResult to compress http response, it's not flexible.


4
now, you can route with regexp like 

srv.RouteTable.Regexp("*", "^/user/?(?P<action>[[:alnum:]]+)?/?(?P<arg>[[:alnum:]]+)?/?").ToController(NewUserController())

it equals to 

srv.RouteTable.Path("/user#/{action}/{arg}").ToController(NewUserController())



Reply all
Reply to author
Forward
0 new messages