Skip to content

Instantly share code, notes, and snippets.

@jolle-c
Last active May 2, 2017 06:15
Show Gist options
  • Select an option

  • Save jolle-c/d72c8af689cb7e79ccc1 to your computer and use it in GitHub Desktop.

Select an option

Save jolle-c/d72c8af689cb7e79ccc1 to your computer and use it in GitHub Desktop.

Revisions

  1. jolle-c revised this gist May 2, 2017. 1 changed file with 21 additions and 0 deletions.
    21 changes: 21 additions & 0 deletions wrp.lasso
    Original file line number Diff line number Diff line change
    @@ -4,12 +4,33 @@ wrp
    Quick way to grap a web_request param
    2017-05-02 JC Added examples
    2014-10-08 JC Added to Gist
    2014-10-08 JC Added separate methods for queryparams and postparams
    2014-08-24 JC Rewrite of the wrp method once again. This time with code suggested by Brad Lindsay in a lassotalk thread. Introduces the param -all
    2014-08-22 JC Complete rewrite to produce leaner and more reliable code. Arrays are now returned as staticarrays
    2013-12-08 JC adjusted to only initiate once
    2013-12-07 JC First version
    EXAMPLES
    local(
    checkboxinput = wrp('checkboxinput', -all),
    myinput = wrp('myinput')
    )
    #checkboxinput -> type // staticarray
    #myinput -> type // string or void depending on if it has content or not
    // this will only find GET parameters
    local(
    myqueryparam = wrpq('myqueryparam')
    )
    // this will only find POST parameters
    local(
    mypostparam = wrpp('mypostparam')
    )
    */
    define wrps => var(__wrp) -> isa(::staticarray) ?
    $__wrp |
  2. jolle-c renamed this gist Oct 8, 2014. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  3. jolle-c created this gist Oct 8, 2014.
    71 changes: 71 additions & 0 deletions wrp
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,71 @@
    [
    /**!
    wrp

    Quick way to grap a web_request param

    2014-10-08 JC Added to Gist
    2014-10-08 JC Added separate methods for queryparams and postparams
    2014-08-24 JC Rewrite of the wrp method once again. This time with code suggested by Brad Lindsay in a lassotalk thread. Introduces the param -all
    2014-08-22 JC Complete rewrite to produce leaner and more reliable code. Arrays are now returned as staticarrays
    2013-12-08 JC adjusted to only initiate once
    2013-12-07 JC First version
    */
    define wrps => var(__wrp) -> isa(::staticarray) ?
    $__wrp |
    $__wrp := (with p in web_request -> params
    let name = #p -> first -> asstring
    let value = #p -> second -> asstring
    select pair(#name = #value)) -> asstaticarray

    define wrp(name::string = string, -all::boolean = false) => {
    local(wrp) = wrps -> find(#name)

    if(#all) => {
    return (with param in #wrp select #param -> second) -> asstaticarray
    }

    #wrp -> isempty ? return void

    return #wrp -> get(1) -> second
    }

    define wrpqs => var(__wrpq) -> isa(::staticarray) ?
    $__wrpq |
    $__wrpq := (with p in web_request -> queryparams
    let name = #p -> first -> asstring
    let value = #p -> second -> asstring
    select pair(#name = #value)) -> asstaticarray

    define wrpq(name::string = string, -all::boolean = false) => {
    local(wrp) = wrpqs -> find(#name)

    if(#all) => {
    return (with param in #wrp select #param -> second) -> asstaticarray
    }

    #wrp -> isempty ? return void

    return #wrp -> get(1) -> second
    }

    define wrpps => var(__wrpp) -> isa(::staticarray) ?
    $__wrpp |
    $__wrpp := (with p in web_request -> postparams
    let name = #p -> first -> asstring
    let value = #p -> second -> asstring
    select pair(#name = #value)) -> asstaticarray

    define wrpp(name::string = string, -all::boolean = false) => {
    local(wrp) = wrpps -> find(#name)

    if(#all) => {
    return (with param in #wrp select #param -> second) -> asstaticarray
    }

    #wrp -> isempty ? return void

    return #wrp -> get(1) -> second
    }

    ]