1
0
Fork 0
mirror of https://github.com/pry/pry.git synced 2022-11-09 12:35:05 -05:00

Fix @example parsing, parse @note and parse @see.

Fixes #314 and #315
Signed-off-by: Jordon Bedwell <jordon@envygeeks.com>
This commit is contained in:
Jordon Bedwell 2011-10-28 22:40:21 -05:00
parent afa6151038
commit 8349a6d9bb
2 changed files with 35 additions and 9 deletions

View file

@ -122,12 +122,15 @@ class Pry
def process_rdoc(comment, code_type)
comment = comment.dup
comment.gsub(/<code>(?:\s*\n)?(.*?)\s*<\/code>/m) { Pry.color ? CodeRay.scan($1, code_type).term : $1 }.
comment.gsub(/!\{/, "{"). # Fix any (Ya)rdoc URI escapes that are found in the comments.
gsub(/<code>(?:\s*\n)?(.*?)\s*<\/code>/m) { |code| code.gsub(/`/, '___TICK___')}. # Prevent tick double hightlights.
gsub(/<code>(?:\s*\n)?(.*?)\s*<\/code>/m) { Pry.color ? CodeRay.scan($1, code_type).term : $1 }.
gsub(/<em>(?:\s*\n)?(.*?)\s*<\/em>/m) { Pry.color ? "\e[1m#{$1}\e[0m": $1 }.
gsub(/<i>(?:\s*\n)?(.*?)\s*<\/i>/m) { Pry.color ? "\e[1m#{$1}\e[0m" : $1 }.
gsub(/\B\+(\w*?)\+\B/) { Pry.color ? "\e[32m#{$1}\e[0m": $1 }.
gsub(/((?:^[ \t]+.+(?:\n+|\Z))+)/) { Pry.color ? CodeRay.scan($1, code_type).term : $1 }.
gsub(/`(?:\s*\n)?(.*?)\s*`/) { Pry.color ? CodeRay.scan($1, code_type).term : $1 }
gsub(/@example(((\n\s{2,})?[^\n]+)+)/) { |code| code.gsub(/`/, '___TICK___') }. # Prevent tick doube highlights.
gsub(/@example(((\n\s{2,})?[^\n]+)+)/) { Pry.color ? "\e[33mexample\e[0m" + CodeRay.scan($1, code_type).term : "example#{$1}" }.
gsub(/`([^`]+)`/) { Pry.color ? CodeRay.scan($1, code_type).term : $1 }.
gsub(/___TICK___/, Pry.color ? "\e[33m`\e[0m" : '`')
end
def process_yardoc_tag(comment, tag)
@ -146,9 +149,8 @@ class Pry
end
def process_yardoc(comment)
yard_tags = ["param", "return", "option", "yield", "attr", "attr_reader", "attr_writer",
"deprecate", "example"]
(yard_tags - ["example"]).inject(comment) { |a, v| process_yardoc_tag(a, v) }.
yard_tags = ["param", "return", "option", "yield", "attr", "attr_reader", "attr_writer", "deprecate", "note", "see"]
(yard_tags).inject(comment) { |a, v| process_yardoc_tag(a, v) }.
gsub(/^@(#{yard_tags.join("|")})/) { Pry.color ? "\e[33m#{$1}\e[0m": $1 }
end

View file

@ -16,7 +16,20 @@ describe "Pry::DefaultCommands::Documentation" do
o = Object.new
# sample comment
# This is a test comment
# This is a test comment
# The Test method `{'one': 'value'}`
# <code>{'two': 'value'}</code>
# <code>`{'three': 'value'}`</code>
# @note A message
# @example `{'four': 'value'}`
# @example {'five': 'value'}
# @example
# `{'six': 'value'}`
# @example
# {'seven': 'value'}
# {'eight': 'value'}
# @see https://github.com/pry/pry
def o.sample
redirect_pry_io(InputTester.new("show-doc", "exit-all"), $str_output) do
binding.pry
@ -24,7 +37,17 @@ describe "Pry::DefaultCommands::Documentation" do
end
o.sample
$str_output.string.should =~ /sample comment/
$str_output.string.should =~ /This is a test comment/
$str_output.string.should =~ / This is a test comment/
$str_output.string.should =~ /The Test method \{'one': 'value'\}/
$str_output.string.should =~ /\{'two': 'value'\}/
$str_output.string.should =~ /`\{'three': 'value'\}`/
$str_output.string.should =~ /note A message/
$str_output.string.should =~ /example `\{'four': 'value'\}`/
$str_output.string.should =~ /example \{'five': 'value'\}/
$str_output.string.should =~ /example\n `\{'six': 'value'\}`/
$str_output.string.should =~ /example\n \{'seven': 'value'\}\n \{'eight': 'value'\}/
$str_output.string.should =~ /see https:\/\/github.com\/pry\/pry/
$str_output = nil
end
@ -52,3 +75,4 @@ describe "Pry::DefaultCommands::Documentation" do
end
end
end