Module: Livetext::Standard
- Included in:
- Processor
- Defined in:
- lib/standard.rb
Constant Summary collapse
- SimpleFormats =
Move this?
{ b: %w[<b> </b>], i: %w[<i> </i>], t: ["<font size=+1><tt>", "</tt></font>"], s: %w[<strike> </strike>] }
Instance Attribute Summary collapse
-
#_data ⇒ Object
readonly
Returns the value of attribute _data.
Instance Method Summary collapse
- #_assign_get_value ⇒ Object
- #_assign_get_var(c, e) ⇒ Object
- #_assign_skip_equal(e) ⇒ Object
- #_def ⇒ Object
- #_include ⇒ Object
- #_include_file(file) ⇒ Object
-
#_mixin(name) ⇒ Object
def include! # FIXME huh? file = @_args.first return unless File.exist?(file).
- #_quoted_value(quote, e) ⇒ Object
- #_seek(file) ⇒ Object
- #_unquoted_value(e) ⇒ Object
- #backtrace ⇒ Object
- #banner ⇒ Object
-
#bits ⇒ Object
dumb name - bold, italic, teletype, striketrough.
- #br ⇒ Object
- #cleanup ⇒ Object
- #comment ⇒ Object
- #copy ⇒ Object
- #data=(val) ⇒ Object
- #debug ⇒ Object
- #dlist ⇒ Object
- #errout ⇒ Object
- #func ⇒ Object
- #heading ⇒ Object
- #heredoc ⇒ Object
-
#in_out ⇒ Object
FIXME dumb name!.
- #inherit ⇒ Object
- #invoke(str) ⇒ Object
- #link ⇒ Object
- #mixin ⇒ Object
- #mono ⇒ Object
- #newpage ⇒ Object
- #nopara ⇒ Object
- #nopass ⇒ Object
- #old_dlist ⇒ Object
- #para ⇒ Object
- #passthru ⇒ Object
- #quit ⇒ Object
- #r ⇒ Object
- #raw ⇒ Object
- #reval ⇒ Object
- #say ⇒ Object
- #seek ⇒ Object
- #set ⇒ Object
- #set_NEW ⇒ Object
- #shell ⇒ Object
- #shell! ⇒ Object
- #variables ⇒ Object
-
#xtable ⇒ Object
Borrowed from bookish - FIXME.
Instance Attribute Details
#_data ⇒ Object (readonly)
Returns the value of attribute _data.
9 10 11 |
# File 'lib/standard.rb', line 9 def _data @_data end |
Instance Method Details
#_assign_get_value ⇒ Object
168 169 170 171 172 173 174 175 176 177 178 179 |
# File 'lib/standard.rb', line 168 def _assign_get_value c = e.peek value = "" case c when ?", ?' value = _quoted_value(c, e) else value = _unquoted_value(e) end c = e.peek value end |
#_assign_get_var(c, e) ⇒ Object
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 |
# File 'lib/standard.rb', line 121 def _assign_get_var(c, e) name = c loop do c = e.peek case c when /[a-zA-Z_\.0-9]/ name << e.next next when / =/ return name else raise "Error: did not expect #{c.inspect} in variable name" end end raise "Error: loop ended parsing variable name" end |
#_assign_skip_equal(e) ⇒ Object
138 139 140 141 142 143 144 145 146 |
# File 'lib/standard.rb', line 138 def _assign_skip_equal(e) loop { break if e.peek != " "; e.next } if e.peek == "=" e.next # skip spaces too loop { break if e.peek != " "; e.next } else raise "Error: expect equal sign" end end |
#_def ⇒ Object
93 94 95 96 97 98 99 100 101 102 |
# File 'lib/standard.rb', line 93 def _def name = @_args[0] str = "def #{name}\n" raise "Illegal name '#{name}'" if _disallowed?(name) str += _body_text(true) str += "\nend\n" eval str rescue => err _error!(err) end |
#_include ⇒ Object
265 266 267 268 269 270 |
# File 'lib/standard.rb', line 265 def _include file = @_args.first _check_existence(file, "No such include file '#{file}'") @parent.process_file(file) _optional_blank_line end |
#_include_file(file) ⇒ Object
272 273 274 275 |
# File 'lib/standard.rb', line 272 def _include_file(file) @_args = [file] _include end |
#_mixin(name) ⇒ Object
def include! # FIXME huh?
file = @_args.first
return unless File.exist?(file)
lines = @parent.process_file(file)
#? File.delete(file)
_optional_blank_line
end
297 298 299 300 |
# File 'lib/standard.rb', line 297 def _mixin(name) @_args = [name] mixin end |
#_quoted_value(quote, e) ⇒ Object
148 149 150 151 152 153 154 155 156 |
# File 'lib/standard.rb', line 148 def _quoted_value(quote, e) value = "" loop do c = e.next break if c == quote value << c end value end |
#_seek(file) ⇒ Object
227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 |
# File 'lib/standard.rb', line 227 def _seek(file) require 'pathname' # ;) value = nil if File.exist?(file) return file else count = 1 loop do front = "../" * count count += 1 here = Pathname.new(front)..dirname.to_s break if here == "/" path = front + file value = path if File.exist?(path) break if value end end return value rescue return nil end |
#_unquoted_value(e) ⇒ Object
158 159 160 161 162 163 164 165 166 |
# File 'lib/standard.rb', line 158 def _unquoted_value(e) value = "" loop do c = e.next break if c == " " || c == "," value << c end value end |
#backtrace ⇒ Object
25 26 27 28 29 |
# File 'lib/standard.rb', line 25 def backtrace arg = @_args.first @backtrace = true @backtrace = false if arg == "off" end |
#banner ⇒ Object
67 68 69 70 71 72 73 |
# File 'lib/standard.rb', line 67 def str = _format(@_data) n = str.length - 1 puts "-"*n puts str puts "-"*n end |
#bits ⇒ Object
dumb name - bold, italic, teletype, striketrough
17 18 19 20 21 22 23 |
# File 'lib/standard.rb', line 17 def bits # dumb name - bold, italic, teletype, striketrough b0, b1, i0, i1, t0, t1, s0, s1 = *@_args SimpleFormats[:b] = [b0, b1] SimpleFormats[:i] = [i0, i1] SimpleFormats[:t] = [t0, t1] SimpleFormats[:s] = [s0, s1] end |
#br ⇒ Object
466 467 468 469 470 471 |
# File 'lib/standard.rb', line 466 def br n = _args.first || "1" out = "" n.to_i.times { out << "<br>" } _out out end |
#cleanup ⇒ Object
83 84 85 86 87 88 89 90 91 |
# File 'lib/standard.rb', line 83 def cleanup @_args.each do |item| if ::File.directory?(item) system("rm -f #{item}/*") else ::FileUtils.rm(item) end end end |
#comment ⇒ Object
31 32 33 |
# File 'lib/standard.rb', line 31 def comment _body end |
#copy ⇒ Object
333 334 335 336 337 338 |
# File 'lib/standard.rb', line 333 def copy file = @_args.first _check_existence(file, "No such file '#{file}' to copy") _out grab_file(file) _optional_blank_line end |
#data=(val) ⇒ Object
11 12 13 14 15 |
# File 'lib/standard.rb', line 11 def data=(val) @_data = val @_args = val.split rescue [] @_mixins = [] end |
#debug ⇒ Object
349 350 351 352 353 |
# File 'lib/standard.rb', line 349 def debug arg = @_args.first self._debug = true self._debug = false if arg == "off" end |
#dlist ⇒ Object
406 407 408 409 410 411 412 413 414 415 416 |
# File 'lib/standard.rb', line 406 def dlist delim = _args.first _out "<dl>" _body do |line| line = _format(line) term, defn = line.split(delim) _out "<dt>#{term}</dt>" _out "<dd>#{defn}</dd>" end _out "</dl>" end |
#errout ⇒ Object
57 58 59 |
# File 'lib/standard.rb', line 57 def errout TTY.puts @_data end |
#func ⇒ Object
41 42 43 44 45 46 47 48 49 50 |
# File 'lib/standard.rb', line 41 def func funcname = @_args[0] _error! "Illegal name '#{funcname}'" if _disallowed?(funcname) func_def = " def \#{funcname}(param)\n \#{_body_text(true)}\n end\n" Livetext::Functions.class_eval func_def end |
#heading ⇒ Object
385 386 387 388 389 |
# File 'lib/standard.rb', line 385 def heading _print "<center><font size=+1><b>" _print @_data _print "</b></font></center>" end |
#heredoc ⇒ Object
213 214 215 216 217 218 219 220 221 222 223 224 225 |
# File 'lib/standard.rb', line 213 def heredoc var = @_args[0] str = _body_text s2 = "" str.each_line do |s| str = FormatLine.var_func_parse(s.chomp) s2 << str # + "<br>" end indent = @parent.indentation.last indented = " " * indent @parent._setvar(var, s2.chomp) _optional_blank_line end |
#in_out ⇒ Object
FIXME dumb name!
258 259 260 261 262 263 |
# File 'lib/standard.rb', line 258 def in_out # FIXME dumb name! file, dest = *@_args _check_existence(file, "No such include file '#{file}'") @parent.process_file(file, dest) _optional_blank_line end |
#inherit ⇒ Object
277 278 279 280 281 282 283 284 285 286 |
# File 'lib/standard.rb', line 277 def inherit file = @_args.first upper = "../#{file}" good = (File.exist?(upper) || File.exist?(file)) _error!("File #{file} not found (local or parent)") unless good @parent.process_file(upper) if File.exist?(upper) @parent.process_file(file) if File.exist?(file) _optional_blank_line end |
#invoke(str) ⇒ Object
396 397 |
# File 'lib/standard.rb', line 396 def invoke(str) end |
#link ⇒ Object
431 432 433 434 435 |
# File 'lib/standard.rb', line 431 def link url = _args.first text = _args[2..-1].join(" ") _out "<a style='text-decoration: none' href='#{url}'>#{text}</a>" end |
#mixin ⇒ Object
302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 |
# File 'lib/standard.rb', line 302 def mixin name = @_args.first # Expect a module name file = "#{Plugins}/" + name.downcase + ".rb" return if @_mixins.include?(name) file = "./#{name}.rb" unless File.exist?(file) if File.exist?(file) # Just keep going... else if File.(".").dirname != "/" Dir.chdir("..") { mixin } return else STDERR.puts "No such mixin '#{name}" puts @body exit! end end @_mixins << name meths = grab_file(file) modname = name.gsub("/","_").capitalize string = "module ::#{modname}; #{meths}\nend" eval(string) newmod = Object.const_get("::" + modname) self.extend(newmod) init = "init_#{name}" self.send(init) if self.respond_to? init _optional_blank_line end |
#mono ⇒ Object
399 400 401 402 403 404 |
# File 'lib/standard.rb', line 399 def mono _out "<pre>" _body(true) {|line| _out line } _out "</pre>" _optional_blank_line end |
#newpage ⇒ Object
391 392 393 394 |
# File 'lib/standard.rb', line 391 def newpage _out '<p style="page-break-after:always;"></p>' _out "<p/>" end |
#nopara ⇒ Object
381 382 383 |
# File 'lib/standard.rb', line 381 def nopara @_nopara = true end |
#nopass ⇒ Object
366 367 368 |
# File 'lib/standard.rb', line 366 def nopass @_nopass = true end |
#old_dlist ⇒ Object
418 419 420 421 422 423 424 425 426 427 428 429 |
# File 'lib/standard.rb', line 418 def old_dlist delim = _args.first _out "<table>" _body do |line| line = _format(line) term, defn = line.split(delim) _out "<tr>" _out "<td width=3%><td width=10%>#{term}</td><td>#{defn}</td>" _out "</tr>" end _out "</table>" end |
#para ⇒ Object
370 371 372 373 374 375 376 377 378 379 |
# File 'lib/standard.rb', line 370 def para # FIXME - add check for args size (helpers); _onoff helper?? onoff = _args.first case onoff when nil; @_nopara = false when "on"; @_nopara = false when "off"; @_nopara = true else _error!("Unknown arg '#{onoff}'") end end |
#passthru ⇒ Object
355 356 357 358 359 360 361 362 363 364 |
# File 'lib/standard.rb', line 355 def passthru # FIXME - add check for args size (helpers); _onoff helper?? onoff = _args.first case onoff when nil; @_nopass = false when "on"; @_nopass = false when "off"; @_nopass = true else _error!("Unknown arg '#{onoff}'") end end |
#quit ⇒ Object
75 76 77 78 79 80 |
# File 'lib/standard.rb', line 75 def quit puts @body @body = "" @output.close # exit! end |
#r ⇒ Object
340 341 342 |
# File 'lib/standard.rb', line 340 def r _out @_data # No processing at all end |
#raw ⇒ Object
344 345 346 347 |
# File 'lib/standard.rb', line 344 def raw # No processing at all (terminate with __EOF__) _raw_body {|x| _out x } # no formatting end |
#reval ⇒ Object
209 210 211 |
# File 'lib/standard.rb', line 209 def reval eval _data end |
#say ⇒ Object
61 62 63 64 65 |
# File 'lib/standard.rb', line 61 def say str = _format(@_data) TTY.puts str _optional_blank_line end |
#seek ⇒ Object
249 250 251 252 253 254 255 256 |
# File 'lib/standard.rb', line 249 def seek # like include, but search upward as needed file = @_args.first file = _seek(file) _error!(file, "No such include file '#{file}'") unless file @parent.process_file(file) _optional_blank_line end |
#set ⇒ Object
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 |
# File 'lib/standard.rb', line 104 def set # FIXME bug -- .set var="RIP, Hope Gallery" assigns = @_data.chomp.split(/, */) # Do a better way? # FIXME *Must* allow for vars/functions assigns.each do |a| var, val = a.split("=") var.strip! val.strip! val = val[1..-2] if val[0] == ?" && val[-1] == ?" val = val[1..-2] if val[0] == ?' && val[-1] == ?' val = FormatLine.var_func_parse(val) @parent._setvar(var, val) end _optional_blank_line end |
#set_NEW ⇒ Object
181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 |
# File 'lib/standard.rb', line 181 def set_NEW line = _data.dup # dup needed? e = line.each_char # enum loop do c = e.next case c when /a-z/i _assign_get_var(c, e) _assign_skip_equal when " " next else raise "set: Huh? line = #{line}" end end end |
#shell ⇒ Object
35 36 37 38 39 |
# File 'lib/standard.rb', line 35 def shell cmd = @_data # _errout("Running: #{cmd}") system(cmd) end |
#shell! ⇒ Object
52 53 54 55 |
# File 'lib/standard.rb', line 52 def shell! cmd = @_data system(cmd) end |
#variables ⇒ Object
198 199 200 201 202 203 204 205 206 207 |
# File 'lib/standard.rb', line 198 def variables prefix = _args[0] _body.each do |line| next if line.strip.empty? var, val = line.split(" ", 2) val = FormatLine.var_func_parse(val) var = prefix + "." + var if prefix @parent._setvar(var, val) end end |
#xtable ⇒ Object
Borrowed from bookish - FIXME
437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 |
# File 'lib/standard.rb', line 437 def xtable # Borrowed from bookish - FIXME title = @_data delim = " :: " _out "<br><center><table width=90% cellpadding=5>" lines = _body(true) maxw = nil lines.each do |line| line = _format(line) line.gsub!(/\n+/, "<br>") cells = line.split(delim) wide = cells.map {|x| x.length } maxw = [0] * cells.size maxw = maxw.map.with_index {|x, i| [x, wide[i]].max } end sum = maxw.inject(0, :+) maxw.map! {|x| (x/sum*100).floor } lines.each do |line| cells = line.split(delim) _out "<tr>" cells.each.with_index do |cell, i| _out " <td valign=top>#{cell}</td>" end _out "</tr>" end _out "</table></center>" end |