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
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 3f447e149e6724975184b8db2c51ff59c58752c3cb5b4037bb86fb1f355015a6
|
|
4
|
+
data.tar.gz: 9740fc3b2bb98e92c91c523656f270a66132d882fbcaa9b1a803294d1e10a65a
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 1ee34071fde07e45b13d8f13aa9889d2b060651901acd8e3876071121ea5222c8bc4b83162c30f772c53fe92e07ea7bada3f28be0c75994f1ad21bcdacbb2905
|
|
7
|
+
data.tar.gz: ce9ed1ac2cd624818b775d19681a406f0a4c43c2a0b9a7f6f8c1f8fb9834b91301a2b65c10d1faa0c4b664a1abcb741c570d1745d996537f4d438e97b65e3f56
|
data/README.lt3
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
.
|
|
2
|
-
.
|
|
1
|
+
.import tutorial
|
|
2
|
+
.import markdown
|
|
3
3
|
|
|
4
4
|
. copy basic.css
|
|
5
5
|
|
|
@@ -186,7 +186,7 @@ the text. Here's an example.
|
|
|
186
186
|
|
|
187
187
|
. This is also a comment, by the way.
|
|
188
188
|
.def chapter
|
|
189
|
-
params =
|
|
189
|
+
params = api.args
|
|
190
190
|
raise "chapter: expecting at least two args" unless params.size > 1
|
|
191
191
|
num, *title = params # Chapter number + title
|
|
192
192
|
title = title.join(" ") # Join all words into one string
|
|
@@ -195,7 +195,7 @@ the text. Here's an example.
|
|
|
195
195
|
<h2>#{title}</h2>
|
|
196
196
|
<hr>
|
|
197
197
|
HTML
|
|
198
|
-
|
|
198
|
+
api.puts text
|
|
199
199
|
.end
|
|
200
200
|
. Now let's invoke it...
|
|
201
201
|
.chapter 1 Why I Went to the Woods
|
|
@@ -270,16 +270,16 @@ in here (and nothing else).
|
|
|
270
270
|
# File: mylib.rb
|
|
271
271
|
|
|
272
272
|
def alpha
|
|
273
|
-
cols =
|
|
273
|
+
cols = api.args.first
|
|
274
274
|
cols = "1" if cols == ""
|
|
275
275
|
cols = cols.to_i
|
|
276
276
|
raise "Columns must be 1-5" unless cols.between?(1,5)
|
|
277
|
-
text =
|
|
277
|
+
text = api.body.join
|
|
278
278
|
text.gsub!(/\n/, " ")
|
|
279
279
|
words = text.split.sort
|
|
280
280
|
words.each_slice(cols) do |row|
|
|
281
|
-
row.each {|w|
|
|
282
|
-
|
|
281
|
+
row.each {|w| api.print '%-15s' % w }
|
|
282
|
+
api.puts
|
|
283
283
|
end
|
|
284
284
|
end
|
|
285
285
|
.end
|
data/bin/livetext
CHANGED
|
@@ -4,12 +4,8 @@ require 'rubygems'
|
|
|
4
4
|
|
|
5
5
|
require_relative '../lib/livetext'
|
|
6
6
|
|
|
7
|
-
def handle_lt3(src)
|
|
8
|
-
abort "Unknown file extension" unless src =~ /.lt3$/
|
|
9
|
-
end
|
|
10
|
-
|
|
11
7
|
def usage
|
|
12
|
-
puts
|
|
8
|
+
STDERR.puts <<~EOF
|
|
13
9
|
Usage:
|
|
14
10
|
livetext filename
|
|
15
11
|
|
|
@@ -41,50 +37,71 @@ def usage
|
|
|
41
37
|
Install plugin:
|
|
42
38
|
livetext -i filename.rb
|
|
43
39
|
livetext -install filename.rb
|
|
40
|
+
|
|
44
41
|
EOF
|
|
45
|
-
puts
|
|
46
42
|
exit
|
|
47
43
|
end
|
|
48
44
|
|
|
49
|
-
|
|
45
|
+
def version
|
|
46
|
+
puts "#{Livetext::VERSION}\n "
|
|
47
|
+
end
|
|
50
48
|
|
|
51
|
-
|
|
49
|
+
def testing
|
|
50
|
+
file = "#{Livetext::Path}/../test/test.rb"
|
|
51
|
+
flag = @backtrace ? "-back" : ""
|
|
52
|
+
cmd = "ruby #{file} cmdline#{flag}"
|
|
53
|
+
puts cmd
|
|
54
|
+
system(cmd)
|
|
55
|
+
end
|
|
52
56
|
|
|
53
|
-
|
|
57
|
+
def mixin_flag
|
|
58
|
+
mod = ARGV.shift
|
|
59
|
+
@live.mixin(ARGV.shift)
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
def read_stdin
|
|
63
|
+
src = STDIN.read
|
|
64
|
+
@live.process(src)
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
def install_plugin
|
|
68
|
+
lib = ARGV.shift
|
|
69
|
+
system("cp #{lib} #{Livetext::Path}/../plugin/")
|
|
70
|
+
end
|
|
54
71
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
when "-t", "--test"
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
cmd = "ruby #{file} cmdline#{flag}"
|
|
67
|
-
puts cmd
|
|
68
|
-
system(cmd)
|
|
69
|
-
when "-p", "--path"
|
|
70
|
-
puts Livetext::Path
|
|
71
|
-
when "-b", "--backtrace"
|
|
72
|
-
@backtrace = true
|
|
72
|
+
def parse_command_line
|
|
73
|
+
usage if ARGV.empty?
|
|
74
|
+
success = true
|
|
75
|
+
loop do
|
|
76
|
+
arg = ARGV.shift
|
|
77
|
+
break if arg.nil?
|
|
78
|
+
case arg
|
|
79
|
+
when "-v", "--version"; version
|
|
80
|
+
when "-t", "--test"; testing
|
|
81
|
+
when "-p", "--path"; puts Livetext::Path
|
|
82
|
+
when "-b", "--backtrace"; @backtrace = true
|
|
73
83
|
when "-m", "--mixin"
|
|
74
|
-
|
|
75
|
-
x.mixin(ARGV.shift)
|
|
84
|
+
mixin_flag
|
|
76
85
|
next
|
|
77
|
-
when "-s", "--stdin"
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
when
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
when Object
|
|
86
|
-
x.process_file(arg, true) # , @backtrace)
|
|
86
|
+
when "-s", "--stdin"; read_stdin
|
|
87
|
+
when "-h", "--help"; usage
|
|
88
|
+
when "-i", "--install"; install_plugin
|
|
89
|
+
when Object; @live.process_file(arg, true) # , @backtrace)
|
|
90
|
+
else
|
|
91
|
+
success = false
|
|
92
|
+
STDERR.puts "Command line - #{arg.inspect} is unknown"
|
|
93
|
+
end
|
|
87
94
|
end
|
|
95
|
+
@live.dump if success
|
|
96
|
+
# rescue => err
|
|
97
|
+
# STDERR.puts "Unexpected error! #{err.inspect}"
|
|
88
98
|
end
|
|
89
99
|
|
|
90
|
-
|
|
100
|
+
# Main
|
|
101
|
+
|
|
102
|
+
@live = Livetext.new
|
|
103
|
+
|
|
104
|
+
@backtrace = false
|
|
105
|
+
|
|
106
|
+
parse_command_line
|
|
107
|
+
|
data/imports/bookish.rb
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
module Bookish
|
|
2
2
|
def hardbreaks(args = nil, body = nil)
|
|
3
3
|
@hard = false
|
|
4
|
-
@hard = true unless
|
|
4
|
+
@hard = true unless api.args.first == "off"
|
|
5
5
|
end
|
|
6
6
|
|
|
7
7
|
def hardbreaks?
|
|
@@ -14,29 +14,25 @@ module Bookish
|
|
|
14
14
|
|
|
15
15
|
# These are duplicated. Remove safely
|
|
16
16
|
|
|
17
|
-
def h1;
|
|
18
|
-
def h2;
|
|
19
|
-
def h3;
|
|
17
|
+
def h1; api.out "<h1>#{api.data}</h1>"; end
|
|
18
|
+
def h2; api.out "<h2>#{api.data}</h2>"; end
|
|
19
|
+
def h3; api.out "<h3>#{api.data}</h3>"; end
|
|
20
20
|
|
|
21
21
|
def alpha_columns(args = nil, body = nil)
|
|
22
|
-
n =
|
|
22
|
+
n = api.args.first.to_i # FIXME: what if missing?
|
|
23
23
|
words = []
|
|
24
|
-
|
|
24
|
+
api.body do |line|
|
|
25
25
|
words << line.chomp
|
|
26
26
|
end
|
|
27
27
|
words.sort!
|
|
28
|
-
|
|
28
|
+
api.out "<table cellpadding=2>"
|
|
29
29
|
words.each_slice(n) do |w|
|
|
30
30
|
items = w.map {|x| "<tt>#{x}</tt>" }
|
|
31
|
-
|
|
31
|
+
api.out "<tr><td width=5% valign=top></td><td>" + items.join("</td><td>") + "</td></tr>"
|
|
32
32
|
end
|
|
33
|
-
|
|
33
|
+
api.out "</table>"
|
|
34
34
|
end
|
|
35
35
|
|
|
36
|
-
# def comment
|
|
37
|
-
# _body { } # ignore body
|
|
38
|
-
# end
|
|
39
|
-
|
|
40
36
|
def _errout(*args)
|
|
41
37
|
::STDERR.puts *args
|
|
42
38
|
end
|
|
@@ -46,37 +42,39 @@ module Bookish
|
|
|
46
42
|
end
|
|
47
43
|
|
|
48
44
|
def _slug(str)
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
45
|
+
str2 = str.chomp.strip
|
|
46
|
+
str2 = str2.gsub(/[?:,()'"\/]/,"")
|
|
47
|
+
str2 = str2.gsub(/ /, "-")
|
|
48
|
+
str2.downcase!
|
|
49
|
+
str2
|
|
52
50
|
end
|
|
53
51
|
|
|
54
|
-
|
|
55
52
|
# FIXME duplicated?
|
|
53
|
+
|
|
56
54
|
def image(args = nil, body = nil)
|
|
57
|
-
name =
|
|
58
|
-
|
|
55
|
+
name = api.args[0]
|
|
56
|
+
api.out "<img src='#{name}'></img>"
|
|
59
57
|
end
|
|
60
58
|
|
|
61
59
|
def figure(args = nil, body = nil)
|
|
62
|
-
name =
|
|
63
|
-
num =
|
|
64
|
-
title =
|
|
65
|
-
title =
|
|
66
|
-
|
|
67
|
-
|
|
60
|
+
name = api.args[0]
|
|
61
|
+
num = api.args[1]
|
|
62
|
+
title = api.args[2..-1].join(" ")
|
|
63
|
+
title = api.format(title)
|
|
64
|
+
api.out "<img src='#{name}'></img>"
|
|
65
|
+
api.out "<center><b>Figure #{num}</b> #{title}</center>"
|
|
68
66
|
end
|
|
69
67
|
|
|
70
68
|
def chapter(args = nil, body = nil)
|
|
71
69
|
# _errout("chapter")
|
|
72
|
-
@chapter =
|
|
70
|
+
@chapter = api.args.first.to_i
|
|
73
71
|
@sec = @sec2 = 0
|
|
74
|
-
title =
|
|
72
|
+
title = api.data.split(" ",2)[1]
|
|
75
73
|
@toc << "<br><b>#@chapter</b> #{title}<br>"
|
|
76
|
-
|
|
74
|
+
api.data = _slug(title)
|
|
77
75
|
next_output
|
|
78
|
-
|
|
79
|
-
|
|
76
|
+
api.out "<title>#{@chapter}. #{title}</title>"
|
|
77
|
+
api.out <<-HTML
|
|
80
78
|
<h2>Chapter #{@chapter}</h2>
|
|
81
79
|
<h1>#{title}</h1>
|
|
82
80
|
|
|
@@ -86,13 +84,13 @@ module Bookish
|
|
|
86
84
|
def chapterN(args = nil, body = nil)
|
|
87
85
|
@chapter += 1
|
|
88
86
|
@sec = @sec2 = 0
|
|
89
|
-
title =
|
|
87
|
+
title = api.data # .split(" ",2)[1]
|
|
90
88
|
_errout("Chapter #@chapter: #{title}")
|
|
91
89
|
@toc << "<br><b>#@chapter</b> #{title}<br>"
|
|
92
|
-
|
|
90
|
+
api.data = _slug(title)
|
|
93
91
|
next_output
|
|
94
|
-
|
|
95
|
-
|
|
92
|
+
api.out "<title>#{@chapter}. #{title}</title>"
|
|
93
|
+
api.out <<-HTML
|
|
96
94
|
<h2>Chapter #{@chapter}</h2>
|
|
97
95
|
<h1>#{title}</h1>
|
|
98
96
|
|
|
@@ -103,80 +101,79 @@ module Bookish
|
|
|
103
101
|
@sec += 1
|
|
104
102
|
@sec2 = 0
|
|
105
103
|
@section = "#@chapter.#@sec"
|
|
106
|
-
title =
|
|
104
|
+
title = api.data.dup
|
|
107
105
|
@toc << "#{_nbsp(3)}<b>#@section</b> #{title}<br>"
|
|
108
|
-
|
|
106
|
+
api.data = _slug(api.data)
|
|
109
107
|
next_output
|
|
110
|
-
|
|
108
|
+
api.out "<h3>#@section #{title}</h3>\n"
|
|
111
109
|
rescue => err
|
|
112
|
-
STDERR.puts "#{err}\n#{err.backtrace}"
|
|
110
|
+
::STDERR.puts "#{err}\n#{err.backtrace}"
|
|
113
111
|
exit
|
|
114
112
|
end
|
|
115
113
|
|
|
116
114
|
def subsec(args = nil, body = nil)
|
|
117
115
|
@sec2 += 1
|
|
118
116
|
@subsec = "#@chapter.#@sec.#@sec2"
|
|
119
|
-
title =
|
|
117
|
+
title = api.data.dup
|
|
120
118
|
@toc << "#{_nbsp(6)}<b>#@subsec</b> #{title}<br>"
|
|
121
|
-
|
|
119
|
+
api.data = _slug(api.data)
|
|
122
120
|
next_output
|
|
123
|
-
|
|
121
|
+
api.out "<h3>#@subsec #{title}</h3>\n"
|
|
124
122
|
end
|
|
125
123
|
|
|
126
124
|
def definition_table(args = nil, body = nil)
|
|
127
|
-
title =
|
|
125
|
+
title = api.data
|
|
128
126
|
wide = "95"
|
|
129
127
|
delim = " :: "
|
|
130
|
-
|
|
131
|
-
lines =
|
|
132
|
-
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) }
|
|
133
131
|
|
|
134
132
|
lines.each do |line|
|
|
135
133
|
cells = line.split(delim)
|
|
136
|
-
|
|
134
|
+
api.out "<tr>"
|
|
137
135
|
cells.each.with_index do |cell, i|
|
|
138
136
|
width = (i == 0) ? "width=15%" : ""
|
|
139
|
-
|
|
137
|
+
api.out " <td #{width} valign=top>#{cell}</td>"
|
|
140
138
|
end
|
|
141
|
-
|
|
139
|
+
api.out "</tr>"
|
|
142
140
|
end
|
|
143
|
-
|
|
141
|
+
api.out "</table></center><br><br>"
|
|
144
142
|
|
|
145
|
-
|
|
143
|
+
api.optional_blank_line
|
|
146
144
|
end
|
|
147
145
|
|
|
148
146
|
def table2(args = nil, body = nil)
|
|
149
|
-
title =
|
|
147
|
+
title = api.data
|
|
150
148
|
wide = "90"
|
|
151
|
-
extra =
|
|
149
|
+
extra = api.args[2]
|
|
152
150
|
delim = " :: "
|
|
153
|
-
|
|
154
|
-
lines =
|
|
155
|
-
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) }
|
|
156
154
|
|
|
157
155
|
lines.each do |line|
|
|
158
156
|
cells = line.split(delim)
|
|
159
157
|
percent = (100/cells.size.to_f).round
|
|
160
|
-
|
|
158
|
+
api.out "<tr>"
|
|
161
159
|
cells.each do |cell|
|
|
162
|
-
|
|
160
|
+
api.out " <td width=#{percent}% valign=top " +
|
|
163
161
|
"#{extra}>#{cell}</td>"
|
|
164
162
|
end
|
|
165
|
-
|
|
163
|
+
api.out "</tr>"
|
|
166
164
|
end
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
_optional_blank_line
|
|
165
|
+
api.out "</table></center><br><br>"
|
|
166
|
+
api.optional_blank_line
|
|
170
167
|
end
|
|
171
168
|
|
|
172
169
|
def simple_table(args = nil, body = nil)
|
|
173
|
-
title =
|
|
170
|
+
title = api.data
|
|
174
171
|
delim = " :: "
|
|
175
|
-
|
|
176
|
-
lines =
|
|
172
|
+
api.out "<table cellpadding=2>"
|
|
173
|
+
lines = api.body(true)
|
|
177
174
|
maxw = nil
|
|
178
175
|
lines.each do |line|
|
|
179
|
-
|
|
176
|
+
api.format(line)
|
|
180
177
|
cells = line.split(delim)
|
|
181
178
|
wide = cells.map {|x| x.length }
|
|
182
179
|
maxw = [0] * cells.size
|
|
@@ -188,26 +185,27 @@ module Bookish
|
|
|
188
185
|
|
|
189
186
|
lines.each do |line|
|
|
190
187
|
cells = line.split(delim)
|
|
191
|
-
|
|
188
|
+
api.out "<tr>"
|
|
192
189
|
cells.each.with_index do |cell, i|
|
|
193
|
-
|
|
190
|
+
api.out " <td width=#{maxw}% valign=top>" +
|
|
194
191
|
"#{cell}</td>"
|
|
195
192
|
end
|
|
196
|
-
|
|
193
|
+
api.out "</tr>"
|
|
197
194
|
end
|
|
198
|
-
|
|
195
|
+
api.out "</table>"
|
|
196
|
+
api.optional_blank_line
|
|
199
197
|
end
|
|
200
198
|
|
|
201
199
|
def table(args = nil, body = nil)
|
|
202
200
|
@table_num ||= 0
|
|
203
201
|
@table_num += 1
|
|
204
|
-
title =
|
|
202
|
+
title = api.data
|
|
205
203
|
delim = " :: "
|
|
206
|
-
|
|
207
|
-
lines =
|
|
204
|
+
api.out "<br><center><table width=90% cellpadding=5>"
|
|
205
|
+
lines = api.body(true)
|
|
208
206
|
maxw = nil
|
|
209
207
|
lines.each do |line|
|
|
210
|
-
|
|
208
|
+
api.format(line)
|
|
211
209
|
cells = line.split(delim)
|
|
212
210
|
wide = cells.map {|x| x.length }
|
|
213
211
|
maxw = [0] * cells.size
|
|
@@ -219,17 +217,18 @@ module Bookish
|
|
|
219
217
|
|
|
220
218
|
lines.each do |line|
|
|
221
219
|
cells = line.split(delim)
|
|
222
|
-
|
|
220
|
+
api.out "<tr>"
|
|
223
221
|
cells.each.with_index do |cell, i|
|
|
224
|
-
|
|
222
|
+
api.out " <td width=#{maxw}% valign=top>" +
|
|
225
223
|
"#{cell}</td>"
|
|
226
224
|
end
|
|
227
|
-
|
|
225
|
+
api.out "</tr>"
|
|
228
226
|
end
|
|
229
|
-
|
|
227
|
+
api.out "</table>"
|
|
230
228
|
@toc << "#{_nbsp(8)}<b>Table #@chapter.#@table_num</b> #{title}<br>"
|
|
231
229
|
# _next_output(_slug("table_#{title}"))
|
|
232
|
-
|
|
230
|
+
api.out "<b>Table #@chapter.#@table_num #{title}</b></center><br>"
|
|
231
|
+
api.optional_blank_line
|
|
233
232
|
end
|
|
234
233
|
|
|
235
234
|
def toc!(args = nil, body = nil)
|
|
@@ -242,7 +241,7 @@ module Bookish
|
|
|
242
241
|
end
|
|
243
242
|
|
|
244
243
|
def toc2(args = nil, body = nil)
|
|
245
|
-
file =
|
|
244
|
+
file = api.args[0]
|
|
246
245
|
@toc.close
|
|
247
246
|
::File.write(file, <<-EOS)
|
|
248
247
|
<p style="page-break-after:always;"></p>
|
|
@@ -255,28 +254,28 @@ module Bookish
|
|
|
255
254
|
end
|
|
256
255
|
|
|
257
256
|
def missing(args = nil, body = nil)
|
|
258
|
-
@toc << "#{_nbsp(8)}<font color=red>TBD:
|
|
259
|
-
stuff =
|
|
260
|
-
|
|
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 "
|
|
261
260
|
end
|
|
262
261
|
|
|
263
262
|
def TBC(args = nil, body = nil)
|
|
264
263
|
@toc << "#{_nbsp(8)}<font color=red>To be continued...</font><br>"
|
|
265
|
-
|
|
264
|
+
api.out "<br><font color=red><i>To be continued...</i></font><br>"
|
|
266
265
|
end
|
|
267
266
|
|
|
268
267
|
def note(args = nil, body = nil)
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
268
|
+
api.out "<br><font color=red><i>Note: "
|
|
269
|
+
api.out api.data
|
|
270
|
+
api.out "</i></font><br>\n "
|
|
272
271
|
end
|
|
273
272
|
|
|
274
273
|
def quote(args = nil, body = nil)
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
274
|
+
api.out "<blockquote>"
|
|
275
|
+
api.body {|line| api.out line }
|
|
276
|
+
api.out "</blockquote>"
|
|
278
277
|
rescue => err
|
|
279
|
-
STDERR.puts "#{err}\n#{err.backtrace}"
|
|
278
|
+
::STDERR.puts "#{err}\n#{err.backtrace}"
|
|
280
279
|
exit
|
|
281
280
|
end
|
|
282
281
|
|
data/imports/calibre.rb
CHANGED
|
@@ -2,9 +2,9 @@ require 'fileutils'
|
|
|
2
2
|
|
|
3
3
|
module Calibre
|
|
4
4
|
def epub!(args = nil, body = nil)
|
|
5
|
-
out =
|
|
6
|
-
src =
|
|
7
|
-
@cover =
|
|
5
|
+
out = api.format(api.args[0])
|
|
6
|
+
src = api.args[1]
|
|
7
|
+
@cover = api.args[2]
|
|
8
8
|
if ::File.directory?(src)
|
|
9
9
|
files = ::Dir["#{src}/*"].grep /\.html$/
|
|
10
10
|
files = files.sort # why is this necessary now?
|
data/imports/livemagick.rb
CHANGED
|
@@ -4,24 +4,24 @@ module Livemagick # FIXME auto-mangle names
|
|
|
4
4
|
include ::Magick
|
|
5
5
|
|
|
6
6
|
def image(args = nil, body = nil)
|
|
7
|
-
xx, yy, bg =
|
|
7
|
+
xx, yy, bg = api.args
|
|
8
8
|
xx, yy = xx.to_i, yy.to_i
|
|
9
9
|
@image = Image.new(xx,yy) { self.background_color = bg }
|
|
10
|
-
|
|
10
|
+
api.optional_blank_line
|
|
11
11
|
end
|
|
12
12
|
|
|
13
13
|
def canvas(args = nil, body = nil)
|
|
14
|
-
color, width, opacity =
|
|
14
|
+
color, width, opacity = api.args
|
|
15
15
|
opacity, width = opacity.to_i, width.to_i
|
|
16
16
|
@canvas = Draw.new
|
|
17
17
|
@canvas.fill_opacity(0)
|
|
18
18
|
@canvas.stroke('black')
|
|
19
19
|
@canvas.stroke_width(1)
|
|
20
|
-
|
|
20
|
+
api.optional_blank_line
|
|
21
21
|
end
|
|
22
22
|
|
|
23
23
|
def rectangle(args = nil, body = nil)
|
|
24
|
-
xy, wxh, stroke_color, stroke_width =
|
|
24
|
+
xy, wxh, stroke_color, stroke_width = api.args
|
|
25
25
|
x, y = xy.split(",").map(&:to_i)
|
|
26
26
|
width, height = wxh.split("x").map(&:to_i)
|
|
27
27
|
stroke_width = stroke_width.to_i
|
|
@@ -32,19 +32,19 @@ module Livemagick # FIXME auto-mangle names
|
|
|
32
32
|
end
|
|
33
33
|
|
|
34
34
|
def pen(args = nil, body = nil)
|
|
35
|
-
@fill, @stroke =
|
|
35
|
+
@fill, @stroke = api.args
|
|
36
36
|
@stroke = "black" if @stroke.nil? || @stroke.empty?
|
|
37
37
|
_debug "pen: fill=#@fill stroke=#@stroke"
|
|
38
|
-
|
|
38
|
+
api.optional_blank_line
|
|
39
39
|
end
|
|
40
40
|
|
|
41
41
|
def font(args = nil, body = nil)
|
|
42
|
-
size, font =
|
|
42
|
+
size, font = api.args
|
|
43
43
|
font = "Helvetica" if font.nil? || font.empty?
|
|
44
44
|
size = "32" if size.nil? || size.empty?
|
|
45
45
|
@size, @font = size.to_i, font
|
|
46
46
|
_debug "font: size=#@size font=#@font"
|
|
47
|
-
|
|
47
|
+
api.optional_blank_line
|
|
48
48
|
end
|
|
49
49
|
|
|
50
50
|
def _text(xy, wxh, str, weight, gravity)
|
|
@@ -62,34 +62,34 @@ module Livemagick # FIXME auto-mangle names
|
|
|
62
62
|
end
|
|
63
63
|
|
|
64
64
|
def text(args = nil, body = nil)
|
|
65
|
-
xy, wxh, str =
|
|
65
|
+
xy, wxh, str = api.data.split
|
|
66
66
|
weight, gravity = BoldWeight, CenterGravity
|
|
67
67
|
_text(xy, wxh, str, weight, gravity)
|
|
68
|
-
|
|
68
|
+
api.optional_blank_line
|
|
69
69
|
end
|
|
70
70
|
|
|
71
71
|
def text!(args = nil, body = nil)
|
|
72
|
-
xy, wxh =
|
|
73
|
-
str =
|
|
72
|
+
xy, wxh = api.data.split
|
|
73
|
+
str = api.body_text # .join
|
|
74
74
|
weight, gravity = BoldWeight, CenterGravity
|
|
75
75
|
_text(xy, wxh, str, weight, gravity)
|
|
76
|
-
|
|
76
|
+
api.optional_blank_line
|
|
77
77
|
end
|
|
78
78
|
|
|
79
79
|
def draw(args = nil, body = nil)
|
|
80
80
|
@canvas.draw(@image)
|
|
81
|
-
|
|
81
|
+
api.optional_blank_line
|
|
82
82
|
end
|
|
83
83
|
|
|
84
84
|
def save(args = nil, body = nil)
|
|
85
85
|
@image.write(_args.first)
|
|
86
|
-
|
|
86
|
+
api.optional_blank_line
|
|
87
87
|
end
|
|
88
88
|
|
|
89
89
|
def save!(args = nil, body = nil)
|
|
90
90
|
save
|
|
91
91
|
system("open #{_args.first}")
|
|
92
|
-
|
|
92
|
+
api.optional_blank_line
|
|
93
93
|
end
|
|
94
94
|
end
|
|
95
95
|
=begin
|
data/imports/markdown.rb
CHANGED
|
@@ -9,12 +9,12 @@ module Markdown
|
|
|
9
9
|
SimpleFormats[:s] = %w[<strike> </strike>]
|
|
10
10
|
|
|
11
11
|
|
|
12
|
-
def h1(args = nil, body = nil);
|
|
13
|
-
def h2(args = nil, body = nil);
|
|
14
|
-
def h3(args = nil, body = nil);
|
|
15
|
-
def h4(args = nil, body = nil);
|
|
16
|
-
def h5(args = nil, body = nil);
|
|
17
|
-
def h6(args = nil, body = nil);
|
|
12
|
+
def h1(args = nil, body = nil); api.out "# #{Livetext.interpolate(api.data)}"; api.optional_blank_line end # atx style for now
|
|
13
|
+
def h2(args = nil, body = nil); api.out "## #{Livetext.interpolate(api.data)}"; api.optional_blank_line end
|
|
14
|
+
def h3(args = nil, body = nil); api.out "### #{Livetext.interpolate(api.data)}"; api.optional_blank_line end
|
|
15
|
+
def h4(args = nil, body = nil); api.out "#### #{Livetext.interpolate(api.data)}"; api.optional_blank_line end
|
|
16
|
+
def h5(args = nil, body = nil); api.out "##### #{Livetext.interpolate(api.data)}"; api.optional_blank_line end
|
|
17
|
+
def h6(args = nil, body = nil); api.out "###### #{Livetext.interpolate(api.data)}"; api.optional_blank_line end
|
|
18
18
|
|
|
19
19
|
def title(args = nil, body = nil)
|
|
20
20
|
h1
|
|
@@ -25,18 +25,18 @@ module Markdown
|
|
|
25
25
|
end
|
|
26
26
|
|
|
27
27
|
def bq(args = nil, body = nil) # block quote
|
|
28
|
-
|
|
28
|
+
api.body {|line| api.out "> #{line}" }
|
|
29
29
|
end
|
|
30
30
|
|
|
31
31
|
def list(args = nil, body = nil)
|
|
32
|
-
|
|
32
|
+
api.body {|line| api.out " * #{line}" }
|
|
33
33
|
end
|
|
34
34
|
|
|
35
35
|
def olist(args = nil, body = nil) # Doesn't handle paragraphs yet
|
|
36
36
|
n = 0
|
|
37
|
-
|
|
37
|
+
api.body do |line|
|
|
38
38
|
n += 1
|
|
39
|
-
|
|
39
|
+
api.out "#{n}. #{_format(line)}"
|
|
40
40
|
end
|
|
41
41
|
end
|
|
42
42
|
|