Module: Livetext::UserAPI
- Included in:
- Processor
- Defined in:
- lib/userapi.rb
Overview
UserAPI deals mostly with user-level methods.
Instance Method Summary collapse
- #_args ⇒ Object
- #_body(raw = false) ⇒ Object
- #_body_text(raw = false) ⇒ Object
- #_check_existence(file, msg) ⇒ Object
- #_comment?(str) ⇒ Boolean
- #_debug(*args) ⇒ Object
- #_debug=(val) ⇒ Object
- #_end?(str) ⇒ Boolean
- #_format(line) ⇒ Object
- #_handle_escapes(str, set) ⇒ Object
- #_optional_blank_line ⇒ Object
- #_out(str = "", file = nil) ⇒ Object
- #_out!(str = "") ⇒ Object
- #_passthru(line) ⇒ Object
- #_print(*args) ⇒ Object
- #_puts(*args) ⇒ Object
- #_raw_body(tag = "__EOF__") ⇒ Object
- #_raw_body! ⇒ Object
- #_source ⇒ Object
- #_trailing?(char) ⇒ Boolean
- #_vars ⇒ Object
- #setvar(var, val) ⇒ Object
Instance Method Details
#_args ⇒ Object
23 24 25 26 27 28 29 30 |
# File 'lib/userapi.rb', line 23 def _args @_args = _format(@_data).chomp.split if block_given? @_args.each {|arg| yield arg } else @_args end end |
#_body(raw = false) ⇒ Object
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/userapi.rb', line 77 def _body(raw=false) lines = [] end_found = false loop do @line = nextline break if @line.nil? @line.chomp! break if _end?(@line) next if _comment?(@line) @line = _format(@line) unless raw lines << @line end raise "Expected .end, found end of file" unless _end?(@line) _optional_blank_line if block_given? lines.each {|line| yield line } # FIXME what about $. ? else lines end end |
#_body_text(raw = false) ⇒ Object
100 101 102 |
# File 'lib/userapi.rb', line 100 def _body_text(raw=false) _raw_body.join("\n") end |
#_check_existence(file, msg) ⇒ Object
15 16 17 |
# File 'lib/userapi.rb', line 15 def _check_existence(file, msg) _error! msg unless File.exist?(file) end |
#_comment?(str) ⇒ Boolean
42 43 44 45 46 47 |
# File 'lib/userapi.rb', line 42 def _comment?(str) sigil = Livetext::Sigil c1 = sigil + Livetext::Space c2 = sigil + sigil + Livetext::Space str.index(c1) == 0 || str.index(c2) == 0 end |
#_debug(*args) ⇒ Object
156 157 158 |
# File 'lib/userapi.rb', line 156 def _debug(*args) TTY.puts *args if @_debug end |
#_debug=(val) ⇒ Object
152 153 154 |
# File 'lib/userapi.rb', line 152 def _debug=(val) @_debug = val end |
#_end?(str) ⇒ Boolean
54 55 56 57 |
# File 'lib/userapi.rb', line 54 def _end?(str) return true if str == ".end" || str =~ / *\$\.end/ return false end |
#_format(line) ⇒ Object
116 117 118 119 120 121 |
# File 'lib/userapi.rb', line 116 def _format(line) return "" if line == "\n" || line.nil? line2 = FormatLine.parse!(line) line.replace(line2) line end |
#_handle_escapes(str, set) ⇒ Object
108 109 110 111 112 113 114 |
# File 'lib/userapi.rb', line 108 def _handle_escapes(str, set) str = str.dup set.each_char do |ch| str.gsub!("\\#{ch}", ch) end str end |
#_optional_blank_line ⇒ Object
36 37 38 39 40 |
# File 'lib/userapi.rb', line 36 def _optional_blank_line peek = peek_nextline return if peek.nil? @line = nextline if peek =~ /^ *$/ end |
#_out(str = "", file = nil) ⇒ Object
130 131 132 133 134 135 136 137 138 |
# File 'lib/userapi.rb', line 130 def _out(str = "", file = nil) return if str.nil? if file.nil? # FIXME do this elsewhere? @parent.body << str @parent.body << "\n" unless str.end_with?("\n") else file.puts str end end |
#_out!(str = "") ⇒ Object
140 141 142 |
# File 'lib/userapi.rb', line 140 def _out!(str = "") @parent.body << str # no newline end |
#_passthru(line) ⇒ Object
123 124 125 126 127 128 |
# File 'lib/userapi.rb', line 123 def _passthru(line) return if @_nopass _out "<p>" if line == "\n" and ! @_nopara line = _format(line) _out line end |
#_print(*args) ⇒ Object
148 149 150 |
# File 'lib/userapi.rb', line 148 def _print(*args) @output.print *args end |
#_puts(*args) ⇒ Object
144 145 146 |
# File 'lib/userapi.rb', line 144 def _puts(*args) @output.puts *args end |
#_raw_body(tag = "__EOF__") ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/userapi.rb', line 59 def _raw_body(tag = "__EOF__") lines = [] # @save_location = @sources.last loop do @line = nextline break if @line.nil? break if @line.chomp.strip == tag lines << @line end _optional_blank_line if block_given? lines.each {|line| yield line } else lines end lines end |
#_raw_body! ⇒ Object
104 105 106 |
# File 'lib/userapi.rb', line 104 def _raw_body! _raw_body(Livetext::Sigil).join("\n") end |
#_source ⇒ Object
19 20 21 |
# File 'lib/userapi.rb', line 19 def _source @input end |
#_trailing?(char) ⇒ Boolean
49 50 51 52 |
# File 'lib/userapi.rb', line 49 def _trailing?(char) return true if ["\n", " ", nil].include?(char) return false end |
#_vars ⇒ Object
32 33 34 |
# File 'lib/userapi.rb', line 32 def _vars @_vars.dup end |