Module: Erubis::SchemeGenerator
Instance Attribute Summary
Attributes included from Generator
Class Method Summary collapse
-
.supported_properties ⇒ Object
:nodoc:.
Instance Method Summary collapse
- #add_expr_debug(src, code) ⇒ Object
- #add_expr_escaped(src, code) ⇒ Object
- #add_expr_literal(src, code) ⇒ Object
- #add_postamble(src) ⇒ Object
- #add_preamble(src) ⇒ Object
- #add_stmt(src, code) ⇒ Object
- #add_text(src, text) ⇒ Object
- #escape_text(text) ⇒ Object
- #escaped_expr(code) ⇒ Object
- #init_generator(properties = {}) ⇒ Object
Class Method Details
.supported_properties ⇒ Object
:nodoc:
17 18 19 20 21 |
# File 'lib/erubis/engine/escheme.rb', line 17 def self.supported_properties() # :nodoc: return [ [:func, '_add', "function name (ex. 'display')"], ] end |
Instance Method Details
#add_expr_debug(src, code) ⇒ Object
72 73 74 75 |
# File 'lib/erubis/engine/escheme.rb', line 72 def add_expr_debug(src, code) s = (code.strip! || code).gsub(/\"/, '\\"') src << "(display \"*** debug: #{s}=\")(display #{code.strip})(display \"\\n\")" end |
#add_expr_escaped(src, code) ⇒ Object
68 69 70 |
# File 'lib/erubis/engine/escheme.rb', line 68 def add_expr_escaped(src, code) add_expr_literal(src, escaped_expr(code)) end |
#add_expr_literal(src, code) ⇒ Object
63 64 65 66 |
# File 'lib/erubis/engine/escheme.rb', line 63 def add_expr_literal(src, code) code.strip! src << "(#{@func} #{code})" end |
#add_postamble(src) ⇒ Object
77 78 79 80 81 |
# File 'lib/erubis/engine/escheme.rb', line 77 def add_postamble(src) return unless @func == '_add' src << "\n" unless src[-1] == ?\n src << " (reverse _buf))\n" end |
#add_preamble(src) ⇒ Object
29 30 31 32 33 34 35 |
# File 'lib/erubis/engine/escheme.rb', line 29 def add_preamble(src) return unless @func == '_add' src << "(let ((_buf '())) " + \ "(define (_add x) (set! _buf (cons x _buf))) " #src << "(let* ((_buf '())" + \ # " (_add (lambda (x) (set! _buf (cons x _buf))))) " end |
#add_stmt(src, code) ⇒ Object
59 60 61 |
# File 'lib/erubis/engine/escheme.rb', line 59 def add_stmt(src, code) src << code end |
#add_text(src, text) ⇒ Object
48 49 50 51 52 53 54 55 56 57 |
# File 'lib/erubis/engine/escheme.rb', line 48 def add_text(src, text) return if text.empty? t = escape_text(text) if t[-1] == ?\n t[-1, 1] = '' src << "(#{@func} \"" << t << "\\n\")\n" else src << "(#{@func} \"" << t << '")' end end |
#escape_text(text) ⇒ Object
37 38 39 40 41 |
# File 'lib/erubis/engine/escheme.rb', line 37 def escape_text(text) @table_ ||= { '"'=>'\\"', '\\'=>'\\\\' } text.gsub!(/["\\]/) { |m| @table_[m] } return text end |
#escaped_expr(code) ⇒ Object
43 44 45 46 |
# File 'lib/erubis/engine/escheme.rb', line 43 def escaped_expr(code) code.strip! return "(#{@escapefunc} #{code})" end |
#init_generator(properties = {}) ⇒ Object
23 24 25 26 27 |
# File 'lib/erubis/engine/escheme.rb', line 23 def init_generator(properties={}) super @escapefunc ||= 'escape' @func = properties[:func] || '_add' # or 'display' end |