livetext 0.9.25 → 0.9.30
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.lt3 +3 -2
- data/imports/bookish.rb +1 -2
- data/lib/livetext/errors.rb +3 -0
- data/lib/livetext/expansion.rb +106 -0
- data/lib/livetext/formatter.rb +104 -0
- data/lib/livetext/functions.rb +9 -0
- data/lib/livetext/global_helpers.rb +5 -0
- data/lib/livetext/handler/import.rb +2 -6
- data/lib/livetext/handler/mixin.rb +2 -6
- data/lib/livetext/helpers.rb +30 -27
- data/lib/livetext/html.rb +73 -0
- data/lib/livetext/more.rb +178 -0
- data/lib/livetext/parser/general.rb +1 -1
- data/lib/livetext/parser/set.rb +10 -3
- data/lib/livetext/parser/string.rb +14 -5
- data/lib/livetext/processor.rb +8 -1
- data/lib/livetext/skeleton.rb +2 -1
- data/lib/livetext/standard.rb +30 -16
- data/lib/livetext/userapi.rb +61 -22
- data/lib/livetext/version.rb +1 -1
- data/lib/livetext.rb +2 -152
- data/plugin/bootstrap_menu.rb +140 -0
- data/plugin/misc/navbar.rb +162 -0
- data/test/snapshots/basic_formatting/expected-output.txt +1 -2
- data/test/snapshots/{import_bookish/toc.tmp → bootstrap_menu/expected-error.txt} +0 -0
- data/test/snapshots/bootstrap_menu/expected-output.txt +4 -0
- data/test/snapshots/bootstrap_menu/source.lt3 +17 -0
- data/test/snapshots/error_invalid_name/foo +5 -0
- data/test/snapshots/import_bookish/expected-output.txt +4 -4
- data/test/snapshots/more_functions/expected-output.txt +1 -1
- data/test/snapshots/more_functions/source.lt3 +1 -1
- data/test/snapshots/subset.txt +50 -46
- data/test/snapshots/{mixin_bookish/toc.tmp → var_into_func/expected-error.txt} +0 -0
- data/test/snapshots/var_into_func/expected-output.txt +16 -0
- data/test/snapshots/var_into_func/source.lt3 +16 -0
- data/test/unit/all.rb +2 -1
- data/test/unit/lineparser.rb +359 -0
- data/test/unit/new_lineparser.rb +359 -0
- data/test/unit/parser/general.rb +2 -2
- data/test/unit/parser/set.rb +12 -20
- metadata +16 -11
- data/lib/livetext/formatline.rb +0 -321
- data/lib/livetext/funcall.rb +0 -84
- data/test/snapshots/error_inc_line_num/OUT +0 -17
- data/test/snapshots/error_no_such_copy/duh +0 -26
- data/test/snapshots/error_no_such_copy/mystery.txt +0 -36
- data/test/testlines.rb +0 -37
- data/test/unit/formatline.rb +0 -769
@@ -0,0 +1,162 @@
|
|
1
|
+
|
2
|
+
private def get_href_title(line)
|
3
|
+
*title, href = line[1..-1].split(@space)
|
4
|
+
if href[0] == "@"
|
5
|
+
blank = true
|
6
|
+
href = href[1..-1]
|
7
|
+
else
|
8
|
+
blank = false
|
9
|
+
end
|
10
|
+
title = title.join(@space)
|
11
|
+
[href, title, blank]
|
12
|
+
end
|
13
|
+
|
14
|
+
private def add_root(url)
|
15
|
+
return url if url =~ /^http/ # already has http[s]
|
16
|
+
return url unless @root # no root defined
|
17
|
+
range1 = 0..-1
|
18
|
+
range1 = 0..-2 if @root[-1] == "/"
|
19
|
+
root = @root[range1]
|
20
|
+
range2 = 0..-1
|
21
|
+
range2 = 1..-1 if url[0] == "/"
|
22
|
+
url = url[range2]
|
23
|
+
root + "/" + url
|
24
|
+
end
|
25
|
+
|
26
|
+
private def get_brand
|
27
|
+
peek = @enum.peek
|
28
|
+
arg = peek[6..-1]
|
29
|
+
href, item, blank = get_href_title(arg)
|
30
|
+
# doesn't honor @root... and blank is unused here
|
31
|
+
if item =~ /\.(jpg|png|gif)$/i
|
32
|
+
item = "<img src='#{item}'></img>"
|
33
|
+
end
|
34
|
+
details = {class: "navbar-brand mr-auto", href: add_root(href)}
|
35
|
+
@brand = html.tag(:a, **details, cdata: item)
|
36
|
+
end
|
37
|
+
|
38
|
+
private def slash_tags
|
39
|
+
@root = @brand = nil
|
40
|
+
@classes = "navbar-light bg-light"
|
41
|
+
loop do # /brand /root ...
|
42
|
+
peek = @enum.peek
|
43
|
+
break if peek[0] != '/'
|
44
|
+
case
|
45
|
+
when peek.start_with?("/brand ")
|
46
|
+
get_brand
|
47
|
+
when peek.start_with?("/root ")
|
48
|
+
@root = peek[6..-1]
|
49
|
+
when peek.start_with?("/classes ")
|
50
|
+
@classes = peek[9..-1]
|
51
|
+
end
|
52
|
+
line = @enum.next
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
private def handle_children
|
57
|
+
value = ""
|
58
|
+
loop do
|
59
|
+
if @enum.peek.start_with?(@space) # it's a child
|
60
|
+
line = @enum.next
|
61
|
+
href, title, blank = get_href_title(line)
|
62
|
+
details = {class: "dropdown-item", href: add_root(href)}
|
63
|
+
details[:target] = "_blank" if blank
|
64
|
+
link = html.tag(:a, **details, cdata: title)
|
65
|
+
str = html.tag(:li, cdata: link)
|
66
|
+
value << str + "\n"
|
67
|
+
else
|
68
|
+
break
|
69
|
+
end
|
70
|
+
end
|
71
|
+
api.out value
|
72
|
+
end
|
73
|
+
|
74
|
+
private def no_children(href, title)
|
75
|
+
html.li(class: "nav-item") do
|
76
|
+
api.out html.tag(:a, class: "nav-link", href: add_root(href), cdata: title)
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
private def has_children(href, title)
|
81
|
+
css = "nav-item dropdown"
|
82
|
+
html.li(class: css) do
|
83
|
+
details = {class: "nav-link dropdown-toggle", href: "#", id: "navbarDropdown",
|
84
|
+
role: "button", :"data-bs-toggle" => "dropdown", :"aria-expanded" => "false"}
|
85
|
+
@dropdowns += 1
|
86
|
+
api.out html.tag(:a, **details, cdata: title)
|
87
|
+
details = {class: "dropdown-menu", :"aria-labelledby" => "navbarDropdown"}
|
88
|
+
html.ul(**details) do # children...
|
89
|
+
handle_children
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
private def handle_body
|
95
|
+
@dropdowns = 1
|
96
|
+
loop do
|
97
|
+
line = @enum.next
|
98
|
+
href, title, blank = get_href_title(line)
|
99
|
+
case line[0]
|
100
|
+
when "-"
|
101
|
+
no_children(href, title)
|
102
|
+
when "="
|
103
|
+
has_children(href, title)
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
def bootstrap
|
109
|
+
api.out <<~HTML
|
110
|
+
<head>
|
111
|
+
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css"
|
112
|
+
rel="stylesheet" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3"
|
113
|
+
crossorigin="anonymous">
|
114
|
+
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js"
|
115
|
+
integrity="sha384-ka7Sk0Gln4gmtz2MlQnikT1wXgYsOg+OMhuP+IlRH9sENBO0LRn5q+8nbTov4+1p"
|
116
|
+
crossorigin="anonymous">
|
117
|
+
</script>
|
118
|
+
</head>
|
119
|
+
HTML
|
120
|
+
end
|
121
|
+
|
122
|
+
private def toggler
|
123
|
+
details = {class: "navbar-toggler", type: "button", "data-bs-toggle": "collapse",
|
124
|
+
"data-bs-target": "#navbarSupportedContent",
|
125
|
+
"aria-controls": "navbarSupportedContent", "aria-expanded": "false",
|
126
|
+
"aria-label": "Toggle navigation"}
|
127
|
+
str = html.tag(:button, **details, cdata: '<span class="navbar-toggler-icon"></span>')
|
128
|
+
api.out str
|
129
|
+
end
|
130
|
+
|
131
|
+
private def branding
|
132
|
+
return if @brand.empty? || @brand.nil?
|
133
|
+
api.out @brand
|
134
|
+
end
|
135
|
+
|
136
|
+
def html
|
137
|
+
@html
|
138
|
+
end
|
139
|
+
|
140
|
+
def navbar
|
141
|
+
@html = HTML.new(api)
|
142
|
+
# bootstrap
|
143
|
+
@space = " "
|
144
|
+
@enum = api.body.each
|
145
|
+
slash_tags
|
146
|
+
|
147
|
+
css = "navbar navbar-expand-md " + @classes
|
148
|
+
html.nav(class: css) do
|
149
|
+
html.div(class: "container-fluid") do
|
150
|
+
toggler
|
151
|
+
branding
|
152
|
+
content = {class: "collapse navbar-collapse", id: "navbarSupportedContent"}
|
153
|
+
html.div(**content) do
|
154
|
+
css = "navbar-nav me-auto mb-2 mb-md-0"
|
155
|
+
html.ul(class: css) do
|
156
|
+
handle_body
|
157
|
+
end
|
158
|
+
end
|
159
|
+
end
|
160
|
+
end
|
161
|
+
end
|
162
|
+
|
@@ -3,11 +3,10 @@ and <i>italics</i>
|
|
3
3
|
and <font size=+1><tt>code</tt></font>
|
4
4
|
as well as <b>more complex</b> examples
|
5
5
|
of <i>italicized text</i>
|
6
|
-
and <
|
6
|
+
and <tt>code font</tt>.
|
7
7
|
<p>
|
8
8
|
|
9
9
|
Here are some random punctuation marks:
|
10
10
|
; # . * _ ` : @ % ^ & $
|
11
11
|
<p>
|
12
|
-
|
13
12
|
No need to escape these: * _ `
|
File without changes
|
@@ -0,0 +1,17 @@
|
|
1
|
+
.nopara
|
2
|
+
|
3
|
+
.mixin bootstrap_menu
|
4
|
+
|
5
|
+
.menu
|
6
|
+
.menu_link "Home", "http://fake.com/home"
|
7
|
+
.menu_dropdown "Blog"
|
8
|
+
.menu_dropdown_link "Home", "http://fake.com/blog"
|
9
|
+
.menu_dropdown_link "Design", "http://fake.com/design"
|
10
|
+
.menu_dropdown_link "HTML", "http://fake.com/html"
|
11
|
+
.menu_dropdown_link "CSS", "http://fake.com/css"
|
12
|
+
.menu_dropdown_link "Javascript", "http://fake.com/jscript"
|
13
|
+
.menu_dropdown "Work"
|
14
|
+
.menu_dropdown_item "Web Design", "http://fake.com/webdes"
|
15
|
+
.menu_dropdown_item "Typography", "http://fake.com/typog"
|
16
|
+
.menu_dropdown_item "Front-end", "http://fake.com/fronten"
|
17
|
+
.menu_link "About", "http://fake.com/about"
|
@@ -1,10 +1,10 @@
|
|
1
1
|
<table cellpadding=2>
|
2
2
|
<tr>
|
3
|
-
<td width=
|
4
|
-
<td width=
|
3
|
+
<td width=0% valign=top>this</td>
|
4
|
+
<td width=0% valign=top>that</td>
|
5
5
|
</tr>
|
6
6
|
<tr>
|
7
|
-
<td width=
|
8
|
-
<td width=
|
7
|
+
<td width=0% valign=top>foo</td>
|
8
|
+
<td width=0% valign=top>bar</td>
|
9
9
|
</tr>
|
10
10
|
</table>
|
data/test/snapshots/subset.txt
CHANGED
@@ -19,66 +19,70 @@ h This file specifies which snapshots will/won't be run.
|
|
19
19
|
|
20
20
|
# Note that QUIT (on a line by itself) will stop processing the file
|
21
21
|
|
22
|
+
# Bootstrap
|
22
23
|
|
23
24
|
# Others (usually passing):
|
24
25
|
|
25
26
|
# import/include/mixin, others...
|
26
27
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
28
|
+
error_no_such_inc # Output BEFORE error doesn't get passed through ("leading" output)
|
29
|
+
error_no_such_copy # ^ Same behavior as error_no_such_inc
|
30
|
+
error_no_such_mixin # ^ Same behavior as error_missing_end
|
31
|
+
simple_copy #
|
32
|
+
simple_import #
|
33
|
+
simple_include #
|
34
|
+
simple_mixin #
|
35
|
+
import # "Leading" output doesn't get generated (same as error_no_such_inc)
|
36
|
+
import2 #
|
37
|
+
mixin_bookish #
|
38
|
+
import_bookish #
|
39
|
+
test_wtf_bookish #
|
40
|
+
|
41
|
+
# raw input
|
42
|
+
|
43
|
+
single_raw_line #
|
44
|
+
raw_lines #
|
45
|
+
raw_text_block #
|
46
|
+
copy_is_raw #
|
47
|
+
|
48
|
+
# comments
|
49
|
+
|
50
|
+
block_comment #
|
51
|
+
comments_ignored_1 #
|
52
|
+
|
53
|
+
# variables and heredocs
|
54
|
+
|
55
|
+
predef_vars #
|
56
|
+
simple_vars #
|
57
|
+
more_complex_vars #
|
58
|
+
table_with_heredocs #
|
57
59
|
|
58
60
|
# testing def
|
59
61
|
|
60
|
-
|
61
|
-
|
62
|
+
def_method #
|
63
|
+
|
62
64
|
# intraline formatting
|
63
65
|
|
64
|
-
|
66
|
+
basic_formatting #
|
67
|
+
test_formatting_34 #
|
68
|
+
test_formatting_35 #
|
65
69
|
|
66
70
|
# Errors
|
67
71
|
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
72
|
+
error_line_num #
|
73
|
+
error_mismatched_end #
|
74
|
+
error_name_not_permitted #
|
75
|
+
error_invalid_name # ^ Same behavior as error_no_such_inc
|
76
|
+
error_missing_end # Output is duplicated somehow. Look for: puts @body or puts @main.body
|
77
|
+
error_inc_line_num # Forgot what's wrong here
|
74
78
|
|
75
79
|
# functions
|
76
80
|
|
77
|
-
|
78
|
-
|
81
|
+
functions #
|
82
|
+
more_functions #
|
83
|
+
|
84
|
+
# More/misc...
|
79
85
|
|
80
|
-
#
|
81
|
-
|
82
|
-
|
83
|
-
example_alpha2 #
|
84
|
-
hello_world #
|
86
|
+
example_alpha #
|
87
|
+
example_alpha2 #
|
88
|
+
hello_world #
|
File without changes
|
@@ -0,0 +1,16 @@
|
|
1
|
+
|
2
|
+
Testing STILL more functions here...
|
3
|
+
|
4
|
+
|
5
|
+
.func reverse
|
6
|
+
param.reverse # just reverse it
|
7
|
+
.end
|
8
|
+
|
9
|
+
Now... let's try passing a variable to a function. Will this work??
|
10
|
+
|
11
|
+
.set alpha = regal
|
12
|
+
|
13
|
+
Variable \$alpha is $alpha, which reversed is $$reverse:$alpha
|
14
|
+
|
15
|
+
That's all.
|
16
|
+
|
data/test/unit/all.rb
CHANGED