Commit 75ae7e63 authored by Rene Saarsoo's avatar Rene Saarsoo
Browse files

Use --img and --link options also when not export.

Previously --img and --link only applied to export, but now they
can also be used to override the links/images in the normal output
of JSDuck.  Currently it's most useful for dealing with {@img} tags
in ExtJS 4.
parent b5b4299f
Loading
Loading
Loading
Loading
+4 −4
Original line number Diff line number Diff line
@@ -38,21 +38,21 @@ opts = OptionParser.new do | opts |
    app.export = :json
  end

  opts.on('--link=TPL', "HTML template for replacing {@link} in export.",
  opts.on('--link=TPL', "HTML template for replacing {@link}.",
    "Possible placeholders:",
    "%c - full class name (e.g. 'Ext.Panel')",
    "%m - class member name (e.g. 'urlEncode')",
    "%M - class member name, prefixed with hash (e.g. '#urlEncode')",
    "%a - anchor text for link",
    "Default value: '<a href=\"%c%M\">%a</a>'") do |tpl|
    "Default value in export: '<a href=\"%c%M\">%a</a>'") do |tpl|
    app.link_tpl = tpl
  end

  opts.on('--img=TPL', "HTML template for replacing {@img} in export.",
  opts.on('--img=TPL', "HTML template for replacing {@img}.",
    "Possible placeholders:",
    "%u - URL from @img tag (e.g. 'some/path.png')",
    "%a - alt text for image",
    "Default value: '<img src=\"%u\" alt=\"%a\"/>'") do |tpl|
    "Default value in export: '<img src=\"%u\" alt=\"%a\"/>'") do |tpl|
    app.img_tpl = tpl
  end

+4 −2
Original line number Diff line number Diff line
@@ -162,8 +162,10 @@ module JsDuck
      @parallel.each(relations.classes) do |cls|
        filename = path + "/" + cls[:name] + ".html"
        puts "Writing to #{filename} ..." if @verbose
        html = Page.new(cls, relations, cache).to_html
        File.open(filename, 'w') {|f| f.write(html) }
        page = Page.new(cls, relations, cache)
        page.link_tpl = @link_tpl if @link_tpl
        page.img_tpl = @img_tpl if @img_tpl
        File.open(filename, 'w') {|f| f.write(page.to_html) }
      end
    end

+8 −0
Original line number Diff line number Diff line
@@ -26,6 +26,14 @@ module JsDuck
      @formatter.relations = relations
    end

    # Setters to override link and image templates
    def link_tpl=(tpl)
      @formatter.link_tpl = tpl
    end
    def img_tpl=(tpl)
      @formatter.img_tpl = tpl
    end

    def to_html
      [
       '<div class="body-wrap">',