Class: Livetext
- Inherits:
-
Object
show all
- 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: 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.47"
Constants included
from Helpers
Helpers::Comment, Helpers::DollarDot, Helpers::DotCmd, Helpers::ESCAPING, Helpers::Sigil, Helpers::Space
Class Attribute Summary collapse
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Methods included from Helpers
#check_disallowed, #check_file_exists, #debug, #escape_html, #find_file, #friendly_error, #get_name_data, #grab_file, #graceful_error, #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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
|
# File 'lib/livetext/more.rb', line 101
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
67
68
69
|
# File 'lib/livetext/more.rb', line 67
def output
@output
end
|
Instance Attribute Details
Returns the value of attribute body.
64
65
66
|
# File 'lib/livetext/more.rb', line 64
def body
@body
end
|
#indentation ⇒ Object
Returns the value of attribute indentation.
64
65
66
|
# File 'lib/livetext/more.rb', line 64
def indentation
@indentation
end
|
Returns the value of attribute main.
62
63
64
|
# File 'lib/livetext/more.rb', line 62
def main
@main
end
|
Returns the value of attribute nopara.
63
64
65
|
# File 'lib/livetext/more.rb', line 63
def nopara
@nopara
end
|
Returns the value of attribute nopass.
63
64
65
|
# File 'lib/livetext/more.rb', line 63
def nopass
@nopass
end
|
Returns the value of attribute sources.
62
63
64
|
# File 'lib/livetext/more.rb', line 62
def sources
@sources
end
|
Class Method Details
.customize(mix: [], call: [], vars: {}) ⇒ Object
117
118
119
120
121
122
123
124
125
126
127
|
# File 'lib/livetext/more.rb', line 117
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]) }
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.expand_path(path)
end
|
.interpolate(str) ⇒ Object
74
75
76
77
78
79
|
# File 'lib/livetext/more.rb', line 74
def self.interpolate(str)
expand = Livetext::Expansion.new(self)
str2 = expand.expand_variables(str)
str3 = expand.expand_function_calls(str2)
str3
end
|
Instance Method Details
151
152
153
|
# File 'lib/livetext/more.rb', line 151
def api
@api
end
|
#api=(obj) ⇒ Object
155
156
157
|
# File 'lib/livetext/more.rb', line 155
def api=(obj)
@api = obj
end
|
#customize(mix: [], call: [], vars: {}) ⇒ Object
129
130
131
132
133
134
135
136
137
|
# File 'lib/livetext/more.rb', line 129
def customize(mix: [], call: [], vars: {})
mix = Array(mix)
call = Array(call)
mix.each {|lib| mixin(lib) }
call.each {|cmd| @main.send(cmd[1..-1]) }
api.setvars(vars)
self
end
|
#initial_vars ⇒ Object
159
160
161
162
163
|
# File 'lib/livetext/more.rb', line 159
def initial_vars
@api.setvar(:User, `whoami`.chomp)
@api.setvar(:Version, Livetext::VERSION)
end
|
139
140
141
142
143
144
145
146
147
148
149
|
# File 'lib/livetext/more.rb', line 139
def inspect
"Livetext:\n" +
" source = #{@source.inspect}\n" +
" mixins = #{@_mixins.inspect}\n" +
" import = #{@_mixins.inspect}\n" +
" main = (not shown)\n" +
" indent = #{@indentation.inspect}\n" +
" vars = #{@_vars.inspect}\n" +
" api = (not shown)\n" +
" body = (#{@body.size} bytes)"
end
|
85
86
87
|
# File 'lib/livetext/more.rb', line 85
def nextline
@main.nextline
end
|
#peek_nextline ⇒ Object
81
82
83
|
# File 'lib/livetext/more.rb', line 81
def peek_nextline
@main.peek_nextline
end
|
#save_location ⇒ Object
93
94
95
|
# File 'lib/livetext/more.rb', line 93
def save_location
@save_location
end
|
#save_location=(where) ⇒ Object
97
98
99
|
# File 'lib/livetext/more.rb', line 97
def save_location=(where)
@save_location = where
end
|
165
166
167
168
169
170
171
172
173
174
175
176
177
178
|
# File 'lib/livetext/more.rb', line 165
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
result
end
|
70
71
72
|
# File 'lib/livetext/more.rb', line 70
def vars
@_vars
end
|
EXPERIMENTAL and incomplete
181
182
183
184
185
186
187
188
189
190
191
192
193
194
|
# File 'lib/livetext/more.rb', line 181
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
|
196
197
198
199
200
201
202
203
|
# File 'lib/livetext/more.rb', line 196
def xform_file(file, vars: nil)
Livetext::Vars.replace(vars) unless vars.nil?
@_vars.replace(vars) unless vars.nil?
self.process_file(file)
self.body
end
|