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:
16 17 18 19 20 |
# File 'lib/erubis/engine/escheme.rb', line 16 def self.supported_properties() # :nodoc: return [ [:func, '_add', "function name (ex. 'display')"], ] end |
Instance Method Details
#add_expr_debug(src, code) ⇒ Object
71 72 73 74 |
# File 'lib/erubis/engine/escheme.rb', line 71 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
67 68 69 |
# File 'lib/erubis/engine/escheme.rb', line 67 def add_expr_escaped(src, code) add_expr_literal(src, escaped_expr(code)) end |
#add_expr_literal(src, code) ⇒ Object
62 63 64 65 |
# File 'lib/erubis/engine/escheme.rb', line 62 def add_expr_literal(src, code) code.strip! src << "(#{@func} #{code})" end |
#add_postamble(src) ⇒ Object
76 77 78 79 80 |
# File 'lib/erubis/engine/escheme.rb', line 76 def add_postamble(src) return unless @func == '_add' src << "\n" unless src[-1] == ?\n src << " (reverse _buf))\n" end |
#add_preamble(src) ⇒ Object
28 29 30 31 32 33 34 |
# File 'lib/erubis/engine/escheme.rb', line 28 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
58 59 60 |
# File 'lib/erubis/engine/escheme.rb', line 58 def add_stmt(src, code) src << code end |
#add_text(src, text) ⇒ Object
47 48 49 50 51 52 53 54 55 56 |
# File 'lib/erubis/engine/escheme.rb', line 47 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
36 37 38 39 40 |
# File 'lib/erubis/engine/escheme.rb', line 36 def escape_text(text) @table_ ||= { '"'=>'\\"', '\\'=>'\\\\' } text.gsub!(/["\\]/) { |m| @table_[m] } return text end |
#escaped_expr(code) ⇒ Object
42 43 44 45 |
# File 'lib/erubis/engine/escheme.rb', line 42 def escaped_expr(code) code.strip! return "(#{@escapefunc} #{code})" end |
#init_generator(properties = {}) ⇒ Object
22 23 24 25 26 |
# File 'lib/erubis/engine/escheme.rb', line 22 def init_generator(properties={}) super @escapefunc ||= 'escape' @func = properties[:func] || '_add' # or 'display' end |