lib/spontaneous/extensions/string.rb in spontaneous-0.2.0.alpha2 vs lib/spontaneous/extensions/string.rb in spontaneous-0.2.0.alpha3

- old
+ new

@@ -6,10 +6,21 @@ module String def /(path) File.join(self, path.to_s) end + def or(alternative) + return alternative if empty? + self + end + + alias_method :'|', :or + + def value(format = :html) + self + end + HTML_ESCAPE_TABLE = { '&' => '&amp;', '<' => '&lt;', '>' => '&gt;', '"' => '&quot;', @@ -32,9 +43,14 @@ def escape_js self.gsub(/(\\|<\/|\r\n|[\n\r"'])/) { JS_ESCAPE_MAP[$1] } end + # Makes it easier to pass either a field or a String around + # in templates + def to_html + self + end end end end