From 711d71637229397b134bebc249c78d266fff3bdc Mon Sep 17 00:00:00 2001 From: cxl Date: Fri, 6 Jul 2012 13:16:37 +0000 Subject: [PATCH] .Skylark tutorial git-svn-id: svn://ultimatepp.org/upp/trunk@5138 f0d560ea-af0d-0410-9eb7-867de7ffcac7 --- uppsrc/Esc/srcdoc.tpp/Esc$en-us.tpp | 2 +- uppsrc/Esc/srcdoc.tpp/Esc$en-us.tppi | 2 +- uppsrc/Skylark/Skylark.upp | 1 + uppsrc/Skylark/src.tpp/Witz$en-us.tpp | 80 ++++++++++++++ uppsrc/Skylark/srcdoc.tpp/Tutorial$en-us.tpp | 103 ++++++++++++++++++- 5 files changed, 184 insertions(+), 4 deletions(-) create mode 100644 uppsrc/Skylark/src.tpp/Witz$en-us.tpp diff --git a/uppsrc/Esc/srcdoc.tpp/Esc$en-us.tpp b/uppsrc/Esc/srcdoc.tpp/Esc$en-us.tpp index 42f66a846..7fddf6f95 100644 --- a/uppsrc/Esc/srcdoc.tpp/Esc$en-us.tpp +++ b/uppsrc/Esc/srcdoc.tpp/Esc$en-us.tpp @@ -473,4 +473,4 @@ function, otherwise is unspecified).] :: [s0; [*C GetSysTime()]] :: [s0; Returns current time as map with `"second`", `"minute`", `"hour`", `"day`", `"month`" and `"year`" members.]}}&] -[s0; ] \ No newline at end of file +[s0; ]] \ No newline at end of file diff --git a/uppsrc/Esc/srcdoc.tpp/Esc$en-us.tppi b/uppsrc/Esc/srcdoc.tpp/Esc$en-us.tppi index 8c5cc3583..ab4ceeb49 100644 --- a/uppsrc/Esc/srcdoc.tpp/Esc$en-us.tppi +++ b/uppsrc/Esc/srcdoc.tpp/Esc$en-us.tppi @@ -19,5 +19,5 @@ COMPRESSED 178,213,174,234,84,69,76,11,13,222,60,220,37,21,212,89,244,193,217,182,69,198,67,163,215,29,70,235,235,174,71,212,206,95,79,81,73,230,166,151,79,63,108,35,1,78,129,56,103,218,122,254,74,79,127,92,226,64,219,61,1,254,219,2,196,222,247,112,159,152,182,38,91,15,159,221,204,67,31,121,242,107,252,25,72,201,247,129,249,250,102,97,70,165,109,231,157,37,186,216,114,199,128,228,188,254,219,79,250,93,27,238,140,152,177,186,209,78,10,25,191,119,162,229,85,188,86,248,250,240,38,41,205,85,69,38,11,154,68,167,224,72,56,190,81,64,105,186,216,21,168,120,181,229,84,37,251,195,197,15,49,108,231,6,143,183,211,27,99,105,170,175,109,109,94,193,161,19,142,207,245,113,42,76,109,186,169,72,50,26,207,243,171,3,4,90,159,174,235,183,58,129,125,122,110,46,212,249,134,198,190,49,135,231,86,165,210,239,214,235,45,202,121,143,0,182,203,132,46,4,150,200,55,221,108,33,156,11,192,56,218,16,185,36,21,150,184,171,46,35,2,241,36,52,116,12, 159,5,140,187,188,88,200,20,156,173,250,215,118,70,39,219,32,207,57,229,227,232,173,113,26,104,95,5,104,154,169,26,64,246,178,232,181,11,93,3,30,213,35,193,243,206,103,80,53,183,6,159,72,122,248,89,164,135,79,36,93,43,135,160,14,26,247,49,211,240,47,86,210,100,82,152,95,79,117,71,125,93,18,245,6,231,151,195,243,211,94,224,149,68,223,233,59,238,7,43,34,124,171,143,203,49,102,108,227,39,60,51,30,11,208,186,193,85,54,33,255,60,145,129,118,77,8,53,102,10,148,79,68,172,127,233,176,23,47,132,175,39,98,165,113,249,94,156,244,110,227,83,144,242,173,224,110,156,38,91,56,101,115,3,78,29,129,204,136,177,192,74,144,46,79,239,64,235,138,174,20,235,120,203,60,250,93,149,5,132,129,189,220,106,62,99,243,210,180,157,237,210,111,29,8,190,122,230,207,36,53,153,189,134,1,69,223,173,44,40,188,105,18,45,70,123,104,242,4,131,123,193,170,202,162,91,24,175,89,184,34,180,194,45,180,144,186,230,2,8,182,108,234,246,103,182, 4,91,91,50,99,74,102,75,245,106,151,251,187,46,186,213,175,189,134,229,96,32,179,105,128,175,222,30,38,112,122,235,163,33,99,122,115,124,204,178,45,47,133,111,25,4,203,146,95,203,85,230,149,146,22,189,118,64,191,242,85,85,26,138,249,247,142,227,35,77,45,116,222,133,177,86,73,63,115,202,236,171,155,222,53,9,3,62,158,41,125,115,253,72,182,240,8,159,192,20,254,22,179,213,192,133,254,141,166,214,3,8,159,127,108,213,237,116,250,189,243,179,115,15,9,254,196,65,201,90,197,214,124,56,189,115,86,205,248,188,34,36,47,202,71,160,81,244,178,238,46,36,36,169,71,98,225,205,77,63,109,220,129,252,90,125,11,5,204,131,90,164,248,133,122,179,191,250,140,14,102,241,125,116,128,47,226,46,225,217,34,58,160,226,35,58,184,151,113,1,95,80,129,123,98,220,181,250,37,89,126,26,93,158,153,105,210,80,111,149,146,63,47,242,117,193,159,246,115,182,148,244,22,220,30,230,254,71,150,239,238,153,193,6,158,166,235,162,160,119,104,19,182,88,235,194, -255,53,214,156,241,70,248,31,156,179,231,1, +255,53,214,156,241,70,24,254,7,132,32,231,94, diff --git a/uppsrc/Skylark/Skylark.upp b/uppsrc/Skylark/Skylark.upp index 972fe88f9..685d8f770 100644 --- a/uppsrc/Skylark/Skylark.upp +++ b/uppsrc/Skylark/Skylark.upp @@ -27,6 +27,7 @@ file Base.witz, skylark.js, Info readonly separator, + src.tpp, srcdoc.tpp; custom() ".css", diff --git a/uppsrc/Skylark/src.tpp/Witz$en-us.tpp b/uppsrc/Skylark/src.tpp/Witz$en-us.tpp new file mode 100644 index 000000000..04f55a43c --- /dev/null +++ b/uppsrc/Skylark/src.tpp/Witz$en-us.tpp @@ -0,0 +1,80 @@ +topic "Witz template language"; +[2 $$0,0#00000000000000000000000000000000:Default] +[l288;i1120;a17;O9;~~~.1408;2 $$1,0#10431211400427159095818037425705:param] +[a83;*R6 $$2,5#31310162474203024125188417583966:caption] +[H4;b83;*4 $$3,5#07864147445237544204411237157677:title] +[i288;O9;C2 $$4,6#40027414424643823182269349404212:item] +[b42;a42;2 $$5,5#45413000475342174754091244180557:text] +[l288;b17;a17;2 $$6,6#27521748481378242620020725143825:desc] +[l321;C@5;1 $$7,7#20902679421464641399138805415013:code] +[b2503;2 $$8,0#65142375456100023862071332075487:separator] +[*@(0.0.255)2 $$9,0#83433469410354161042741608181528:base] +[C2 $$10,0#37138531426314131251341829483380:class] +[l288;a17;*1 $$11,11#70004532496200323422659154056402:requirement] +[i417;b42;a42;O9;~~~.416;2 $$12,12#10566046415157235020018451313112:tparam] +[b167;C2 $$13,13#92430459443460461911108080531343:item1] +[i288;a42;O9;C2 $$14,14#77422149456609303542238260500223:item2] +[*@2$(0.128.128)2 $$15,15#34511555403152284025741354420178:NewsDate] +[l321;*C$7;2 $$16,16#03451589433145915344929335295360:result] +[l321;b83;a83;*C$7;2 $$17,17#07531550463529505371228428965313:result`-line] +[l160;*C+117 $$18,5#88603949442205825958800053222425:package`-title] +[2 $$19,0#53580023442335529039900623488521:gap] +[C2 $$20,20#70211524482531209251820423858195:class`-nested] +[b50;2 $$21,21#03324558446220344731010354752573:Par] +[{_}%EN-US +[s2; Witz&] +[s3; 1. Preprocessing&] +[s0; &] +[s0; First phase in compilation of witz templates is preprocessing. +Preprocessing itself can be broken to include phase, when other +template or template snippets are combined to form single body +and subblock replacement phase, when all references to subblocks +are replaced with defined subblocks.&] +[s0; &] +[s0; [@5 #include] [/ path]&] +[s0; &] +[s0; This attempts to retrieve and include another witz template +into current body. Witz preprocessor attempts to retrieve language +specific version of template first, then defaults to common version.&] +[s0; &] +[s0; [@5 #define] [/ id]&] +[s0; &] +[s0; This starts a new template subblock which ends with another +subblock. First subblock (the one befure first #define is encountered) +has [/ id] `"MAIN`". The value of `"MAIN`" subblock represents +the template at the end of preprocessing process.&] +[s0; &] +[s0; [@5 #][/ id]&] +[s0; &] +[s0; Occurence of # followed by [/ id] that is neither `"include`" +or `"define`" inserts a subblock defined by [@5 #define] [/ id]. +Thus process is recursive `- subblock keep replacing until there +are no more #[/ id] in the block. If [/ id ]is encountered for which +there is corresponding [@5 #define], it is replaced by empty text. +If there are more definition for single id, the last one is used.&] +[s0; &] +[s0; Example:&] +[s0; &] +[s0; [* base.witz:]&] +[s0; &] +[s7; &] +[s7; #TITLE&] +[s7; #BODY&] +[s7; &] +[s7; &] +[s7; #define TITLE Generic title&] +[s0; &] +[s0; [* page.witz:]&] +[s0;* &] +[s7; #include base&] +[s7; #define TITLE The page title&] +[s7; #define BODY&] +[s7; Hello world!&] +[s0; &] +[s3; 2. Witz code&] +[s0; &] +[s0; Witz code is marked by `'`$`' character (the end of code within +template is determined by syntax rules, in rare situations you +might have to enclose expressions in parenthesis).&] +[s0; &] +[s0; ]] \ No newline at end of file diff --git a/uppsrc/Skylark/srcdoc.tpp/Tutorial$en-us.tpp b/uppsrc/Skylark/srcdoc.tpp/Tutorial$en-us.tpp index 9522a1d92..a3449e6b7 100644 --- a/uppsrc/Skylark/srcdoc.tpp/Tutorial$en-us.tpp +++ b/uppsrc/Skylark/srcdoc.tpp/Tutorial$en-us.tpp @@ -112,7 +112,7 @@ be able to access it from your browser by entering &] [s0; 127.0.0.1:8001/myapp/params/1/2/3&] [s0; 127.0.0.1:8001/myapp/anythingelse&] [s0; 127.0.0.1:8001&] -[s5; (last one should result in error `"Page not found`", as no such +[s5; (last one should result in error `"Page not found`", as no matching handler is present)&] [s5; &] [s3; 2. Witz templates&] @@ -194,5 +194,104 @@ and you start the application from theide. Note that [* path] is also used to search for static files.&] [s5; String values are normally HTML escaped; if you need to pass raw html code as parameter, you have to either use [@5 Raw ]C`+`+ -function in application logic or [@5 raw] function in witz.&] +function in application logic or [@5 raw] function in Witz.&] +[s5; &] +[s3; 3. Witz links to handlers&] +[s5; Skylark handlers are represented in witz templates as function +calls returning `" quoted path that matches the handler path +pattern. If pattern contains parameter placeholder, it is passed +as argument of the function:&] +[s7; &] +[s7; #include &] +[s7; &] +[s7; using namespace Upp;&] +[s7; &] +[s7; SKYLARK([* HomePage], `"`")&] +[s7; `{&] +[s7; -|http.RenderResult(`"Skylark03/index`");&] +[s7; `}&] +[s7; &] +[s7; SKYLARK([* Page2], `"page2`")&] +[s7; `{&] +[s7; -|http.RenderResult(`"Skylark03/page2`");&] +[s7; `}&] +[s7; &] +[s7; SKYLARK([* Param], `"paramtest/`*`")&] +[s7; `{&] +[s7; -|http(`"PARAM`", http`[0`]).RenderResult(`"Skylark03/param`");&] +[s7; `}&] +[s7; &] +[s7; struct MyApp : SkylarkApp `{&] +[s7; -|MyApp() `{&] +[s7; -|-|root `= `"myapp`";&] +[s7; -|#ifdef `_DEBUG&] +[s7; -|-|prefork `= 0;&] +[s7; -|-|use`_caching `= false;&] +[s7; -|#endif&] +[s7; -|`}&] +[s7; `};&] +[s7; &] +[s7; CONSOLE`_APP`_MAIN&] +[s7; `{&] +[s7; #ifdef `_DEBUG&] +[s7; -|StdLogSetup(LOG`_FILE`|LOG`_COUT);&] +[s7; -|Ini`::skylark`_log `= true;&] +[s7; #endif&] +[s7; &] +[s7; -|MyApp().Run();-|&] +[s7; `}&] +[s7; &] +[s7; &] +[s5; [* Skylark03/index.witz:]&] +[s7; &] +[s7; &] +[s7; Link to page2
&] +[s7; `$for(i in `[`"param`_test`", 123, `"param`_test3`"`])&] +[s7; -|Param test: `$i
&] +[s7; `$endfor&] +[s7; &] +[s7; &] +[s7; &] +[s5; [* Skylark03/page2.witz:]&] +[s7; &] +[s7; &] +[s7; Back to index
&] +[s7; &] +[s7; &] +[s7; &] +[s5; [* Skylark03/index.witz:]&] +[s7; &] +[s7; &] +[s7; Link to page2
&] +[s7; `$for(i in `[`"param`_test`", 123, `"param`_test3`"`])&] +[s7; -|Param test: `$i
&] +[s7; `$endfor&] +[s7; &] +[s7; &] +[s7; &] +[s7; &] +[s3; 4. Combining Witz templates using #define and #include&] +[s5; Witz templates can be parametrized using subblock [@5 #define] +[/@5 id] and [@5 #][/@5 id] insertion and combined from several files +using [@5 #include]:&] +[s5; [* Skylark04/base.witz:]&] +[s7; &] +[s7; #TITLE&] +[s7; &] +[s7; #BODY&] +[s7; &] +[s7; &] +[s7; &] +[s7; #define TITLE Generic title&] +[s7; &] +[s7; &] +[s5; [* Skylark04/index.witz:]&] +[s7; #include Skylark04/base&] +[s7; &] +[s7; #define TITLE MyApp title&] +[s7; &] +[s7; #define BODY&] +[s7; This is MyApp body html!&] +[s7; &] +[s7; &] [s5; ]] \ No newline at end of file