roxen.lists.roxen.general

Subject Author Date
Are there smart way to modify parent scope variable? Eiichiro ITANI <emu[at]ceres[dot]dti[dot]ne[dot]jp> 15-12-2008
Dear Roxen developers and users,

I have one question.  Are there any smart way to modify variable defined
in parent scope?  It doesn't matter whether through RXML or pike.


Situation is:

I have many pages which accepts form.limit and form.offset variables,
and produce list with limit/offest parameters.

Page A-1:
<html>
<body>
...
<list_a id="1" limit="&form.limit;" offset="&form.offset;" />
...
</body>
</html>

Tag definition for list_a follows like this:

<define tag="list_a">
  <ul>
  <emit source="sql"
     query="SELECT x,y FROM table_a WHERE id=:id
            LIMIT :limit OFFSET :offset"
     bindings="id=id, limit=limit, offset=offset">
    <li>&_.x; - &_.y;</li>
  </emit>
  </ul>
</define>


I must sanitize these form variables to be proper integer, and limit
must be positive, offset must be positive and smaller than 100 or so,
and, and...

Same time I also have Page B(s), which use tag list_b, accepts same
limit/offset form variables.  They should be get sanitzed same way.


If it is possible, I want to do like this:

<define tag="cleanup_limit_offset" >
  <sscanf format="%d" variables="Parent.limit">&Parent.limit;</sscanf>
  <sscanf format="%d" variables="Parent.offset">&Parent.offset;</sscanf>
  <if variable="Parent.limit < 0">
   <set variable="Parent.limit" value="0" />
  </if>
  ...same for offset...
</define>

And modify list_a definition as:
<define tag="list_a">
  <clean_formvars />
  <ul>
  <emit source="sql" ...
  ...
</define>


I know this below works:

<define tag="list_a">
  <clean_limit_offset limit="&_.limit;" offset="&_.offset;"
         parentscope="list_a" />
  <ul>
  <emit source="sql" ...
  ...
</define>

<define tag="clean_limit_offset" >
  ...some sanitization coding...
  <set variable="limit" from="_.limit" scope="&_.parentscope;" />
  <set variable="offset" from="_.offset" scope="&_.parentscope;" />
</define>


But making variation tags later (like list_e, list_f,...), I know I will
forget to modify parentscope parameter as "list_x" for tag list_x.


So, are there any way to modify parent scope(name not known) variable
directly/indirecly anyway, or pass scope name(no hardcode) to child?


Best regards,

--
  ITANI Eiichiro