* declare a widget as "cachable" (or "cacheable") in its class file
* when it's first rendered (in #to_s or #widget) it'll save the
rendered text off into a hash table
* next time it's rendered it'll use that text instead
* the widget is keyed off of class and parameters (but not block -- in
fact, if the widget takes a block then it's not cachable at all,
sorry)
* the hash is tied to the Widget class so it stays around forever (or
until server restart, whichever comes first)... but I'd like to move
to Moneta so we can use memcache or Redis or maybe just an in-memory
LRU cache
I also made Page's HEAD emit only the externals from widgets that were
actually rendered on it, not all externals from everywhere in
ObjectSpace like it was before.
It's on the "output" branch but I'd like to get some resolution on the
Rails issues from the other thread so we can get this stuff onto the
main branch.
http://github.com/pivotal/erector/commit/9c6bdca1ae33f81cb02cc0129a4c25e9b41fbdbe
http://github.com/pivotal/erector/commit/9bd07ccf67cf821f403af135ca2bd55fec56e3fe
---
Alex Chaffee - al...@cohuman.com - http://alexch.github.com
Stalk me: http://friendfeed.com/alexch | http://twitter.com/alexch |
http://alexch.tumblr.com
Working on it.
Would anyone object to changing Widget#h to be idempotent, i.e.
h(text) returns raw(text.html_escape), and h(h(text)) doesn't
double-escape? It would make integrating with rails output safety
easier, would match the behavior of ERB::Util.h in rails 3.0 and
2.3+rails_xss plugin, and we could remove this warning:
# Note that the #text method automatically HTML-escapes
# its parameter, so be careful *not* to do something like text(h("2<4"))
# since that will double-escape the less-than sign (you'll get
# "2&lt;4" instead of "2<4").
--
You received this message because you are subscribed to the Google Groups "erector" group.
To post to this group, send email to ere...@googlegroups.com.
To unsubscribe from this group, send email to erector+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/erector?hl=en.
The way idempotency is accomplished is by tagging the result with a
special String subclass (RawString) and then checking for the presence
of that tag (albeit a bit indirectly, in order to be compatible with
rails and other libraries with a similar concept).
It is still quite possible to output 2<4, 2<4 or 2&lt;4. Choose between:
rawtext "2<4" # => "2<4"
text! "2<4" # => "2<4"
text "2<4" # => "2<4"
text "2<4" # => "2&lt;4"
text CGI.html_escape("2<4") # => "2&lt;4"
Patch:
http://github.com/bigfix/erector/commit/838ed3c38f8959dd24676752c26eb51851739aef