yard 0.6.5 → 0.6.6

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of yard might be problematic. Click here for more details.

data/ChangeLog CHANGED
@@ -1,3 +1,53 @@
1
+ 2011-04-06 Loren Segal <lsegal@soen.ca>
2
+
3
+ * ChangeLog, README.md, lib/yard.rb: 0.6.6 release
4
+
5
+ * lib/yard/templates/helpers/markup_helper.rb: Remove loading of 'rdoc' lib
6
+ (not all systems have even this file)
7
+
8
+ 2011-04-05 Loren Segal <lsegal@soen.ca>
9
+
10
+ * lib/yard/cli/yardoc.rb, lib/yard/templates/helpers/html_helper.rb,
11
+ lib/yard/templates/helpers/markup_helper.rb, spec/cli/yardoc_spec.rb,
12
+ spec/templates/helpers/html_helper_spec.rb: Add :none markup format (yard -m
13
+ none) to bypass markup, and fallback on this format if RDoc is not present
14
+ and no markup type is provided.
15
+
16
+ 2011-04-04 Loren Segal <lsegal@soen.ca>
17
+
18
+ * lib/yard/templates/helpers/html_helper.rb,
19
+ spec/templates/helpers/html_helper_spec.rb: Fix matching of {http://link
20
+ description} matches when description has newline in it. Closes #267
21
+
22
+ * lib/yard/autoload.rb, lib/yard/templates/helpers/html_helper.rb,
23
+ lib/yard/templates/helpers/markup_helper.rb,
24
+ spec/templates/helpers/html_helper_spec.rb,
25
+ spec/templates/helpers/markup_helper_spec.rb: Refactor RDoc markup into
26
+ Templates::Helpers::Markup::RDocMarkup class and improve early error
27
+ detection if RDoc is not present on the system. Closes #270
28
+
29
+ * Rakefile, lib/yard/rubygems/specification.rb: Add support for RubyGems
30
+ 1.7.x Closes #272
31
+
32
+ 2011-03-22 Loren Segal <lsegal@soen.ca>
33
+
34
+ * benchmarks/splat_vs_flatten.rb, lib/yard/docstring.rb,
35
+ lib/yard/tags/overload_tag.rb: Remove hackish OverloadTag#to_a support to
36
+ workaround create_tag(*tags) issue (and fix support in JRuby)
37
+
38
+ 2011-03-17 Akzhan Abdulin <akzhan.abdulin@gmail.com>
39
+
40
+ * lib/yard/core_ext/hash.rb: Fix RDoc failure in lib/yard/core_ext/hash.rb at
41
+ or around line 13 column 11 Before reporting this, could you check that the
42
+ file you're documenting compiles cleanly--RDoc is not a full Ruby parser, and
43
+ gets confused easily if fed invalid programs. The internal error was:
44
+ ERROR: While generating documentation for yard-0.6.5 ... MESSAGE: Name or
45
+ symbol expected (got #<RubyToken::TkfLBRACK:0x1025e40e0>) ... RDOC args: --ri
46
+ --op /Users/akzhanabdulin/.rvm/gems/ree-1.8.7-2011.03/doc/yard-0.6.5/ri
47
+ --quiet lib --title yard-0.6.5 Documentation (continuing with the rest of the
48
+ installation) Installing RDoc documentation for ripper-1.0.2... Installing
49
+ RDoc documentation for yard-0.6.5...
50
+
1
51
  2011-03-13 Loren Segal <lsegal@soen.ca>
2
52
 
3
53
  * ChangeLog, LICENSE, README.md, docs/WhatsNew.md, lib/yard.rb, yard.gemspec:
data/README.md CHANGED
@@ -8,8 +8,8 @@ YARD: Yay! A Ruby Documentation Tool
8
8
  **Contributors**: See Contributors section below
9
9
  **Copyright**: 2007-2011
10
10
  **License**: MIT License
11
- **Latest Version**: 0.6.5 (codename "Happy Birthday!")
12
- **Release Date**: March 13th 2011
11
+ **Latest Version**: 0.6.6 (codename "No codename")
12
+ **Release Date**: April 6th 2011
13
13
 
14
14
  Synopsis
15
15
  --------
@@ -289,6 +289,12 @@ More options can be seen by typing `yard-graph --help`, but here is an example:
289
289
  Changelog
290
290
  ---------
291
291
 
292
+ - **April.6.11**: 0.6.6 release
293
+ - Fix error message when RDoc is not present (#270)
294
+ - Add markup type 'none' to perform basic HTML translation (fallback when RDoc is not present)
295
+ - Add support for RubyGems 1.7.x (#272)
296
+ - Fix rendering of `{url description}` syntax when description contains newline
297
+
292
298
  - **March.13.11**: 0.6.5 release
293
299
  - Support `ripper` gem in Ruby 1.8.7
294
300
  - Upgrade jQuery to 1.5.1
data/Rakefile CHANGED
@@ -1,4 +1,5 @@
1
1
  require File.dirname(__FILE__) + '/lib/yard'
2
+ require File.dirname(__FILE__) + '/lib/yard/rubygems/specification'
2
3
  require 'rbconfig'
3
4
 
4
5
  YARD::VERSION.replace(ENV['YARD_VERSION']) if ENV['YARD_VERSION']
@@ -9,7 +10,6 @@ task :default => :specs
9
10
 
10
11
  desc "Builds the gem"
11
12
  task :gem do
12
- Gem.load_plugins # load plugins because they are not autoloaded anymore
13
13
  load 'yard.gemspec'
14
14
  Gem::Builder.new(SPEC).build
15
15
  end
@@ -0,0 +1,12 @@
1
+ require "benchmark"
2
+
3
+ # To prove that flattening a small list is not significantly slower than
4
+ # calling *list (used to get around create_tag list issue)
5
+ $a = "FOO BAR BAZ"
6
+ def foo(*args) args.last.inspect end
7
+
8
+ TESTS = 10_000
9
+ Benchmark.bmbm do |x|
10
+ x.report("splat") { TESTS.times { foo *$a } }
11
+ x.report("flatten") { TESTS.times { foo *[$a].flatten } }
12
+ end
data/lib/yard.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  module YARD
2
- VERSION = "0.6.5"
2
+ VERSION = "0.6.6"
3
3
 
4
4
  # The root path for YARD source libraries
5
5
  ROOT = File.expand_path(File.dirname(__FILE__))
data/lib/yard/autoload.rb CHANGED
@@ -195,6 +195,10 @@ module YARD
195
195
  # Namespace for templating system
196
196
  module Templates
197
197
  module Helpers # Namespace for template helpers
198
+ module Markup # Namespace for markup providers
199
+ autoload :RDocMarkup, __p('templates/helpers/markup/rdoc_markup')
200
+ end
201
+
198
202
  autoload :BaseHelper, __p('templates/helpers/base_helper')
199
203
  autoload :FilterHelper, __p('templates/helpers/filter_helper')
200
204
  autoload :HtmlHelper, __p('templates/helpers/html_helper')
@@ -158,7 +158,7 @@ module YARD
158
158
  @options.update(
159
159
  :format => :html,
160
160
  :template => :default,
161
- :markup => :rdoc,
161
+ :markup => nil, # default is :rdoc but falls back on :none
162
162
  :serializer => YARD::Serializers::FileSystemSerializer.new,
163
163
  :default_return => "Object",
164
164
  :hide_void_return => false,
@@ -302,9 +302,20 @@ module YARD
302
302
  #
303
303
  # @return (see YARD::Templates::Helpers::MarkupHelper#load_markup_provider)
304
304
  def verify_markup_options
305
+ has_markup = options[:markup] ? true : false
306
+ options[:markup] ||= :rdoc
307
+ result, lvl = false, has_markup ? log.level : Logger::FATAL
305
308
  obj = Struct.new(:options).new(options)
306
309
  obj.extend(Templates::Helpers::MarkupHelper)
307
- obj.load_markup_provider
310
+ log.enter_level(lvl) { result = obj.load_markup_provider }
311
+ if !result && !has_markup
312
+ log.warn "Could not load default RDoc formatter, " +
313
+ "ignoring any markup (install RDoc to get default formatting)."
314
+ options[:markup] = :none
315
+ true
316
+ else
317
+ result
318
+ end
308
319
  end
309
320
 
310
321
  # Copies any assets to the output directory
@@ -9,7 +9,7 @@ class Hash
9
9
  create_186(*args)
10
10
  end
11
11
  end
12
- alias create_186 []
13
- alias [] create
12
+ alias :create_186 :[]
13
+ alias :[] :create
14
14
  end
15
15
  end if RUBY_VERSION < "1.8.7"
@@ -199,7 +199,7 @@ module YARD
199
199
  tag_factory = Tags::Library.instance
200
200
  tag_method = "#{tag_name}_tag"
201
201
  if tag_name && tag_factory.respond_to?(tag_method)
202
- add_tag(*tag_factory.send(tag_method, tag_buf))
202
+ add_tag(*[tag_factory.send(tag_method, tag_buf)].flatten)
203
203
  else
204
204
  log.warn "Unknown tag @#{tag_name}" + (object ? " in file `#{object.file}` near line #{object.line}" : "")
205
205
  end
@@ -1,13 +1,9 @@
1
1
  require 'rubygems/specification'
2
2
 
3
3
  class Gem::Specification
4
- # has_rdoc should not be ignored!
5
- overwrite_accessor(:has_rdoc) { @has_rdoc }
6
- overwrite_accessor(:has_rdoc=) {|v| @has_rdoc = v }
7
-
8
4
  # @since 0.5.3
9
5
  def has_yardoc=(value)
10
- @has_rdoc = 'yard'
6
+ @has_rdoc = value ? 'yard' : false
11
7
  end
12
8
 
13
9
  def has_yardoc
@@ -20,4 +16,26 @@ class Gem::Specification
20
16
  end
21
17
 
22
18
  alias has_yardoc? has_yardoc
19
+
20
+ # has_rdoc should not be ignored!
21
+ if respond_to?(:overwrite_accessor)
22
+ overwrite_accessor(:has_rdoc) { @has_rdoc }
23
+ overwrite_accessor(:has_rdoc=) {|v| @has_rdoc = v }
24
+ else
25
+ attr_accessor :has_rdoc
26
+ end
27
+
28
+ if defined?(Gem::VERSION) && Gem::VERSION =~ /^1\.7\./
29
+ def _dump_with_rdoc(limit)
30
+ dmp = _dump_without_rdoc(limit)
31
+ dmp[15] = @has_rdoc
32
+ dmp
33
+ end
34
+ alias _dump_without_rdoc _dump
35
+ alias _dump _dump_with_rdoc
36
+
37
+ @@default_value[:has_rdoc] = true if defined?(@@default_value)
38
+ @@attributes << 'has_rdoc' if defined?(@@attributes)
39
+ @@non_nil_attributes << 'has_rdoc' if defined?(@@non_nil_attributes)
40
+ end
23
41
  end
@@ -37,11 +37,6 @@ module YARD
37
37
  alias kind_of? is_a?
38
38
 
39
39
  private
40
-
41
- if RUBY19
42
- def to_a; nil end
43
- def to_ary; nil end
44
- end
45
40
 
46
41
  def parse_tag(text)
47
42
  @signature, text = *text.split(/\r?\n/, 2)
@@ -77,13 +77,9 @@ module YARD
77
77
  # @return [String] output HTML
78
78
  # @since 0.6.0
79
79
  def html_markup_rdoc(text)
80
- begin
81
- simple_markup_html.instance_variable_set("@from_path", url_for(object))
82
- html = markup_class(:rdoc).new.convert(text, simple_markup_html)
83
- end
84
-
85
- html = fix_dash_dash(html)
86
- html = fix_typewriter(html)
80
+ doc = markup_class(:rdoc).new(text)
81
+ doc.from_path = url_for(object) if doc.respond_to?(:from_path=)
82
+ doc.to_html
87
83
  end
88
84
 
89
85
  # Converts plaintext to HTML
@@ -94,6 +90,12 @@ module YARD
94
90
  "<pre>" + text + "</pre>"
95
91
  end
96
92
 
93
+ # @return [String] the same text with no markup
94
+ # @since 0.6.6
95
+ def html_markup_none(text)
96
+ h(text).gsub(/(?:\r?\n){2}/, '<br/>')
97
+ end
98
+
97
99
  # Converts HTML to HTML
98
100
  # @param [String] text input html
99
101
  # @return [String] output HTML
@@ -107,29 +109,6 @@ module YARD
107
109
  "<div class='inline'>" + htmlify(*args) + "</div>"
108
110
  end
109
111
 
110
- # Fixes RDoc behaviour with ++ only supporting alphanumeric text.
111
- #
112
- # @todo Refactor into own SimpleMarkup subclass
113
- def fix_typewriter(text)
114
- text.gsub(/(\s|^|>)\+(?! )([^\n\+]{1,900})(?! )\+/) do
115
- first_text, type_text, pre_text, no_match = $1, $2, $`, $&
116
- pre_match = (pre_text+first_text).scan(%r(</?(?:(?:pre|tt|code).*?>|[^>]+)\Z))
117
- if pre_match.last.nil? || pre_match.last[1,1] == '/'
118
- first_text + '<tt>' + h(type_text) + '</tt>'
119
- else
120
- no_match
121
- end
122
- end
123
- end
124
-
125
- # Don't allow -- to turn into &#8212; element. The chances of this being
126
- # some --option is far more likely than the typographical meaning.
127
- #
128
- # @todo Refactor into own SimpleMarkup subclass
129
- def fix_dash_dash(text)
130
- text.gsub(/&#8212;(?=\S)/, '--')
131
- end
132
-
133
112
  # @group Syntax Highlighting Source Code
134
113
 
135
114
  # Syntax highlights +source+ in language +type+.
@@ -175,7 +154,7 @@ module YARD
175
154
  # @return [String] HTML with linkified references
176
155
  def resolve_links(text)
177
156
  code_tags = 0
178
- text.gsub(/<(\/)?(pre|code|tt)|\{(\S+?)(?:\s(.*?\S))?\}(?=[\W<]|.+<\/|$)/) do |str|
157
+ text.gsub(/<(\/)?(pre|code|tt)|\{(\S+?)(?:\s(.*?\S))?\}(?=[\W<]|.+<\/|$)/m) do |str|
179
158
  closed, tag, name, title, match = $1, $2, $3, $4, $&
180
159
  if tag
181
160
  code_tags += (closed ? -1 : 1)
@@ -235,12 +214,13 @@ module YARD
235
214
  # (see BaseHelper#link_url)
236
215
  def link_url(url, title = nil, params = {})
237
216
  title ||= url
217
+ title.gsub!(/[\r\n]/, ' ')
238
218
  params = SymbolHash.new(false).update(
239
219
  :href => url,
240
220
  :title => h(title)
241
221
  ).update(params)
242
222
  params[:target] ||= '_parent' if url =~ /^(\w+):\/\//
243
- "<a #{tag_attrs(params)}>#{title}</a>"
223
+ "<a #{tag_attrs(params)}>#{title}</a>".gsub(/[\r\n]/, ' ')
244
224
  end
245
225
 
246
226
  # @group URL Helpers
@@ -445,22 +425,7 @@ module YARD
445
425
  # @endgroup
446
426
 
447
427
  private
448
-
449
- # Gets the SimpleMarkup class for the local thread
450
- #
451
- # @return [RDoc::Markup::ToHtml] if RDoc 2.x is loaded
452
- # @return [SM::ToHtml] if RDoc 1.x is loaded
453
- # @since 0.6.5
454
- def simple_markup_html
455
- begin
456
- require 'rdoc/markup/to_html'
457
- rescue LoadError
458
- require 'rdoc/markup/simple_markup/to_html'
459
- end
460
- Thread.current[:__yard_simple_markup_html__] ||=
461
- (RDoc::Markup::ToHtml.new rescue SM::ToHtml.new)
462
- end
463
-
428
+
464
429
  # Converts a set of hash options into HTML attributes for a tag
465
430
  #
466
431
  # @param [Hash{String => String}] opts the tag options
@@ -0,0 +1,80 @@
1
+ module YARD
2
+ module Templates
3
+ module Helpers
4
+ module Markup
5
+ begin
6
+ require 'rdoc/markup'
7
+ require 'rdoc/markup/to_html'
8
+ class RDocMarkup; MARKUP = RDoc::Markup end
9
+ class RDocMarkupToHtml < RDoc::Markup::ToHtml; end
10
+ rescue LoadError
11
+ begin
12
+ require 'rdoc/markup/simple_markup'
13
+ require 'rdoc/markup/simple_markup/to_html'
14
+ class RDocMarkup; MARKUP = SM::SimpleMarkup end
15
+ class RDocMarkupToHtml < SM::ToHtml; end
16
+ rescue LoadError
17
+ raise NameError, "could not load RDocMarkup (rdoc is not installed)"
18
+ end
19
+ end
20
+
21
+ class RDocMarkup
22
+ attr_accessor :from_path
23
+
24
+ def initialize(text)
25
+ @text = text
26
+ @markup = MARKUP.new
27
+ end
28
+
29
+ def to_html
30
+ formatter = RDocMarkupToHtml.new
31
+ formatter.from_path = from_path
32
+ html = @markup.convert(@text, formatter)
33
+ html = fix_dash_dash(html)
34
+ html = fix_typewriter(html)
35
+ html
36
+ end
37
+
38
+ private
39
+
40
+ # Fixes RDoc behaviour with ++ only supporting alphanumeric text.
41
+ #
42
+ # @todo Refactor into own SimpleMarkup subclass
43
+ def fix_typewriter(text)
44
+ text.gsub(/(\s|^|>)\+(?! )([^\n\+]{1,900})(?! )\+/) do
45
+ first_text, type_text, pre_text, no_match = $1, $2, $`, $&
46
+ pre_match = (pre_text+first_text).scan(%r(</?(?:(?:pre|tt|code).*?>|[^>]+)\Z))
47
+ if pre_match.last.nil? || pre_match.last[1,1] == '/'
48
+ first_text + '<tt>' + CGI.escapeHTML(type_text) + '</tt>'
49
+ else
50
+ no_match
51
+ end
52
+ end
53
+ end
54
+
55
+ # Don't allow -- to turn into &#8212; element. The chances of this being
56
+ # some --option is far more likely than the typographical meaning.
57
+ #
58
+ # @todo Refactor into own SimpleMarkup subclass
59
+ def fix_dash_dash(text)
60
+ text.gsub(/&#8212;(?=\S)/, '--')
61
+ end
62
+ end
63
+
64
+ class RDocMarkupToHtml
65
+ attr_accessor :from_path
66
+
67
+ # Disable auto-link of URLs
68
+ def handle_special_HYPERLINK(special)
69
+ @hyperlink ? special.text : super
70
+ end
71
+
72
+ def accept_paragraph(par)
73
+ @hyperlink = !!(par.text =~ /\{(https?:|mailto:|link:|www\.)/)
74
+ super
75
+ end
76
+ end
77
+ end
78
+ end
79
+ end
80
+ end
@@ -32,11 +32,11 @@ module YARD
32
32
  {:lib => :redcloth, :const => 'RedCloth'}
33
33
  ],
34
34
  :rdoc => [
35
- {:lib => 'rdoc/markup', :const => 'RDoc::Markup'},
36
- {:lib => 'rdoc/markup/simple_markup', :const => 'SM::SimpleMarkup'}
35
+ {:lib => nil, :const => 'YARD::Templates::Helpers::Markup::RDocMarkup'},
37
36
  ],
38
37
  :text => [],
39
- :html => []
38
+ :html => [],
39
+ :none => []
40
40
  }
41
41
 
42
42
  # Returns a list of extensions for various markup types. To register
@@ -48,7 +48,7 @@ module YARD
48
48
  :text => ['txt'],
49
49
  :textile => ['textile', 'txtile'],
50
50
  :markdown => ['markdown', 'md', 'mdown', 'mkd'],
51
- :rdoc => ['rdoc']
51
+ :rdoc => ['rdoc'],
52
52
  }
53
53
 
54
54
  # Contains the Regexp object that matches the shebang line of extra
@@ -84,7 +84,7 @@ module YARD
84
84
 
85
85
  # Search for provider, return the library class name as const if found
86
86
  providers.each do |provider|
87
- begin require provider[:lib].to_s; rescue LoadError; next end
87
+ begin require provider[:lib].to_s; rescue LoadError; next end if provider[:lib]
88
88
  begin klass = eval("::" + provider[:const]); rescue NameError; next end
89
89
  MarkupHelper.markup_cache[type][:provider] = provider[:lib] # Cache the provider
90
90
  MarkupHelper.markup_cache[type][:class] = klass
@@ -92,8 +92,8 @@ module YARD
92
92
  end
93
93
 
94
94
  # Show error message telling user to install first potential provider
95
- name, lib = providers.first[:const], providers.first[:lib]
96
- log.error "Missing #{name} gem for #{options[:markup].to_s.capitalize} formatting. Install it with `gem install #{lib}`"
95
+ name, lib = *[providers.first[:const], providers.first[:lib] || type]
96
+ log.error "Missing '#{lib}' gem for #{options[:markup].to_s.capitalize} formatting. Install it with `gem install #{lib}`"
97
97
  false
98
98
  end
99
99
 
@@ -44,8 +44,8 @@ describe YARD::CLI::Yardoc do
44
44
  @yardoc.files.should == ['lib/**/*.rb', 'ext/**/*.c']
45
45
  end
46
46
 
47
- it "should use rdoc as default markup type" do
48
- @yardoc.options[:markup].should == :rdoc
47
+ it "should be nil as default markup type (but defaults to rdoc and falls back on none)" do
48
+ @yardoc.options[:markup].should == nil
49
49
  end
50
50
 
51
51
  it "should use default as default template" do
@@ -517,4 +517,22 @@ describe YARD::CLI::Yardoc do
517
517
  @yardoc.run('--template-path', 'foo')
518
518
  end
519
519
  end
520
+
521
+ describe 'Markup Loading' do
522
+ it "should load rdoc markup if no markup is provided" do
523
+ @yardoc.generate = true
524
+ @yardoc.run
525
+ @yardoc.options[:markup].should == :rdoc
526
+ end
527
+
528
+ it "should warn if rdoc cannot be loaded and fallback to :none" do
529
+ mod = YARD::Templates::Helpers::MarkupHelper
530
+ mod.clear_markup_cache
531
+ mod.const_get(:MARKUP_PROVIDERS).should_receive(:[]).with(:rdoc).and_return([{:lib => 'INVALID'}])
532
+ log.should_receive(:warn).with(/Could not load default RDoc formatter/)
533
+ @yardoc.generate = true
534
+ @yardoc.run
535
+ @yardoc.options[:markup].should == :none
536
+ end
537
+ end
520
538
  end
@@ -14,39 +14,6 @@ describe YARD::Templates::Helpers::HtmlHelper do
14
14
  end
15
15
  end
16
16
 
17
- describe '#fix_typewriter' do
18
- it "should use #fix_typewriter to convert +text+ to <tt>text</tt>" do
19
- fix_typewriter("Some +typewriter text+.").should ==
20
- "Some <tt>typewriter" +
21
- " text</tt>."
22
- fix_typewriter("Not +typewriter text.").should ==
23
- "Not +typewriter text."
24
- fix_typewriter("Alternating +type writer+ text +here+.").should ==
25
- "Alternating <tt>type writer" +
26
- "</tt> text <tt>here</tt>."
27
- fix_typewriter("No ++problem.").should ==
28
- "No ++problem."
29
- fix_typewriter("Math + stuff +is ok+").should ==
30
- "Math + stuff <tt>is ok</tt>"
31
- fix_typewriter("Hello +{Foo}+ World").should == "Hello <tt>{Foo}</tt> World"
32
- end
33
-
34
- it "should not apply to code blocks" do
35
- fix_typewriter("<code>+hello+</code>").should == "<code>+hello+</code>"
36
- end
37
-
38
- it "should not apply to HTML tag attributes" do
39
- fix_typewriter("<a href='http://foo.com/A+b+c'>A+b+c</a>").should ==
40
- "<a href='http://foo.com/A+b+c'>A+b+c</a>"
41
- fix_typewriter("<foo class='foo+bar+baz'/>").should ==
42
- "<foo class='foo+bar+baz'/>"
43
- end
44
-
45
- it "should still apply inside of other tags" do
46
- fix_typewriter("<p>+foo+</p>").should == "<p><tt>foo</tt></p>"
47
- end
48
- end
49
-
50
17
  describe '#charset' do
51
18
  it "should return foo if LANG=foo" do
52
19
  ENV.should_receive(:[]).with('LANG').and_return('shift_jis') if RUBY18
@@ -122,6 +89,10 @@ describe YARD::Templates::Helpers::HtmlHelper do
122
89
  htmlify("\xB0\xB1", :text)
123
90
  # TODO: add more encoding tests
124
91
  end
92
+
93
+ it "should return regular text with :none markup" do
94
+ htmlify("fo\no\n\nbar<>", :none).should == "fo\no<br/>bar&lt;&gt;"
95
+ end
125
96
  end
126
97
 
127
98
  describe "#link_object" do
@@ -229,10 +200,9 @@ describe YARD::Templates::Helpers::HtmlHelper do
229
200
  describe '#resolve_links' do
230
201
  def parse_link(link)
231
202
  results = {}
232
- link =~ /<a (.+?)>(.+?)<\/a>/
203
+ link =~ /<a (.+?)>(.+?)<\/a>/m
233
204
  params, results[:inner_text] = $1, $2
234
- params.split(/\s+/).each do |match|
235
- key, value = *match.split('=')
205
+ params.scan(/\s*(\S+?)=['"](.+?)['"]\s*/).each do |key, value|
236
206
  results[key.to_sym] = value.gsub(/^["'](.+)["']$/, '\1')
237
207
  end
238
208
  results
@@ -294,6 +264,25 @@ describe YARD::Templates::Helpers::HtmlHelper do
294
264
  resolve_links(text).should == text
295
265
  end
296
266
  end
267
+
268
+ it "should resolve {Name}" do
269
+ should_receive(:link_file).with('TEST', 'TEST', nil).and_return('')
270
+ resolve_links("{file:TEST}")
271
+ end
272
+
273
+ it "should resolve ({Name})" do
274
+ should_receive(:link_file).with('TEST', 'TEST', nil).and_return('')
275
+ resolve_links("({file:TEST})")
276
+ end
277
+
278
+ it "should resolve link with newline in title-part" do
279
+ parse_link(resolve_links("{http://example.com foo\nbar}")).should == {
280
+ :inner_text => "foo bar",
281
+ :target => "_parent",
282
+ :href => "http://example.com",
283
+ :title => "foo bar"
284
+ }
285
+ end
297
286
 
298
287
  it "should warn about missing reference at right file location for object" do
299
288
  YARD.parse_string <<-eof
@@ -427,18 +416,6 @@ describe YARD::Templates::Helpers::HtmlHelper do
427
416
  end
428
417
  end
429
418
 
430
- describe '#resolve_links' do
431
- it "should resolve {Name}" do
432
- should_receive(:link_file).with('TEST', 'TEST', nil).and_return('')
433
- resolve_links("{file:TEST}")
434
- end
435
-
436
- it "should resolve ({Name})" do
437
- should_receive(:link_file).with('TEST', 'TEST', nil).and_return('')
438
- resolve_links("({file:TEST})")
439
- end
440
- end
441
-
442
419
  describe '#link_url' do
443
420
  it "should add target if scheme is provided" do
444
421
  link_url("http://url.com").should include(" target=\"_parent\"")
@@ -0,0 +1,84 @@
1
+ require File.dirname(__FILE__) + "/../../spec_helper"
2
+
3
+ describe YARD::Templates::Helpers::Markup::RDocMarkup do
4
+ describe 'loading mechanism' do
5
+ before { @good_libs = [] }
6
+
7
+ def require(lib)
8
+ return true if @good_libs.include?(lib)
9
+ raise LoadError
10
+ end
11
+
12
+ def load_markup
13
+ begin
14
+ require 'rdoc/markup'
15
+ require 'rdoc/markup/to_html'
16
+ return :RDoc2
17
+ rescue LoadError
18
+ begin
19
+ require 'rdoc/markup/simple_markup'
20
+ require 'rdoc/markup/simple_markup/to_html'
21
+ return :RDoc1
22
+ rescue LoadError
23
+ raise NameError, "could not load RDocMarkup (rdoc is not installed)"
24
+ end
25
+ end
26
+ end
27
+
28
+ it "should load RDoc2.x if rdoc/markup is present" do
29
+ @good_libs += ['rdoc/markup', 'rdoc/markup/to_html']
30
+ load_markup.should == :RDoc2
31
+ end
32
+
33
+ it "should fail on RDoc2.x if rdoc/markup/to_html is not present" do
34
+ @good_libs += ['rdoc/markup']
35
+ lambda { load_markup }.should raise_error(NameError)
36
+ end
37
+
38
+ it "should load RDoc1.x if RDoc2 fails and rdoc/markup/simple_markup is present" do
39
+ @good_libs += ['rdoc/markup/simple_markup', 'rdoc/markup/simple_markup/to_html']
40
+ load_markup.should == :RDoc1
41
+ end
42
+
43
+ it "should error on loading if neither lib is present" do
44
+ lambda { load_markup }.should raise_error(NameError)
45
+ end
46
+ end
47
+
48
+ describe '#fix_typewriter' do
49
+ def fix_typewriter(text)
50
+ YARD::Templates::Helpers::Markup::RDocMarkup.new('').send(:fix_typewriter, text)
51
+ end
52
+
53
+ it "should use #fix_typewriter to convert +text+ to <tt>text</tt>" do
54
+ fix_typewriter("Some +typewriter text <+.").should ==
55
+ "Some <tt>typewriter" +
56
+ " text &lt;</tt>."
57
+ fix_typewriter("Not +typewriter text.").should ==
58
+ "Not +typewriter text."
59
+ fix_typewriter("Alternating +type writer+ text +here+.").should ==
60
+ "Alternating <tt>type writer" +
61
+ "</tt> text <tt>here</tt>."
62
+ fix_typewriter("No ++problem.").should ==
63
+ "No ++problem."
64
+ fix_typewriter("Math + stuff +is ok+").should ==
65
+ "Math + stuff <tt>is ok</tt>"
66
+ fix_typewriter("Hello +{Foo}+ World").should == "Hello <tt>{Foo}</tt> World"
67
+ end
68
+
69
+ it "should not apply to code blocks" do
70
+ fix_typewriter("<code>+hello+</code>").should == "<code>+hello+</code>"
71
+ end
72
+
73
+ it "should not apply to HTML tag attributes" do
74
+ fix_typewriter("<a href='http://foo.com/A+b+c'>A+b+c</a>").should ==
75
+ "<a href='http://foo.com/A+b+c'>A+b+c</a>"
76
+ fix_typewriter("<foo class='foo+bar+baz'/>").should ==
77
+ "<foo class='foo+bar+baz'/>"
78
+ end
79
+
80
+ it "should still apply inside of other tags" do
81
+ fix_typewriter("<p>+foo+</p>").should == "<p><tt>foo</tt></p>"
82
+ end
83
+ end
84
+ end
@@ -32,24 +32,17 @@ describe YARD::Templates::Helpers::MarkupHelper do
32
32
  @gen.markup_class.should == nil
33
33
  end
34
34
 
35
- it "should load RDoc 2.x if rdoc is specified and 2.x is installed" do
36
- rdoc_lib = mock(:rdoc)
35
+ it "should load RDocMarkup if rdoc is specified and it is installed" do
37
36
  @gen.stub!(:options).and_return({:markup => :rdoc})
38
- @gen.should_receive(:eval).with('::RDoc::Markup').and_return(rdoc_lib)
39
- @gen.should_receive(:require).with('rdoc/markup').and_return(true)
40
37
  @gen.load_markup_provider.should == true
41
- @gen.markup_class.should == rdoc_lib
38
+ @gen.markup_class.should == YARD::Templates::Helpers::Markup::RDocMarkup
42
39
  end
43
40
 
44
- it "should load RDoc 1.x if rdoc 1.x is installed" do
45
- rdoc_lib = mock(:rdoc)
41
+ it "should fail if RDoc cannot be loaded" do
46
42
  @gen.stub!(:options).and_return({:markup => :rdoc})
47
- @gen.should_receive(:eval).with('::RDoc::Markup').and_raise(NameError)
48
- @gen.should_receive(:eval).with('::SM::SimpleMarkup').and_return(rdoc_lib)
49
- @gen.should_receive(:require).with('rdoc/markup').and_return(true)
50
- @gen.should_receive(:require).with('rdoc/markup/simple_markup').and_return(true)
51
- @gen.load_markup_provider.should == true
52
- @gen.markup_class.should == rdoc_lib
43
+ @gen.should_receive(:eval).with('::YARD::Templates::Helpers::Markup::RDocMarkup').and_raise(NameError)
44
+ @gen.load_markup_provider.should == false
45
+ @gen.markup_provider.should == nil
53
46
  end
54
47
 
55
48
  it "should search through available markup providers for the markup type if none is set" do
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: yard
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.6.5
5
+ version: 0.6.6
6
6
  platform: ruby
7
7
  authors:
8
8
  - Loren Segal
@@ -10,8 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-03-13 00:00:00 -05:00
14
- default_executable:
13
+ date: 2011-04-06 00:00:00 Z
15
14
  dependencies: []
16
15
 
17
16
  description: " YARD is a documentation generation tool for the Ruby programming language.\n It enables the user to generate consistent, usable documentation that can be\n exported to a number of formats very easily, and also supports extending for\n custom Ruby constructs such as custom class level definitions.\n"
@@ -186,6 +185,7 @@ files:
186
185
  - lib/yard/templates/helpers/filter_helper.rb
187
186
  - lib/yard/templates/helpers/html_helper.rb
188
187
  - lib/yard/templates/helpers/html_syntax_highlight_helper.rb
188
+ - lib/yard/templates/helpers/markup/rdoc_markup.rb
189
189
  - lib/yard/templates/helpers/markup_helper.rb
190
190
  - lib/yard/templates/helpers/method_helper.rb
191
191
  - lib/yard/templates/helpers/module_helper.rb
@@ -329,6 +329,7 @@ files:
329
329
  - spec/templates/helpers/base_helper_spec.rb
330
330
  - spec/templates/helpers/html_helper_spec.rb
331
331
  - spec/templates/helpers/html_syntax_highlight_helper_spec.rb
332
+ - spec/templates/helpers/markup/rdoc_markup_spec.rb
332
333
  - spec/templates/helpers/markup_helper_spec.rb
333
334
  - spec/templates/helpers/method_helper_spec.rb
334
335
  - spec/templates/helpers/shared_signature_examples.rb
@@ -459,6 +460,7 @@ files:
459
460
  - benchmarks/rdoc_vs_yardoc.rb
460
461
  - benchmarks/ri_vs_yri.rb
461
462
  - benchmarks/ripper_parser.rb
463
+ - benchmarks/splat_vs_flatten.rb
462
464
  - benchmarks/template_erb.rb
463
465
  - benchmarks/template_format.rb
464
466
  - benchmarks/template_profile.rb
@@ -469,7 +471,6 @@ files:
469
471
  - README.md
470
472
  - Rakefile
471
473
  - .yardopts
472
- has_rdoc: yard
473
474
  homepage: http://yardoc.org
474
475
  licenses: []
475
476
 
@@ -493,9 +494,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
493
494
  requirements: []
494
495
 
495
496
  rubyforge_project: yard
496
- rubygems_version: 1.5.2
497
+ rubygems_version: 1.7.2
497
498
  signing_key:
498
499
  specification_version: 3
499
500
  summary: Documentation tool for consistent and usable documentation in Ruby.
500
501
  test_files: []
501
502
 
503
+ has_rdoc: yard