From ffc48c02f7f028b4bcd6f3f56f675e9020bf9dd9 Mon Sep 17 00:00:00 2001 From: Andy Joslin Date: Wed, 12 Mar 2014 17:23:37 -0600 Subject: [PATCH] docs: fix problems with multiple versions --- docs/docs.config.js | 1 + docs/nightly/index.md | 15 --------- docs/processors/index-page.js | 6 ++-- docs/processors/pages-data.js | 23 ------------- docs/processors/version-data.js | 43 +++++++++++++++++++++++++ docs/templates/lib/yaml.template.html | 3 +- docs/templates/pages-data.template.html | 17 +++++----- gulpfile.js | 7 ++-- 8 files changed, 62 insertions(+), 53 deletions(-) delete mode 100644 docs/nightly/index.md create mode 100644 docs/processors/version-data.js diff --git a/docs/docs.config.js b/docs/docs.config.js index f9b4cd8e98..f98fc91481 100644 --- a/docs/docs.config.js +++ b/docs/docs.config.js @@ -59,6 +59,7 @@ module.exports = function(config) { }); config.append('processing.processors', [ + require('./processors/version-data'), require('./processors/git-data'), require('./processors/keywords'), require('./processors/pages-data'), diff --git a/docs/nightly/index.md b/docs/nightly/index.md deleted file mode 100644 index a0bceee5c4..0000000000 --- a/docs/nightly/index.md +++ /dev/null @@ -1,15 +0,0 @@ ---- -layout: docs_0.9.0 -active: javascript -title: Javascript -header_sub_title: Extend Ionic even further with the power of AngularJS ---- - -# AngularJS Extensions - -Ionic is both a CSS framework and a Javascript UI library. Many components need Javascript in order to produce magic, though often components -can easily be used without coding through framework extensions such as our AngularIonic extensions. - -Ionic follows the View Controller pattern popularized in such frameworks as Cocoa Touch. In the View Controller pattern, we treat different sections of the interface as child Views or even child View Controllers that contain other views. View Controllers then "power" the Views inside of them to provide interaction and UI functionality. A great example is the Tab Bar View Controller which processes taps on a Tab Bar to switch between a set of viewable panes. - -Explore our API docs for detailed information on the View Controllers and Javascript utilities available in Ionic. diff --git a/docs/processors/index-page.js b/docs/processors/index-page.js index 37154fffc3..dc4dce6556 100644 --- a/docs/processors/index-page.js +++ b/docs/processors/index-page.js @@ -1,6 +1,7 @@ var path = require('canonical-path'); var log = require('winston'); +var currentVersion; var contentsFolder; module.exports = { name: 'index-page', @@ -8,15 +9,16 @@ module.exports = { runBefore: ['extra-docs-added'], description: 'Create documentation index page', init: function(config) { + currentVersion = config.get('currentVersion'); contentsFolder = config.get('rendering.contentsFolder'); }, process: function(docs) { docs.push({ docType: 'index-page', id: 'index-page', + currentVersion: currentVersion, template: 'index.template.html', - outputPath: path.resolve(__dirname, '../../tmp/ionic-site/', contentsFolder, 'index.md') + outputPath: contentsFolder + '/index.md' }); - log.warn(docs[docs.length-1]); } }; diff --git a/docs/processors/pages-data.js b/docs/processors/pages-data.js index cc4f652503..20777ec1b5 100644 --- a/docs/processors/pages-data.js +++ b/docs/processors/pages-data.js @@ -1,8 +1,6 @@ var _ = require('lodash'); var path = require('canonical-path'); var log = require('winston'); -var fs = require('fs'); -var semver = require('semver'); var AREA_NAMES = { api: 'API', @@ -209,7 +207,6 @@ module.exports = { .indexBy('path') .value(); - var docData = { docType: 'pages-data', id: 'pages-data', @@ -220,26 +217,6 @@ module.exports = { pages: pages }; - var docsBaseFolder = path.resolve(__dirname, '../../tmp/ionic-site/docs'); - var pkg = require('../../package.json'); - - //Array of versions sorted backwards - var versions = fs.readdirSync(docsBaseFolder) - .filter(function(name) { - return semver.valid(name) || name == 'nightly'; - }) - .sort(semver.rcompare); - if (!_.contains(versions, currentVersion)) { - versions.unshift(currentVersion); - } - docData.versions = versions.map(function(ver) { - return { - href: '/docs/' + ver, - name: ver - }; - }); - docData.currentVersion = _.find(docData.versions, { name: currentVersion }); - docs.push(docData); } }; diff --git a/docs/processors/version-data.js b/docs/processors/version-data.js new file mode 100644 index 0000000000..76a6d01429 --- /dev/null +++ b/docs/processors/version-data.js @@ -0,0 +1,43 @@ +var _ = require('lodash'); +var fs = require('fs'); +var semver = require('semver'); +var path = require('canonical-path'); + +var basePath; +var outputFolder; +var currentVersion; +module.exports = { + name: 'version-data', + description: 'Give a list of all available versions to the template', + runBefore: ['pages-data'], + init: function(config) { + basePath = config.get('basePath'); + outputFolder = config.get('rendering.outputFolder'); + currentVersion = config.get('currentVersion'); + }, + process: function(docs, extraData) { + var docsBaseFolder = path.resolve(basePath, outputFolder, 'docs'); + + //Array of versions sorted backwards + var versions = fs.readdirSync(docsBaseFolder) + .filter(semver.valid) + .sort(semver.rcompare); + + //Add current version to the top of the list if not exists + !_.contains(versions, currentVersion) && versions.unshift(currentVersion); + + //Add nightly to the top of the list if not exists + !_.contains(versions, 'nightly') && versions.unshift('nightly'); + + versions = versions.map(function(ver) { + return { + href: '/docs/' + ver, + name: ver + }; + }); + extraData.version = { + list: versions, + current: _.find(versions, { name: currentVersion }) + }; + } +}; diff --git a/docs/templates/lib/yaml.template.html b/docs/templates/lib/yaml.template.html index 3fd487f8f9..87daeb4917 100644 --- a/docs/templates/lib/yaml.template.html +++ b/docs/templates/lib/yaml.template.html @@ -1,3 +1,4 @@ layout: docs_0.9.0 active: javascript -version: "nightly" +version: "<$ version.current.name $>" +versionHref: "<$ version.current.href $>" diff --git a/docs/templates/pages-data.template.html b/docs/templates/pages-data.template.html index 5fe53b2cc9..89179b3bb2 100644 --- a/docs/templates/pages-data.template.html +++ b/docs/templates/pages-data.template.html @@ -152,31 +152,32 @@