Module: WLang::Html::HighOrderFunctions
- Included in:
- WLang::Html
- Defined in:
- lib/wlang/html.rb
Instance Method Summary collapse
- #ampersand(buf, fn) ⇒ Object
- #bang(buf, fn) ⇒ Object
- #caret(buf, fn_if, fn_then, fn_else) ⇒ Object
- #dollar(buf, fn) ⇒ Object
- #greater(buf, fn) ⇒ Object
- #modulo(buf, fn) ⇒ Object
- #plus(buf, fn) ⇒ Object
- #question(buf, fn_if, fn_then, fn_else) ⇒ Object
- #sharp(buf, who_fn, then_fn) ⇒ Object
- #slash(buf, fn) ⇒ Object
- #star(buf, coll_fn, elm_fn, between_fn) ⇒ Object
Instance Method Details
#ampersand(buf, fn) ⇒ Object
41 42 43 44 |
# File 'lib/wlang/html.rb', line 41 def ampersand(buf, fn) val = escape_html(render(fn)) render(val, nil, buf) end |
#bang(buf, fn) ⇒ Object
25 26 27 28 |
# File 'lib/wlang/html.rb', line 25 def bang(buf, fn) val = evaluate(fn).to_s render(val, nil, buf) end |
#caret(buf, fn_if, fn_then, fn_else) ⇒ Object
60 61 62 |
# File 'lib/wlang/html.rb', line 60 def caret(buf, fn_if, fn_then, fn_else) question(buf, fn_if, fn_else, fn_then) end |
#dollar(buf, fn) ⇒ Object
36 37 38 39 |
# File 'lib/wlang/html.rb', line 36 def dollar(buf, fn) val = escape_html(plus("", fn)) render(val, nil, buf) end |
#greater(buf, fn) ⇒ Object
72 73 74 75 76 77 |
# File 'lib/wlang/html.rb', line 72 def greater(buf, fn) val = evaluate(fn) val = self.class.compile(val) if String === val val = val.call if Proc === val and val.arity<=0 render(val, nil, buf) end |
#modulo(buf, fn) ⇒ Object
49 50 51 |
# File 'lib/wlang/html.rb', line 49 def modulo(buf, fn) render(fn, nil, buf) end |
#plus(buf, fn) ⇒ Object
30 31 32 33 34 |
# File 'lib/wlang/html.rb', line 30 def plus(buf, fn) val = evaluate(fn) val = to_html(val) unless val.is_a?(Template) render(val, nil, buf) end |
#question(buf, fn_if, fn_then, fn_else) ⇒ Object
53 54 55 56 57 58 |
# File 'lib/wlang/html.rb', line 53 def question(buf, fn_if, fn_then, fn_else) val = evaluate(fn_if) val = val.call if Proc===val block = val ? fn_then : fn_else render(block, nil, buf) if block end |
#sharp(buf, who_fn, then_fn) ⇒ Object
79 80 81 82 83 84 |
# File 'lib/wlang/html.rb', line 79 def sharp(buf, who_fn, then_fn) val = evaluate(who_fn, nil) if val and not(val.respond_to?(:empty?) and val.empty?) render(then_fn, val, buf) end end |
#slash(buf, fn) ⇒ Object
46 47 |
# File 'lib/wlang/html.rb', line 46 def slash(buf, fn) end |
#star(buf, coll_fn, elm_fn, between_fn) ⇒ Object
64 65 66 67 68 69 70 |
# File 'lib/wlang/html.rb', line 64 def star(buf, coll_fn, elm_fn, between_fn) collection = evaluate(coll_fn) collection.each_with_index do |elm,i| render(between_fn, elm, buf) if between_fn and (i > 0) render(elm_fn, elm, buf) end end |