[RULE] How to track, and compare, previous RULE matches to the current RULE match?

56 views
Skip to first unread message

Micky Hulse

unread,
Nov 12, 2012, 5:03:52 PM11/12/12
to intersystems. public. cache
I've written a really basic RULE that allows me to insert HTML into
the <head> or footer of a CSP page:

"Caché for Windows (x86-64) 2009.1.5 (Build 901_0_11112U): Rule
example for putting HTML in <head> or foot of html documents."
<https://gist.github.com/4062140>

Note: Non-DTI customers should remove <csr:class
super="dt.common.page.Rule" />, do ##this.RenderDTStartTag() and do
##this.RenderDTEndTag() from the RULE.

... here's an example of how it might get used:

<https://gist.github.com/4062140#file_enque.csp>

... where:

<custom:rg:enque>...</custom:rg:enque> will append the contents of the
tag pair to the <head>, right before the closing </head> tag.

... and:

<custom:rg:enque:body>...</custom:rg:enque:body> will append the
contents of the tag pair to the <body>, right before the closing
</body> tag.

I really love this functionality of RULEs and Caché! There have been
many times where I write a chunk of HTML and insert it into a template
and need to have related JS/CSS in the <head> and/or (in the case of
javascript) the foot of the document.

My question:

In the real world, I might have several calls to <custom:rg:enque> or
<custom:rg:enque:body>... I'd LOVE to have the ability to check if
I've already inserted the contents of the current tag pair into the
<head> or <body>.

I think what I need to play with is:

"OnMatch Method"
<http://docs.intersystems.com/cache20091/csp/docbook/DocBook.UI.Page.cls?KEY=GCSP_customtags#GCSP_C140848>

Based on some of the example RULEs I've found in %SYS, I've played
with OnMatch, but I have not had any success "tracking" what's already
been called and appended.

I can live with the tag as it stands currently (it'll still be helpful
to me, even if it does not do any checking), but it would be so much
more useful if I could, somehow, check for the existence of the
current tag pair content before appending to <head> or <body>.

It's almost like I need create a hash of each tag call, store that key
in a global array, and for each subsequent call check that array for
the existence of said hash before appending the next tag's tag pair
contents.

Does any of that make sense?

Maybe OnMatch is not what I need? I'm just looking for some tips here. :)

Please let me know if I can explain things better.

--
Micky Hulse
Web Content Editor
The Register-Guard
3500 Chad Drive
Eugene, OR 97408
Phone: (541) 338-2621
Fax: (541) 683-7631
Web: <http://www.registerguard.com>

Micky Hulse

unread,
Nov 12, 2012, 6:42:11 PM11/12/12
to intersystems...@googlegroups.com
I've added what the HTML output looks like:

<https://gist.github.com/4062140#file_enque.html>

Thanks,
M

Micky Hulse

unread,
Nov 14, 2012, 9:25:22 PM11/14/12
to intersystems...@googlegroups.com
Update: I've found a similar question here:

"In need of CSR rule advice"
<https://groups.google.com/d/topic/intersystems-public-cache/rhaOntJQWGA/discussion>

If I'm understanding that thread correctly, it looks like I can just
set a variable and do a $data(var) check... Now I'm thinking I'll
create some sort of hash of the value of ##this.InnerText(), put that
in a variable, and for any duplicate tag calls (not that there would
be any in the first place) I can choose to skip insertion into the
<head> or foot of the document.

If I head this route, I'm wondering how I can kill any of these "hash"
variable after all of the tags have been processed? Maybe something
like:

<csr:section name="POSTHTML">
<script language="Cache" runat="server">
kill hashvar // $list (or local array var?) that holds all my hashes.
</script>
</csr:section>

For completeness' sake, I'll be back if I make any significant progress. :)

Thanks for listening.

Cheers,
Micky

Micky Hulse

unread,
Nov 16, 2012, 2:45:42 PM11/16/12
to intersystems...@googlegroups.com
On Wed, Nov 14, 2012 at 6:25 PM, Micky Hulse <rgm...@gmail.com> wrote:
> For completeness' sake, I'll be back if I make any significant progress. :)

Success!!!!

The solution was much simpler than I had originally suspected (i.e. I
didn't have to override/extend the OnMatch Method).

I was able to create a $list variable for each rule that contained an
encoded version of the RULE tag pair children (using
##this.InnerText()); from there, I was able to use $listfind to check
if string had been previous encoded.

For those interested, I'll post my final RULEs once I've finished
polishing my code.

Currently, I'm trying to find the best hash/encode method to convert
my html into a more manageable string. So far, these are the
candidates:

"Caché for Windows (x86-64) 2009.1.5 (Build 901_0_11112U): Testing the
various %SYSTEM.Encryption methods..."
<https://gist.github.com/4090128>

I'm wondering if I'm barking up the wrong tree looking in
%SYSTEM.Encryption? I just want a fast way to make a simple hash (or
encode) of an HTML string (I don't care about any sort of security).
In other words, I just want a quick way to uniquely identify and
compare a string using some sort of hash or string identifier.

Based on the above test cases, Base64Encode seems like the best pick
(I like that one because it doesn't have a bunch of high ascii
characters).

I've tested both Base64Encode and SHA1Hash, and both work... For now,
I think I'll stick with Base64Encode unless someone can suggest an
alternative?

Thanks for listening!

Cheers,
Micky

Micky Hulse

unread,
Nov 24, 2012, 5:04:04 PM11/24/12
to intersystems...@googlegroups.com
On Fri, Nov 16, 2012 at 11:45 AM, Micky Hulse <rgm...@gmail.com> wrote:
> For those interested, I'll post my final RULEs once I've finished
> polishing my code.

Here's the latest version of my code:

<https://github.com/registerguard/csp-enque>

I'm open to feedback.

Cheers,
Micky
Reply all
Reply to author
Forward
0 new messages