[Rg 93] [PATCH] Gestalt improvements
Stephan Maka
stephan at spaceboyz.net
Thu Sep 20 14:18:09 EDT 2007
Hi there,
I'm working on XSLT templates and Gestalt came handy for bringing
controller instance data to XML, which is needed as template input.
The attached patch extends the parameters to be not only the attributes
but also text children. Both are being properly escaped now. Two specs
are added.
I hope the patch is in proper form, I've never used Darcs before.
Stephan
-------------- next part --------------
New patches:
[Gestalt: allow text in arguments, properly escape this text and attributes
stephan at spaceboyz.net**20070920153337] {
hunk ./lib/ramaze/gestalt.rb 75
- _gestalt_build_tag meth, *args, &block
+ _gestalt_call_tag meth, args, &block
hunk ./lib/ramaze/gestalt.rb 81
- _gestalt_build_tag :p, *args, &block
+ _gestalt_call_tag :p, args, &block
+ end
+
+ def _gestalt_call_tag name, args, &block
+ if args.size == 1 and args[0].kind_of? Hash
+ # args are just attributes, children in block...
+ _gestalt_build_tag name, args[0], &block
+ else
+ # no attributes, but text
+ _gestalt_build_tag name, {}, args, &block
+ end
hunk ./lib/ramaze/gestalt.rb 97
- def _gestalt_build_tag name, args = []
+ def _gestalt_build_tag name, attr={}, text=[]
hunk ./lib/ramaze/gestalt.rb 99
- if block_given?
- @out << args.inject(''){ |s,v| s << %{ #{v[0]}="#{v[1]}"} }
+ @out << attr.inject(''){ |s,v| s << %{ #{v[0]}="#{_gestalt_escape_entities(v[1])}"} }
+ if text != [] or block_given?
hunk ./lib/ramaze/gestalt.rb 102
- text = yield
- @out << text if text != @out and text.respond_to?(:to_str)
+ @out << _gestalt_escape_entities(text.to_s)
+ if block_given?
+ text = yield
+ @out << text.to_str if text != @out and text.respond_to?(:to_str)
+ end
hunk ./lib/ramaze/gestalt.rb 109
- @out << args.inject(''){ |s,v| s << %{ #{v[0]}="#{v[1]}"} }
hunk ./lib/ramaze/gestalt.rb 112
+
+ def _gestalt_escape_entities(s)
+ s.gsub(/&/, '&').
+ gsub(/"/, '"').
+ gsub(/'/, ''').
+ gsub(/</, '<').
+ gsub(/>/, '>')
+ end
hunk ./spec/ramaze/gestalt.rb 91
+ end
+
+ it "children as parameters" do
+ gestalt {
+ a "Hello"
+ b(23, 5) { "1" }
+ c(42) {
+ d
+ }
+ e("f & g")
+ }.should == '<a>Hello</a><b>2351</b><c>42<d /></c><e>f & g</e>'
+ end
+
+ it "escapeable attributes" do
+ gestalt {
+ a(:href => "http://example.org/?a=one&b=two") {
+ "Click here"
+ }
+ }.should == '<a href="http://example.org/?a=one&b=two">Click here</a>'
}
Context:
[Add $0 to files being sourcereloaded.
Michael Fellinger <m.fellinger at gmail.com>**20070919062417]
[Implement Global.ignore and spec it.
Michael Fellinger <m.fellinger at gmail.com>**20070919062143]
[Add Global.cache_alternative so you can specify a different cache-class to use for only certain caches. For example: Ramaze::Global.cache_alternative[:sessions] = Ramaze::MemcachedCache
Michael Fellinger <m.fellinger at gmail.com>**20070918104659]
[Small improvment to the sequel/fill contrib
Michael Fellinger <m.fellinger at gmail.com>**20070918054112]
[Add contrib/sequel/fill
Michael Fellinger <m.fellinger at gmail.com>**20070918053330]
[alias redirect_referer to redirect_referrer in RedirectHelper
Michael Fellinger <m.fellinger at gmail.com>**20070918045439]
[Allow custom /helper directory in apps, will be searched before ramazes helpers.
Michael Fellinger <m.fellinger at gmail.com>**20070918014843]
[Add the wikore example and fix spec for wiktacular a little.
Michael Fellinger <m.fellinger at gmail.com>**20070917114503]
[Improve output of spec wrapper a bit.
Michael Fellinger <m.fellinger at gmail.com>**20070917114458]
[Adding path for OSX to tool/tidy and improve readability of the spec for it a bit.
Michael Fellinger <m.fellinger at gmail.com>**20070912125255]
[Fixing dependence on the debug.rb implementation of ruby, since this may vary between different versions/implementations, use gestalt.rb instead, the oldest and most stable file we have.
Michael Fellinger <m.fellinger at gmail.com>**20070912090809]
[Small beautification/speedup for the mocked http
Michael Fellinger <m.fellinger at gmail.com>**20070911084731]
[Clean up the controller/resolve part a bit, implement raise_no_filter which throws a NoFilter error now and fix a minor bug that would result in a faulty response if an element of Cache.resolved was no valid action. Added docs for all methods in Controller.
Michael Fellinger <m.fellinger at gmail.com>**20070911162955]
[Restructuring of how contribs are handled, introducing the Ramaze::Contrib namespace, adding Global.contribs so we can add a unified shutdown in future, fixing routing so it won't try to match an already resolved route again and thereby avoiding recursion.
Michael Fellinger <m.fellinger at gmail.com>**20070911144843]
[Adding snippet for Array#put_within/put_before/put_after plus specs. docs missing.
Michael Fellinger <m.fellinger at gmail.com>**20070911054158]
[Updated spec for route
Aman Gupta <ramaze at tmm1.net>**20070910063242]
[This introduces the first contrib for routes, slight restructuring of Controller::resolve to allow filtering based on Controller::FILTER like we know it from Dispatcher. Added dictionary.rb from facets to allow sorted but hash-like routes-adding. Spec for routes added as small showcase.
Michael Fellinger <m.fellinger at gmail.com>**20070910044521]
[Add basic Ramaze::contrib as future helping instance for contributed things.
Michael Fellinger <m.fellinger at gmail.com>**20070910044506]
[make snippets/struct/values_at behaviour compatible with standard ruby (orig. by riffraff)
Michael Fellinger <m.fellinger at gmail.com>**20070907083216]
[Fix for directory-listing, always sort files/dirs shown
Michael Fellinger <m.fellinger at gmail.com>**20070907083158]
[TAG 0.1.4
Michael Fellinger <m.fellinger at gmail.com>**20070906135219]
Patch bundle hash:
0e37f422edda9ea3cd13c87954f6b61150a46fd5
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
Url : http://rubyforge.org/pipermail/ramaze-general/attachments/20070920/56fea048/attachment.bin
More information about the Ramaze-general
mailing list