yard 0.7.3 → 0.7.4

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,143 @@
1
+ 2011-12-03 Loren Segal <lsegal@soen.ca>
2
+
3
+ * ChangeLog, README.md, docs/WhatsNew.md, lib/yard.rb: Bump to version 0.7.4
4
+ and update README/ChangeLog/WhatsNew
5
+
6
+ * lib/yard/templates/helpers/markup_helper.rb: Revert loading of RDoc inside
7
+ of markup helper, load it in RDocMarkup instead (since JRuby does not like
8
+ this all the time)
9
+
10
+ * lib/yard/templates/helpers/markup/rdoc_markup.rb: JRuby doesn't like doing
11
+ a require 'rdoc' without the gem.
12
+
13
+ * lib/yard/templates/helpers/markup/rdoc_markup.rb,
14
+ spec/templates/helpers/html_helper_spec.rb: Add support for RDoc 3.10 which
15
+ no longer requires 'rdoc' inside markup sources
16
+
17
+ * lib/yard/server/commands/search_command.rb: Prune search results according
18
+ to verifiers (no-private, etc.) This should ensure that the server side
19
+ search results are in sync with the statically generated class/method lists.
20
+ Closes #420
21
+
22
+ * lib/yard/parser/c_parser.rb, spec/parser/c_parser_spec.rb: Add support for
23
+ rb_define_alias Closes #413
24
+
25
+ * lib/yard/templates/helpers/html_helper.rb,
26
+ lib/yard/templates/helpers/markup_helper.rb,
27
+ spec/templates/helpers/html_helper_spec.rb: Re-organize markup types text,
28
+ none, and add type 'pre'. The new behaviour for the types are as follows:
29
+ pre: Pre-formatted text, wrapping input inside <pre> tags. text: No
30
+ formatting except for replacing newlines with <br> tags. none: No formatting
31
+ at all. In all cases, HTML is escaped. Note that syntax highlighting does
32
+ not work in these markup types. Closes #416
33
+
34
+ 2011-12-02 Loren Segal <lsegal@soen.ca>
35
+
36
+ * lib/yard/templates/helpers/html_helper.rb,
37
+ lib/yard/templates/helpers/markup_helper.rb,
38
+ spec/templates/helpers/html_helper_spec.rb: Add 'textile_strict' markup type
39
+ that uses strict hard breaks on newlines
40
+
41
+ * lib/yard/templates/helpers/markup/rdoc_markup.rb,
42
+ spec/templates/helpers/markup/rdoc_markup_spec.rb: Ignore +typewritertext+
43
+ inside code blocks Closes #403
44
+
45
+ * lib/yard/templates/helpers/markup_helper.rb,
46
+ spec/templates/helpers/markup_helper_spec.rb: Redcarpet is now the default
47
+ markdown provider for YARD
48
+
49
+ * lib/yard/templates/helpers/html_helper.rb: Autolink when using red carpet
50
+
51
+ * .../helpers/html_syntax_highlight_helper_spec.rb: Fix specs to use new css
52
+ rules when generating HTML syntax highlighted Ruby
53
+
54
+ * .../helpers/html_syntax_highlight_helper.rb,
55
+ templates/default/fulldoc/html/css/style.css,
56
+ templates/guide/fulldoc/html/css/style.css: Change generated HTML when
57
+ performing syntax highlighting of Ruby code to generate ids with CSS prefix
58
+ "rubyid_" to avoid collisions with other CSS class names.
59
+
60
+ 2011-12-01 Mark Morga <markmorga@gmail.com>
61
+
62
+ * lib/yard/rake/yardoc_task.rb: Documentation improvements in YardocTask.
63
+ Fixed attr :options to indicate that it should be an Array<String> rather
64
+ than Hash. Added an example for attr :files to show correct use of "-" for
65
+ extra files.
66
+
67
+ 2011-11-28 Loren Segal <lsegal@soen.ca>
68
+
69
+ * lib/yard/server/commands/library_command.rb,
70
+ .../doc_server/processing/html/processing.erb: Server "processing" response
71
+ should return HTTP code 202 Accepted instead of 302. This change makes
72
+ IE8/IE9 happier about redirects, and is the proper response code for this
73
+ situation. Closes #418
74
+
75
+ 2011-11-26 Kouhei Sutou <kou@clear-code.com>
76
+
77
+ * lib/yard/parser/source_parser.rb, spec/parser/source_parser_spec.rb:
78
+ support encoding detection in C source file.
79
+
80
+ * spec/parser/source_parser_spec.rb: accept 'coding: ENCODING; OTHER
81
+ PARAMTERS' style encoding line.
82
+
83
+ * lib/yard/parser/source_parser.rb, spec/parser/source_parser_spec.rb:
84
+ support UTF-8 as encoding name.
85
+
86
+ 2011-11-25 Kouhei Sutou <kou@clear-code.com>
87
+
88
+ * spec/registry_store_spec.rb: ensure test directory nonexistent.
89
+
90
+ 2011-11-09 yuta yamada <yamada@clear-code.com>
91
+
92
+ * README.md: fix a typo.
93
+
94
+ 2011-11-06 Loren Segal <lsegal@soen.ca>
95
+
96
+ * templates/default/fulldoc/html/css/style.css,
97
+ templates/guide/fulldoc/html/css/style.css: Better CSS targeting to handle
98
+ example identifiers inside code blocks Closes #410
99
+
100
+ 2011-11-04 Loren Segal <lsegal@soen.ca>
101
+
102
+ * lib/yard/templates/helpers/markup_helper.rb: Require 'rdoc' when loading
103
+ RDoc markup. Fixes issues with new RDoc 3.x markup loading. Closes #406,
104
+ #407
105
+
106
+ 2011-10-21 Loren Segal <lsegal@soen.ca>
107
+
108
+ * templates/default/fulldoc/html/js/app.js: Actually want nextAll(), not
109
+ next() when filtering next elements in collapse/view source links
110
+
111
+ * templates/default/fulldoc/html/js/app.js: Be more specific about which
112
+ next() element to toggle (collapse and view source JS event handlers)
113
+
114
+ * docs/GettingStarted.md: Fix link to types.html
115
+
116
+ 2011-10-20 Loren Segal <lsegal@soen.ca>
117
+
118
+ * lib/yard/rubygems/specification.rb: Also ensure that has_rdoc is always
119
+ boolean inside of has_rdoc? (in case accessor was not called by newer
120
+ RubyGems) References #401
121
+
122
+ * lib/yard/rubygems/specification.rb: Ensure that has_rdoc is true by default
123
+ (always boolean) Closes #401
124
+
125
+ 2011-10-16 Loren Segal <lsegal@soen.ca>
126
+
127
+ * lib/yard/cli/yardoc.rb, spec/cli/yardoc_spec.rb: Error early if files have
128
+ markup formats that are not available on the system
129
+
130
+ * lib/yard/code_objects/base.rb: Remove unused self.line setting method.
131
+ This method was initiating a dispatch to method_missing, since the method did
132
+ not exist, and was silently setting an attribute on the object that is never
133
+ used.
134
+
135
+ * lib/yard/code_objects/base.rb: Implement to_ary on CodeObjects::Base Ruby
136
+ 1.9.2+ likes to ask the base object if it responds to to_ary when
137
+ Array#flatten is called on a list. This causes method_missing to be
138
+ dispatched to and incurs significant overhead. A 6% performance improvement
139
+ was noted for implementing this method alone.
140
+
1
141
  2011-10-15 Loren Segal <lsegal@soen.ca>
2
142
 
3
143
  * ChangeLog, README.md, lib/yard.rb: Update README, ChangeLog and bump to
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.7.3 (codename "Rhombus")
12
- **Release Date**: October 15th 2011
11
+ **Latest Version**: 0.7.4 (codename "Kennedy")
12
+ **Release Date**: December 2nd 2011
13
13
 
14
14
  Synopsis
15
15
  --------
@@ -171,7 +171,7 @@ the globs and the filenames with '-'.
171
171
 
172
172
  $ yardoc 'app/**/*.rb' - README LICENSE FAQ
173
173
 
174
- If no globs preceed the '-' argument, the default glob (`lib/**/*.rb`) is
174
+ If no globs precede the '-' argument, the default glob (`lib/**/*.rb`) is
175
175
  used:
176
176
 
177
177
  $ yardoc - README LICENSE FAQ
@@ -289,6 +289,18 @@ More options can be seen by typing `yard-graph --help`, but here is an example:
289
289
  Changelog
290
290
  ---------
291
291
 
292
+ - **December.2.11**: 0.7.4 release
293
+ - Redcarpet is now the default Markdown formatting library. GFM now works out-of-box (#404)
294
+ - Fix server side searching for elements that are marked private (#420)
295
+ - Add 'textile_strict' and 'pre' markup types, reorganize text and none (#416)
296
+ - Improve encoding line detection (#415)
297
+ - Add support for `rb_define_alias` in CRuby code (#413)
298
+ - Fix rendering of some keywords in source view (#410)
299
+ - Add support for RDoc 3.10+ (#406, #407)
300
+ - Fix typewriter text being processed in code blocks (#403)
301
+ - Improve support for has_rdoc in RubyGems 1.8.x (#401)
302
+ - See the {file:docs/WhatsNew.md} document for details on added features
303
+
292
304
  - **October.15.11**: 0.7.3 release
293
305
  - Improve support for parsing under Ruby 1.9.2p290 and 1.9.3 (#365, #370)
294
306
  - Add support for SWIG generated CRuby code (#369)
@@ -308,7 +320,7 @@ Changelog
308
320
  - Fixes a bug in `yard server` not displaying class list properly.
309
321
 
310
322
  - **May.17.11**: 0.7.0 release
311
- - See the {docs/WhatsNew.md} document for details on added features
323
+ - See the {file:docs/WhatsNew.md} document for details on added features
312
324
  - Make sure that Docstring#line_range is filled when possible (#243)
313
325
  - Set #verifier in YardocTask (#282)
314
326
  - Parse BOM in UTF-8 files (#288)
@@ -181,8 +181,9 @@ Symbols:
181
181
  We mentioned that these type fields are "mostly" free-form. In truth, they
182
182
  are defined "by convention". To view samples of common type specifications
183
183
  and recommended conventions for writing type specifications, see
184
- http://yardoc.org/types.html. Note that these conventions may change every now
185
- and then, although we are working on a more "formal" type specification proposal.
184
+ [http://yardoc.org/types.html](http://yardoc.org/types.html). Note that these
185
+ conventions may change every now and then, although we are working on a more
186
+ "formal" type specification proposal.
186
187
 
187
188
  ## Documenting DSL Methods
188
189
 
data/docs/WhatsNew.md CHANGED
@@ -16,6 +16,10 @@
16
16
  12. **Added before/after callbacks to SourceParser** (0.7.0)
17
17
  13. **Can now use `--yardopts FILE` to specify a custom yardopts file** (0.7.0)
18
18
  14. **Added new `-t guide` template for guide based docs** (0.7.0)
19
+ 15. **Github Flavoured Markdown now works out-of-box** (0.7.4)
20
+ 16. **Added `-m textile_strict` and `-m pre` markup types** (0.7.4)
21
+ 17. **Reorganized markup types 'text' and 'none'** (0.7.4)
22
+ 18. **Add support for `rb_define_alias`** (0.7.4)
19
23
 
20
24
  ## Macro support and detection of DSL methods (0.7.0)
21
25
 
@@ -175,6 +179,56 @@ questions, trouble shooting and license page.
175
179
  If you need to refer to class / method documentation, you can embed API documentation
176
180
  using the `{render:Object}` tag discussed above.
177
181
 
182
+ ## Github Flavoured Markdown now works out-of-box (0.7.4)
183
+
184
+ Due to the growing popularity of Github-Flavoured-Markdown (GFM), YARD now uses
185
+ the Redcarpet library as the default Markdown formatting library with GFM fenced
186
+ code blocks enabled. This means that you can use fenced code blocks inside of
187
+ Markdown files with redcarpet installed without any extra code. Previously, users
188
+ who wanted GFM in their Markdown would have to specify `-m markdown -M redcarpet`,
189
+ but this is now the default behaviour for YARD.
190
+
191
+ Note that you can still specify language types in code blocks without GFM in YARD
192
+ by using the "!!!lang" prefix syntax. For example (plain means no markup):
193
+
194
+ !!!plain
195
+ !!!plain
196
+ Some code
197
+ block here.
198
+
199
+ The GFM version would be:
200
+
201
+ !!!plain
202
+ ```plain
203
+ Some code
204
+ block here.
205
+ ```
206
+
207
+ ## Added `-m textile_strict` and `-m pre` markup types (0.7.4)
208
+
209
+ A new "textile_strict" markup type was added which behaves exactly like "textile"
210
+ except it enables hard breaks, so newlines behave as line breaks in the HTML
211
+ (using `<br>` tags). This option is added for users who want the classic textile
212
+ behaviour.
213
+
214
+ ## Reorganized markup types 'text' and 'none' (0.7.4)
215
+
216
+ Due to the new pre markup type, the behaviour for text and none were slightly
217
+ reorganized to be more intuitive. The following behaviours now represent these
218
+ markup types:
219
+
220
+ * pre: Used to wrap text inside `<pre>` tags
221
+ * text: No formatting except for hard breaks (`<br>`) on newlines
222
+ * none: No formatting at all.
223
+
224
+ In all cases, HTML is escaped from input. If you want no HTML escaping, use the
225
+ html markup type.
226
+
227
+ ## Add support for `rb_define_alias` (0.7.4)
228
+
229
+ CRuby code can now make use of the `rb_define_alias` function. Documentation
230
+ for aliases is not supported, however.
231
+
178
232
  # What's New in 0.6.x?
179
233
 
180
234
  1. **Local documentation server for RubyGems or projects (`yard server`)** (0.6.0)
data/lib/yard.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  module YARD
2
- VERSION = "0.7.3"
2
+ VERSION = "0.7.4"
3
3
 
4
4
  # The root path for YARD source libraries
5
5
  ROOT = File.expand_path(File.dirname(__FILE__))
@@ -311,10 +311,15 @@ module YARD
311
311
  #
312
312
  # @return (see YARD::Templates::Helpers::MarkupHelper#load_markup_provider)
313
313
  def verify_markup_options
314
- options[:markup] = :rdoc unless has_markup
315
314
  result, lvl = false, has_markup ? log.level : Logger::FATAL
316
315
  obj = Struct.new(:options).new(options)
317
316
  obj.extend(Templates::Helpers::MarkupHelper)
317
+ options[:files].each do |file|
318
+ markup = file.attributes[:markup] || obj.markup_for_file('', file.filename)
319
+ result = obj.load_markup_provider(markup)
320
+ return false if !result && markup != :rdoc
321
+ end
322
+ options[:markup] = :rdoc unless has_markup
318
323
  log.enter_level(lvl) { result = obj.load_markup_provider }
319
324
  if !result && !has_markup
320
325
  log.warn "Could not load default RDoc formatter, " +
@@ -284,6 +284,9 @@ module YARD
284
284
 
285
285
  # @return [Integer] the object's hash value (for equality checking)
286
286
  def hash; path.hash end
287
+
288
+ # @return [nil] this object does not turn into an array
289
+ def to_ary; nil end
287
290
 
288
291
  # Accesses a custom attribute on the object
289
292
  # @param [#to_s] key the name of the custom attribute
@@ -336,7 +339,6 @@ module YARD
336
339
  # as a +String+ for the definition of the code object only (not the block)
337
340
  def source=(statement)
338
341
  if statement.respond_to?(:source)
339
- self.line = statement.line
340
342
  self.signature = statement.first_line
341
343
  @source = format_source(statement.source.strip)
342
344
  else
@@ -15,6 +15,7 @@ module YARD
15
15
  parse_modules
16
16
  parse_classes
17
17
  parse_methods
18
+ parse_aliases
18
19
  parse_attributes
19
20
  parse_constants
20
21
  parse_includes
@@ -100,6 +101,30 @@ module YARD
100
101
  obj
101
102
  end
102
103
 
104
+ def handle_alias(var_name, new_name, old_name)
105
+ namespace = P(remove_var_prefix(var_name))
106
+ ensure_loaded!(namespace)
107
+ new_meth, old_meth = new_name.to_sym, old_name.to_sym
108
+ old_obj = namespace.child(:name => old_meth, :scope => :instance)
109
+ new_obj = YARD::CodeObjects::MethodObject.new(namespace, new_meth, :instance) do |o|
110
+ o.visibility = :public
111
+ o.scope = :instance
112
+ o.add_file(@file)
113
+ o.source_type = :c
114
+ end
115
+
116
+ if old_obj
117
+ new_obj.signature = old_obj.signature
118
+ new_obj.source = old_obj.source
119
+ new_obj.docstring = old_obj.docstring
120
+ new_obj.docstring.object = new_obj
121
+ else
122
+ new_obj.signature = "def #{new_meth}" # this is all we know.
123
+ end
124
+
125
+ namespace.aliases[new_obj] = old_meth
126
+ end
127
+
103
128
  def handle_attribute(var_name, name, func_name, read, write, source_file = nil)
104
129
  values = {:read => read.to_i, :write => write.to_i}
105
130
  {:read => name, :write => "#{name}="}.each do |type, meth_name|
@@ -379,6 +404,18 @@ module YARD
379
404
  end
380
405
  end
381
406
 
407
+ def parse_aliases
408
+ @content.scan(%r{rb_define_alias
409
+ \s*\(\s*([\w\.]+),
410
+ \s*"([^"]+)",
411
+ \s*"([^"]+)"\s*\)
412
+ }xm) do |var_name, new_name, old_name|
413
+
414
+ var_name = "rb_cObject" if var_name == "rb_mKernel"
415
+ handle_alias(var_name, new_name, old_name)
416
+ end
417
+ end
418
+
382
419
  def parse_attributes
383
420
  @content.scan(%r{rb_define_attr
384
421
  \s*\(\s*([\w\.]+),
@@ -43,7 +43,7 @@ module YARD
43
43
  # @see CodeObjects::Base
44
44
  class SourceParser
45
45
  SHEBANG_LINE = /\A\s*#!\S+/
46
- ENCODING_LINE = /\A(?:\s*#*!.*\r?\n)?\s*#+.*coding\s*[:=]{1,2}\s*(\S+)/i
46
+ ENCODING_LINE = /\A(?:\s*#*!.*\r?\n)?\s*(?:#+|\/\*+|\/\/+).*coding\s*[:=]{1,2}\s*([a-z\d_\-]+)/i
47
47
 
48
48
  # Byte order marks for various encodings
49
49
  # @since 0.7.0
@@ -11,11 +11,15 @@ module YARD
11
11
  attr_accessor :name
12
12
 
13
13
  # Options to pass to {CLI::Yardoc}
14
- # @return [Hash] the options passed to the commandline utility
14
+ # @return [Array<String>] the options passed to the commandline utility
15
15
  attr_accessor :options
16
16
 
17
17
  # The Ruby source files (and any extra documentation files separated by '-')
18
- # to process
18
+ # to process.
19
+ # @example Task files assignment
20
+ # YARD::Rake::YardocTask.new do |t|
21
+ # t.files = ['app/**/*.rb', 'lib/**/*.rb', '-', 'doc/FAQ.md', 'doc/Changes.md']
22
+ # end
19
23
  # @return [Array<String>] a list of files
20
24
  attr_accessor :files
21
25
 
@@ -12,14 +12,14 @@ class Gem::Specification
12
12
 
13
13
  undef has_rdoc?
14
14
  def has_rdoc?
15
- @has_rdoc && @has_rdoc != 'yard'
15
+ (@has_rdoc ||= true) && @has_rdoc != 'yard'
16
16
  end
17
17
 
18
18
  alias has_yardoc? has_yardoc
19
19
 
20
20
  # has_rdoc should not be ignored!
21
21
  if respond_to?(:overwrite_accessor)
22
- overwrite_accessor(:has_rdoc) { @has_rdoc }
22
+ overwrite_accessor(:has_rdoc) { @has_rdoc ||= true }
23
23
  overwrite_accessor(:has_rdoc=) {|v| @has_rdoc = v }
24
24
  else
25
25
  attr_accessor :has_rdoc
@@ -89,7 +89,7 @@ module YARD
89
89
  def not_prepared
90
90
  self.caching = false
91
91
  options.update(:path => request.path, :template => :doc_server, :type => :processing)
92
- [302, {'Content-Type' => 'text/html'}, [render]]
92
+ [202, {'Content-Type' => 'text/html'}, [render]]
93
93
  end
94
94
 
95
95
  # @private
@@ -4,6 +4,9 @@ module YARD
4
4
  # Performs a search over the objects inside of a library and returns
5
5
  # the results as HTML or plaintext
6
6
  class SearchCommand < LibraryCommand
7
+ include Templates::Helpers::BaseHelper
8
+ include Templates::Helpers::ModuleHelper
9
+
7
10
  attr_accessor :results, :query
8
11
 
9
12
  def run
@@ -47,7 +50,7 @@ module YARD
47
50
 
48
51
  def search_for_object
49
52
  splitquery = query.split(/\s+/).map {|c| c.downcase }.reject {|m| m.empty? }
50
- self.results = Registry.all.select {|o|
53
+ self.results = run_verifier(Registry.all).select {|o|
51
54
  o.path.downcase.include?(query.downcase)
52
55
  }.reject {|o|
53
56
  name = (o.type == :method ? o.name(true) : o.name).to_s.downcase
@@ -8,7 +8,7 @@
8
8
  <script type="text/javascript" charset="utf-8" src="/js/jquery.js"></script>
9
9
  <script type="text/javascript" charset="utf-8">
10
10
  function checkPage(process) {
11
- $.ajax({cache: false, url: "<%= @path %>" + (process ? "?process=true" : ""), success: function() { window.location = "<%= @path %>"; } });
11
+ $.ajax({cache: false, url: "<%= @path %>" + (process ? "?process=true" : ""), statusCode: { 200: function() { window.location = "<%= @path %>"; } } });
12
12
  setTimeout('checkPage()', 2000);
13
13
  }
14
14
  function setFade() {
@@ -51,7 +51,7 @@ module YARD
51
51
  string = html_syntax_highlight(CGI.unescapeHTML(string), language) unless options[:no_highlight]
52
52
  classes = ['code', language].compact.join(' ')
53
53
  %Q{<pre class="#{classes}">#{string}</pre>}
54
- end unless markup == :text
54
+ end unless [:text, :none, :pre].include?(markup)
55
55
  html
56
56
  end
57
57
 
@@ -63,11 +63,11 @@ module YARD
63
63
  # TODO: other libraries might be more complex
64
64
  provider = markup_class(:markdown)
65
65
  if provider.to_s == 'RDiscount'
66
- markup_class(:markdown).new(text, :autolink).to_html
66
+ provider.new(text, :autolink).to_html
67
67
  elsif provider.to_s == 'RedcarpetCompat'
68
- provider.new(text, :gh_blockcode, :fenced_code).to_html
68
+ provider.new(text, :gh_blockcode, :fenced_code, :autolink).to_html
69
69
  else
70
- markup_class(:markdown).new(text).to_html
70
+ provider.new(text).to_html
71
71
  end
72
72
  end
73
73
 
@@ -81,6 +81,14 @@ module YARD
81
81
  doc.to_html
82
82
  end
83
83
 
84
+ # Converts plaintext to strict Textile (hard breaks)
85
+ # @param [String] text the input textile data
86
+ # @return [String] the output HTML
87
+ # @since 0.6.0
88
+ def html_markup_textile_strict(text)
89
+ markup_class(:textile).new(text).to_html
90
+ end
91
+
84
92
  # Converts RDoc formatting (SimpleMarkup) to HTML
85
93
  # @param [String] text the input RDoc formatted text
86
94
  # @return [String] output HTML
@@ -91,18 +99,26 @@ module YARD
91
99
  doc.to_html
92
100
  end
93
101
 
94
- # Converts plaintext to HTML
102
+ # Converts plaintext to pre-formatted HTML
95
103
  # @param [String] text the input text
96
104
  # @return [String] the output HTML
97
105
  # @since 0.6.0
98
- def html_markup_text(text)
106
+ def html_markup_pre(text)
99
107
  "<pre>" + h(text) + "</pre>"
100
108
  end
101
109
 
110
+ # Converts plaintext to regular HTML
111
+ # @param [String] text the input text
112
+ # @return [String] the output HTML
113
+ # @since 0.6.0
114
+ def html_markup_text(text)
115
+ h(text).gsub(/\r?\n/, '<br/>')
116
+ end
117
+
102
118
  # @return [String] the same text with no markup
103
119
  # @since 0.6.6
104
120
  def html_markup_none(text)
105
- h(text).gsub(/(?:\r?\n){2}/, '<br/>')
121
+ h(text)
106
122
  end
107
123
 
108
124
  # Converts HTML to HTML
@@ -25,7 +25,7 @@ module YARD
25
25
  when :nl, :ignored_nl, :sp
26
26
  output << h(s.last)
27
27
  when :ident
28
- output << "<span class='id #{h(s.last)}'>#{h(s.last)}</span>"
28
+ output << "<span class='id identifier rubyid_#{h(s.last)}'>#{h(s.last)}</span>"
29
29
  else
30
30
  output << "<span class='#{s.first}'>#{h(s.last)}</span>"
31
31
  end
@@ -47,7 +47,7 @@ module YARD
47
47
  h s.text
48
48
  when Parser::Ruby::Legacy::RubyToken::TkId
49
49
  prettyval = h(s.text)
50
- "<span class='#{prettyval} #{prettyclass} #{prettysuper}'>#{prettyval}</span>"
50
+ "<span class='rubyid_#{prettyval} #{prettyclass} #{prettysuper}'>#{prettyval}</span>"
51
51
  else
52
52
  "<span class='#{prettyclass} #{prettysuper}'>#{h s.text}</span>"
53
53
  end
@@ -2,6 +2,7 @@ module YARD
2
2
  module Templates
3
3
  module Helpers
4
4
  module Markup
5
+ begin require 'rdoc'; rescue LoadError; end
5
6
  begin
6
7
  require 'rdoc/markup'
7
8
  require 'rdoc/markup/to_html'
@@ -41,14 +42,16 @@ module YARD
41
42
  #
42
43
  # @todo Refactor into own SimpleMarkup subclass
43
44
  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
45
+ code_tags = 0
46
+ text.gsub(/<(\/)?(pre|code|tt)|(\s|^|>)\+(?! )([^\n\+]{1,900})(?! )\+/) do |str|
47
+ closed, tag, first_text, type_text, pre_text, no_match = $1, $2, $3, $4, $`, $&
48
+
49
+ if tag
50
+ code_tags += (closed ? -1 : 1)
51
+ next str
51
52
  end
53
+ next str unless code_tags == 0
54
+ first_text + '<tt>' + CGI.escapeHTML(type_text) + '</tt>'
52
55
  end
53
56
  end
54
57
 
@@ -22,21 +22,25 @@ module YARD
22
22
  # The default list of markup providers for each markup type
23
23
  MARKUP_PROVIDERS = {
24
24
  :markdown => [
25
+ {:lib => :redcarpet, :const => 'RedcarpetCompat'},
25
26
  {:lib => :rdiscount, :const => 'RDiscount'},
26
27
  {:lib => :kramdown, :const => 'Kramdown::Document'},
27
28
  {:lib => :bluecloth, :const => 'BlueCloth'},
28
29
  {:lib => :maruku, :const => 'Maruku'},
29
- {:lib => :redcarpet, :const => 'RedcarpetCompat'},
30
30
  {:lib => :'rpeg-markdown', :const => 'PEGMarkdown'},
31
31
  ],
32
32
  :textile => [
33
33
  {:lib => :redcloth, :const => 'RedCloth'},
34
34
  ],
35
+ :textile_strict => [
36
+ {:lib => :redcloth, :const => 'RedCloth'},
37
+ ],
35
38
  :rdoc => [
36
39
  {:lib => nil, :const => 'YARD::Templates::Helpers::Markup::RDocMarkup'},
37
40
  ],
38
41
  :ruby => [],
39
42
  :text => [],
43
+ :pre => [],
40
44
  :html => [],
41
45
  :none => [],
42
46
  }
@@ -580,11 +580,33 @@ describe YARD::CLI::Yardoc do
580
580
  mod.clear_markup_cache
581
581
  mod.const_get(:MARKUP_PROVIDERS).should_receive(:[]).with(:rdoc).and_return([{:lib => 'INVALID'}])
582
582
  log.should_receive(:warn).with(/Could not load default RDoc formatter/)
583
- @yardoc.generate = true
583
+ @yardoc.stub(:generate) { @yardoc.options[:files] = []; true }
584
584
  @yardoc.run
585
585
  @yardoc.options[:markup].should == :none
586
586
  mod.clear_markup_cache
587
587
  end
588
+
589
+ it "should error immediately if markup for any files are missing" do
590
+ mod = YARD::Templates::Helpers::MarkupHelper
591
+ mod.clear_markup_cache
592
+ mod.const_get(:MARKUP_PROVIDERS).should_receive(:[]).with(:markdown).and_return([{:lib => 'INVALID'}])
593
+ log.should_receive(:error).with(/Missing 'INVALID' gem for Markdown formatting/)
594
+ files = [CodeObjects::ExtraFileObject.new('test.md', '')]
595
+ @yardoc.stub(:generate) { @yardoc.options[:files] = files; true }
596
+ @yardoc.run
597
+ mod.clear_markup_cache
598
+ end
599
+
600
+ it "should error immediately if markup for any files are missing (file markup specified in attributes)" do
601
+ mod = YARD::Templates::Helpers::MarkupHelper
602
+ mod.clear_markup_cache
603
+ mod.const_get(:MARKUP_PROVIDERS).should_receive(:[]).with(:markdown).and_return([{:lib => 'INVALID'}])
604
+ log.should_receive(:error).with(/Missing 'INVALID' gem for Markdown formatting/)
605
+ files = [CodeObjects::ExtraFileObject.new('test', '# @markup markdown')]
606
+ @yardoc.stub(:generate) { @yardoc.options[:files] = files; true }
607
+ @yardoc.run
608
+ mod.clear_markup_cache
609
+ end
588
610
  end
589
611
 
590
612
  describe '#run' do
@@ -165,6 +165,28 @@ describe YARD::Parser::CParser do
165
165
  Registry.at('Foo#foo=').should be_writer
166
166
  end
167
167
  end
168
+
169
+ describe 'Defining aliases' do
170
+ before do
171
+ Registry.clear
172
+ end
173
+
174
+ it "should allow defining of aliases (rb_define_alias)" do
175
+ @contents = <<-eof
176
+ /* FOO */
177
+ VALUE foo(VALUE x) { int value = x; }
178
+ void Init_Foo() {
179
+ rb_cFoo = rb_define_class("Foo", rb_cObject);
180
+ rb_define_method(rb_cFoo, "foo", foo, 1);
181
+ rb_define_alias(rb_cFoo, "bar", "foo");
182
+ }
183
+ eof
184
+ parse
185
+
186
+ Registry.at('Foo#bar').should be_is_alias
187
+ Registry.at('Foo#bar').docstring.should == 'FOO'
188
+ end
189
+ end
168
190
  end
169
191
 
170
192
  describe '#find_override_comment' do
@@ -462,11 +462,13 @@ describe YARD::Parser::SourceParser do
462
462
  it "should convert file contents to proper encoding if coding line is present" do
463
463
  valid = []
464
464
  valid << "# encoding: sjis"
465
+ valid << "# encoding: utf-8"
465
466
  valid << "# xxxxxencoding: sjis"
466
467
  valid << "# xxxxxencoding: sjis xxxxxx"
467
468
  valid << "# ENCODING: sjis"
468
469
  valid << "#coDiNG: sjis"
469
470
  valid << "# -*- coding: sjis -*-"
471
+ valid << "# -*- coding: utf-8; indent-tabs-mode: nil"
470
472
  valid << "### coding: sjis"
471
473
  valid << "# encoding=sjis"
472
474
  valid << "# encoding:sjis"
@@ -487,7 +489,7 @@ describe YARD::Parser::SourceParser do
487
489
  File.should_receive(:read_binary).with('tmpfile').and_return(src)
488
490
  result = parser.parse("tmpfile")
489
491
  if HAVE_RIPPER && RUBY19
490
- ['Shift_JIS', 'Windows-31J'].send(msg, include(
492
+ ['Shift_JIS', 'Windows-31J', 'UTF-8'].send(msg, include(
491
493
  result.enumerator[0].source.encoding.to_s))
492
494
  end
493
495
  result.encoding_line.send(msg) == src.split("\n").last
@@ -495,6 +497,25 @@ describe YARD::Parser::SourceParser do
495
497
  end
496
498
  end
497
499
 
500
+ it "should convert C file contents to proper encoding if coding line is present" do
501
+ valid = []
502
+ valid << "/* coding: utf-8 */"
503
+ valid << "/* -*- coding: utf-8; c-file-style: \"ruby\" -*- */"
504
+ valid << "// coding: utf-8"
505
+ valid << "// -*- coding: utf-8; c-file-style: \"ruby\" -*-"
506
+ invalid = []
507
+ {:should => valid, :should_not => invalid}.each do |msg, list|
508
+ list.each do |src|
509
+ Registry.clear
510
+ parser = Parser::SourceParser.new
511
+ File.should_receive(:read_binary).with('tmpfile.c').and_return(src)
512
+ result = parser.parse("tmpfile.c")
513
+ content = result.instance_variable_get("@content")
514
+ ['UTF-8'].send(msg, include(content.encoding.to_s))
515
+ end
516
+ end
517
+ end if RUBY19
518
+
498
519
  Parser::SourceParser::ENCODING_BYTE_ORDER_MARKS.each do |encoding, bom|
499
520
  it "should understand #{encoding.upcase} BOM" do
500
521
  parser = Parser::SourceParser.new
@@ -571,4 +592,4 @@ describe YARD::Parser::SourceParser do
571
592
  Registry.at('A#baz').group.should == "Group 2"
572
593
  end
573
594
  end
574
- end
595
+ end
@@ -2,6 +2,7 @@ require File.join(File.dirname(__FILE__), "spec_helper")
2
2
 
3
3
  describe YARD::RegistryStore do
4
4
  before do
5
+ FileUtils.rm_rf("foo")
5
6
  @store = RegistryStore.new
6
7
  @serializer = Serializers::YardocSerializer.new('foo')
7
8
  Serializers::YardocSerializer.stub!(:new).and_return(@serializer)
@@ -251,4 +252,4 @@ describe YARD::RegistryStore do
251
252
  @store.destroy(true).should == true
252
253
  end
253
254
  end
254
- end
255
+ end
@@ -103,15 +103,28 @@ describe YARD::Templates::Helpers::HtmlHelper do
103
103
  htmlify("A\nB", :textile).should_not include("<br")
104
104
  end
105
105
 
106
+ it "should use hard breaks for textile_strict markup (RedCloth specific)" do
107
+ begin; require 'redcloth'; rescue LoadError; pending 'test requires redcloth gem' end
108
+ htmlify("A\nB", :textile_strict).should include("<br")
109
+ end
110
+
106
111
  it "should handle various encodings" do
107
112
  stub!(:object).and_return(Registry.root)
108
113
  Encoding.default_internal = 'utf-8' if defined?(Encoding)
109
114
  htmlify("\xB0\xB1", :text)
110
115
  # TODO: add more encoding tests
111
116
  end
117
+
118
+ it "should return pre-formatted text with :pre markup" do
119
+ htmlify("fo\no\n\nbar<>", :pre).should == "<pre>fo\no\n\nbar&lt;&gt;</pre>"
120
+ end
112
121
 
113
- it "should return regular text with :none markup" do
114
- htmlify("fo\no\n\nbar<>", :none).should == "fo\no<br/>bar&lt;&gt;"
122
+ it "should return regular text with :text markup" do
123
+ htmlify("fo\no\n\nbar<>", :text).should == "fo<br/>o<br/><br/>bar&lt;&gt;"
124
+ end
125
+
126
+ it "should return unmodified text with :none markup" do
127
+ htmlify("fo\no\n\nbar<>", :none).should == "fo\no\n\nbar&lt;&gt;"
115
128
  end
116
129
 
117
130
  it "should highlight ruby if markup is :ruby" do
@@ -121,8 +134,8 @@ describe YARD::Templates::Helpers::HtmlHelper do
121
134
  it "should include file and htmlify it" do
122
135
  load_markup_provider(:rdoc)
123
136
  File.should_receive(:file?).with('foo.rdoc').and_return(true)
124
- File.should_receive(:read).with('foo.rdoc').and_return('= HI')
125
- htmlify("{include:file:foo.rdoc}", :rdoc).gsub(/\s+/, '').should == "<p><h1>HI</h1></p>"
137
+ File.should_receive(:read).with('foo.rdoc').and_return('HI')
138
+ htmlify("{include:file:foo.rdoc}", :rdoc).gsub(/\s+/, '').should == "<p><p>HI</p></p>"
126
139
  end
127
140
 
128
141
  it "should autolink URLs (markdown specific)" do
@@ -19,9 +19,9 @@ describe YARD::Templates::Helpers::HtmlSyntaxHighlightHelper do
19
19
  type = Parser::SourceParser.parser_type
20
20
  Parser::SourceParser.parser_type = :ruby18
21
21
  should_receive(:options).and_return(:no_highlight => false)
22
- expect = "<span class='def def kw'>def</span><span class='x identifier id'>x</span>
22
+ expect = "<span class='rubyid_def def kw'>def</span><span class='rubyid_x identifier id'>x</span>
23
23
  <span class='string val'>'x'</span><span class='plus op'>+</span>
24
- <span class='regexp val'>/x/i</span><span class='end end kw'>end</span>"
24
+ <span class='regexp val'>/x/i</span><span class='rubyid_end end kw'>end</span>"
25
25
  result = html_syntax_highlight("def x\n 'x' + /x/i\nend")
26
26
  html_equals_string(result, expect)
27
27
  Parser::SourceParser.parser_type = type
@@ -30,7 +30,7 @@ describe YARD::Templates::Helpers::HtmlSyntaxHighlightHelper do
30
30
  it "should highlight source (ripper)" do
31
31
  should_receive(:options).and_return(:no_highlight => false)
32
32
  Parser::SourceParser.parser_type = :ruby
33
- expect = "<span class='kw'>def</span> <span class='id x'>x</span>
33
+ expect = "<span class='kw'>def</span> <span class='id identifier rubyid_x'>x</span>
34
34
  <span class='tstring'><span class='tstring_beg'>'</span>
35
35
  <span class='tstring_content'>x</span><span class='tstring_end'>'</span>
36
36
  </span> <span class='op'>+</span> <span class='tstring'>
@@ -67,7 +67,7 @@ describe YARD::Templates::Helpers::Markup::RDocMarkup do
67
67
  end
68
68
 
69
69
  it "should not apply to code blocks" do
70
- fix_typewriter("<code>+hello+</code>").should == "<code>+hello+</code>"
70
+ fix_typewriter("<code>Hello +hello+</code>").should == "<code>Hello +hello+</code>"
71
71
  end
72
72
 
73
73
  it "should not apply to HTML tag attributes" do
@@ -46,23 +46,23 @@ describe YARD::Templates::Helpers::MarkupHelper do
46
46
  end
47
47
 
48
48
  it "should search through available markup providers for the markup type if none is set" do
49
- @gen.should_receive(:eval).with('::RDiscount').and_return(mock(:bluecloth))
50
- @gen.should_receive(:require).with('rdiscount').and_return(true)
49
+ @gen.should_receive(:eval).with('::RedcarpetCompat').and_return(mock(:bluecloth))
50
+ @gen.should_receive(:require).with('redcarpet').and_return(true)
51
51
  @gen.should_not_receive(:require).with('maruku')
52
52
  @gen.stub!(:options).and_return({:markup => :markdown})
53
53
  # this only raises an exception because we mock out require to avoid
54
54
  # loading any libraries but our implementation tries to return the library
55
55
  # name as a constant
56
56
  @gen.load_markup_provider.should == true
57
- @gen.markup_provider.should == :rdiscount
57
+ @gen.markup_provider.should == :redcarpet
58
58
  end
59
59
 
60
60
  it "should continue searching if some of the providers are unavailable" do
61
+ @gen.should_receive(:require).with('redcarpet').and_raise(LoadError)
61
62
  @gen.should_receive(:require).with('rdiscount').and_raise(LoadError)
62
63
  @gen.should_receive(:require).with('kramdown').and_raise(LoadError)
63
64
  @gen.should_receive(:require).with('bluecloth').and_raise(LoadError)
64
65
  @gen.should_receive(:require).with('maruku').and_raise(LoadError)
65
- @gen.should_receive(:require).with('redcarpet').and_raise(LoadError)
66
66
  @gen.should_receive(:require).with('rpeg-markdown').and_return(true)
67
67
  @gen.should_receive(:eval).with('::PEGMarkdown').and_return(true)
68
68
  @gen.stub!(:options).and_return({:markup => :markdown})
@@ -163,7 +163,7 @@ p.signature .aliases .names { font-family: Monaco, Consolas, Courier, monospace;
163
163
 
164
164
  #content a:link, #content a:visited { text-decoration: none; color: #05a; }
165
165
  #content a:hover { background: #ffffa5; }
166
- .docstring { margin-right: 6em; }
166
+ div.docstring, p.docstring { margin-right: 6em; }
167
167
 
168
168
  ul.summary {
169
169
  list-style: none;
@@ -294,7 +294,7 @@ li.r2 { background: #fafafa; }
294
294
  #filecontents pre.code, .docstring pre.code { display: block; }
295
295
  .source_code .lines { padding-right: 12px; color: #555; text-align: right; }
296
296
  #filecontents pre.code, .docstring pre.code,
297
- .tags .example { padding: 5px 12px; margin-top: 4px; border: 1px solid #eef; background: #f5f5ff; }
297
+ .tags pre.example { padding: 5px 12px; margin-top: 4px; border: 1px solid #eef; background: #f5f5ff; }
298
298
  pre.code { color: #000; }
299
299
  pre.code .info.file { color: #555; }
300
300
  pre.code .val { color: #036A07; }
@@ -302,21 +302,21 @@ pre.code .tstring_content,
302
302
  pre.code .heredoc_beg, pre.code .heredoc_end,
303
303
  pre.code .qwords_beg, pre.code .qwords_end,
304
304
  pre.code .tstring, pre.code .dstring { color: #036A07; }
305
- pre.code .fid, pre.code .id.new, pre.code .id.to_s,
306
- pre.code .id.to_sym, pre.code .id.to_f,
305
+ pre.code .fid, pre.code .rubyid_new, pre.code .rubyid_to_s,
306
+ pre.code .rubyid_to_sym, pre.code .rubyid_to_f,
307
307
  pre.code .dot + pre.code .id,
308
- pre.code .id.to_i pre.code .id.each { color: #0085FF; }
308
+ pre.code .rubyid_to_i pre.code .rubyid_each { color: #0085FF; }
309
309
  pre.code .comment { color: #0066FF; }
310
310
  pre.code .const, pre.code .constant { color: #585CF6; }
311
311
  pre.code .symbol { color: #C5060B; }
312
312
  pre.code .kw,
313
313
  pre.code .label,
314
- pre.code .id.require,
315
- pre.code .id.extend,
316
- pre.code .id.include { color: #0000FF; }
314
+ pre.code .rubyid_require,
315
+ pre.code .rubyid_extend,
316
+ pre.code .rubyid_include { color: #0000FF; }
317
317
  pre.code .ivar { color: #318495; }
318
318
  pre.code .gvar,
319
- pre.code .id.backref,
320
- pre.code .id.nth_ref { color: #6D79DE; }
319
+ pre.code .rubyid_backref,
320
+ pre.code .rubyid_nth_ref { color: #6D79DE; }
321
321
  pre.code .regexp, .dregexp { color: #036A07; }
322
322
  pre.code a { border-bottom: 1px dotted #bbf; }
@@ -2,11 +2,11 @@ function createSourceLinks() {
2
2
  $('.method_details_list .source_code').
3
3
  before("<span class='showSource'>[<a href='#' class='toggleSource'>View source</a>]</span>");
4
4
  $('.toggleSource').toggle(function() {
5
- $(this).parent().next().slideDown(100);
5
+ $(this).parent().nextAll('.source_code').slideDown(100);
6
6
  $(this).text("Hide source");
7
7
  },
8
8
  function() {
9
- $(this).parent().next().slideUp(100);
9
+ $(this).parent().nextAll('.source_code').slideUp(100);
10
10
  $(this).text("View source");
11
11
  });
12
12
  }
@@ -109,10 +109,10 @@ function summaryToggle() {
109
109
  $('.summary_toggle').click(function() {
110
110
  localStorage.summaryCollapsed = $(this).text();
111
111
  $(this).text($(this).text() == "collapse" ? "expand" : "collapse");
112
- var next = $(this).parent().parent().next();
112
+ var next = $(this).parent().parent().nextAll('ul.summary').first();
113
113
  if (next.hasClass('compact')) {
114
114
  next.toggle();
115
- next.next().toggle();
115
+ next.nextAll('ul.summary').first().toggle();
116
116
  }
117
117
  else if (next.hasClass('summary')) {
118
118
  var list = $('<ul class="summary compact" />');
@@ -57,7 +57,7 @@ a:hover { color: #060; background: #8e0; }
57
57
  #filecontents pre.code, .docstring pre.code { display: block; }
58
58
  .source_code .lines { padding-right: 12px; color: #555; text-align: right; }
59
59
  #filecontents pre.code, .docstring pre.code,
60
- .tags .example {
60
+ .tags pre.example {
61
61
  font-size: 0.9em;
62
62
  padding: 7px 30px;
63
63
  margin: 15px -30px;
@@ -73,21 +73,21 @@ pre.code .tstring_content,
73
73
  pre.code .heredoc_beg, pre.code .heredoc_end,
74
74
  pre.code .qwords_beg, pre.code .qwords_end,
75
75
  pre.code .tstring, pre.code .dstring { color: #036A07; }
76
- pre.code .fid, pre.code .id.new, pre.code .id.to_s,
77
- pre.code .id.to_sym, pre.code .id.to_f,
76
+ pre.code .fid, pre.code .rubyid_new, pre.code .rubyid_to_s,
77
+ pre.code .rubyid_to_sym, pre.code .rubyid_to_f,
78
78
  pre.code .dot + pre.code .id,
79
- pre.code .id.to_i pre.code .id.each { color: #0085FF; }
79
+ pre.code .rubyid_to_i pre.code .rubyid_each { color: #0085FF; }
80
80
  pre.code .comment { color: #0066FF; }
81
81
  pre.code .const, pre.code .constant { color: #585CF6; }
82
82
  pre.code .symbol { color: #C5060B; }
83
83
  pre.code .kw,
84
84
  pre.code .label,
85
- pre.code .id.require,
86
- pre.code .id.extend,
87
- pre.code .id.include { color: #0000FF; }
85
+ pre.code .rubyid_require,
86
+ pre.code .rubyid_extend,
87
+ pre.code .rubyid_include { color: #0000FF; }
88
88
  pre.code .ivar { color: #318495; }
89
89
  pre.code .gvar,
90
- pre.code .id.backref,
91
- pre.code .id.nth_ref { color: #6D79DE; }
90
+ pre.code .rubyid_backref,
91
+ pre.code .rubyid_nth_ref { color: #6D79DE; }
92
92
  pre.code .regexp, .dregexp { color: #036A07; }
93
93
  pre.code a { border-bottom: 1px dotted #bbf; }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: yard
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.3
4
+ version: 0.7.4
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: 2011-10-15 00:00:00.000000000 -04:00
12
+ date: 2011-12-03 00:00:00.000000000 -05:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
  description: ! " YARD is a documentation generation tool for the Ruby programming