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

Add --examples-base-url option.

This replaces the previous Docs.exampleBaseUrl JS-side option, which
was a bit of a hack.

Now all URL-s are prefixed in parsing stage, so the docs app doesn't need
to deal with the prefixing at all.

Additionally the externalUrl field in examples.json is no more supported.
Simply using the url field beginning with http:// will do the trick.
parent ed63dbd6
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -232,7 +232,6 @@ class JsDuckRunner

    head_html = <<-EOHTML
      <script type="text/javascript">
        Docs.exampleBaseUrl = "#{relative_touch_path}examples/";
        if (Ext.is.Phone) { window.location = "#{relative_touch_path}examples/"; }
      </script>
    EOHTML
@@ -240,7 +239,8 @@ class JsDuckRunner
    @options += [
      "--body-html", head_html,
      "--welcome", "template-min/welcome.html",
      "--eg-iframe", "template-min/eg-iframe.html"
      "--eg-iframe", "template-min/eg-iframe.html",
      "--examples-base-url", "#{relative_touch_path}examples/",
    ]
  end

+1 −1
Original line number Diff line number Diff line
@@ -52,7 +52,7 @@ module JsDuck
      @welcome = Welcome.create(@opts.welcome)
      @guides = Guides.create(@opts.guides, DocFormatter.new(@relations, @opts))
      @videos = Videos.create(@opts.videos)
      @examples = Examples.create(@opts.examples)
      @examples = Examples.create(@opts.examples, @opts)
      @categories = Categories.create(@opts.categories_path, DocFormatter.new(@relations, @opts), @relations)

      if @opts.export
+16 −3
Original line number Diff line number Diff line
@@ -6,17 +6,30 @@ module JsDuck
  # Reads in examples JSON file
  class Examples
    # Creates Examples object from filename.
    def self.create(filename)
    def self.create(filename, opts)
      if filename
        Examples.new(filename)
        Examples.new(filename, opts)
      else
        NullObject.new(:to_array => [])
      end
    end

    # Parses examples config file
    def initialize(filename)
    def initialize(filename, opts)
      @examples = JsonDuck.read(filename)
      @opts = opts
      prefix_urls
    end

    # Prefix all relative URL-s in examples list with path given in --examples-base-url
    def prefix_urls
      @examples.each do |group|
        group["items"].each do |ex|
          unless ex["url"] =~ /^https?:\/\//
            ex["url"] = @opts.examples_base_url + ex["url"]
          end
        end
      end
    end

    # Writes examples JSON file to dir
+7 −0
Original line number Diff line number Diff line
@@ -31,6 +31,7 @@ module JsDuck
    attr_accessor :export
    attr_accessor :seo
    attr_accessor :eg_iframe
    attr_accessor :examples_base_url

    # Debugging
    attr_accessor :processes
@@ -94,6 +95,7 @@ module JsDuck
      @export = nil
      @seo = false
      @eg_iframe = nil
      @examples_base_url = "extjs/examples/"

      # Debugging
      # Turn multiprocessing off by default in Windows
@@ -276,6 +278,11 @@ module JsDuck
          @eg_iframe = canonical(path)
        end

        opts.on('--examples_base_url=URL',
          "Base URL for examples with relative URL-s.", " ") do |path|
          @examples_base_url = path
        end

        opts.separator "Debugging:"
        opts.separator ""

+1 −2
Original line number Diff line number Diff line
@@ -131,7 +131,6 @@ Ext.define('Docs.controller.Examples', {
    },

    openInNewWindow: function() {
        var example = this.getExample(this.activeUrl);
        window.open((Docs.exampleBaseUrl || "touch/examples/") + example.url);
        window.open(this.getExample(this.activeUrl).url);
    }
});
Loading