开发者

KRL using a bee sting inside extended quotes

开发者 https://www.devze.com 2023-02-04 23:17 出处:网络
What are valid bee sting expressions within an extended quote? rule set_persistents { select when pageview \".*\"

What are valid bee sting expressions within an extended quote?

rule set_persistents {
  select when pageview ".*"
  noop();
  always {
    ent:ecount += 1 from 1;
    app:acount += 1 from 1;
  }
}

rule test_bee_stings {
  select when pageview ".*"
  pre { 
    sum = ent:ecount + app:acount;
    content = <<
      sum is #{sum}<br/>
      sum + 1 is #{sum+1}<br/>
      ecount is #{ent:ecount}<br/>
      acount is #{app:acount}
    >>;
  }
  notify("Results", content) with sticky = true;
}

When I run this I get nothing (never see the notify box). If I remove the ecount and acount lines I get

sum is 2
sum + 1 is 21

What bee sting expressions are valid within an ex开发者_Go百科tended quote? Is it any different for a normal quoted string?


Variables used in beestings in extended quotes should already have an assigned value and not be an expression. This is because beestings in extended quotes are evaluated on the client side and not the server side. I would also, for the previously explained reason, advise against using 'sum+1' in a beesting even though it currently works for endpoints that understand JavaScript.

Here is how I would write what you are trying to do:

ruleset a60x546 {
  meta {
    name "extended-quotes-beesting"
    description <<
      extended-quotes-beesting
    >>
    author "Mike Grace"
    logging on
  }

  rule test_bee_stings {
    select when pageview ".*"
    pre { 
      ecount = ent:ecount + 1;
      acount = app:acount + 1;
      sum = ecount + acount;
      sumplus = sum + 1;
      content = <<
        sum is #{sum}<br/>
        sum + 1 is #{sumplus}<br/>
        ecount is #{ecount}<br/>
        acount is #{acount}
      >>;
    }
    {
      notify("Results", content) with sticky = true;
    }
    always {
      ent:ecount += 1 from 1;
      app:acount += 1 from 1;
    }
  }
}

action shot of app run several times on example.com using bookmarklet:

KRL using a bee sting inside extended quotes

*I would also advise against using a previous rules postlude to modify app and entity variables that you then use in the next rule expecting it to be incremented. While what you did works it's semantically messy and would probably be a bit cleaner the way I have demonstrated.

**should be taken with a grain of salt since this is only one crazy guy's opinion. : )*

0

精彩评论

暂无评论...
验证码 换一张
取 消