From 4a48b68eaed99e2f87b987d124d6334a5b9fe61b Mon Sep 17 00:00:00 2001 From: cxl Date: Fri, 6 Jul 2012 16:16:25 +0000 Subject: [PATCH] .Skylark tutorial git-svn-id: svn://ultimatepp.org/upp/trunk@5142 f0d560ea-af0d-0410-9eb7-867de7ffcac7 --- uppsrc/Skylark/StdLib.icpp | 6 ++ uppsrc/Skylark/srcdoc.tpp/Tutorial$en-us.tpp | 72 +++++++++++++++++++- 2 files changed, 77 insertions(+), 1 deletion(-) diff --git a/uppsrc/Skylark/StdLib.icpp b/uppsrc/Skylark/StdLib.icpp index 8a75e574f..a364b8a7d 100644 --- a/uppsrc/Skylark/StdLib.icpp +++ b/uppsrc/Skylark/StdLib.icpp @@ -9,6 +9,11 @@ Value Cycle(const Vector& arg, const Renderer *) return arg[1 + int(arg[0]) % (arg.GetCount() - 1)]; } +Value CountFn(const Vector& arg, const Renderer *) +{ + return arg.GetCount() && IsValueArray(arg[0]) ? ValueArray(arg[0]).GetCount() : 0; +} + Value RawFn(const Vector& arg, const Renderer *) { RawHtmlText r; @@ -44,6 +49,7 @@ Value JsIdentity(const Vector&, const Renderer *r) INITBLOCK { Compiler::Register("cycle", Cycle); Compiler::Register("raw", RawFn); + Compiler::Register("count", CountFn); Compiler::Register("post_identity", PostIdentity); Compiler::Register("js_identity", JsIdentity); }; diff --git a/uppsrc/Skylark/srcdoc.tpp/Tutorial$en-us.tpp b/uppsrc/Skylark/srcdoc.tpp/Tutorial$en-us.tpp index 876ac1aa3..6691bdc4b 100644 --- a/uppsrc/Skylark/srcdoc.tpp/Tutorial$en-us.tpp +++ b/uppsrc/Skylark/srcdoc.tpp/Tutorial$en-us.tpp @@ -434,4 +434,74 @@ enctype`=`"multipart/form`-data`">&] [s5; Note: There also exists alternative POST`_RAW method marker in SKYLARK handler definition `- such handler also reacts to POST requests, but it avoids identity checks to prevent CSRF attacks.&] -[s5; ]] \ No newline at end of file +[s5; &] +[s3; 7. Session variables&] +[s5; Http`::SessioSet method can be used to store `'session variables`' +that are persistent for specific browser across requests. Implementation +is based on cookie, session variables are stored either in filesystem +or in database (see Skylark configuration for details). Session +variables reflected in shared variable space (means its values +are accessible using [* Http`::operator`[`]]).&] +[s7; &] +[s7; #include &] +[s7; &] +[s7; using namespace Upp;&] +[s7; &] +[s7; SKYLARK(HomePage, `"`")&] +[s7; `{&] +[s7; -|http.RenderResult(`"Skylark07/index`");&] +[s7; `}&] +[s7; &] +[s7; SKYLARK(Submit, `"submit:POST`")&] +[s7; `{&] +[s7; -|Value h `= [* http`[`"LIST`"`];]&] +[s7; -|ValueArray va;&] +[s7; -|if(IsValueArray(h))&] +[s7; -|-|va `= h;&] +[s7; -|va.Add(http`[`"id`"`]);&] +[s7; -|[* http.SessionSet(`"LIST`", va);]&] +[s7; -|http.Redirect(HomePage);&] +[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; [* Skylark07/index.witz:]&] +[s7; &] +[s7; &] +[s7; &] +[s7;
&] +[s7;

&] +[s7; `$post`_identity()&] +[s7; &] +[s7; &] +[s7;

&] +[s7;
&] +[s7; List (`$count(LIST)):
&] +[s7; `$for(i in LIST)&] +[s7; -|`"`$i`" &] +[s7; `$endfor&] +[s7; &] +[s7; &] +[s7; &] +[s7; &] +[s5;* ]] \ No newline at end of file