trac-wiki 0.3.12 → 0.3.13

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/lib/trac-wiki/env.rb CHANGED
@@ -111,7 +111,7 @@ module TracWiki
111
111
  return @env[key] || default if key.is_a? Symbol
112
112
  prepare_y if key =~ /^y\./
113
113
  key = "argv.#{key}" if key =~ /^\d+$/
114
- print "key: #{key}\n"
114
+ #print "key: #{key}\n"
115
115
  cur = @env
116
116
  key.split(/\./).each do |subkey|
117
117
  subkey = at($1, '') if subkey =~ /\A\$(.*)/
@@ -127,7 +127,7 @@ module TracWiki
127
127
  #print "at(#{key}) -> default\n" if cur.nil?
128
128
  return default if cur.nil?
129
129
  end
130
- print "at(#{key})->#{cur}\n"
130
+ #rint "at(#{key})->#{cur}\n"
131
131
  to_str ? cur.to_s : cur
132
132
  end
133
133
  def atput(key, val = nil)
@@ -182,7 +182,9 @@ module TracWiki
182
182
 
183
183
  if ! @parser.template_handler.nil?
184
184
  str = @parser.template_handler.call(macro_name, env)
185
- if !str.nil?
185
+ is_defined = !str.nil?
186
+ @parser.used_templates[macro_name] = is_defined
187
+ if is_defined
186
188
  #print "dep:#{env[:depth]}(#{macro_name}, #{str})\n"
187
189
  if env[:depth] > 32
188
190
  return "TOO_DEEP_RECURSION(`#{str}`)\n"
@@ -57,9 +57,13 @@ module TracWiki
57
57
  attr_accessor :headings
58
58
 
59
59
  def env
60
- env
60
+ @env
61
61
  end
62
62
 
63
+ attr_reader :used_templates
64
+ @used_templates = {}
65
+
66
+
63
67
  # url base for links
64
68
  attr_writer :base
65
69
 
@@ -151,6 +155,7 @@ module TracWiki
151
155
 
152
156
  def to_html(text = nil)
153
157
  text(text) if ! text.nil?
158
+ @used_templates = {}
154
159
  @was_math = false
155
160
  @anames = {}
156
161
  @count_lines_level = 0
@@ -1,3 +1,3 @@
1
1
  module TracWiki
2
- VERSION = '0.3.12'
2
+ VERSION = '0.3.13'
3
3
  end
data/test/parser_test.rb CHANGED
@@ -19,6 +19,16 @@ class Bacon::Context
19
19
  parser.to_html(wiki)
20
20
  parser.env.at(var).should.equal val
21
21
  end
22
+ def used_templates(wiki, used_templates, options={})
23
+ options[:macro_commands] = { '!print' => proc { |env| env.arg(0) + '! ' }, }
24
+ options[:template_handler] = self.method(:template_handler)
25
+ parser = TracWiki.parser(options)
26
+ parser.to_html(wiki)
27
+ parser.used_templates.sort.map do |key,value|
28
+ "#{key}:#{value}"
29
+ end.join(',').should.equal used_templates
30
+
31
+ end
22
32
 
23
33
  def template_handler(tname, env)
24
34
  case tname
@@ -36,6 +46,8 @@ class Bacon::Context
36
46
  "nulanula:{{$00}},a:{{$a}}"
37
47
  when 'vartest'
38
48
  "jedna:{{$1}},dve:{{$2}},p:{{$p}},arg:{{$00}}"
49
+ when 'testundef'
50
+ "{{westundef}}"
39
51
  when 'test'
40
52
  "{{west}}"
41
53
  when 'west'
@@ -1132,9 +1144,14 @@ eos
1132
1144
  end
1133
1145
  it 'should parse env' do
1134
1146
  env '{{!set b|ahoj}}', 'b', 'ahoj'
1135
- # env '{{!set *|ahoj}}', '*', 'ahoj'
1136
- # env '{{!set *|{}|}}', '*', '{}'
1137
- # tc "<p>a</p>\n" , "{{!set qq|a}}{{$qq}}"
1147
+ env '{{!set *|ahoj}}', '*', 'ahoj'
1148
+ env '{{!set *|{}|}}', '*', '{}'
1149
+ tc "<p>a</p>\n" , "{{!set qq|a}}{{$qq}}"
1150
+ end
1151
+ it 'should know used templates' do
1152
+ used_templates "{{varnula}}", "varnula:true"
1153
+ used_templates "{{test}}", "test:true,west:true"
1154
+ used_templates "{{testundef}}", "testundef:true,westundef:false"
1138
1155
  end
1139
1156
  end
1140
1157
  # 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.12
4
+ version: 0.3.13
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-06-07 00:00:00.000000000 Z
12
+ date: 2014-06-08 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bacon