trac-wiki 0.3.10 → 0.3.12
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.
- data/Gemfile +1 -0
- data/Gemfile.lock +3 -1
- data/README +16 -0
- data/lib/trac-wiki/env.rb +10 -33
- data/lib/trac-wiki/parser.rb +9 -3
- data/lib/trac-wiki/version.rb +1 -1
- data/test/parser_test.rb +39 -1
- metadata +2 -2
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,13 +1,14 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
trac-wiki (0.
|
4
|
+
trac-wiki (0.3.10)
|
5
5
|
|
6
6
|
GEM
|
7
7
|
remote: https://rubygems.org/
|
8
8
|
specs:
|
9
9
|
bacon (1.2.0)
|
10
10
|
rake (10.0.4)
|
11
|
+
unicode_utils (1.4.0)
|
11
12
|
|
12
13
|
PLATFORMS
|
13
14
|
ruby
|
@@ -16,3 +17,4 @@ DEPENDENCIES
|
|
16
17
|
bacon
|
17
18
|
rake
|
18
19
|
trac-wiki!
|
20
|
+
unicode_utils
|
data/README
CHANGED
@@ -104,6 +104,22 @@ Project page on github:
|
|
104
104
|
create html toc from previously parsed text
|
105
105
|
|
106
106
|
* `parser.add_macro_command(name, &block)`
|
107
|
+
|
108
|
+
* `parser.env.(env|at(key))`
|
109
|
+
access to env values after parse
|
110
|
+
|
111
|
+
== Macros ==
|
112
|
+
|
113
|
+
* `{{template}}`
|
114
|
+
* `{{$variable}}`
|
115
|
+
* can be set by {{!set variable|value}}
|
116
|
+
* `$1`, `$2` parameters send to template {{template ONE|TWO}}
|
117
|
+
* parameters send to template can be named {{template ahoj=test|hi=west}}
|
118
|
+
* `$0` all parameters (without named)
|
119
|
+
* `$00` all parameters (with named)
|
120
|
+
|
121
|
+
* `{{!command}}`
|
122
|
+
|
107
123
|
== BUGS ==
|
108
124
|
|
109
125
|
If you found a bug, please report it at the TracWiki project's tracker
|
data/lib/trac-wiki/env.rb
CHANGED
@@ -2,6 +2,7 @@
|
|
2
2
|
module TracWiki
|
3
3
|
|
4
4
|
class Env
|
5
|
+
attr_accessor :env
|
5
6
|
def initialize(parser, env = {})
|
6
7
|
@parser = parser
|
7
8
|
@env = env
|
@@ -33,34 +34,6 @@ module TracWiki
|
|
33
34
|
return do_macro_templ(macro_name, args)
|
34
35
|
end
|
35
36
|
|
36
|
-
# # parse to next }} (with balanced {{..}})
|
37
|
-
# # output will be parsed tree: [ "string", [ "string", ... ], "string", [..],[..] ]
|
38
|
-
# def parse_macro_tree(macro_name, str)
|
39
|
-
# return do_macro_cmd(macro_name, []), $', 0 if str =~ /\A}}/
|
40
|
-
# #print "_parse_macro_cmd: #{macro_name}, str#{str}\n"
|
41
|
-
# lines = 0
|
42
|
-
# tree = []
|
43
|
-
# cur = tree
|
44
|
-
# stack = []
|
45
|
-
# while str =~ /{{|}}/
|
46
|
-
# prefix, match, str = $`, $&, $'
|
47
|
-
# cur.push(prefix) if prefix.size > 0
|
48
|
-
# lines += prefix.count("\n")
|
49
|
-
# if match == '{{'
|
50
|
-
# stack.push(cur)
|
51
|
-
# cur.push([])
|
52
|
-
# cur = cur[-1]
|
53
|
-
# elsif match == '}}'
|
54
|
-
# return tree, str, lines if cur == tree
|
55
|
-
# cur = stack.pop
|
56
|
-
# else
|
57
|
-
# raise "never happen"
|
58
|
-
# end
|
59
|
-
# end
|
60
|
-
# raise "eol in parsing macro params"
|
61
|
-
# end
|
62
|
-
|
63
|
-
|
64
37
|
# parse to next }} (with balanced {{..}})
|
65
38
|
# like parse_macro_vartempl but not expand content
|
66
39
|
# r: [expansion, rest_of_str, count_of_consumed_lines]
|
@@ -119,7 +92,8 @@ module TracWiki
|
|
119
92
|
def prepare_y
|
120
93
|
#print "prepare_y\n"
|
121
94
|
return if @env.key? 'y'
|
122
|
-
arg = @env['
|
95
|
+
#arg = @env['argv']['00']
|
96
|
+
arg = @env['argv']['00']
|
123
97
|
return if arg.nil?
|
124
98
|
begin
|
125
99
|
@env['y'] = YAML.load(arg)
|
@@ -137,7 +111,7 @@ module TracWiki
|
|
137
111
|
return @env[key] || default if key.is_a? Symbol
|
138
112
|
prepare_y if key =~ /^y\./
|
139
113
|
key = "argv.#{key}" if key =~ /^\d+$/
|
140
|
-
|
114
|
+
print "key: #{key}\n"
|
141
115
|
cur = @env
|
142
116
|
key.split(/\./).each do |subkey|
|
143
117
|
subkey = at($1, '') if subkey =~ /\A\$(.*)/
|
@@ -153,7 +127,7 @@ module TracWiki
|
|
153
127
|
#print "at(#{key}) -> default\n" if cur.nil?
|
154
128
|
return default if cur.nil?
|
155
129
|
end
|
156
|
-
|
130
|
+
print "at(#{key})->#{cur}\n"
|
157
131
|
to_str ? cur.to_s : cur
|
158
132
|
end
|
159
133
|
def atput(key, val = nil)
|
@@ -232,18 +206,21 @@ module TracWiki
|
|
232
206
|
env[k] = v if k != :depth && k != 'arg' && k!='argv'
|
233
207
|
end
|
234
208
|
env[:depth] = (@env[:depth]||0)+1
|
235
|
-
env['arg'] = args.join('|')
|
236
209
|
env['argv'] = {}
|
210
|
+
env['argv']['00'] = args.join('|')
|
211
|
+
arg0 = []
|
237
212
|
|
238
213
|
idx = 1
|
239
214
|
args.each do |arg|
|
240
|
-
if arg =~ /\A\s*(\w+)
|
215
|
+
if arg =~ /\A\s*(\w+)=\s*(.*)/m
|
241
216
|
env[$1] = $2
|
242
217
|
else
|
243
218
|
env['argv'][idx.to_s] = arg
|
219
|
+
arg0.push arg
|
244
220
|
idx+=1
|
245
221
|
end
|
246
222
|
end
|
223
|
+
env['argv']['0'] = arg0.join('|')
|
247
224
|
return Env.new(@parser, env)
|
248
225
|
end
|
249
226
|
|
data/lib/trac-wiki/parser.rb
CHANGED
@@ -56,6 +56,10 @@ module TracWiki
|
|
56
56
|
# ]
|
57
57
|
attr_accessor :headings
|
58
58
|
|
59
|
+
def env
|
60
|
+
env
|
61
|
+
end
|
62
|
+
|
59
63
|
# url base for links
|
60
64
|
attr_writer :base
|
61
65
|
|
@@ -117,11 +121,13 @@ module TracWiki
|
|
117
121
|
# result fo `template_handler('myCoolMacro') inserted
|
118
122
|
attr_accessor :template_handler
|
119
123
|
|
124
|
+
|
125
|
+
# macro {{$var}} | {{#comment}} | {{!cmd}} | {{template}} | {{/template}}
|
120
126
|
# string begins with macro
|
121
|
-
MACRO_BEG_REX = /\A\{\{ ( \$[\$\.\w]+ | [
|
122
|
-
MACRO_BEG_INSIDE_REX = /\A(.*?)(?<!\{)\{\{ ( \$[\$\.\w]+ | [
|
127
|
+
MACRO_BEG_REX = /\A\{\{ ( \$[\$\.\w]+ | [\#!\/]\w* |\w+ ) /x
|
128
|
+
MACRO_BEG_INSIDE_REX = /\A(.*?)(?<!\{)\{\{ ( \$[\$\.\w]+ | [\#!\/]\w* | \w+ ) /xm
|
123
129
|
# find end of marcro or begin of inner macro
|
124
|
-
MACRO_END_REX = /\A(.*?) ( \}\} | \{\{ ( \$[\$\.\w]+ | [
|
130
|
+
MACRO_END_REX = /\A(.*?) ( \}\} | \{\{ ( \$[\$\.\w]+ | [\#!\/]\w* | \w+) )/mx
|
125
131
|
|
126
132
|
# Create a new Parser instance.
|
127
133
|
def initialize(options = nil)
|
data/lib/trac-wiki/version.rb
CHANGED
data/test/parser_test.rb
CHANGED
@@ -12,6 +12,13 @@ class Bacon::Context
|
|
12
12
|
parser = TracWiki.parser(options)
|
13
13
|
parser.to_html(wiki).should.equal html
|
14
14
|
end
|
15
|
+
def env(wiki, var, val,options = {})
|
16
|
+
options[:macro_commands] = { '!print' => proc { |env| env.arg(0) + '! ' }, }
|
17
|
+
options[:template_handler] = self.method(:template_handler)
|
18
|
+
parser = TracWiki.parser(options)
|
19
|
+
parser.to_html(wiki)
|
20
|
+
parser.env.at(var).should.equal val
|
21
|
+
end
|
15
22
|
|
16
23
|
def template_handler(tname, env)
|
17
24
|
case tname
|
@@ -23,8 +30,12 @@ class Bacon::Context
|
|
23
30
|
"{{$y.ahoj}},{{$y.bhoj.1}}"
|
24
31
|
when 'ytest2'
|
25
32
|
"{{!set i|ahoj}}{{$y.$i}},{{$y.bhoj.1}}"
|
33
|
+
when 'varnula'
|
34
|
+
"nula:{{$0}},a:{{$a}}"
|
35
|
+
when 'varnulanula'
|
36
|
+
"nulanula:{{$00}},a:{{$a}}"
|
26
37
|
when 'vartest'
|
27
|
-
"jedna:{{$1}},dve:{{$2}},p:{{$p}},arg:{{$
|
38
|
+
"jedna:{{$1}},dve:{{$2}},p:{{$p}},arg:{{$00}}"
|
28
39
|
when 'test'
|
29
40
|
"{{west}}"
|
30
41
|
when 'west'
|
@@ -39,6 +50,10 @@ class Bacon::Context
|
|
39
50
|
"maclen:{{$maclen}}"
|
40
51
|
when 'wide'
|
41
52
|
"0123456789{{wide}}" * 10
|
53
|
+
when 'testoff'
|
54
|
+
"off:{{$offset}}"
|
55
|
+
when '/slash'
|
56
|
+
"slash/slash"
|
42
57
|
else
|
43
58
|
nil
|
44
59
|
#"UNK_TEMPL(#{tname})"
|
@@ -1057,7 +1072,11 @@ eos
|
|
1057
1072
|
tc "<p><blockquote>2<blockquote>6</blockquote></blockquote></p>\n", "> {{$offset}}\n> > {{$offset}}"
|
1058
1073
|
tc "<p>test:5,17</p>\n", "test:{{$offset}},{{$offset}}"
|
1059
1074
|
tc "<p>test:5,17,<strong>31</strong></p>\n", "test:{{$offset}},{{$offset}},**{{$offset}}**"
|
1075
|
+
tc "<p>off:0</p>\n", "{{testoff}}"
|
1076
|
+
tc "<p>A:off:2</p>\n", "A:{{testoff}}"
|
1077
|
+
tc "<p>A:off:2</p>\n", "A:{{#echo {{testoff}}}}"
|
1060
1078
|
end
|
1079
|
+
|
1061
1080
|
it 'should parse offset and template' do
|
1062
1081
|
tc "<p>ahoj ahoj,19</p>\n" , "ahoj {{$mac|ahoj}},{{$offset}}"
|
1063
1082
|
tc "<p>ahoj line one line two ,12</p>\n" , "ahoj {{nl}},{{$offset}}"
|
@@ -1081,6 +1100,9 @@ eos
|
|
1081
1100
|
tc "<p>28</p>\n" , "{{$maclen|a=e|b=c|d={{$e}}}}"
|
1082
1101
|
tc "<p>maclen:14</p>\n" , "{{maclentest}}"
|
1083
1102
|
end
|
1103
|
+
it 'should parse macro slash' do
|
1104
|
+
tc "<p>slash/slash</p>\n" , "{{/slash}}"
|
1105
|
+
end
|
1084
1106
|
it 'should parse lineno' do
|
1085
1107
|
tc "<p>1</p>\n" , "{{$lineno}}"
|
1086
1108
|
tc "<p>3</p>\n" , "\n\n{{$lineno}}"
|
@@ -1098,5 +1120,21 @@ eos
|
|
1098
1120
|
tc "<ul><li>[[ahoj|bhoj]]</li>\n</ul>\n<p>3</p>\n", "* [[ahoj|bhoj]]\n\n{{$lineno}}", :no_link => true
|
1099
1121
|
tc "<ul><li>[[ahoj|bhoj]] 2</li>\n</ul>\n", "* [[ahoj|bhoj]]\n{{$lineno}}", :no_link => true
|
1100
1122
|
end
|
1123
|
+
it 'should parse nula' do
|
1124
|
+
tc "<p>nula:TEXT,a:</p>\n" , "{{varnula TEXT}}"
|
1125
|
+
tc "<p>nula:TEXT,a:AHOJ</p>\n" , "{{varnula a=AHOJ|TEXT}}"
|
1126
|
+
tc "<p>nula:TEXT,a:AHOJ</p>\n" , "{{varnula TEXT|a=AHOJ}}"
|
1127
|
+
tc "<p>nula:TEXT,a:</p>\n" , "{{varnula TEXT|b=AHOJ}}"
|
1128
|
+
tc "<p>nula:TE|XT,a:AHOJ</p>\n" , "{{varnula TE|XT|a=AHOJ}}"
|
1129
|
+
tc "<p>nula:TE|XT,a:AHOJ</p>\n" , "{{varnula TE|a=AHOJ|XT}}"
|
1130
|
+
tc "<p>nula:TE|XT,a:AHOJ</p>\n" , "{{varnula TE|a=AHOJ|XT}}"
|
1131
|
+
tc "<p>nulanula:TE|a=AHOJ|XT,a:AHOJ</p>\n" , "{{varnulanula TE|a=AHOJ|XT}}"
|
1132
|
+
end
|
1133
|
+
it 'should parse env' do
|
1134
|
+
env '{{!set b|ahoj}}', 'b', 'ahoj'
|
1135
|
+
# env '{{!set *|ahoj}}', '*', 'ahoj'
|
1136
|
+
# env '{{!set *|{}|}}', '*', '{}'
|
1137
|
+
# tc "<p>a</p>\n" , "{{!set qq|a}}{{$qq}}"
|
1138
|
+
end
|
1101
1139
|
end
|
1102
1140
|
# vim: tw=0
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: trac-wiki
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.12
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-
|
12
|
+
date: 2014-06-07 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bacon
|