Loading lib/jsduck/app.rb +1 −0 Original line number Diff line number Diff line Loading @@ -245,6 +245,7 @@ module JsDuck out_dir = out_path + "/" + guide_name puts "Creating guide #{out_dir} ..." if @verbose FileUtils.cp_r(in_dir, out_dir) formatter.doc_context = {:filename => out_dir + "/README.md", :linenr => 0} guide = formatter.format(IO.read(out_dir + "/README.md")) guide.gsub!(/<img src="/, "<img src=\"guides/#{guide_name}/") write_jsonp_file(out_dir+"/README.js", guide_name, {:guide => guide}) Loading lib/jsduck/doc_formatter.rb +20 −5 Original line number Diff line number Diff line Loading @@ -31,7 +31,11 @@ module JsDuck # Sets up instance to work in context of particular class, so # that when {@link #blah} is encountered it knows that # Context#blah is meant. attr_accessor :context attr_accessor :class_context # Sets up instance to work in context of particular doc object. # Used for error reporting. attr_accessor :doc_context # Maximum length for text that doesn't get shortened, defaults to 120 attr_accessor :max_length Loading @@ -44,7 +48,8 @@ module JsDuck attr_accessor :relations def initialize @context = "" @class_context = "" @doc_context = {} @max_length = 120 @relations = {} @link_tpl = '<a href="%c%#%m">%a</a>' Loading Loading @@ -86,7 +91,7 @@ module JsDuck target = $1 text = $2 if target =~ /^(.*)#(.*)$/ cls = $1.empty? ? @context : $1 cls = $1.empty? ? @class_context : $1 member = $2 else cls = target Loading @@ -97,14 +102,24 @@ module JsDuck if text text = text elsif member text = (cls == @context) ? member : (cls + "." + member) text = (cls == @class_context) ? member : (cls + "." + member) else text = cls end file = @doc_context[:filename] line = @doc_context[:linenr] if !@relations[cls] puts "Warning: #{file} line #{line} #{input} links to non-existing class." input elsif member && !get_member_type(cls, member) puts "Warning: #{file} line #{line} #{input} links to non-existing member." input else link(cls, member, text) end end end def replace_img_tag(input) input.sub(@img_re) { img($1, $2) } Loading lib/jsduck/exporter.rb +3 −1 Original line number Diff line number Diff line Loading @@ -35,7 +35,8 @@ module JsDuck # converts :doc properties from markdown to html and resolve @links def format_class(c) @formatter.context = c[:name] @formatter.class_context = c[:name] @formatter.doc_context = c c[:doc] = @formatter.format(c[:doc]) if c[:doc] [:cfg, :property, :method, :event, :cssVar, :cssMixin].each do |type| c[type] = c[type].map {|m| format_member(m) } Loading @@ -45,6 +46,7 @@ module JsDuck def format_member(m) m = m.clone @formatter.doc_context = m m[:doc] = @formatter.format(m[:doc]) if m[:doc] if m[:params] || @formatter.too_long?(m[:doc]) m[:shortDoc] = @formatter.shorten(m[:doc]) Loading lib/jsduck/page.rb +1 −1 Original line number Diff line number Diff line Loading @@ -21,7 +21,7 @@ module JsDuck @relations = relations @cache = cache @formatter = DocFormatter.new @formatter.context = cls.full_name @formatter.class_context = cls.full_name @formatter.link_tpl = '<a href="output/%c.html%M" rel="%c%M" class="docClass">%a</a>' @formatter.relations = relations end Loading spec/doc_formatter_spec.rb +1 −1 Original line number Diff line number Diff line Loading @@ -4,7 +4,7 @@ describe JsDuck::DocFormatter do before do @formatter = JsDuck::DocFormatter.new @formatter.context = "Context" @formatter.class_context = "Context" @formatter.relations = { 'Context' => JsDuck::Class.new({ :method => [{:name => "bar", :tagname => :method}] Loading Loading
lib/jsduck/app.rb +1 −0 Original line number Diff line number Diff line Loading @@ -245,6 +245,7 @@ module JsDuck out_dir = out_path + "/" + guide_name puts "Creating guide #{out_dir} ..." if @verbose FileUtils.cp_r(in_dir, out_dir) formatter.doc_context = {:filename => out_dir + "/README.md", :linenr => 0} guide = formatter.format(IO.read(out_dir + "/README.md")) guide.gsub!(/<img src="/, "<img src=\"guides/#{guide_name}/") write_jsonp_file(out_dir+"/README.js", guide_name, {:guide => guide}) Loading
lib/jsduck/doc_formatter.rb +20 −5 Original line number Diff line number Diff line Loading @@ -31,7 +31,11 @@ module JsDuck # Sets up instance to work in context of particular class, so # that when {@link #blah} is encountered it knows that # Context#blah is meant. attr_accessor :context attr_accessor :class_context # Sets up instance to work in context of particular doc object. # Used for error reporting. attr_accessor :doc_context # Maximum length for text that doesn't get shortened, defaults to 120 attr_accessor :max_length Loading @@ -44,7 +48,8 @@ module JsDuck attr_accessor :relations def initialize @context = "" @class_context = "" @doc_context = {} @max_length = 120 @relations = {} @link_tpl = '<a href="%c%#%m">%a</a>' Loading Loading @@ -86,7 +91,7 @@ module JsDuck target = $1 text = $2 if target =~ /^(.*)#(.*)$/ cls = $1.empty? ? @context : $1 cls = $1.empty? ? @class_context : $1 member = $2 else cls = target Loading @@ -97,14 +102,24 @@ module JsDuck if text text = text elsif member text = (cls == @context) ? member : (cls + "." + member) text = (cls == @class_context) ? member : (cls + "." + member) else text = cls end file = @doc_context[:filename] line = @doc_context[:linenr] if !@relations[cls] puts "Warning: #{file} line #{line} #{input} links to non-existing class." input elsif member && !get_member_type(cls, member) puts "Warning: #{file} line #{line} #{input} links to non-existing member." input else link(cls, member, text) end end end def replace_img_tag(input) input.sub(@img_re) { img($1, $2) } Loading
lib/jsduck/exporter.rb +3 −1 Original line number Diff line number Diff line Loading @@ -35,7 +35,8 @@ module JsDuck # converts :doc properties from markdown to html and resolve @links def format_class(c) @formatter.context = c[:name] @formatter.class_context = c[:name] @formatter.doc_context = c c[:doc] = @formatter.format(c[:doc]) if c[:doc] [:cfg, :property, :method, :event, :cssVar, :cssMixin].each do |type| c[type] = c[type].map {|m| format_member(m) } Loading @@ -45,6 +46,7 @@ module JsDuck def format_member(m) m = m.clone @formatter.doc_context = m m[:doc] = @formatter.format(m[:doc]) if m[:doc] if m[:params] || @formatter.too_long?(m[:doc]) m[:shortDoc] = @formatter.shorten(m[:doc]) Loading
lib/jsduck/page.rb +1 −1 Original line number Diff line number Diff line Loading @@ -21,7 +21,7 @@ module JsDuck @relations = relations @cache = cache @formatter = DocFormatter.new @formatter.context = cls.full_name @formatter.class_context = cls.full_name @formatter.link_tpl = '<a href="output/%c.html%M" rel="%c%M" class="docClass">%a</a>' @formatter.relations = relations end Loading
spec/doc_formatter_spec.rb +1 −1 Original line number Diff line number Diff line Loading @@ -4,7 +4,7 @@ describe JsDuck::DocFormatter do before do @formatter = JsDuck::DocFormatter.new @formatter.context = "Context" @formatter.class_context = "Context" @formatter.relations = { 'Context' => JsDuck::Class.new({ :method => [{:name => "bar", :tagname => :method}] Loading