Commit b414e2b5 authored by Rene Saarsoo's avatar Rene Saarsoo
Browse files

Refactor production export rake command.

Removed index_production.html - it goes too easily out of sync.
Instead using index.html as a template where placeholders are
replaced with data optionally passed from command line.  For that
added new options:

  --title - to set the title of page.
  --extjs-path - to use extjs/ext-all.js in production.
  --append-html - to add the analytics code.
parent 06f6222a
Loading
Loading
Loading
Loading
+28 −8
Original line number Diff line number Diff line
@@ -36,21 +36,18 @@ def load_sdk_vars
  end
end

def run_jsduck(paths, template_links = true)
def run_jsduck(extra_options)
  system [
    "ruby bin/jsduck",
    # --external=Error to ignore the Error class that Ext.Error extends.
    "--external=Error",
    # to create symbolic links to template files instead of copying them over.
    # Useful for development.  Turn off for deployment.
    (template_links ? "--template-links" : ""),
    '--link=\'<a href="#/api/%c%-%m" rel="%c%-%m" class="docClass">%a</a>\'',
    # Note that we wrap image template inside <p> because {@img} often
    # appears inline withing text, but that just looks ugly in HTML
    '--img=\'<p><img src="doc-resources/%u" alt="%a"></p>\'',
    "--guides=#{SDK_DIR}/guides",
    "--output=#{OUT_DIR}",
  ].concat(paths).join(" ")
  ].concat(extra_options).join(" ")

  # Finally copy over the images that documentation links to.
  system "cp -r #{SDK_DIR}/extjs/doc-resources #{OUT_DIR}/doc-resources"
@@ -61,6 +58,9 @@ desc "Run JSDuck on ExtJS SDK"
task :sdk do
  load_sdk_vars
  run_jsduck([
    # to create symbolic links to template files instead of copying them over.
    # Useful for development.  Turn off for deployment.
    "--template-links",
    "#{SDK_DIR}/extjs/src",
    "#{SDK_DIR}/platform/src",
    "#{SDK_DIR}/platform/core/src",
@@ -70,11 +70,31 @@ end
desc "Run JSDuck on ExtJS SDK for export"
task :export do
  load_sdk_vars

  analytics = <<-EOHTML
    <script type="text/javascript">
      var _gaq = _gaq || [];
      _gaq.push(['_setAccount', 'UA-1396058-10']);
      _gaq.push(['_trackPageview']);
      (function() {
        var ga = document.createElement('script');
        ga.type = 'text/javascript';
        ga.async = true;
        ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
        var s = document.getElementsByTagName('script')[0];
        s.parentNode.insertBefore(ga, s);
      })();
    </script>
  EOHTML

  run_jsduck([
    "--title='Ext JS 4.0.1 API Documentation'",
    "--extjs-path=extjs/ext-all.js",
    "--append-html='" + analytics.gsub(/'/, "\'") + "'",
    "#{SDK_DIR}/extjs/src",
    "#{SDK_DIR}/platform/src",
    "#{SDK_DIR}/platform/core/src",
  ], false)
  ])

  system "rm #{OUT_DIR}/extjs"
  system "mkdir -p #{OUT_DIR}/extjs/resources/themes/images"
@@ -82,13 +102,13 @@ task :export do
  system "cp -r #{SDK_DIR}/extjs/build/sdk/resources/themes/images/default #{OUT_DIR}/extjs/resources/themes/images"
  system "rm -rf #{OUT_DIR}/resources/sass"
  system "rm -rf #{OUT_DIR}/resources/.sass-cache"
  system "cp template/index_production.html #{OUT_DIR}/index.html" 
end

desc "Run JSDuck on the Docs app itself"
task :docs do
  load_sdk_vars
  run_jsduck([
    "--template-links",
    "#{SDK_DIR}/extjs/src",
    "#{SDK_DIR}/platform/src",
    "#{SDK_DIR}/platform/core/src",
+14 −0
Original line number Diff line number Diff line
@@ -26,6 +26,10 @@ app.template_dir = File.dirname(File.dirname(__FILE__)) + "/template"
opts = OptionParser.new do | opts |
  opts.banner = "Usage: jsduck [options] files/dirs...\n\n"

  opts.on('--append-html=HTML', "Extra code to append to the index.html page.", " ") do |html|
    app.append_html = html
  end

  opts.on('--external=CLASSNAME',
    "Declares an external class.  When declared as",
    "external, inheriting from this class will not",
@@ -34,6 +38,12 @@ opts = OptionParser.new do | opts |
    app.external_classes << classname
  end

  opts.on('--extjs-path=PATH',
    "Path for main ExtJS JavaScript file.  Useful for specifying",
    "something different than extjs/ext-all-debug.js", " ") do |path|
    app.extjs_path = path
  end

  opts.on('--guides=PATH', "Path to guides directory.",
    "Each subdirectory of that is treated as a guide",
    "and is expectd to contain a REAME.md file,",
@@ -107,6 +117,10 @@ opts = OptionParser.new do | opts |
    app.template_links = true
  end

  opts.on('--title=TEXT', "Custom title for the documentation app.", " ") do |text|
    app.title = text
  end

  opts.on('-v', '--verbose', "This will fill up your console.", " ") do
    app.verbose = true
  end
+17 −0
Original line number Diff line number Diff line
@@ -32,6 +32,9 @@ module JsDuck
    attr_accessor :ignore_global
    attr_accessor :external_classes
    attr_accessor :show_private_classes
    attr_accessor :title
    attr_accessor :extjs_path
    attr_accessor :append_html

    def initialize
      @output_dir = nil
@@ -46,6 +49,9 @@ module JsDuck
      @ignore_global = false
      @external_classes = []
      @show_private_classes = false
      @title = "Ext JS API Documentation"
      @extjs_path = "extjs/ext-all-debug.js"
      @append_html = ""
      @timer = Timer.new
      @parallel = ParallelWrap.new
    end
@@ -86,6 +92,7 @@ module JsDuck
        else
          copy_template(@template_dir, @output_dir)
        end
        create_index_html(@template_dir, @output_dir)
        @timer.time(:generating) { write_src(@output_dir+"/source", parsed_files) }
        @timer.time(:generating) { write_tree(@output_dir+"/output/tree.js", relations) }
        @timer.time(:generating) { write_members(@output_dir+"/output/members.js", relations) }
@@ -307,6 +314,16 @@ module JsDuck
      FileUtils.mkdir(dir + "/output")
      FileUtils.mkdir(dir + "/source")
    end

    def create_index_html(template_dir, dir)
      Logger.instance.log("Creating #{dir}/index.html...")
      html = IO.read(template_dir+"/index.html")
      html.gsub!("{title}", @title)
      html.gsub!("{extjs_path}", @extjs_path)
      html.gsub!("{append_html}", @append_html)
      FileUtils.rm(dir+"/index.html")
      File.open(dir+"/index.html", 'w') {|f| f.write(html) }
    end
  end

end
+5 −2
Original line number Diff line number Diff line
@@ -11,7 +11,7 @@ Ext.define('Docs.view.cls.List', {
        var data = this.classData;

        var tpl = new Ext.XTemplate(
            '<h1 class="pb">Ext JS 4.0.1 API Documentation</h1>',
            '<h1 class="pb">{title}</h1>',
            '<div class="legend icons">',
                '<h4>Legend</h4>',
                '<ul>',
@@ -70,7 +70,10 @@ Ext.define('Docs.view.cls.List', {
            }
        );

        this.html = tpl.apply(data);
        this.html = tpl.apply(Ext.apply({
            // Use the same title as in <title>
            title: document.getElementsByTagName("title")[0].innerHTML
        }, data));

        this.callParent(arguments);
    }
+3 −2
Original line number Diff line number Diff line
<!DOCTYPE html>
<html>
<head>
  <title>Ext JS 4.0.1 API Documentation</title>
  <title>{title}</title>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <link rel="shortcut icon" type="image/ico" href="favicon.ico" />
  <link rel="stylesheet" href="resources/css/reset.css" type="text/css" />
@@ -17,7 +17,7 @@
    <link rel="stylesheet" href="resources/css/ie.css" type="text/css" />
  <![endif]-->

  <script type="text/javascript" src="extjs/ext-all-debug.js"></script>
  <script type="text/javascript" src="{extjs_path}"></script>
  <script type="text/javascript" src="prettify/prettify.js"></script>

  <script type="text/javascript" src="app.js"></script>
@@ -34,5 +34,6 @@
        <input type="hidden" id="x-history-field" />
        <iframe id="x-history-frame"></iframe>
    </form>
    {append_html}
</body>
</html>
Loading