livetext 0.9.23 → 0.9.26

Sign up to get free protection for your applications and to get access to all the features.
Files changed (115) hide show
  1. checksums.yaml +4 -4
  2. data/README.lt3 +6 -6
  3. data/bin/livetext +57 -40
  4. data/imports/bookish.rb +81 -81
  5. data/imports/calibre.rb +3 -3
  6. data/imports/livemagick.rb +17 -17
  7. data/imports/markdown.rb +10 -10
  8. data/imports/pyggish.rb +13 -13
  9. data/imports/tutorial.rb +15 -15
  10. data/lib/cmdargs.rb +7 -4
  11. data/lib/{errors.rb → livetext/errors.rb} +4 -3
  12. data/lib/{formatline.rb → livetext/formatline.rb} +119 -18
  13. data/lib/livetext/funcall.rb +168 -0
  14. data/lib/{functions.rb → livetext/functions.rb} +0 -2
  15. data/lib/{global_helpers.rb → livetext/global_helpers.rb} +6 -3
  16. data/lib/{handler → livetext/handler}/import.rb +5 -9
  17. data/lib/livetext/handler/mixin.rb +33 -0
  18. data/lib/{handler.rb → livetext/handler.rb} +1 -1
  19. data/lib/{helpers.rb → livetext/helpers.rb} +78 -66
  20. data/lib/{html.rb → livetext/html.rb} +2 -3
  21. data/lib/livetext/lineparser.rb +441 -0
  22. data/lib/livetext/more.rb +158 -0
  23. data/lib/{parser → livetext/parser}/general.rb +0 -0
  24. data/lib/{parser → livetext/parser}/set.rb +0 -0
  25. data/lib/{parser → livetext/parser}/string.rb +0 -0
  26. data/lib/{parser.rb → livetext/parser.rb} +0 -3
  27. data/lib/{parsing.rb → livetext/parsing.rb} +0 -2
  28. data/lib/livetext/paths.rb +13 -0
  29. data/lib/{processor.rb → livetext/processor.rb} +18 -8
  30. data/lib/livetext/reopen.rb +12 -0
  31. data/lib/livetext/skeleton.rb +22 -0
  32. data/lib/{standard.rb → livetext/standard.rb} +150 -127
  33. data/lib/livetext/userapi.rb +170 -0
  34. data/lib/livetext/version.rb +6 -0
  35. data/lib/livetext.rb +14 -152
  36. data/plugin/bookish.rb +82 -81
  37. data/plugin/calibre.rb +3 -3
  38. data/plugin/livemagick.rb +17 -17
  39. data/plugin/markdown.rb +10 -10
  40. data/plugin/pyggish.rb +118 -118
  41. data/plugin/tutorial.rb +15 -15
  42. data/test/all.rb +6 -0
  43. data/test/snapshots/{error_inc_line_num → basic_formatting}/actual-error.txt +0 -0
  44. data/test/snapshots/basic_formatting/actual-output.txt +13 -0
  45. data/test/snapshots/basic_formatting/err-sdiff.txt +1 -0
  46. data/test/snapshots/basic_formatting/out-sdiff.txt +14 -0
  47. data/test/snapshots/def_method/expected-output.txt +2 -0
  48. data/test/snapshots/def_method/source.lt3 +4 -2
  49. data/test/snapshots/error_inc_line_num/{OUT → README.txt} +11 -8
  50. data/test/snapshots/error_inc_line_num/expected-output.txt +0 -6
  51. data/test/snapshots/error_inc_line_num/match-error.txt +1 -1
  52. data/test/snapshots/error_invalid_name/foo +5 -0
  53. data/test/snapshots/error_line_num/match-error.txt +1 -1
  54. data/test/snapshots/error_missing_end/expected-output.txt +0 -1
  55. data/test/snapshots/error_name_not_permitted/expected-output.txt +4 -0
  56. data/test/snapshots/error_name_not_permitted/match-error.txt +1 -1
  57. data/test/snapshots/error_no_such_copy/expected-output.txt +1 -0
  58. data/test/snapshots/error_no_such_mixin/expected-output.txt +1 -0
  59. data/test/snapshots/error_no_such_mixin/match-error.txt +1 -1
  60. data/test/snapshots/error_no_such_mixin/source.lt3 +1 -1
  61. data/test/snapshots/example_alpha/source.lt3 +2 -2
  62. data/test/snapshots/example_alpha2/expected-output.txt +0 -2
  63. data/test/snapshots/example_alpha2/source.lt3 +5 -4
  64. data/test/snapshots/import/expected-output.txt +2 -1
  65. data/test/snapshots/import/match-error.txt +1 -1
  66. data/test/snapshots/import/simple_import.rb +1 -1
  67. data/test/snapshots/import2/simple_import.rb +1 -1
  68. data/test/snapshots/import_bookish/expected-output.txt +4 -4
  69. data/test/snapshots/{error_invalid_name/actual-output.txt → more_functions/actual-error.txt} +0 -0
  70. data/test/snapshots/more_functions/actual-output.txt +37 -0
  71. data/test/snapshots/more_functions/err-sdiff.txt +1 -0
  72. data/test/snapshots/more_functions/expected-output.txt +1 -1
  73. data/test/snapshots/more_functions/out-sdiff.txt +38 -0
  74. data/test/snapshots/more_functions/source.lt3 +1 -1
  75. data/test/snapshots/raw_lines/expected-output.txt +0 -2
  76. data/test/snapshots/simple_import/simple_import.rb +1 -1
  77. data/test/snapshots/simple_mixin/simple_mixin.rb +1 -1
  78. data/test/snapshots/{error_missing_end/actual-output.txt → simple_vars/actual-error.txt} +0 -0
  79. data/test/snapshots/simple_vars/actual-output.txt +6 -0
  80. data/test/snapshots/simple_vars/err-sdiff.txt +1 -0
  81. data/test/snapshots/simple_vars/out-sdiff.txt +7 -0
  82. data/test/snapshots/single_raw_line/expected-output.txt +0 -2
  83. data/test/snapshots/subset.txt +9 -7
  84. data/test/snapshots/{error_no_such_copy/actual-output.txt → var_into_func/actual-error.txt} +0 -0
  85. data/test/snapshots/var_into_func/actual-output.txt +16 -0
  86. data/test/snapshots/var_into_func/err-sdiff.txt +1 -0
  87. data/test/snapshots/{error_no_such_inc/actual-output.txt → var_into_func/expected-error.txt} +0 -0
  88. data/test/snapshots/var_into_func/expected-output.txt +16 -0
  89. data/test/snapshots/var_into_func/out-sdiff.txt +17 -0
  90. data/test/snapshots/var_into_func/source.lt3 +16 -0
  91. data/test/snapshots.rb +16 -7
  92. data/test/unit/all.rb +3 -1
  93. data/test/unit/formatline.rb +145 -276
  94. data/test/unit/html.rb +1 -2
  95. data/test/unit/lineparser.rb +650 -0
  96. data/test/unit/parser/set.rb +13 -12
  97. data/test/unit/standard.rb +0 -1
  98. data/test/unit/tokenizer.rb +534 -0
  99. metadata +49 -39
  100. data/lib/funcall.rb +0 -93
  101. data/lib/parser/file.rb +0 -6
  102. data/lib/parser/mixin.rb +0 -34
  103. data/lib/userapi.rb +0 -164
  104. data/test/snapshots/error_inc_line_num/actual-output.txt +0 -17
  105. data/test/snapshots/error_invalid_name/actual-error.txt +0 -10
  106. data/test/snapshots/error_invalid_name/out-sdiff.txt +0 -6
  107. data/test/snapshots/error_missing_end/actual-error.txt +0 -10
  108. data/test/snapshots/error_missing_end/out-sdiff.txt +0 -6
  109. data/test/snapshots/error_no_such_copy/actual-error.txt +0 -10
  110. data/test/snapshots/error_no_such_copy/out-sdiff.txt +0 -5
  111. data/test/snapshots/error_no_such_inc/actual-error.txt +0 -10
  112. data/test/snapshots/error_no_such_inc/out-sdiff.txt +0 -6
  113. data/test/snapshots/error_no_such_mixin/actual-error.txt +0 -13
  114. data/test/snapshots/error_no_such_mixin/actual-output.txt +0 -0
  115. data/test/snapshots/error_no_such_mixin/out-sdiff.txt +0 -6
data/lib/livetext.rb CHANGED
@@ -1,157 +1,19 @@
1
- # p __FILE__
2
1
 
3
- require_relative 'parser/string'
2
+ require_relative 'livetext/skeleton'
3
+ require_relative 'livetext/version'
4
+ require_relative 'livetext/paths'
4
5
 
5
- # Class Livetext skeleton (top level).
6
+ require_relative 'livetext/reopen'
6
7
 
7
- class Livetext
8
- VERSION = "0.9.23"
9
- Path = File.expand_path(File.join(File.dirname(__FILE__)))
8
+ require_relative 'livetext/errors'
9
+ require_relative 'livetext/standard'
10
+ require_relative 'livetext/functions'
11
+ require_relative 'livetext/userapi'
12
+ # require_relative 'livetext/formatline'
13
+ require_relative 'livetext/lineparser'
14
+ require_relative 'livetext/processor'
15
+ require_relative 'livetext/helpers'
16
+ require_relative 'livetext/handler'
10
17
 
11
- module Handler
12
- end
13
-
14
- module ParsingConstants
15
- end
16
-
17
- class FormatLine < StringParser
18
- module FunCall
19
- end
20
- end
21
- end
22
-
23
- require 'fileutils'
24
-
25
- class Object
26
- def send?(meth, *args)
27
- if self.respond_to?(meth)
28
- self.send(meth, *args)
29
- else
30
- return nil
31
- end
32
- end
33
- end
34
-
35
- require_relative 'errors'
36
- require_relative 'standard'
37
- require_relative 'functions'
38
- require_relative 'userapi'
39
- require_relative 'formatline'
40
- require_relative 'processor'
41
- require_relative 'helpers'
42
- require_relative 'handler'
43
-
44
-
45
- Plugins = File.expand_path(File.join(File.dirname(__FILE__), "../plugin"))
46
- Imports = File.expand_path(File.join(File.dirname(__FILE__), "../imports"))
47
-
48
- TTY = ::File.open("/dev/tty", "w")
49
-
50
- make_exception(:EndWithoutOpening, "Error: found .end with no opening command")
51
-
52
- # Class Livetext reopened (top level).
53
-
54
- class Livetext
55
-
56
- include Helpers
57
-
58
- Vars = {}
59
-
60
-
61
- attr_reader :main
62
- attr_accessor :no_puts
63
- attr_accessor :body, :indentation
64
-
65
- class << self
66
- attr_accessor :output # bad solution?
67
- end
68
-
69
- def vars
70
- Livetext::Vars.dup
71
- end
72
-
73
- def self.interpolate(str)
74
- # FIXME There are issues here...
75
- Livetext::FormatLine.var_func_parse(str)
76
- end
77
-
78
- def self.customize(mix: [], call: [], vars: {})
79
- obj = self.new
80
- mix = Array(mix)
81
- call = Array(call)
82
- mix.each {|lib| obj.mixin(lib) }
83
- call.each {|cmd| obj.main.send(cmd[1..-1]) } # ignores leading dot, no param
84
- vars.each_pair {|var, val| obj.setvar(var, val.to_s) }
85
- obj
86
- end
87
-
88
- def customize(mix: [], call: [], vars: {})
89
- mix = Array(mix)
90
- call = Array(call)
91
- mix.each {|lib| mixin(lib) } # FIXME HF won't this break??
92
- call.each {|cmd| @main.send(cmd[1..-1]) } # ignores leading dot, no param
93
- vars.each_pair {|var, val| setvar(var, val.to_s) }
94
- self
95
- end
96
-
97
- def initialize(output = ::STDOUT)
98
- @source = nil
99
- @_mixins = []
100
- @_outdir = "."
101
- @no_puts = output.nil?
102
- @body = ""
103
- @main = Processor.new(self, output)
104
- @indentation = [0]
105
- @_vars = Livetext::Vars
106
- initial_vars
107
- end
108
-
109
- def interpolate(str)
110
- end
111
-
112
- def initial_vars
113
- # Other predefined variables (see also setfile)
114
- setvar(:User, `whoami`.chomp)
115
- setvar(:Version, Livetext::VERSION)
116
- end
117
-
118
- def transform(text)
119
- setfile!("(string)")
120
- enum = text.each_line
121
- front = text.match(/.*?\n/).to_a.first.chomp rescue ""
122
- @main.source(enum, "STDIN: '#{front}...'", 0)
123
- loop do
124
- line = @main.nextline
125
- break if line.nil?
126
- process_line(line)
127
- end
128
- result = @body
129
- @body = ""
130
- result
131
- end
132
-
133
- # EXPERIMENTAL and incomplete
134
- def xform(*args, file: nil, text: nil, vars: {})
135
- case
136
- when file && text.nil?
137
- xform_file(file)
138
- when file.nil? && text
139
- transform(text)
140
- when file.nil? && text.nil?
141
- raise "Must specify file or text"
142
- when file && text
143
- raise "Cannot specify file and text"
144
- end
145
- self.process_file(file)
146
- self.body
147
- end
148
-
149
- def xform_file(file, vars: nil)
150
- Livetext::Vars.replace(vars) unless vars.nil?
151
- @_vars.replace(vars) unless vars.nil?
152
- self.process_file(file)
153
- self.body
154
- end
155
-
156
- end
18
+ require_relative 'livetext/more'
157
19
 
data/plugin/bookish.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  def hardbreaks(args = nil, body = nil)
2
2
  @hard = false
3
- @hard = true unless @_args.first == "off"
3
+ @hard = true unless api.args.first == "off"
4
4
  end
5
5
 
6
6
  def hardbreaks?
@@ -13,27 +13,27 @@ end
13
13
 
14
14
  # These are duplicated. Remove safely
15
15
 
16
- def h1; _out "<h1>#{@_data}</h1>"; end
17
- def h2; _out "<h2>#{@_data}</h2>"; end
18
- def h3; _out "<h3>#{@_data}</h3>"; end
16
+ def h1; api.out "<h1>#{api.data}</h1>"; end
17
+ def h2; api.out "<h2>#{api.data}</h2>"; end
18
+ def h3; api.out "<h3>#{api.data}</h3>"; end
19
19
 
20
20
  def alpha_columns(args = nil, body = nil)
21
- n = @_args.first.to_i # FIXME: what if it's missing?
21
+ n = api.args.first.to_i # FIXME: what if it's missing?
22
22
  words = []
23
- _body do |line|
23
+ api.body do |line|
24
24
  words << line.chomp
25
25
  end
26
26
  words.sort!
27
- _out "<table cellpadding=2>"
27
+ api.out "<table cellpadding=2>"
28
28
  words.each_slice(n) do |w|
29
29
  items = w.map {|x| "<tt>#{x}</tt>" }
30
- _out "<tr><td width=5% valign=top></td><td>" + items.join("</td><td>") + "</td></tr>"
30
+ api.out "<tr><td width=5% valign=top></td><td>" + items.join("</td><td>") + "</td></tr>"
31
31
  end
32
- _out "</table>"
32
+ api.out "</table>"
33
33
  end
34
34
 
35
35
  # def comment
36
- # _body { } # ignore body
36
+ # api.body { } # ignore body
37
37
  # end
38
38
 
39
39
  def _errout(*args)
@@ -53,28 +53,28 @@ end
53
53
  # FIXME duplicated?
54
54
 
55
55
  def image(args = nil, body = nil)
56
- name = @_args[0]
57
- _out "<img src='#{name}'></img>"
56
+ name = api.args[0]
57
+ api.out "<img src='#{name}'></img>"
58
58
  end
59
59
 
60
60
  def figure(args = nil, body = nil)
61
- name = @_args[0]
62
- num = @_args[1]
63
- title = @_args[2..-1].join(" ")
64
- title = _format(title)
65
- _out "<img src='#{name}'></img>"
66
- _out "<center><b>Figure #{num}</b> #{title}</center>"
61
+ name = api.args[0]
62
+ num = api.args[1]
63
+ title = api.args[2..-1].join(" ")
64
+ title = api.format(title)
65
+ api.out "<img src='#{name}'></img>"
66
+ api.out "<center><b>Figure #{num}</b> #{title}</center>"
67
67
  end
68
68
 
69
69
  def chapter(args = nil, body = nil)
70
- @chapter = @_args.first.to_i
70
+ @chapter = api.args.first.to_i
71
71
  @sec = @sec2 = 0
72
- title = @_data.split(" ",2)[1]
72
+ title = api.data.split(" ",2)[1]
73
73
  @toc << "<br><b>#@chapter</b> #{title}<br>"
74
- @_data = _slug(title)
74
+ api.data = _slug(title)
75
75
  next_output
76
- _out "<title>#{@chapter}. #{title}</title>"
77
- _out <<-HTML
76
+ api.out "<title>#{@chapter}. #{title}</title>"
77
+ api.out <<-HTML
78
78
  <h2>Chapter #{@chapter}</h2>
79
79
  <h1>#{title}</h1>
80
80
 
@@ -84,13 +84,13 @@ end
84
84
  def chapterN(args = nil, body = nil)
85
85
  @chapter += 1
86
86
  @sec = @sec2 = 0
87
- title = @_data # .split(" ",2)[1]
87
+ title = api.data # .split(" ",2)[1]
88
88
  _errout("Chapter #@chapter: #{title}")
89
89
  @toc << "<br><b>#@chapter</b> #{title}<br>"
90
- @_data = _slug(title)
90
+ api.data = _slug(title)
91
91
  next_output
92
- _out "<title>#{@chapter}. #{title}</title>"
93
- _out <<-HTML
92
+ api.out "<title>#{@chapter}. #{title}</title>"
93
+ api.out <<-HTML
94
94
  <h2>Chapter #{@chapter}</h2>
95
95
  <h1>#{title}</h1>
96
96
 
@@ -101,11 +101,11 @@ def sec(args = nil, body = nil)
101
101
  @sec += 1
102
102
  @sec2 = 0
103
103
  @section = "#@chapter.#@sec"
104
- title = @_data.dup
104
+ title = api.data.dup
105
105
  @toc << "#{_nbsp(3)}<b>#@section</b> #{title}<br>"
106
- @_data = _slug(@_data)
106
+ api.data = _slug(api.data)
107
107
  next_output
108
- _out "<h3>#@section #{title}</h3>\n"
108
+ api.out "<h3>#@section #{title}</h3>\n"
109
109
  rescue => err
110
110
  ::STDERR.puts "#{err}\n#{err.backtrace}"
111
111
  exit
@@ -114,67 +114,66 @@ end
114
114
  def subsec(args = nil, body = nil)
115
115
  @sec2 += 1
116
116
  @subsec = "#@chapter.#@sec.#@sec2"
117
- title = @_data.dup
117
+ title = api.data.dup
118
118
  @toc << "#{_nbsp(6)}<b>#@subsec</b> #{title}<br>"
119
- @_data = _slug(@_data)
119
+ api.data = _slug(api.data)
120
120
  next_output
121
- _out "<h3>#@subsec #{title}</h3>\n"
121
+ api.out "<h3>#@subsec #{title}</h3>\n"
122
122
  end
123
123
 
124
124
  def definition_table(args = nil, body = nil)
125
- title = @_data
125
+ title = api.data
126
126
  wide = "95"
127
127
  delim = " :: "
128
- _out "<br><center><table width=#{wide}% cellpadding=5>"
129
- lines = _body(true)
130
- lines.map! {|line| _format(line) }
128
+ api.out "<br><center><table width=#{wide}% cellpadding=5>"
129
+ lines = api.body(true)
130
+ lines.map! {|line| api.format(line) }
131
131
 
132
132
  lines.each do |line|
133
133
  cells = line.split(delim)
134
- _out "<tr>"
134
+ api.out "<tr>"
135
135
  cells.each.with_index do |cell, i|
136
136
  width = (i == 0) ? "width=15%" : ""
137
- _out " <td #{width} valign=top>#{cell}</td>"
137
+ api.out " <td #{width} valign=top>#{cell}</td>"
138
138
  end
139
- _out "</tr>"
139
+ api.out "</tr>"
140
140
  end
141
- _out "</table></center><br><br>"
141
+ api.out "</table></center><br><br>"
142
142
 
143
- _optional_blank_line
143
+ api.optional_blank_line
144
144
  end
145
145
 
146
146
  def table2(args = nil, body = nil)
147
- title = @_data
147
+ title = api.data
148
148
  wide = "90"
149
- extra = _args[2]
149
+ extra = api.args[2]
150
150
  delim = " :: "
151
- _out "<br><center><table width=#{wide}% cellpadding=5>"
152
- lines = _body(true)
153
- lines.map! {|line| _format(line) }
151
+ api.out "<br><center><table width=#{wide}% cellpadding=5>"
152
+ lines = api.body(true)
153
+ lines.map! {|line| api.format(line) }
154
154
 
155
155
  lines.each do |line|
156
156
  cells = line.split(delim)
157
157
  percent = (100/cells.size.to_f).round
158
- _out "<tr>"
158
+ api.out "<tr>"
159
159
  cells.each do |cell|
160
- _out " <td width=#{percent}% valign=top " +
160
+ api.out " <td width=#{percent}% valign=top " +
161
161
  "#{extra}>#{cell}</td>"
162
162
  end
163
- _out "</tr>"
163
+ api.out "</tr>"
164
164
  end
165
- _out "</table></center><br><br>"
166
-
167
- _optional_blank_line
165
+ api.out "</table></center><br><br>"
166
+ api.optional_blank_line
168
167
  end
169
168
 
170
169
  def simple_table(args = nil, body = nil)
171
- title = @_data
170
+ title = api.data
172
171
  delim = " :: "
173
- _out "<table cellpadding=2>"
174
- lines = _body(true)
172
+ api.out "<table cellpadding=2>"
173
+ lines = api.body(true)
175
174
  maxw = nil
176
175
  lines.each do |line|
177
- _format(line)
176
+ api.format(line)
178
177
  cells = line.split(delim)
179
178
  wide = cells.map {|x| x.length }
180
179
  maxw = [0] * cells.size
@@ -186,26 +185,27 @@ def simple_table(args = nil, body = nil)
186
185
 
187
186
  lines.each do |line|
188
187
  cells = line.split(delim)
189
- _out "<tr>"
188
+ api.out "<tr>"
190
189
  cells.each.with_index do |cell, i|
191
- _out " <td width=#{maxw}% valign=top>" +
190
+ api.out " <td width=#{maxw}% valign=top>" +
192
191
  "#{cell}</td>"
193
192
  end
194
- _out "</tr>"
193
+ api.out "</tr>"
195
194
  end
196
- _out "</table>"
195
+ api.out "</table>"
196
+ api.optional_blank_line
197
197
  end
198
198
 
199
199
  def table(args = nil, body = nil)
200
200
  @table_num ||= 0
201
201
  @table_num += 1
202
- title = @_data
202
+ title = api.data
203
203
  delim = " :: "
204
- _out "<br><center><table width=90% cellpadding=5>"
205
- lines = _body(true)
204
+ api.out "<br><center><table width=90% cellpadding=5>"
205
+ lines = api.body(true)
206
206
  maxw = nil
207
207
  lines.each do |line|
208
- _format(line)
208
+ api.format(line)
209
209
  cells = line.split(delim)
210
210
  wide = cells.map {|x| x.length }
211
211
  maxw = [0] * cells.size
@@ -217,17 +217,18 @@ def table(args = nil, body = nil)
217
217
 
218
218
  lines.each do |line|
219
219
  cells = line.split(delim)
220
- _out "<tr>"
220
+ api.out "<tr>"
221
221
  cells.each.with_index do |cell, i|
222
- _out " <td width=#{maxw}% valign=top>" +
222
+ api.out " <td width=#{maxw}% valign=top>" +
223
223
  "#{cell}</td>"
224
224
  end
225
- _out "</tr>"
225
+ api.out "</tr>"
226
226
  end
227
- _out "</table>"
227
+ api.out "</table>"
228
228
  @toc << "#{_nbsp(8)}<b>Table #@chapter.#@table_num</b> #{title}<br>"
229
229
  # _next_output(_slug("table_#{title}"))
230
- _out "<b>Table #@chapter.#@table_num &nbsp;&nbsp; #{title}</b></center><br>"
230
+ api.out "<b>Table #@chapter.#@table_num &nbsp;&nbsp; #{title}</b></center><br>"
231
+ api.optional_blank_line
231
232
  end
232
233
 
233
234
  def toc!(args = nil, body = nil)
@@ -240,7 +241,7 @@ rescue => err
240
241
  end
241
242
 
242
243
  def toc2(args = nil, body = nil)
243
- file = @_args[0]
244
+ file = api.args[0]
244
245
  @toc.close
245
246
  ::File.write(file, <<-EOS)
246
247
  <p style="page-break-after:always;"></p>
@@ -253,26 +254,26 @@ EOS
253
254
  end
254
255
 
255
256
  def missing(args = nil, body = nil)
256
- @toc << "#{_nbsp(8)}<font color=red>TBD: #@_data</font><br>"
257
- stuff = @_data.empty? ? "" : ": #@_data"
258
- _out "<br><font color=red><i>[Material missing#{stuff}]</i></font><br>\n "
257
+ @toc << "#{_nbsp(8)}<font color=red>TBD: #{api.data}</font><br>"
258
+ stuff = api.data.empty? ? "" : ": #{api.data}"
259
+ api.out "<br><font color=red><i>[Material missing#{stuff}]</i></font><br>\n "
259
260
  end
260
261
 
261
262
  def TBC(args = nil, body = nil)
262
263
  @toc << "#{_nbsp(8)}<font color=red>To be continued...</font><br>"
263
- _out "<br><font color=red><i>To be continued...</i></font><br>"
264
+ api.out "<br><font color=red><i>To be continued...</i></font><br>"
264
265
  end
265
266
 
266
267
  def note(args = nil, body = nil)
267
- _out "<br><font color=red><i>Note: "
268
- _out @_data
269
- _out "</i></font><br>\n "
268
+ api.out "<br><font color=red><i>Note: "
269
+ api.out api.data
270
+ api.out "</i></font><br>\n "
270
271
  end
271
272
 
272
273
  def quote(args = nil, body = nil)
273
- _out "<blockquote>"
274
- _body {|line| _out line }
275
- _out "</blockquote>"
274
+ api.out "<blockquote>"
275
+ api.body {|line| api.out line }
276
+ api.out "</blockquote>"
276
277
  rescue => err
277
278
  ::STDERR.puts "#{err}\n#{err.backtrace}"
278
279
  exit
data/plugin/calibre.rb CHANGED
@@ -1,9 +1,9 @@
1
1
  require 'fileutils'
2
2
 
3
3
  def epub!(args = nil, body = nil)
4
- out = _format(@_args[0])
5
- src = @_args[1]
6
- @cover = @_args[2]
4
+ out = api.format(api.args[0])
5
+ src = api.args[1]
6
+ @cover = api.args[2]
7
7
  if ::File.directory?(src)
8
8
  files = ::Dir["#{src}/*"].grep /\.html$/
9
9
  files = files.sort # why is this necessary now?
data/plugin/livemagick.rb CHANGED
@@ -2,24 +2,24 @@ require 'rmagick'
2
2
  include ::Magick
3
3
 
4
4
  def image(args = nil, body = nil)
5
- xx, yy, bg = _args
5
+ xx, yy, bg = api.args
6
6
  xx, yy = xx.to_i, yy.to_i
7
7
  @image = Image.new(xx,yy) { self.background_color = bg }
8
- _optional_blank_line
8
+ api.optional_blank_line
9
9
  end
10
10
 
11
11
  def canvas(args = nil, body = nil)
12
- color, width, opacity = _args
12
+ color, width, opacity = api.args
13
13
  opacity, width = opacity.to_i, width.to_i
14
14
  @canvas = Draw.new
15
15
  @canvas.fill_opacity(0)
16
16
  @canvas.stroke('black')
17
17
  @canvas.stroke_width(1)
18
- _optional_blank_line
18
+ api.optional_blank_line
19
19
  end
20
20
 
21
21
  def rectangle(args = nil, body = nil)
22
- xy, wxh, stroke_color, stroke_width = _args
22
+ xy, wxh, stroke_color, stroke_width = api.args
23
23
  x, y = xy.split(",").map(&:to_i)
24
24
  width, height = wxh.split("x").map(&:to_i)
25
25
  stroke_width = stroke_width.to_i
@@ -30,19 +30,19 @@ def rectangle(args = nil, body = nil)
30
30
  end
31
31
 
32
32
  def pen(args = nil, body = nil)
33
- @fill, @stroke = _args
33
+ @fill, @stroke = api.args
34
34
  @stroke = "black" if @stroke.nil? || @stroke.empty?
35
35
  _debug "pen: fill=#@fill stroke=#@stroke"
36
- _optional_blank_line
36
+ api.optional_blank_line
37
37
  end
38
38
 
39
39
  def font(args = nil, body = nil)
40
- size, font = _args
40
+ size, font = api.args
41
41
  font = "Helvetica" if font.nil? || font.empty?
42
42
  size = "32" if size.nil? || size.empty?
43
43
  @size, @font = size.to_i, font
44
44
  _debug "font: size=#@size font=#@font"
45
- _optional_blank_line
45
+ api.optional_blank_line
46
46
  end
47
47
 
48
48
  def _text(xy, wxh, str, weight, gravity)
@@ -60,34 +60,34 @@ def _text(xy, wxh, str, weight, gravity)
60
60
  end
61
61
 
62
62
  def text(args = nil, body = nil)
63
- xy, wxh, str = _data.split
63
+ xy, wxh, str = api.data.split
64
64
  weight, gravity = BoldWeight, CenterGravity
65
65
  _text(xy, wxh, str, weight, gravity)
66
- _optional_blank_line
66
+ api.optional_blank_line
67
67
  end
68
68
 
69
69
  def text!(args = nil, body = nil)
70
- xy, wxh = _data.split
71
- str = _body_text # .join
70
+ xy, wxh = api.data.split
71
+ str = api.body_text # .join
72
72
  weight, gravity = BoldWeight, CenterGravity
73
73
  _text(xy, wxh, str, weight, gravity)
74
- _optional_blank_line
74
+ api.optional_blank_line
75
75
  end
76
76
 
77
77
  def draw(args = nil, body = nil)
78
78
  @canvas.draw(@image)
79
- _optional_blank_line
79
+ api.optional_blank_line
80
80
  end
81
81
 
82
82
  def save(args = nil, body = nil)
83
83
  @image.write(_args.first)
84
- _optional_blank_line
84
+ api.optional_blank_line
85
85
  end
86
86
 
87
87
  def save!(args = nil, body = nil)
88
88
  save
89
89
  system("open #{_args.first}")
90
- _optional_blank_line
90
+ api.optional_blank_line
91
91
  end
92
92
 
93
93
  =begin
data/plugin/markdown.rb CHANGED
@@ -8,12 +8,12 @@ SimpleFormats[:t] = %w[` `]
8
8
  SimpleFormats[:s] = %w[<strike> </strike>]
9
9
 
10
10
 
11
- def h1(args = nil, body = nil); _out "# #{Livetext.interpolate(@_data)}"; _optional_blank_line end # atx style for now
12
- def h2(args = nil, body = nil); _out "## #{Livetext.interpolate(@_data)}"; _optional_blank_line end
13
- def h3(args = nil, body = nil); _out "### #{Livetext.interpolate(@_data)}"; _optional_blank_line end
14
- def h4(args = nil, body = nil); _out "#### #{Livetext.interpolate(@_data)}"; _optional_blank_line end
15
- def h5(args = nil, body = nil); _out "##### #{Livetext.interpolate(@_data)}"; _optional_blank_line end
16
- def h6(args = nil, body = nil); _out "###### #{Livetext.interpolate(@_data)}"; _optional_blank_line end
11
+ def h1(args = nil, body = nil); api.out "# #{Livetext.interpolate(api.data)}"; api.optional_blank_line end # atx style for now
12
+ def h2(args = nil, body = nil); api.out "## #{Livetext.interpolate(api.data)}"; api.optional_blank_line end
13
+ def h3(args = nil, body = nil); api.out "### #{Livetext.interpolate(api.data)}"; api.optional_blank_line end
14
+ def h4(args = nil, body = nil); api.out "#### #{Livetext.interpolate(api.data)}"; api.optional_blank_line end
15
+ def h5(args = nil, body = nil); api.out "##### #{Livetext.interpolate(api.data)}"; api.optional_blank_line end
16
+ def h6(args = nil, body = nil); api.out "###### #{Livetext.interpolate(api.data)}"; api.optional_blank_line end
17
17
 
18
18
  def title(args = nil, body = nil)
19
19
  h1
@@ -24,18 +24,18 @@ def section(args = nil, body = nil)
24
24
  end
25
25
 
26
26
  def bq(args = nil, body = nil) # block quote
27
- _body {|line| _out "> #{line}" }
27
+ api.body {|line| api.out "> #{line}" }
28
28
  end
29
29
 
30
30
  def list(args = nil, body = nil)
31
- _body {|line| _out " * #{line}" }
31
+ api.body {|line| api.out " * #{line}" }
32
32
  end
33
33
 
34
34
  def olist(args = nil, body = nil) # Doesn't handle paragraphs yet
35
35
  n = 0
36
- _body do |line|
36
+ api.body do |line|
37
37
  n += 1
38
- _out "#{n}. #{_format(line)}"
38
+ api.out "#{n}. #{_format(line)}"
39
39
  end
40
40
  end
41
41