yard 0.2.3 → 0.2.3.2

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.

Files changed (46) hide show
  1. data/.yardopts +12 -0
  2. data/README.markdown +20 -2
  3. data/Rakefile +3 -2
  4. data/lib/rubygems_plugin.rb +91 -0
  5. data/lib/yard.rb +2 -1
  6. data/lib/yard/cli/yardoc.rb +41 -9
  7. data/lib/yard/code_objects/base.rb +2 -12
  8. data/lib/yard/docstring.rb +19 -8
  9. data/lib/yard/generators/full_doc_generator.rb +2 -1
  10. data/lib/yard/generators/helpers/html_helper.rb +6 -2
  11. data/lib/yard/generators/tags_generator.rb +23 -2
  12. data/lib/yard/handlers/base.rb +6 -5
  13. data/lib/yard/parser/ruby/ast_node.rb +2 -1
  14. data/lib/yard/parser/ruby/legacy/ruby_lex.rb +9 -1
  15. data/lib/yard/parser/ruby/legacy/statement.rb +24 -16
  16. data/lib/yard/parser/ruby/legacy/statement_list.rb +82 -13
  17. data/lib/yard/parser/ruby/legacy/token_list.rb +10 -2
  18. data/lib/yard/parser/ruby/ruby_parser.rb +1 -0
  19. data/lib/yard/parser/source_parser.rb +1 -5
  20. data/lib/yard/tags/library.rb +1 -1
  21. data/lib/yard/tags/overload_tag.rb +1 -0
  22. data/spec/cli/yardoc_spec.rb +33 -0
  23. data/spec/docstring_spec.rb +24 -0
  24. data/spec/generators/helpers/html_helper_spec.rb +104 -102
  25. data/spec/handlers/ruby/legacy/base_spec.rb +25 -0
  26. data/spec/parser/examples/parse_in_order_001.rb.txt +2 -0
  27. data/spec/parser/examples/parse_in_order_002.rb.txt +2 -0
  28. data/spec/parser/ruby/ast_node_spec.rb +13 -9
  29. data/spec/parser/ruby/legacy/statement_list_spec.rb +122 -44
  30. data/spec/parser/ruby/legacy/token_list_spec.rb +57 -23
  31. data/spec/parser/ruby/ruby_parser_spec.rb +53 -0
  32. data/spec/parser/source_parser_spec.rb +59 -16
  33. data/spec/spec_helper.rb +2 -4
  34. data/spec/tags/library_spec.rb +23 -0
  35. data/templates/default/deprecated/html/main.erb +5 -3
  36. data/templates/default/fulldoc/html/all_methods.erb +1 -1
  37. data/templates/default/fulldoc/html/all_namespaces.erb +1 -1
  38. data/templates/default/fulldoc/html/custom.css +1 -0
  39. data/templates/default/fulldoc/html/file.erb +1 -0
  40. data/templates/default/fulldoc/html/footer.erb +5 -0
  41. data/templates/default/fulldoc/html/header.erb +1 -0
  42. data/templates/default/fulldoc/html/html_head.erb +1 -0
  43. data/templates/default/fulldoc/html/index.erb +1 -1
  44. data/templates/default/fulldoc/html/style.css +6 -0
  45. data/templates/default/tags/html/see.erb +1 -1
  46. metadata +13 -5
@@ -0,0 +1,12 @@
1
+ -
2
+ docs/WHATSNEW.markdown
3
+ docs/GETTING_STARTED.markdown
4
+ docs/OVERVIEW.markdown
5
+ docs/CODE_OBJECTS.markdown
6
+ docs/TAGS.markdown
7
+ docs/PARSER.markdown
8
+ docs/HANDLERS.markdown
9
+ docs/GENERATORS.markdown
10
+ docs/FAQ.markdown
11
+ docs/GLOSSARY.markdown
12
+ LICENSE
@@ -1,5 +1,5 @@
1
- YARD Release 0.2.3 (June 7th 2009)
2
- ===================================
1
+ YARD Release 0.2.3.2 (July 6th 2009)
2
+ =====================================
3
3
 
4
4
  **Homepage**: [http://yard.rubyforge.org](http://yard.rubyforge.org)
5
5
  **IRC**: **Join us on IRC in #yard on irc.freenode.net!**
@@ -178,6 +178,24 @@ More options can be seen by typing `yard-graph --help`, but here is an example:
178
178
  CHANGELOG
179
179
  ---------
180
180
 
181
+ - **July.06.09**: 0.2.3.2 release
182
+ - Fix Textile hard-break issues
183
+ - Add description for @see tag to use as link title in HTML docs.
184
+ - Add --title CLI option to specify a title for HTML doc files.
185
+ - Add custom.css file that can be overridden with various custom
186
+ styelsheet declarations. To use this, simply add `default/fulldoc/html/custom.css`
187
+ inside your code directory and use the `-t` template directory yardoc CLI
188
+ option to point to that template directory (the dir holding 'default').
189
+ - Add support in `yardoc` CLI to specify extra files (formerly --files)
190
+ by appending "- extra files here" after regular source files. Example:
191
+
192
+ yardoc --private lib/**/*.rb - FAQ LICENSE
193
+
194
+ - **Jun.13.09**: 0.2.3.1 release.
195
+ - Add a RubyGems 1.3.2+ plugin to generate YARD documentation instead of
196
+ RDoc. To take advantage of this plugin, set `has_rdoc = 'yard'` in your
197
+ .gemspec file.
198
+
181
199
  - **Jun.07.09**: 0.2.3 release. See the {file:WHATSNEW.markdown} file for a
182
200
  list of important new features.
183
201
 
data/Rakefile CHANGED
@@ -27,10 +27,11 @@ Spec::Rake::SpecTask.new("specs") do |t|
27
27
  $DEBUG = true if ENV['DEBUG']
28
28
  t.spec_opts = ["--format", "specdoc", "--colour"]
29
29
  t.spec_files = Dir["spec/**/*_spec.rb"].sort
30
- # t.rcov = true
30
+ t.rcov = true if ENV['RCOV']
31
31
  t.rcov_opts = ['-x', '_spec\.rb$,spec_helper\.rb$']
32
32
  end
33
+ task :spec => :specs
33
34
 
34
35
  YARD::Rake::YardocTask.new do |t|
35
36
  t.after = lambda { `cp -R docs/images/ doc/images/` }
36
- end
37
+ end
@@ -0,0 +1,91 @@
1
+ require 'rubygems/specification'
2
+ require 'rubygems/doc_manager'
3
+
4
+ class Gem::Specification
5
+ # has_rdoc should not be ignored!
6
+ overwrite_accessor(:has_rdoc) { @has_rdoc }
7
+ overwrite_accessor(:has_rdoc=) {|v| @has_rdoc = v }
8
+
9
+ def self.has_yardoc=(value)
10
+ @has_rdoc = 'yard'
11
+ end
12
+
13
+ def has_yardoc
14
+ @has_rdoc == 'yard'
15
+ end
16
+
17
+ def has_rdoc?
18
+ @has_rdoc && @has_rdoc != 'yard'
19
+ end
20
+
21
+ alias has_yardoc? has_yardoc
22
+ end
23
+
24
+ class Gem::DocManager
25
+ def self.load_yardoc
26
+ require File.dirname(__FILE__) + '/yard'
27
+ end
28
+
29
+ def run_yardoc(*args)
30
+ args << @spec.rdoc_options
31
+ args << '--quiet'
32
+ if @spec.extra_rdoc_files.size > 0
33
+ args << '--files'
34
+ args << @spec.extra_rdoc_files.join(",")
35
+ end
36
+ args << @spec.require_paths.map {|p| p + "/**/*.rb" }
37
+ args = args.flatten.map do |arg| arg.to_s end
38
+
39
+ old_pwd = Dir.pwd
40
+ Dir.chdir(@spec.full_gem_path)
41
+ YARD::CLI::Yardoc.run(*args)
42
+ rescue Errno::EACCES => e
43
+ dirname = File.dirname e.message.split("-")[1].strip
44
+ raise Gem::FilePermissionError.new(dirname)
45
+ rescue RuntimeError => ex
46
+ alert_error "While generating documentation for #{@spec.full_name}"
47
+ ui.errs.puts "... MESSAGE: #{ex}"
48
+ ui.errs.puts "... YARDDOC args: #{args.join(' ')}"
49
+ ui.errs.puts "\t#{ex.backtrace.join "\n\t"}" if
50
+ Gem.configuration.backtrace
51
+ ui.errs.puts "(continuing with the rest of the installation)"
52
+ ensure
53
+ Dir.chdir(old_pwd)
54
+ end
55
+
56
+ def setup_rdoc
57
+ if File.exist?(@doc_dir) && !File.writable?(@doc_dir) then
58
+ raise Gem::FilePermissionError.new(@doc_dir)
59
+ end
60
+
61
+ FileUtils.mkdir_p @doc_dir unless File.exist?(@doc_dir)
62
+
63
+ self.class.load_rdoc if @spec.has_rdoc?
64
+ self.class.load_yardoc if @spec.has_yardoc?
65
+ end
66
+
67
+ def install_yardoc
68
+ rdoc_dir = File.join(@doc_dir, 'rdoc')
69
+
70
+ FileUtils.rm_rf rdoc_dir
71
+
72
+ say "Installing YARD documentation for #{@spec.full_name}..."
73
+ run_yardoc '-o', rdoc_dir
74
+ end
75
+
76
+ def install_ri_yard
77
+ install_ri_yard_orig if @spec.has_rdoc?
78
+ end
79
+ alias install_ri_yard_orig install_ri
80
+ alias install_ri install_ri_yard
81
+
82
+ def install_rdoc_yard
83
+ if @spec.has_rdoc?
84
+ install_rdoc_yard_orig
85
+ elsif @spec.has_yardoc?
86
+ install_yardoc
87
+ end
88
+ end
89
+ alias install_rdoc_yard_orig install_rdoc
90
+ alias install_rdoc install_rdoc_yard
91
+ end
@@ -1,9 +1,10 @@
1
1
  module YARD
2
- VERSION = "0.2.3"
2
+ VERSION = "0.2.3.2"
3
3
  ROOT = File.dirname(__FILE__)
4
4
  TEMPLATE_ROOT = File.join(File.dirname(__FILE__), '..', 'templates')
5
5
 
6
6
  def self.parse(*args) Parser::SourceParser.parse(*args) end
7
+ def self.parse_string(*args) Parser::SourceParser.parse_string(*args) end
7
8
  end
8
9
 
9
10
  # Keep track of Ruby version for compatibility code
@@ -16,14 +16,15 @@ module YARD
16
16
  :format => :html,
17
17
  :template => :default,
18
18
  :serializer => YARD::Serializers::FileSystemSerializer.new,
19
+ :files => [],
19
20
  :verifier => lambda do |gen, obj|
20
21
  return false if gen.respond_to?(:visibility) && !visibilities.include?(gen.visibility)
21
22
  end
22
23
  ]
24
+ @files = []
23
25
  @visibilities = [:public]
24
26
  @reload = true
25
27
  @generate = true
26
- @files = ['lib/**/*.rb']
27
28
  @options_file = DEFAULT_YARDOPTS_FILE
28
29
  end
29
30
 
@@ -56,14 +57,45 @@ module YARD
56
57
  []
57
58
  end
58
59
 
60
+ def add_extra_files(*files)
61
+ files.map! {|f| f.include?("*") ? Dir.glob(f) : f }.flatten!
62
+ files.each do |file|
63
+ raise Errno::ENOENT, "Could not find extra file: #{file}" unless File.file?(file)
64
+ options[:files] << file
65
+ end
66
+ end
67
+
68
+ def parse_files(*files)
69
+ self.files = []
70
+ seen_extra_files_marker = false
71
+
72
+ files.each do |file|
73
+ if file == "-"
74
+ seen_extra_files_marker = true
75
+ next
76
+ end
77
+
78
+ if seen_extra_files_marker
79
+ add_extra_files(file)
80
+ else
81
+ self.files << file
82
+ end
83
+ end
84
+ end
85
+
59
86
  def optparse(*args)
60
87
  serialopts = SymbolHash.new
61
88
 
62
89
  opts = OptionParser.new
63
- opts.banner = "Usage: yardoc [options] [source files]"
90
+ opts.banner = "Usage: yardoc [options] [source_files [- extra_files]]"
64
91
 
65
92
  opts.separator "(if a list of source files is omitted, lib/**/*.rb is used.)"
66
93
  opts.separator ""
94
+ opts.separator "Example: yardoc -o documentation/ - FAQ LICENSE"
95
+ opts.separator " The above example outputs documentation for files in"
96
+ opts.separator " lib/**/*.rb to documentation/ including the extra files"
97
+ opts.separator " FAQ and LICENSE."
98
+ opts.separator ""
67
99
  opts.separator "A base set of options can be specified by adding a .yardopts"
68
100
  opts.separator "file to your base path containing all extra options separated"
69
101
  opts.separator "by whitespace."
@@ -113,6 +145,10 @@ module YARD
113
145
  opts.on('--no-highlight', "Don't highlight code in docs as Ruby.") do
114
146
  options[:no_highlight] = true
115
147
  end
148
+
149
+ opts.on('--title TITLE', 'Add a specific title to HTML documents') do |title|
150
+ options[:title] = title
151
+ end
116
152
 
117
153
  opts.on('-r', '--readme FILE', 'The readme file used as the title page of documentation.') do |readme|
118
154
  raise Errno::ENOENT, readme unless File.file?(readme)
@@ -120,11 +156,7 @@ module YARD
120
156
  end
121
157
 
122
158
  opts.on('--files FILE1,FILE2,...', 'Any extra comma separated static files to be included (eg. FAQ)') do |files|
123
- options[:files] = []
124
- files.split(",").each do |file|
125
- raise Errno::ENOENT, file unless File.file?(file)
126
- options[:files] << file
127
- end
159
+ add_extra_files *files.split(",")
128
160
  end
129
161
 
130
162
  opts.on('-m', '--markup MARKUP',
@@ -174,8 +206,8 @@ module YARD
174
206
  end
175
207
 
176
208
  # Last minute modifications
177
- self.files = args unless args.empty?
178
- self.reload = false if self.files.empty?
209
+ parse_files(*args) unless args.empty?
210
+ self.files = ['lib/**/*.rb'] if self.files.empty?
179
211
  self.visibilities.uniq!
180
212
  options[:serializer] ||= Serializers::FileSystemSerializer.new(serialopts)
181
213
  end
@@ -171,21 +171,11 @@ module YARD
171
171
  ##
172
172
  # Attaches source code to a code object with an optional file location
173
173
  #
174
- # @param [Parser::Statement, String] statement
174
+ # @param [#source, String] statement
175
175
  # the +Parser::Statement+ holding the source code or the raw source
176
176
  # as a +String+ for the definition of the code object only (not the block)
177
177
  def source=(statement)
178
- if statement.is_a? Parser::Ruby::Legacy::Statement
179
- src = statement.tokens.to_s
180
- blk = statement.block ? statement.block.to_s : ""
181
- if src =~ /^def\s.*[^\)]$/ && blk[0,1] !~ /\r|\n/
182
- blk = ";" + blk
183
- end
184
-
185
- @source = format_source(src + blk)
186
- self.line = statement.tokens.first.line_no
187
- self.signature = src
188
- elsif statement.respond_to?(:source)
178
+ if statement.respond_to?(:source)
189
179
  self.line = statement.line
190
180
  self.signature = statement.first_line
191
181
  @source = format_source(statement.source.strip)
@@ -1,14 +1,26 @@
1
1
  module YARD
2
2
  class Docstring < String
3
3
  attr_reader :ref_tags
4
- attr_accessor :object
4
+ attr_accessor :object, :line_range, :all
5
+
6
+ META_MATCH = /^@([a-z_]+)(?:\s+(.*))?$/i
5
7
 
6
8
  def initialize(content = '', object = nil)
7
9
  @tag_factory = Tags::Library.new
8
- @tags, @ref_tags = [], []
9
10
  @object = object
10
11
 
11
- replace parse_comments(content)
12
+ self.all = content
13
+ end
14
+
15
+ def replace(content)
16
+ @tags, @ref_tags = [], []
17
+ @all = content
18
+ super parse_comments(content)
19
+ end
20
+ alias all= replace
21
+
22
+ def line
23
+ line_range.first
12
24
  end
13
25
 
14
26
  ##
@@ -126,9 +138,8 @@ module YARD
126
138
  # @return [String] the non-metadata portion of the comments to
127
139
  # be used as a docstring
128
140
  def parse_comments(comments)
141
+ comments = comments.split(/\r?\n/) if comments.is_a?(String)
129
142
  return '' if !comments || comments.empty?
130
- meta_match = /^@(\S+)\s*(.*)/
131
- comments = comments.split(/\r?\n/) if comments.is_a? String
132
143
  docstring = ""
133
144
 
134
145
  indent, last_indent = comments.first[/^\s*/].length, 0
@@ -142,16 +153,16 @@ module YARD
142
153
  done = comments.size == index
143
154
 
144
155
  if tag_name && (((indent < orig_indent && !empty) || done) ||
145
- (indent <= last_indent && line =~ meta_match))
156
+ (indent <= last_indent && line =~ META_MATCH))
146
157
  create_tag(tag_name, tag_buf, raw_buf)
147
158
  tag_name, tag_buf, raw_buf = nil, '', []
148
159
  orig_indent = 0
149
160
  end
150
161
 
151
162
  # Found a meta tag
152
- if line =~ meta_match
163
+ if line =~ META_MATCH
153
164
  orig_indent = indent
154
- tag_name, tag_buf = $1, $2
165
+ tag_name, tag_buf = $1, ($2 || '')
155
166
  raw_buf = [tag_buf.dup]
156
167
  elsif tag_name && indent >= orig_indent && !empty
157
168
  # Extra data added to the tag on the next line
@@ -26,6 +26,7 @@ module YARD
26
26
  end
27
27
 
28
28
  def css_file; 'style.css' end
29
+ def css_custom_file; 'custom.css' end
29
30
  def css_syntax_file; 'syntax_highlight.css' end
30
31
  def js_file; 'jquery.js' end
31
32
  def js_app_file; 'app.js' end
@@ -44,7 +45,7 @@ module YARD
44
45
 
45
46
  def generate_assets
46
47
  if format == :html && serializer
47
- [css_file, css_syntax_file, js_file, js_app_file].each do |filename|
48
+ [css_file, css_custom_file, css_syntax_file, js_file, js_app_file].each do |filename|
48
49
  template_file = find_template template_path(filename)
49
50
  serializer.serialize(filename, File.read(template_file))
50
51
  end
@@ -20,10 +20,14 @@ module YARD
20
20
  return text unless markup
21
21
  load_markup_provider(markup)
22
22
 
23
+ # TODO: other libraries might be more complex
23
24
  case markup
24
- when :markdown, :textile
25
- # TODO: other libraries might be more complex
25
+ when :markdown
26
26
  html = markup_class(markup).new(text).to_html
27
+ when :textile
28
+ doc = markup_class(markup).new(text)
29
+ doc.hard_breaks = false if doc.respond_to?(:hard_breaks=)
30
+ html = doc.to_html
27
31
  when :rdoc
28
32
  html = MarkupHelper::SimpleMarkup.convert(text, SimpleMarkupHtml)
29
33
  html = fix_dash_dash(html)
@@ -4,9 +4,24 @@ module YARD
4
4
  before_section :header, :has_tags?
5
5
  before_section :option, :has_options?
6
6
  before_section :param, :has_params?
7
+ before_section :todo, :has_todo?
7
8
 
8
9
  def sections_for(object)
9
- [:header, [:example, :param, :yield, :yieldparam, :yieldreturn, :return, :raise, :todo, :author, :version, :since, :see]]
10
+ sections = [
11
+ :header, [ :example, :param, :yield, :yieldparam, :yieldreturn,
12
+ :return, :raise, :todo, :author, :version, :since, :see ]
13
+ ]
14
+ if object.tags(:overload).size == 1
15
+ size = sections.last.size
16
+ sections.last.reverse.each_with_index do |item, index|
17
+ sections.last[size - index - 1, 1] = [:with_overload, [item]]
18
+ end
19
+ end
20
+ sections
21
+ end
22
+
23
+ def with_overload(object)
24
+ yield(object.tag(:overload)) + yield(object)
10
25
  end
11
26
 
12
27
  def yield(object)
@@ -44,13 +59,19 @@ module YARD
44
59
  protected
45
60
 
46
61
  def has_params?(object)
47
- object.is_a?(CodeObjects::MethodObject) && tags_by_param(object).size > 0
62
+ (object.is_a?(Tags::OverloadTag) ||
63
+ object.is_a?(CodeObjects::MethodObject)) &&
64
+ tags_by_param(object).size > 0
48
65
  end
49
66
 
50
67
  def has_tags?(object)
51
68
  object.tags.size > 0
52
69
  end
53
70
 
71
+ def has_todo?(object)
72
+ object.has_tag?(:todo)
73
+ end
74
+
54
75
  def has_options?(object)
55
76
  object.has_tag?(:option)
56
77
  end
@@ -295,6 +295,7 @@ module YARD
295
295
 
296
296
  # Add docstring if there is one.
297
297
  object.docstring = statement.comments if statement.comments
298
+ object.docstring.line_range = statement.comments_range
298
299
 
299
300
  # Add source only to non-class non-module objects
300
301
  unless object.is_a?(NamespaceObject)
@@ -309,6 +310,7 @@ module YARD
309
310
  end
310
311
 
311
312
  def ensure_loaded!(object, max_retries = 1)
313
+ return if object == Registry.root
312
314
  unless parser.load_order_errors
313
315
  if object.is_a?(Proxy)
314
316
  raise NamespaceMissingError, object
@@ -322,20 +324,19 @@ module YARD
322
324
  raise NamespaceMissingError, object
323
325
  end
324
326
 
325
- retries, context = 0, nil
326
- callcc {|c| context = c }
327
-
327
+ retries = 0
328
+ context = callcc {|c| c }
328
329
  retries += 1
329
330
 
330
331
  if object.is_a?(Proxy)
331
332
  if retries <= max_retries
332
- log.debug "Missing object #{object.parent} in file `#{parser.file}', moving it to the back of the line."
333
+ log.debug "Missing object #{object} in file `#{parser.file}', moving it to the back of the line."
333
334
  raise Parser::LoadOrderError, context
334
335
  else
335
336
  raise NamespaceMissingError, object
336
337
  end
337
338
  else
338
- log.debug "Object #{object} successfully resolved. Adding item to #{object.parent}'s children"
339
+ log.debug "Object #{object} successfully resolved. Adding children."
339
340
  end
340
341
  object
341
342
  end