Module: Feather::Support
Instance Method Summary collapse
- #cast_as_vars(object, stack) ⇒ Object
- #css_escape(object) ⇒ Object
- #html_escape(object) ⇒ Object
- #iterate(object) ⇒ Object
- #js_escape(object) ⇒ Object
-
#uri_escape(object) ⇒ Object
Module/Mixin Methods =================================================.
- #variable_stack(variables, force_as_array = true) ⇒ Object
Instance Method Details
#cast_as_vars(object, stack) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/feather/support.rb', line 33 def cast_as_vars(object, stack) if (object.is_a?(Hash)) stack.each do |parent| if (parent.is_a?(Hash)) object = parent.merge(object) end end object else object.respond_to?(:each) ? object : [ object ] end end |
#css_escape(object) ⇒ Object
19 20 21 |
# File 'lib/feather/support.rb', line 19 def css_escape(object) [ object ].flatten.join(' ') end |
#html_escape(object) ⇒ Object
11 12 13 |
# File 'lib/feather/support.rb', line 11 def html_escape(object) CGI.escapeHTML(object.to_s) end |
#iterate(object) ⇒ Object
23 24 25 26 27 28 29 30 31 |
# File 'lib/feather/support.rb', line 23 def iterate(object) if (object.respond_to?(:each)) object.each do |i| yield(i) end elsif (object) yield(object) end end |
#js_escape(object) ⇒ Object
15 16 17 |
# File 'lib/feather/support.rb', line 15 def js_escape(object) object.inspect end |
#uri_escape(object) ⇒ Object
Module/Mixin Methods =================================================
7 8 9 |
# File 'lib/feather/support.rb', line 7 def uri_escape(object) Addressable::URI.normalize_component(object.to_s, /[^a-z0-9\-\.]/i) end |
#variable_stack(variables, force_as_array = true) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/feather/support.rb', line 47 def variable_stack(variables, force_as_array = true) case (variables) when Hash remapped = Hash[ variables.collect do |k, v| [ k ? k.to_sym : k, variable_stack(v, false) ] end ] if (default = variables.default) remapped.default = default end if (default_proc = variables.default_proc) remapped.default_proc = default_proc end remapped when Array variables.collect do |v| variable_stack(v, false) end else force_as_array ? [ variables ] : variables end end |