Commit 9920980e authored by Rene Saarsoo's avatar Rene Saarsoo
Browse files

Add {DATE} and {JSDUCK} placeholders to --footer.

To easily insert current data and link to JSDuck homepage.

Fixes: #343
parent b2a30218
Loading
Loading
Loading
Loading
+15 −5
Original line number Diff line number Diff line
@@ -97,7 +97,7 @@ module JsDuck
      # Customizing output
      @title = "Documentation - JSDuck"
      @header = "<strong>Documentation</strong> JSDuck"
      @footer = "Generated with <a href='https://github.com/senchalabs/jsduck'>JSDuck</a> #{@version}."
      @footer = format_footer("Generated on {DATE} by {JSDUCK} {VERSION}.")
      @head_html = ""
      @body_html = ""
      @message = ""
@@ -272,11 +272,14 @@ module JsDuck
        opts.on('--footer=TEXT',
          "Custom footer text for the documentation.",
          "",
          "Defaults to: 'Generated with JSDuck {VERSION}.'",
          "The text can contain various placeholders:",
          "",
          "'{VERSION}' is a placeholder that will get substituted",
          "with the current version of JSDuck.  See --version.") do |text|
          @footer = text.gsub(/\{VERSION\}/, @version)
          "  {DATE} - current date and time.",
          "  {JSDUCK} - link to JSDuck homepage.",
          "  {VERSION} - JSDuck version number.",
          "",
          "Defaults to: 'Generated on {DATE} by {JSDUCK} {VERSION}.'") do |text|
          @footer = format_footer(text)
        end

        opts.on('--head-html=HTML',
@@ -769,6 +772,13 @@ module JsDuck
      File.expand_path(path, @working_dir)
    end

    # Replace special placeholders in footer text
    def format_footer(text)
      jsduck = "<a href='https://github.com/senchalabs/jsduck'>JSDuck</a>"
      date = Time.new.strftime('%a %d %b %Y %H:%M:%S')
      text.gsub(/\{VERSION\}/, @version).gsub(/\{JSDUCK\}/, jsduck).gsub(/\{DATE\}/, date)
    end

    # Runs checks on the options
    def validate
      if @input_files.length == 0 && !@welcome && !@guides && !@videos && !@examples