livetext 0.9.21 → 0.9.25
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.lt3 +8 -8
- data/bin/livetext +57 -40
- data/imports/bookish.rb +89 -90
- data/imports/calibre.rb +3 -3
- data/imports/livemagick.rb +17 -17
- data/imports/markdown.rb +10 -10
- data/imports/pyggish.rb +15 -47
- data/imports/tutorial.rb +18 -18
- data/lib/cmdargs.rb +10 -6
- data/lib/{errors.rb → livetext/errors.rb} +1 -1
- data/lib/{formatline.rb → livetext/formatline.rb} +69 -125
- data/lib/livetext/funcall.rb +84 -0
- data/lib/{functions.rb → livetext/functions.rb} +16 -3
- data/lib/livetext/global_helpers.rb +37 -0
- data/lib/livetext/handler/import.rb +44 -0
- data/lib/livetext/handler/mixin.rb +37 -0
- data/lib/livetext/handler.rb +3 -0
- data/lib/{helpers.rb → livetext/helpers.rb} +89 -67
- data/lib/{html.rb → livetext/html.rb} +3 -2
- data/lib/{parser → livetext/parser}/general.rb +0 -3
- data/lib/{parser → livetext/parser}/set.rb +1 -6
- data/lib/{parser → livetext/parser}/string.rb +2 -2
- data/lib/{parser.rb → livetext/parser.rb} +0 -1
- data/lib/livetext/parsing.rb +29 -0
- data/lib/livetext/paths.rb +13 -0
- data/lib/livetext/processor.rb +89 -0
- data/lib/livetext/reopen.rb +12 -0
- data/lib/livetext/skeleton.rb +17 -0
- data/lib/{standard.rb → livetext/standard.rb} +152 -122
- data/lib/livetext/userapi.rb +153 -0
- data/lib/livetext/version.rb +6 -0
- data/lib/livetext.rb +66 -27
- data/plugin/bookish.rb +85 -85
- data/plugin/calibre.rb +3 -3
- data/plugin/livemagick.rb +17 -17
- data/plugin/markdown.rb +10 -10
- data/plugin/pyggish.rb +131 -162
- data/plugin/tutorial.rb +15 -16
- data/test/all.rb +6 -0
- data/test/snapshots/def_method/expected-output.txt +2 -0
- data/test/snapshots/def_method/source.lt3 +4 -2
- data/test/snapshots/error_inc_line_num/OUT +17 -0
- data/test/snapshots/error_inc_line_num/README.txt +20 -0
- data/test/snapshots/error_inc_line_num/expected-output.txt +0 -6
- data/test/snapshots/error_inc_line_num/match-error.txt +1 -1
- data/test/snapshots/error_line_num/match-error.txt +1 -1
- data/test/snapshots/error_missing_end/expected-output.txt +0 -1
- data/test/snapshots/error_name_not_permitted/expected-output.txt +4 -0
- data/test/snapshots/error_name_not_permitted/match-error.txt +1 -1
- data/test/snapshots/error_no_such_copy/duh +26 -0
- data/test/snapshots/error_no_such_copy/expected-output.txt +1 -0
- data/test/snapshots/error_no_such_copy/match-error.txt +1 -1
- data/test/snapshots/error_no_such_copy/mystery.txt +36 -0
- data/test/snapshots/error_no_such_inc/match-error.txt +1 -1
- data/test/snapshots/error_no_such_mixin/expected-output.txt +1 -0
- data/test/snapshots/error_no_such_mixin/match-error.txt +1 -1
- data/test/snapshots/error_no_such_mixin/source.lt3 +1 -1
- data/test/snapshots/example_alpha/source.lt3 +2 -2
- data/test/snapshots/example_alpha2/expected-output.txt +0 -2
- data/test/snapshots/example_alpha2/source.lt3 +5 -4
- data/test/snapshots/{icanhaz → import}/expected-output.txt +2 -1
- data/test/snapshots/import/match-error.txt +1 -0
- data/test/snapshots/{icanhaz → import}/simple_import.rb +1 -1
- data/test/snapshots/{icanhaz → import}/source.lt3 +2 -2
- data/test/snapshots/{icanhaz2 → import2}/expected-error.txt +0 -0
- data/test/snapshots/{icanhaz2 → import2}/expected-output.txt +3 -1
- data/test/snapshots/{icanhaz2/simple_canhaz.rb → import2/simple_import.rb} +1 -1
- data/test/snapshots/import2/source.lt3 +8 -0
- data/test/snapshots/import_bookish/expected-error.txt +0 -0
- data/test/snapshots/import_bookish/expected-output.txt +10 -0
- data/test/snapshots/import_bookish/source.lt3 +7 -0
- data/test/snapshots/import_bookish/toc.tmp +0 -0
- data/test/snapshots/mixin_bookish/expected-error.txt +0 -0
- data/test/snapshots/mixin_bookish/expected-output.txt +10 -0
- data/test/snapshots/mixin_bookish/source.lt3 +7 -0
- data/test/snapshots/mixin_bookish/toc.tmp +0 -0
- data/test/snapshots/more_functions/expected-error.txt +0 -0
- data/test/snapshots/more_functions/expected-output.txt +37 -0
- data/test/snapshots/more_functions/source.lt3 +40 -0
- data/test/snapshots/raw_lines/expected-output.txt +0 -2
- data/test/snapshots/simple_import/expected-output.txt +2 -0
- data/test/snapshots/simple_import/simple_import.rb +1 -1
- data/test/snapshots/simple_import/source.lt3 +3 -1
- data/test/snapshots/simple_mixin/simple_mixin.rb +1 -1
- data/test/snapshots/single_raw_line/expected-output.txt +0 -2
- data/test/snapshots/subset.txt +14 -14
- data/test/snapshots.rb +30 -13
- data/test/unit/formatline.rb +253 -134
- data/test/unit/html.rb +2 -3
- data/test/unit/parser/general.rb +1 -2
- data/test/unit/parser/mixin.rb +1 -3
- data/test/unit/parser/set.rb +8 -12
- data/test/unit/parser/string.rb +6 -6
- data/test/unit/parser.rb +0 -1
- data/test/unit/standard.rb +0 -2
- metadata +47 -30
- data/imports/markdown_importable.rb +0 -45
- data/lib/handler/icanhaz.rb +0 -35
- data/lib/handler.rb +0 -1
- data/lib/livetext/importable.rb +0 -2
- data/lib/parser/file.rb +0 -8
- data/lib/parser/import.rb +0 -15
- data/lib/parser/mixin.rb +0 -38
- data/lib/processor.rb +0 -83
- data/lib/userapi.rb +0 -160
- data/test/snapshots/icanhaz/match-error.txt +0 -1
- data/test/snapshots/icanhaz2/source.lt3 +0 -6
- data/test/unit/parser/importable.rb +0 -19
data/lib/livetext.rb
CHANGED
|
@@ -1,32 +1,23 @@
|
|
|
1
|
-
# Class Livetext skeleton (top level).
|
|
2
1
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
module Handler
|
|
8
|
-
end
|
|
9
|
-
end
|
|
2
|
+
require_relative 'livetext/skeleton'
|
|
3
|
+
require_relative 'livetext/version'
|
|
4
|
+
require_relative 'livetext/paths'
|
|
10
5
|
|
|
11
|
-
|
|
6
|
+
require_relative 'livetext/reopen'
|
|
12
7
|
|
|
13
|
-
|
|
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/processor'
|
|
14
|
+
require_relative 'livetext/helpers'
|
|
15
|
+
require_relative 'livetext/handler'
|
|
14
16
|
|
|
15
|
-
require_relative 'errors'
|
|
16
|
-
require_relative 'functions'
|
|
17
|
-
require_relative 'userapi'
|
|
18
|
-
require_relative 'standard'
|
|
19
|
-
require_relative 'formatline'
|
|
20
|
-
require_relative 'processor'
|
|
21
|
-
require_relative 'helpers'
|
|
22
|
-
require_relative 'handler'
|
|
23
17
|
|
|
24
|
-
Plugins = File.expand_path(File.join(File.dirname(__FILE__), "../plugin"))
|
|
25
|
-
Imports = File.expand_path(File.join(File.dirname(__FILE__), "../imports"))
|
|
26
|
-
|
|
27
|
-
TTY = ::File.open("/dev/tty", "w")
|
|
28
18
|
|
|
29
19
|
make_exception(:EndWithoutOpening, "Error: found .end with no opening command")
|
|
20
|
+
make_exception(:UnknownMethod, "Error: name '%1' is unknown")
|
|
30
21
|
|
|
31
22
|
# Class Livetext reopened (top level).
|
|
32
23
|
|
|
@@ -36,9 +27,10 @@ class Livetext
|
|
|
36
27
|
|
|
37
28
|
Vars = {}
|
|
38
29
|
|
|
30
|
+
TTY = ::File.open("/dev/tty", "w")
|
|
39
31
|
|
|
40
|
-
attr_reader :main
|
|
41
|
-
attr_accessor :
|
|
32
|
+
attr_reader :main, :sources
|
|
33
|
+
attr_accessor :nopass, :nopara
|
|
42
34
|
attr_accessor :body, :indentation
|
|
43
35
|
|
|
44
36
|
class << self
|
|
@@ -46,7 +38,14 @@ class Livetext
|
|
|
46
38
|
end
|
|
47
39
|
|
|
48
40
|
def vars
|
|
49
|
-
|
|
41
|
+
@_vars
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def self.interpolate(str)
|
|
45
|
+
# FIXME There are issues here...
|
|
46
|
+
# Livetext::FormatLine.var_func_parse(str)
|
|
47
|
+
parse = Livetext::FormatLine.new(str)
|
|
48
|
+
parse.var_func_parse
|
|
50
49
|
end
|
|
51
50
|
|
|
52
51
|
def self.customize(mix: [], call: [], vars: {})
|
|
@@ -59,10 +58,41 @@ class Livetext
|
|
|
59
58
|
obj
|
|
60
59
|
end
|
|
61
60
|
|
|
61
|
+
def peek_nextline
|
|
62
|
+
@main.peek_nextline # delegate
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
def nextline
|
|
66
|
+
@main.nextline # delegate
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
def sources
|
|
70
|
+
@main.sources # delegate
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
def save_location
|
|
74
|
+
@save_location # delegate
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
def save_location=(where)
|
|
78
|
+
@save_location = where # delegate
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
def dump(file = nil) # not a dot command!
|
|
82
|
+
file ||= ::STDOUT
|
|
83
|
+
file.puts @body
|
|
84
|
+
rescue => err
|
|
85
|
+
TTY.puts "#dump had an error: #{err.inspect}"
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
def graceful_error(err)
|
|
89
|
+
dump
|
|
90
|
+
raise err
|
|
91
|
+
end
|
|
92
|
+
|
|
62
93
|
def customize(mix: [], call: [], vars: {})
|
|
63
94
|
mix = Array(mix)
|
|
64
95
|
call = Array(call)
|
|
65
|
-
# FIXME HF won't this break??
|
|
66
96
|
mix.each {|lib| mixin(lib) }
|
|
67
97
|
call.each {|cmd| @main.send(cmd[1..-1]) } # ignores leading dot, no param
|
|
68
98
|
vars.each_pair {|var, val| setvar(var, val.to_s) }
|
|
@@ -72,6 +102,7 @@ class Livetext
|
|
|
72
102
|
def initialize(output = ::STDOUT)
|
|
73
103
|
@source = nil
|
|
74
104
|
@_mixins = []
|
|
105
|
+
@_imports = []
|
|
75
106
|
@_outdir = "."
|
|
76
107
|
@no_puts = output.nil?
|
|
77
108
|
@body = ""
|
|
@@ -79,6 +110,14 @@ class Livetext
|
|
|
79
110
|
@indentation = [0]
|
|
80
111
|
@_vars = Livetext::Vars
|
|
81
112
|
initial_vars
|
|
113
|
+
@api = UserAPI.new(self)
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
def api
|
|
117
|
+
@api
|
|
118
|
+
end
|
|
119
|
+
|
|
120
|
+
def interpolate(str)
|
|
82
121
|
end
|
|
83
122
|
|
|
84
123
|
def initial_vars
|
|
@@ -98,7 +137,7 @@ class Livetext
|
|
|
98
137
|
process_line(line)
|
|
99
138
|
end
|
|
100
139
|
result = @body
|
|
101
|
-
|
|
140
|
+
# @body = ""
|
|
102
141
|
result
|
|
103
142
|
end
|
|
104
143
|
|
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
|
|
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;
|
|
17
|
-
def h2;
|
|
18
|
-
def h3;
|
|
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 =
|
|
21
|
+
n = api.args.first.to_i # FIXME: what if it's missing?
|
|
22
22
|
words = []
|
|
23
|
-
|
|
23
|
+
api.body do |line|
|
|
24
24
|
words << line.chomp
|
|
25
25
|
end
|
|
26
26
|
words.sort!
|
|
27
|
-
|
|
27
|
+
api.out "<table cellpadding=2>"
|
|
28
28
|
words.each_slice(n) do |w|
|
|
29
29
|
items = w.map {|x| "<tt>#{x}</tt>" }
|
|
30
|
-
|
|
30
|
+
api.out "<tr><td width=5% valign=top></td><td>" + items.join("</td><td>") + "</td></tr>"
|
|
31
31
|
end
|
|
32
|
-
|
|
32
|
+
api.out "</table>"
|
|
33
33
|
end
|
|
34
34
|
|
|
35
35
|
# def comment
|
|
36
|
-
#
|
|
36
|
+
# api.body { } # ignore body
|
|
37
37
|
# end
|
|
38
38
|
|
|
39
39
|
def _errout(*args)
|
|
@@ -50,32 +50,31 @@ def _slug(str)
|
|
|
50
50
|
s2
|
|
51
51
|
end
|
|
52
52
|
|
|
53
|
-
|
|
54
53
|
# FIXME duplicated?
|
|
54
|
+
|
|
55
55
|
def image(args = nil, body = nil)
|
|
56
|
-
name =
|
|
57
|
-
|
|
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 =
|
|
62
|
-
num =
|
|
63
|
-
title =
|
|
64
|
-
title =
|
|
65
|
-
|
|
66
|
-
|
|
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
|
-
|
|
71
|
-
@chapter = @_args.first.to_i
|
|
70
|
+
@chapter = api.args.first.to_i
|
|
72
71
|
@sec = @sec2 = 0
|
|
73
|
-
title =
|
|
72
|
+
title = api.data.split(" ",2)[1]
|
|
74
73
|
@toc << "<br><b>#@chapter</b> #{title}<br>"
|
|
75
|
-
|
|
74
|
+
api.data = _slug(title)
|
|
76
75
|
next_output
|
|
77
|
-
|
|
78
|
-
|
|
76
|
+
api.out "<title>#{@chapter}. #{title}</title>"
|
|
77
|
+
api.out <<-HTML
|
|
79
78
|
<h2>Chapter #{@chapter}</h2>
|
|
80
79
|
<h1>#{title}</h1>
|
|
81
80
|
|
|
@@ -85,13 +84,13 @@ end
|
|
|
85
84
|
def chapterN(args = nil, body = nil)
|
|
86
85
|
@chapter += 1
|
|
87
86
|
@sec = @sec2 = 0
|
|
88
|
-
title =
|
|
87
|
+
title = api.data # .split(" ",2)[1]
|
|
89
88
|
_errout("Chapter #@chapter: #{title}")
|
|
90
89
|
@toc << "<br><b>#@chapter</b> #{title}<br>"
|
|
91
|
-
|
|
90
|
+
api.data = _slug(title)
|
|
92
91
|
next_output
|
|
93
|
-
|
|
94
|
-
|
|
92
|
+
api.out "<title>#{@chapter}. #{title}</title>"
|
|
93
|
+
api.out <<-HTML
|
|
95
94
|
<h2>Chapter #{@chapter}</h2>
|
|
96
95
|
<h1>#{title}</h1>
|
|
97
96
|
|
|
@@ -102,80 +101,79 @@ def sec(args = nil, body = nil)
|
|
|
102
101
|
@sec += 1
|
|
103
102
|
@sec2 = 0
|
|
104
103
|
@section = "#@chapter.#@sec"
|
|
105
|
-
title =
|
|
104
|
+
title = api.data.dup
|
|
106
105
|
@toc << "#{_nbsp(3)}<b>#@section</b> #{title}<br>"
|
|
107
|
-
|
|
106
|
+
api.data = _slug(api.data)
|
|
108
107
|
next_output
|
|
109
|
-
|
|
108
|
+
api.out "<h3>#@section #{title}</h3>\n"
|
|
110
109
|
rescue => err
|
|
111
|
-
STDERR.puts "#{err}\n#{err.backtrace}"
|
|
110
|
+
::STDERR.puts "#{err}\n#{err.backtrace}"
|
|
112
111
|
exit
|
|
113
112
|
end
|
|
114
113
|
|
|
115
114
|
def subsec(args = nil, body = nil)
|
|
116
115
|
@sec2 += 1
|
|
117
116
|
@subsec = "#@chapter.#@sec.#@sec2"
|
|
118
|
-
title =
|
|
117
|
+
title = api.data.dup
|
|
119
118
|
@toc << "#{_nbsp(6)}<b>#@subsec</b> #{title}<br>"
|
|
120
|
-
|
|
119
|
+
api.data = _slug(api.data)
|
|
121
120
|
next_output
|
|
122
|
-
|
|
121
|
+
api.out "<h3>#@subsec #{title}</h3>\n"
|
|
123
122
|
end
|
|
124
123
|
|
|
125
124
|
def definition_table(args = nil, body = nil)
|
|
126
|
-
title =
|
|
125
|
+
title = api.data
|
|
127
126
|
wide = "95"
|
|
128
127
|
delim = " :: "
|
|
129
|
-
|
|
130
|
-
lines =
|
|
131
|
-
lines.map! {|line|
|
|
128
|
+
api.out "<br><center><table width=#{wide}% cellpadding=5>"
|
|
129
|
+
lines = api.body(true)
|
|
130
|
+
lines.map! {|line| api.format(line) }
|
|
132
131
|
|
|
133
132
|
lines.each do |line|
|
|
134
133
|
cells = line.split(delim)
|
|
135
|
-
|
|
134
|
+
api.out "<tr>"
|
|
136
135
|
cells.each.with_index do |cell, i|
|
|
137
136
|
width = (i == 0) ? "width=15%" : ""
|
|
138
|
-
|
|
137
|
+
api.out " <td #{width} valign=top>#{cell}</td>"
|
|
139
138
|
end
|
|
140
|
-
|
|
139
|
+
api.out "</tr>"
|
|
141
140
|
end
|
|
142
|
-
|
|
141
|
+
api.out "</table></center><br><br>"
|
|
143
142
|
|
|
144
|
-
|
|
143
|
+
api.optional_blank_line
|
|
145
144
|
end
|
|
146
145
|
|
|
147
146
|
def table2(args = nil, body = nil)
|
|
148
|
-
title =
|
|
147
|
+
title = api.data
|
|
149
148
|
wide = "90"
|
|
150
|
-
extra =
|
|
149
|
+
extra = api.args[2]
|
|
151
150
|
delim = " :: "
|
|
152
|
-
|
|
153
|
-
lines =
|
|
154
|
-
lines.map! {|line|
|
|
151
|
+
api.out "<br><center><table width=#{wide}% cellpadding=5>"
|
|
152
|
+
lines = api.body(true)
|
|
153
|
+
lines.map! {|line| api.format(line) }
|
|
155
154
|
|
|
156
155
|
lines.each do |line|
|
|
157
156
|
cells = line.split(delim)
|
|
158
157
|
percent = (100/cells.size.to_f).round
|
|
159
|
-
|
|
158
|
+
api.out "<tr>"
|
|
160
159
|
cells.each do |cell|
|
|
161
|
-
|
|
160
|
+
api.out " <td width=#{percent}% valign=top " +
|
|
162
161
|
"#{extra}>#{cell}</td>"
|
|
163
162
|
end
|
|
164
|
-
|
|
163
|
+
api.out "</tr>"
|
|
165
164
|
end
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
_optional_blank_line
|
|
165
|
+
api.out "</table></center><br><br>"
|
|
166
|
+
api.optional_blank_line
|
|
169
167
|
end
|
|
170
168
|
|
|
171
169
|
def simple_table(args = nil, body = nil)
|
|
172
|
-
title =
|
|
170
|
+
title = api.data
|
|
173
171
|
delim = " :: "
|
|
174
|
-
|
|
175
|
-
lines =
|
|
172
|
+
api.out "<table cellpadding=2>"
|
|
173
|
+
lines = api.body(true)
|
|
176
174
|
maxw = nil
|
|
177
175
|
lines.each do |line|
|
|
178
|
-
|
|
176
|
+
api.format(line)
|
|
179
177
|
cells = line.split(delim)
|
|
180
178
|
wide = cells.map {|x| x.length }
|
|
181
179
|
maxw = [0] * cells.size
|
|
@@ -187,26 +185,27 @@ def simple_table(args = nil, body = nil)
|
|
|
187
185
|
|
|
188
186
|
lines.each do |line|
|
|
189
187
|
cells = line.split(delim)
|
|
190
|
-
|
|
188
|
+
api.out "<tr>"
|
|
191
189
|
cells.each.with_index do |cell, i|
|
|
192
|
-
|
|
190
|
+
api.out " <td width=#{maxw}% valign=top>" +
|
|
193
191
|
"#{cell}</td>"
|
|
194
192
|
end
|
|
195
|
-
|
|
193
|
+
api.out "</tr>"
|
|
196
194
|
end
|
|
197
|
-
|
|
195
|
+
api.out "</table>"
|
|
196
|
+
api.optional_blank_line
|
|
198
197
|
end
|
|
199
198
|
|
|
200
199
|
def table(args = nil, body = nil)
|
|
201
200
|
@table_num ||= 0
|
|
202
201
|
@table_num += 1
|
|
203
|
-
title =
|
|
202
|
+
title = api.data
|
|
204
203
|
delim = " :: "
|
|
205
|
-
|
|
206
|
-
lines =
|
|
204
|
+
api.out "<br><center><table width=90% cellpadding=5>"
|
|
205
|
+
lines = api.body(true)
|
|
207
206
|
maxw = nil
|
|
208
207
|
lines.each do |line|
|
|
209
|
-
|
|
208
|
+
api.format(line)
|
|
210
209
|
cells = line.split(delim)
|
|
211
210
|
wide = cells.map {|x| x.length }
|
|
212
211
|
maxw = [0] * cells.size
|
|
@@ -218,17 +217,18 @@ def table(args = nil, body = nil)
|
|
|
218
217
|
|
|
219
218
|
lines.each do |line|
|
|
220
219
|
cells = line.split(delim)
|
|
221
|
-
|
|
220
|
+
api.out "<tr>"
|
|
222
221
|
cells.each.with_index do |cell, i|
|
|
223
|
-
|
|
222
|
+
api.out " <td width=#{maxw}% valign=top>" +
|
|
224
223
|
"#{cell}</td>"
|
|
225
224
|
end
|
|
226
|
-
|
|
225
|
+
api.out "</tr>"
|
|
227
226
|
end
|
|
228
|
-
|
|
227
|
+
api.out "</table>"
|
|
229
228
|
@toc << "#{_nbsp(8)}<b>Table #@chapter.#@table_num</b> #{title}<br>"
|
|
230
229
|
# _next_output(_slug("table_#{title}"))
|
|
231
|
-
|
|
230
|
+
api.out "<b>Table #@chapter.#@table_num #{title}</b></center><br>"
|
|
231
|
+
api.optional_blank_line
|
|
232
232
|
end
|
|
233
233
|
|
|
234
234
|
def toc!(args = nil, body = nil)
|
|
@@ -241,7 +241,7 @@ rescue => err
|
|
|
241
241
|
end
|
|
242
242
|
|
|
243
243
|
def toc2(args = nil, body = nil)
|
|
244
|
-
file =
|
|
244
|
+
file = api.args[0]
|
|
245
245
|
@toc.close
|
|
246
246
|
::File.write(file, <<-EOS)
|
|
247
247
|
<p style="page-break-after:always;"></p>
|
|
@@ -254,28 +254,28 @@ EOS
|
|
|
254
254
|
end
|
|
255
255
|
|
|
256
256
|
def missing(args = nil, body = nil)
|
|
257
|
-
@toc << "#{_nbsp(8)}<font color=red>TBD:
|
|
258
|
-
stuff =
|
|
259
|
-
|
|
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 "
|
|
260
260
|
end
|
|
261
261
|
|
|
262
262
|
def TBC(args = nil, body = nil)
|
|
263
263
|
@toc << "#{_nbsp(8)}<font color=red>To be continued...</font><br>"
|
|
264
|
-
|
|
264
|
+
api.out "<br><font color=red><i>To be continued...</i></font><br>"
|
|
265
265
|
end
|
|
266
266
|
|
|
267
267
|
def note(args = nil, body = nil)
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
268
|
+
api.out "<br><font color=red><i>Note: "
|
|
269
|
+
api.out api.data
|
|
270
|
+
api.out "</i></font><br>\n "
|
|
271
271
|
end
|
|
272
272
|
|
|
273
273
|
def quote(args = nil, body = nil)
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
274
|
+
api.out "<blockquote>"
|
|
275
|
+
api.body {|line| api.out line }
|
|
276
|
+
api.out "</blockquote>"
|
|
277
277
|
rescue => err
|
|
278
|
-
STDERR.puts "#{err}\n#{err.backtrace}"
|
|
278
|
+
::STDERR.puts "#{err}\n#{err.backtrace}"
|
|
279
279
|
exit
|
|
280
280
|
end
|
|
281
281
|
|
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 =
|
|
5
|
-
src =
|
|
6
|
-
@cover =
|
|
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 =
|
|
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
|
-
|
|
8
|
+
api.optional_blank_line
|
|
9
9
|
end
|
|
10
10
|
|
|
11
11
|
def canvas(args = nil, body = nil)
|
|
12
|
-
color, width, opacity =
|
|
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
|
-
|
|
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 =
|
|
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 =
|
|
33
|
+
@fill, @stroke = api.args
|
|
34
34
|
@stroke = "black" if @stroke.nil? || @stroke.empty?
|
|
35
35
|
_debug "pen: fill=#@fill stroke=#@stroke"
|
|
36
|
-
|
|
36
|
+
api.optional_blank_line
|
|
37
37
|
end
|
|
38
38
|
|
|
39
39
|
def font(args = nil, body = nil)
|
|
40
|
-
size, font =
|
|
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
|
-
|
|
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 =
|
|
63
|
+
xy, wxh, str = api.data.split
|
|
64
64
|
weight, gravity = BoldWeight, CenterGravity
|
|
65
65
|
_text(xy, wxh, str, weight, gravity)
|
|
66
|
-
|
|
66
|
+
api.optional_blank_line
|
|
67
67
|
end
|
|
68
68
|
|
|
69
69
|
def text!(args = nil, body = nil)
|
|
70
|
-
xy, wxh =
|
|
71
|
-
str =
|
|
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
|
-
|
|
74
|
+
api.optional_blank_line
|
|
75
75
|
end
|
|
76
76
|
|
|
77
77
|
def draw(args = nil, body = nil)
|
|
78
78
|
@canvas.draw(@image)
|
|
79
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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);
|
|
12
|
-
def h2(args = nil, body = nil);
|
|
13
|
-
def h3(args = nil, body = nil);
|
|
14
|
-
def h4(args = nil, body = nil);
|
|
15
|
-
def h5(args = nil, body = nil);
|
|
16
|
-
def h6(args = nil, body = nil);
|
|
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
|
-
|
|
27
|
+
api.body {|line| api.out "> #{line}" }
|
|
28
28
|
end
|
|
29
29
|
|
|
30
30
|
def list(args = nil, body = nil)
|
|
31
|
-
|
|
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
|
-
|
|
36
|
+
api.body do |line|
|
|
37
37
|
n += 1
|
|
38
|
-
|
|
38
|
+
api.out "#{n}. #{_format(line)}"
|
|
39
39
|
end
|
|
40
40
|
end
|
|
41
41
|
|