Class: Livetext
- Includes:
- Helpers
- Defined in:
- lib/livetext/more.rb,
lib/livetext/paths.rb,
lib/livetext/version.rb,
lib/livetext/skeleton.rb
Overview
Class Livetext skeleton (top level).
Defined Under Namespace
Modules: Handler, Helpers, ParsingConstants, Standard Classes: CmdData, Expansion, Functions, LineParser, ParseGeneral, ParseSet, UserAPI, Variables
Constant Summary collapse
- Vars =
Variables.new
- TTY =
::File.open("/dev/tty", "w")
- Path =
self.get_path
- Plugins =
self.get_path("../plugin")
- Imports =
self.get_path("../imports")
- VERSION =
"0.9.42"
Constants included from Helpers
Helpers::Comment, Helpers::DollarDot, Helpers::DotCmd, Helpers::ESCAPING, Helpers::Sigil, Helpers::Space
Class Attribute Summary collapse
-
.output ⇒ Object
bad solution?.
Instance Attribute Summary collapse
-
#body ⇒ Object
Returns the value of attribute body.
-
#indentation ⇒ Object
Returns the value of attribute indentation.
-
#main ⇒ Object
readonly
Returns the value of attribute main.
-
#nopara ⇒ Object
Returns the value of attribute nopara.
-
#nopass ⇒ Object
Returns the value of attribute nopass.
-
#sources ⇒ Object
readonly
Returns the value of attribute sources.
Class Method Summary collapse
- .customize(mix: [], call: [], vars: {}) ⇒ Object
- .get_path(dir = "") ⇒ Object
- .interpolate(str) ⇒ Object
Instance Method Summary collapse
- #api ⇒ Object
- #api=(obj) ⇒ Object
- #customize(mix: [], call: [], vars: {}) ⇒ Object
-
#dump(file = nil) ⇒ Object
not a dot command!.
- #graceful_error(err, msg = nil) ⇒ Object
- #initial_vars ⇒ Object
-
#initialize(output = ::STDOUT) ⇒ Livetext
constructor
A new instance of Livetext.
- #nextline ⇒ Object
- #peek_nextline ⇒ Object
- #save_location ⇒ Object
- #save_location=(where) ⇒ Object
- #transform(text) ⇒ Object
- #vars ⇒ Object
-
#xform(*args, file: nil, text: nil, vars: {}) ⇒ Object
EXPERIMENTAL and incomplete.
- #xform_file(file, vars: nil) ⇒ Object
Methods included from Helpers
#check_disallowed, #check_file_exists, #debug, #escape_html, #find_file, #friendly_error, #get_name_data, #grab_file, #handle_dollar_dot, #handle_dotcmd, #handle_scomment, #include_file, #invoke_dotcmd, #onoff, #process_file, #process_line, #read_variables, rx, #search_upward, #set_variables, #setfile, #setfile!, #setvar, #showme
Constructor Details
#initialize(output = ::STDOUT) ⇒ Livetext
Returns a new instance of Livetext.
122 123 124 125 126 127 128 129 130 131 132 133 134 |
# File 'lib/livetext/more.rb', line 122 def initialize(output = ::STDOUT) @source = nil @_mixins = [] @_imports = [] @_outdir = "." @no_puts = output.nil? @body = "" @main = Processor.new(self, output) @indentation = [0] @_vars = Livetext::Vars @api = UserAPI.new(self) initial_vars end |
Class Attribute Details
.output ⇒ Object
bad solution?
53 54 55 |
# File 'lib/livetext/more.rb', line 53 def output @output end |
Instance Attribute Details
#body ⇒ Object
Returns the value of attribute body.
50 51 52 |
# File 'lib/livetext/more.rb', line 50 def body @body end |
#indentation ⇒ Object
Returns the value of attribute indentation.
50 51 52 |
# File 'lib/livetext/more.rb', line 50 def indentation @indentation end |
#main ⇒ Object (readonly)
Returns the value of attribute main.
48 49 50 |
# File 'lib/livetext/more.rb', line 48 def main @main end |
#nopara ⇒ Object
Returns the value of attribute nopara.
49 50 51 |
# File 'lib/livetext/more.rb', line 49 def nopara @nopara end |
#nopass ⇒ Object
Returns the value of attribute nopass.
49 50 51 |
# File 'lib/livetext/more.rb', line 49 def nopass @nopass end |
#sources ⇒ Object (readonly)
Returns the value of attribute sources.
48 49 50 |
# File 'lib/livetext/more.rb', line 48 def sources @sources end |
Class Method Details
.customize(mix: [], call: [], vars: {}) ⇒ Object
100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/livetext/more.rb', line 100 def self.customize(mix: [], call: [], vars: {}) obj = self.new mix = Array(mix) call = Array(call) mix.each do |lib| obj.invoke_dotcmd(:mixin, lib.dup) end call.each {|cmd| obj.main.send(cmd[1..-1]) } # ignores leading dot, no param obj.api.setvars(vars) obj end |
.get_path(dir = "") ⇒ Object
4 5 6 7 |
# File 'lib/livetext/paths.rb', line 4 def self.get_path(dir = "") path = File.join(File.dirname(__FILE__), dir) File.(path) end |
Instance Method Details
#api ⇒ Object
136 137 138 |
# File 'lib/livetext/more.rb', line 136 def api @api end |
#api=(obj) ⇒ Object
140 141 142 |
# File 'lib/livetext/more.rb', line 140 def api=(obj) @api = obj end |
#customize(mix: [], call: [], vars: {}) ⇒ Object
112 113 114 115 116 117 118 119 120 |
# File 'lib/livetext/more.rb', line 112 def customize(mix: [], call: [], vars: {}) mix = Array(mix) call = Array(call) mix.each {|lib| mixin(lib) } call.each {|cmd| @main.send(cmd[1..-1]) } # ignores leading dot, no param # vars.each_pair {|var, val| @api.set(var, val.to_s) } api.setvars(vars) self end |
#dump(file = nil) ⇒ Object
not a dot command!
87 88 89 90 91 92 |
# File 'lib/livetext/more.rb', line 87 def dump(file = nil) # not a dot command! file ||= ::STDOUT file.puts @body rescue => err TTY.puts "#dump had an error: #{err.inspect}" end |
#graceful_error(err, msg = nil) ⇒ Object
94 95 96 97 98 |
# File 'lib/livetext/more.rb', line 94 def graceful_error(err, msg = nil) dump STDERR.puts msg if msg raise err end |
#initial_vars ⇒ Object
144 145 146 147 148 |
# File 'lib/livetext/more.rb', line 144 def initial_vars # Other predefined variables (see also setfile) @api.setvar(:User, `whoami`.chomp) @api.setvar(:Version, Livetext::VERSION) end |
#nextline ⇒ Object
71 72 73 |
# File 'lib/livetext/more.rb', line 71 def nextline @main.nextline # delegate end |
#peek_nextline ⇒ Object
67 68 69 |
# File 'lib/livetext/more.rb', line 67 def peek_nextline @main.peek_nextline # delegate end |
#save_location ⇒ Object
79 80 81 |
# File 'lib/livetext/more.rb', line 79 def save_location @save_location # delegate end |
#save_location=(where) ⇒ Object
83 84 85 |
# File 'lib/livetext/more.rb', line 83 def save_location=(where) @save_location = where # delegate end |
#transform(text) ⇒ Object
150 151 152 153 154 155 156 157 158 159 160 161 162 163 |
# File 'lib/livetext/more.rb', line 150 def transform(text) setfile!("(string)") enum = text.each_line front = text.match(/.*?\n/).to_a.first.chomp rescue "" @main.source(enum, "STDIN: '#{front}...'", 0) loop do line = @main.nextline break if line.nil? process_line(line) end result = @body # @body = "" result end |
#vars ⇒ Object
56 57 58 |
# File 'lib/livetext/more.rb', line 56 def vars @_vars end |
#xform(*args, file: nil, text: nil, vars: {}) ⇒ Object
EXPERIMENTAL and incomplete
166 167 168 169 170 171 172 173 174 175 176 177 178 179 |
# File 'lib/livetext/more.rb', line 166 def xform(*args, file: nil, text: nil, vars: {}) case when file && text.nil? xform_file(file) when file.nil? && text transform(text) when file.nil? && text.nil? raise "Must specify file or text" when file && text raise "Cannot specify file and text" end self.process_file(file) self.body end |