From f3ebe45bb69e0486acf8b2758d7d87cbfeb5a8bd Mon Sep 17 00:00:00 2001 From: Rene Saarsoo Date: Fri, 3 Feb 2012 18:39:34 -0800 Subject: [PATCH] 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. --- Rakefile | 4 ++-- lib/jsduck/app.rb | 2 +- lib/jsduck/examples.rb | 19 ++++++++++++++++--- lib/jsduck/options.rb | 7 +++++++ template/app/controller/Examples.js | 3 +-- template/app/view/examples/Container.js | 9 +-------- template/app/view/examples/TouchContainer.js | 8 +------- 7 files changed, 29 insertions(+), 23 deletions(-) diff --git a/Rakefile b/Rakefile index 9cc3e9f8..8028c52b 100644 --- a/Rakefile +++ b/Rakefile @@ -232,7 +232,6 @@ class JsDuckRunner head_html = <<-EOHTML 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 diff --git a/lib/jsduck/app.rb b/lib/jsduck/app.rb index 2bc8332f..23ce0131 100644 --- a/lib/jsduck/app.rb +++ b/lib/jsduck/app.rb @@ -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 diff --git a/lib/jsduck/examples.rb b/lib/jsduck/examples.rb index b6678738..3970ca2a 100644 --- a/lib/jsduck/examples.rb +++ b/lib/jsduck/examples.rb @@ -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 diff --git a/lib/jsduck/options.rb b/lib/jsduck/options.rb index 67be4ac9..011c5fe5 100644 --- a/lib/jsduck/options.rb +++ b/lib/jsduck/options.rb @@ -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 "" diff --git a/template/app/controller/Examples.js b/template/app/controller/Examples.js index f1927916..1ff40dab 100644 --- a/template/app/controller/Examples.js +++ b/template/app/controller/Examples.js @@ -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); } }); diff --git a/template/app/view/examples/Container.js b/template/app/view/examples/Container.js index 1fa3cace..cf03f69c 100644 --- a/template/app/view/examples/Container.js +++ b/template/app/view/examples/Container.js @@ -8,17 +8,11 @@ Ext.define('Docs.view.examples.Container', { alias: 'widget.examplecontainer', layout: 'fit', - exampleBaseUrl: "extjs/examples/", - initComponent: function() { this.tpl = new Ext.XTemplate( - '' + '' ); - if (Docs.exampleBaseUrl) { - this.exampleBaseUrl = Docs.exampleBaseUrl; - } - this.callParent(arguments); }, @@ -27,7 +21,6 @@ Ext.define('Docs.view.examples.Container', { * @param {Object} example Example object */ load: function(example) { - example.baseUrl = this.exampleBaseUrl; this.update(this.tpl.apply(example)); }, diff --git a/template/app/view/examples/TouchContainer.js b/template/app/view/examples/TouchContainer.js index 103e023a..cf712a14 100644 --- a/template/app/view/examples/TouchContainer.js +++ b/template/app/view/examples/TouchContainer.js @@ -14,7 +14,6 @@ Ext.define('Docs.view.examples.TouchContainer', { cls: 'example-container iScroll', autoScroll: true, bodyPadding: '10 0 5 0', - exampleBaseUrl: "touch/examples/", initComponent: function() { this.dockedItems = [{ @@ -40,10 +39,6 @@ Ext.define('Docs.view.examples.TouchContainer', { ].join('') }]; - if (Docs.exampleBaseUrl) { - this.exampleBaseUrl = Docs.exampleBaseUrl; - } - this.callParent(arguments); }, @@ -52,10 +47,9 @@ Ext.define('Docs.view.examples.TouchContainer', { * @param {Object} example Example object */ load: function(example) { - var url = example.externalUrl || (this.exampleBaseUrl + example.url); this.title = example.text + " Example"; this.device = Ext.create('Docs.view.examples.Device', { - url: url, + url: example.url, device: example.device || "phone", orientation: example.orientation || "landscape" }); -- GitLab