mirror of
https://github.com/ultimatepp/ultimatepp.git
synced 2026-06-01 06:12:23 -06:00
.Skylark tutorial
git-svn-id: svn://ultimatepp.org/upp/trunk@5142 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
parent
81e10147be
commit
4a48b68eae
2 changed files with 77 additions and 1 deletions
|
|
@ -9,6 +9,11 @@ Value Cycle(const Vector<Value>& arg, const Renderer *)
|
|||
return arg[1 + int(arg[0]) % (arg.GetCount() - 1)];
|
||||
}
|
||||
|
||||
Value CountFn(const Vector<Value>& arg, const Renderer *)
|
||||
{
|
||||
return arg.GetCount() && IsValueArray(arg[0]) ? ValueArray(arg[0]).GetCount() : 0;
|
||||
}
|
||||
|
||||
Value RawFn(const Vector<Value>& arg, const Renderer *)
|
||||
{
|
||||
RawHtmlText r;
|
||||
|
|
@ -44,6 +49,7 @@ Value JsIdentity(const Vector<Value>&, 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);
|
||||
};
|
||||
|
|
|
|||
|
|
@ -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; ]]
|
||||
[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 <Skylark/Skylark.h>&]
|
||||
[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; <html>&]
|
||||
[s7; <body>&]
|
||||
[s7; <form action`=`$Submit method`=`"post`" accept`-charset`=`"utf`-8`"
|
||||
enctype`=`"multipart/form`-data`">&]
|
||||
[s7; <P>&]
|
||||
[s7; `$post`_identity()&]
|
||||
[s7; <INPUT type`=`"text`" name`=`"id`">&]
|
||||
[s7; <INPUT type`=`"submit`" value`=`"Add to list`">&]
|
||||
[s7; </P>&]
|
||||
[s7; </form>&]
|
||||
[s7; List (`$count(LIST)):<br>&]
|
||||
[s7; `$for(i in LIST)&]
|
||||
[s7; -|`"`$i`" &]
|
||||
[s7; `$endfor&]
|
||||
[s7; </body>&]
|
||||
[s7; </html>&]
|
||||
[s7; &]
|
||||
[s7; &]
|
||||
[s5;* ]]
|
||||
Loading…
Add table
Add a link
Reference in a new issue