Loading lib/jsduck/inline/link.rb +17 −7 Original line number Diff line number Diff line Loading @@ -41,6 +41,8 @@ module JsDuck @tpl = opts[:link_tpl] || '<a href="%c%#%m">%a</a>' @re = /\{@link\s+(\S*?)(?:\s+(.+?))?\}/m @magic_link_re = magic_link_re end # Takes StringScanner instance. Loading Loading @@ -131,14 +133,22 @@ module JsDuck # class names containing a dot "." # def create_magic_links(input) cls_re = "([A-Z][A-Za-z0-9.]*[A-Za-z0-9])" member_re = "(?:#([A-Za-z0-9]+))" input.gsub(/\b#{cls_re}#{member_re}?\b|#{member_re}\b/m) do replace_magic_link($1, $2 || $3) input.gsub(@magic_link_re) do cls = $1 || $3 member = $2 || $4 replace_magic_link(cls, member) end end # Generates regex for auto-linking class and member names in text. def magic_link_re ident_re = "(?:[A-Za-z][A-Za-z0-9]*)" cls_re = "(#{ident_re}(?:\\.#{ident_re})*)" ns_cls_re = "(#{ident_re}(?:\\.#{ident_re})+)" member_re = "(?:#(#{ident_re}))" /\b#{cls_re}#{member_re}\b|\b#{ns_cls_re}\b|#{member_re}\b/m end def replace_magic_link(cls, member) if cls && member if @relations[cls] && get_matching_member(cls, {:name => member}) Loading @@ -146,7 +156,7 @@ module JsDuck else warn_magic_link("#{cls}##{member} links to non-existing " + (@relations[cls] ? "member" : "class")) end elsif cls && cls =~ /\./ elsif cls if @relations[cls] return link(cls, nil, cls) else Loading @@ -159,7 +169,7 @@ module JsDuck warn_magic_link("#{cls} links to non-existing class") end end elsif !cls && member else if get_matching_member(@class_context, {:name => member}) return link(@class_context, member, member) elsif member =~ /\A([A-F0-9]{3}|[A-F0-9]{6})\Z/i || member =~ /\A[0-9]/ Loading spec/doc_formatter_spec.rb +16 −0 Original line number Diff line number Diff line Loading @@ -169,6 +169,12 @@ describe JsDuck::DocFormatter do {:tagname => :method, :name => "privMeth", :id => "method-privMeth", :private => true}, ] }), JsDuck::Class.new({ :name => "downcase.ClassName", :members => [ {:tagname => :method, :name => "blah", :id => "method-blah"}, ] }), ]) end Loading Loading @@ -212,6 +218,11 @@ describe JsDuck::DocFormatter do 'Look at <a href="Ext.XTemplate">Ext.AltXTemplate</a>' end it "converts downcase.ClassName to class link" do @formatter.replace("Look at downcase.ClassName").should == 'Look at <a href="downcase.ClassName">downcase.ClassName</a>' end it "converts ClassName ending with dot to class link" do @formatter.replace("Look at Foo.Bar.").should == 'Look at <a href="Foo.Bar">Foo.Bar</a>.' Loading Loading @@ -239,6 +250,11 @@ describe JsDuck::DocFormatter do 'Look at <a href="Ext.form.Field#method-getValues">Ext.form.Field.getValues</a>' end it "converts downcase.ClassName#blah to method link" do @formatter.replace("Look at downcase.ClassName#blah").should == 'Look at <a href="downcase.ClassName#method-blah">downcase.ClassName.blah</a>' end it "converts Ext.encode to method link" do @formatter.replace("Look at Ext.encode").should == 'Look at <a href="Ext#method-encode">Ext.encode</a>' Loading Loading
lib/jsduck/inline/link.rb +17 −7 Original line number Diff line number Diff line Loading @@ -41,6 +41,8 @@ module JsDuck @tpl = opts[:link_tpl] || '<a href="%c%#%m">%a</a>' @re = /\{@link\s+(\S*?)(?:\s+(.+?))?\}/m @magic_link_re = magic_link_re end # Takes StringScanner instance. Loading Loading @@ -131,14 +133,22 @@ module JsDuck # class names containing a dot "." # def create_magic_links(input) cls_re = "([A-Z][A-Za-z0-9.]*[A-Za-z0-9])" member_re = "(?:#([A-Za-z0-9]+))" input.gsub(/\b#{cls_re}#{member_re}?\b|#{member_re}\b/m) do replace_magic_link($1, $2 || $3) input.gsub(@magic_link_re) do cls = $1 || $3 member = $2 || $4 replace_magic_link(cls, member) end end # Generates regex for auto-linking class and member names in text. def magic_link_re ident_re = "(?:[A-Za-z][A-Za-z0-9]*)" cls_re = "(#{ident_re}(?:\\.#{ident_re})*)" ns_cls_re = "(#{ident_re}(?:\\.#{ident_re})+)" member_re = "(?:#(#{ident_re}))" /\b#{cls_re}#{member_re}\b|\b#{ns_cls_re}\b|#{member_re}\b/m end def replace_magic_link(cls, member) if cls && member if @relations[cls] && get_matching_member(cls, {:name => member}) Loading @@ -146,7 +156,7 @@ module JsDuck else warn_magic_link("#{cls}##{member} links to non-existing " + (@relations[cls] ? "member" : "class")) end elsif cls && cls =~ /\./ elsif cls if @relations[cls] return link(cls, nil, cls) else Loading @@ -159,7 +169,7 @@ module JsDuck warn_magic_link("#{cls} links to non-existing class") end end elsif !cls && member else if get_matching_member(@class_context, {:name => member}) return link(@class_context, member, member) elsif member =~ /\A([A-F0-9]{3}|[A-F0-9]{6})\Z/i || member =~ /\A[0-9]/ Loading
spec/doc_formatter_spec.rb +16 −0 Original line number Diff line number Diff line Loading @@ -169,6 +169,12 @@ describe JsDuck::DocFormatter do {:tagname => :method, :name => "privMeth", :id => "method-privMeth", :private => true}, ] }), JsDuck::Class.new({ :name => "downcase.ClassName", :members => [ {:tagname => :method, :name => "blah", :id => "method-blah"}, ] }), ]) end Loading Loading @@ -212,6 +218,11 @@ describe JsDuck::DocFormatter do 'Look at <a href="Ext.XTemplate">Ext.AltXTemplate</a>' end it "converts downcase.ClassName to class link" do @formatter.replace("Look at downcase.ClassName").should == 'Look at <a href="downcase.ClassName">downcase.ClassName</a>' end it "converts ClassName ending with dot to class link" do @formatter.replace("Look at Foo.Bar.").should == 'Look at <a href="Foo.Bar">Foo.Bar</a>.' Loading Loading @@ -239,6 +250,11 @@ describe JsDuck::DocFormatter do 'Look at <a href="Ext.form.Field#method-getValues">Ext.form.Field.getValues</a>' end it "converts downcase.ClassName#blah to method link" do @formatter.replace("Look at downcase.ClassName#blah").should == 'Look at <a href="downcase.ClassName#method-blah">downcase.ClassName.blah</a>' end it "converts Ext.encode to method link" do @formatter.replace("Look at Ext.encode").should == 'Look at <a href="Ext#method-encode">Ext.encode</a>' Loading