diff --git a/JetCore.txt b/JetCore.txt index a63a5f8..cbf3bfc 100644 --- a/JetCore.txt +++ b/JetCore.txt @@ -40,6 +40,16 @@ Keywords are not defined as part of the tag definition and any attribute added to the implementation of the tag is passed into the tag process as a local variable for that container. +Tag definitions can also be defined as scoped or unscoped, as follows: + +scoped - local variables using the #[n] format can be scoped to just +your tag contents. Access to local variables where your tag is being +used must use the 'parent' scope option to retrieve variables from the +parent. + +unscoped - local variables are shared with the parent tag environment +and are not unique to your tag definition. + A tag can be inserted into the container and will take the contents of the container at runtime and insert it into the output when processing the user defined tag definition. The container tag of @@ -57,7 +67,11 @@ higher tag. Variables are used to contain dynamic content values and can be sourced from several locations and limited in scope depending on use. Some variable types can be set to reflect script state or are read -only from other outside sources of data. The following is a list of +only from other outside sources of data. + +Jet tags can be either scoped or unscoped. + +The following is a list of variable types and a brief description of their source: \begin{itemize} @@ -71,6 +85,9 @@ specifying the scope of global. \section{Global Variables} +Global variables are available to all logic once the values have been +set. + Global is the default if the scope is not specified for any function that writes to a variable. @@ -81,7 +98,9 @@ not specified for any function that writes to a variable. \section{CGI Variables} - +When operating Jet in CGI mode you have access to the form data +submitted by the remote client (usually a browser or curl request) +using the POST method. \chapter{Expressions} @@ -178,6 +197,8 @@ input error +The call tag is unscoped. + \begin{verbatim} \end{verbatim} @@ -216,7 +237,10 @@ end step -name +name - defines a name for the iterator that will be available within +the loop. + +scope - defines the scope of the iterator for the loop. \section{header} diff --git a/__call.cpp b/__call.cpp index 242d432..200a301 100644 --- a/__call.cpp +++ b/__call.cpp @@ -54,9 +54,9 @@ namespace jet { if(!variableDefined("scope") || (variables["scope"] == "global")) global.variables[variables["name"]].read(fdo[0]); else if(variables["scope"] == "local") - parent->variables[variables["name"]].read(fdo[0]); + local->variables[variables["name"]].read(fdo[0]); else if(variables["scope"] == "parent") - parent->parent->variables[variables["name"]].read(fdo[0]); + local->parent->local->variables[variables["name"]].read(fdo[0]); else throw coreutils::Exception("scope value is not valid."); diff --git a/__dotag.cpp b/__dotag.cpp index 15eaec2..55a839a 100644 --- a/__dotag.cpp +++ b/__dotag.cpp @@ -3,7 +3,7 @@ namespace jet { - __dotag::__dotag(coreutils::ZString &in, coreutils::MString &parentOut, Global &global, Tag *parent, Tag *local) : Tag(in, parentOut, global, parent, this) { + __dotag::__dotag(coreutils::ZString &in, coreutils::MString &parentOut, Global &global, Tag *parent, Tag *local) : Tag(in, parentOut, global, parent, local) { if(hasContainer) parseContainer(container, containerOut); containerOut.reset(); diff --git a/__include.cpp b/__include.cpp index 5c5f4b6..5609931 100644 --- a/__include.cpp +++ b/__include.cpp @@ -14,7 +14,23 @@ namespace jet { coreutils::File file(variables["file"]); file.read(); container = file.asZString(); - processContainer(container); + try { + processContainer(container); + } + catch(coreutils::Exception e) { + container.setCursor(global.errorCursor); + container.moveBackToLineStart(); + std::cout << "-----------------------------" << std::endl; + std::cout << "Error in included script '" << variables["file"] << "' at line " << container.getLineNumberAtCursor() << std::endl; + std::cout << "Error text: " << e.text << std::endl; + std::cout << "-----------------------------" << std::endl; + std::cout << container.parsed() << std::endl; + std::cout << "******** Error caught: " << e.text << std::endl; + std::cout << container.unparsed() << std::endl; + global.errorCursor = in.getCursor(); + throw coreutils::Exception("error in included file."); + } + } } diff --git a/__stream.cpp b/__stream.cpp index 7ae236d..6d5c055 100644 --- a/__stream.cpp +++ b/__stream.cpp @@ -1,16 +1,22 @@ #include "__stream.h" #include "Exception.h" +#include +#include namespace jet { __stream::__stream(coreutils::ZString &in, coreutils::MString &parentOut, Global &global, Tag *parent, Tag *local) : Tag(in, parentOut, global, parent, this) { + output = false; if(!variableDefined("name")) throw coreutils::Exception("stream tag must have a file name to stream."); - - // TODO: Output headers that have been written so far. - // TODO: Open file with fairly small buffer size and write to end to cout and not the out buffers. - // TODO: Force no further output from jet-2.0 at end of stream. - + global.outputHeaders(); + int len; + char buffer[1024]; + int fd = open(variables["name"].c_str(), O_RDONLY); + do { + len = read(fd, &buffer, 1024); + std::cout << buffer; + } while (len > 0); } } diff --git a/sessionctl/sessionctl.tag b/sessionctl/sessionctl.tag new file mode 100755 index 0000000..0310c58 --- /dev/null +++ b/sessionctl/sessionctl.tag @@ -0,0 +1,433 @@ +# -------------------------------------------------------------- +# SESSIONCTL lib +# +# Session Control Function Library +# +# +# -------------------------------------------------------------- + +#============================================================================== +# RETAIN tag definition. +#============================================================================== + + + + + + + + + + + + + + + +#============================================================================== +# IFNOTSESSION tag definition. +#============================================================================== + + + + + +#------------------------------------------------------------------------------ +# LINKBUTTON tag definition. +#------------------------------------------------------------------------------ + + + + + + + + document.forms[0].PROCESS.value=''; + + document.forms[0].PROCESS.value='#[PROCESS]'; + + + + + document.forms[0].PAGE.value='$[PAGE]'; + + document.forms[0].PAGE.value='#[PAGE]'; + + + + + document.forms[0].#[NAME].value='#[VALUE]'; + + + + + document.forms[0].#[NAME2].value='#[VALUE2]'; + + + + + document.forms[0].encoding='multipart/form-data'; + + + + + document.forms[0].target='#[TARGET]'; + + + + + document.forms[0].P_$[L_LEVEL].value='$[PAGE]'; + document.forms[0].L_$[L_LEVEL].value='$[X_TITLE]'; + document.forms[0].D_$[N_LEVEL].value='#[PAGEDIR]'; + document.forms[0].P_$[N_LEVEL].value='#[PAGE]'; + document.forms[0].P_LEVEL.value=$[L_LEVEL]; + document.forms[0].L_LEVEL.value=$[N_LEVEL]; + document.forms[0].N_LEVEL.value='$[X_LEVEL]'; + + + + document.forms[0].submit(); + document.forms[0].target='';" + + CLASS="#[CLASS]" + + > + + + + +#------------------------------------------------------------------------------ +# ABUTTON tag definition. +#------------------------------------------------------------------------------ + + + + + +# ---------------------------------------------- +# CREATESESSION +# ---------------------------------------------- + + + + delete from sessions + where uuid='$[_session_id]' + + + + + + + + + insert into sessions + set uuid='$[_uuid]', + timestamp='$[_timestamp]', + timeout_page='#[page]', + timeout=#[timeout] + + + + +# ---------------------------------------------- +# ENDSESSION +# ---------------------------------------------- + + + + delete from sessions + where uuid='$[_session_id]' + + + + + +#-------------------------------------------------- +#SETENV +#-------------------------------------------------- + + + + + + replace into sessionenv + set session_uuid='$[_session_id]', + name='#[name]', + value='#[_envvalue]' + $[sqlerror] + + + + +#-------------------------------------------------- +#CLEARENV +#-------------------------------------------------- + + + + DELETE FROM sessionenv + WHERE seid='$[_SESSIONID]' + AND sename='#[NAME]' + + + + + +#-------------------------------------------------- +#SETPAGE +#-------------------------------------------------- + + + + + + + + +#-------------------------------------------------- +#SETPROCESS +#-------------------------------------------------- + + + + + +#-------------------------------------------------- +#CHECKSESSION +#-------------------------------------------------- + + + + + select *, + if((timeout > 0) && (unix_timestamp(now()) - unix_timestamp(timestamp) > (timeout * 60)),'0','1') as session_valid + from sessions + where uuid="$[_session_id]" + $[sqlerror] + + + + + + + update sessions + set timestamp='$[_timestamp]' + where uuid="$[_session_id]" + + + + select * from sessionenv where session_uuid="$[_session_id]" + $[sqlerror] + + $[.value] + + + + + + + + + + + + + + +#-------------------------------------------------- +#FIRST RUN - See FETCHPROC in SESSIONCTL tag +#-------------------------------------------------- + + + + $[_FIRSTRUN] + + + +#-------------------------------------------------- +#RUNERROR - See FETCHPROC in SESSIONCTL tag +#-------------------------------------------------- + + + + $[_RUNERROR] + + + +#-------------------------------------------------- +#SESSIONCTL +#-------------------------------------------------- + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + $[_BODY] + + + + + + + + + + + + + + + + + + + + + + + + + + + $[head] + + + + class="#[CLASS]" + onload="#[onload]"> + +
+ + + + + + + + + + + $[_BODY] + + + #[TEMPLATEDATA] + + +
+ + + + +
+ + +
+ + + +
+ + + + + + + + + + + + $[_FIRSTRUN] + $[_RUNERROR] + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
diff --git a/tests/dump.txt b/tests/dump.txt index e137525..a54f8e4 100644 --- a/tests/dump.txt +++ b/tests/dump.txt @@ -8,7 +8,7 @@ divisor=[8] error=[] include=[yes] ix=[1] -lefty=[01234] +lefty=[] modified1=[ABCD] multiplication=[15] nested=[64] diff --git a/tests/testinclude.jet b/tests/testinclude.jet index 4724a8d..0dba399 100644 --- a/tests/testinclude.jet +++ b/tests/testinclude.jet @@ -1,6 +1,7 @@ This is a container set with '#[name1]' This is from an include tag. localname='#[name1]' +$[$xxxx] test='#[testinclude]'