diff options
| author | Vojta Jina | 2011-05-19 16:48:05 +0200 | 
|---|---|---|
| committer | Igor Minar | 2011-06-06 22:52:01 -0700 | 
| commit | 43b2cd45f0b42efb67497a6471f3a1b26d792bd9 (patch) | |
| tree | 4c51a94684a7f4906113d5a260e8cd1a713b1980 /docs/src/ngdoc.js | |
| parent | e389911a35a4838ddba4f22f962c484c42f1017f (diff) | |
| download | angular.js-43b2cd45f0b42efb67497a6471f3a1b26d792bd9.tar.bz2 | |
Allow relative links in docs
So you can use links without section when they link within the section.
Diffstat (limited to 'docs/src/ngdoc.js')
| -rw-r--r-- | docs/src/ngdoc.js | 58 | 
1 files changed, 22 insertions, 36 deletions
| diff --git a/docs/src/ngdoc.js b/docs/src/ngdoc.js index e1ffb858..70e393a8 100644 --- a/docs/src/ngdoc.js +++ b/docs/src/ngdoc.js @@ -57,36 +57,25 @@ Doc.prototype = {      return words.join(' ');    }, - -  /* -   * This function is here to act as a huristic based translator from the old style urls to -   * the new style which use sections. +  /** +   * Converts relative urls (without section) into absolute +   * Absolute url means url with section +   * +   * @example +   * - if the link is inside any api doc: +   * angular.widget -> api/angular.widget +   * +   * - if the link is inside any guid doc: +   * intro -> guide/intro +   * +   * @param {string} url Absolute or relative url +   * @returns {string} Absolute url     */ -  sectionHuristic: function (url){ -    // if we are new styl URL with section/id then just return; +  convertUrlToAbsolute: function(url) {      if (url.match(/\//)) return url; -    var match = url.match(/(\w+)(\.(.*))?/); -    var section = match[1]; -    var id = match[3] || 'index'; -    switch(section) { -      case 'angular': -        section = 'api'; -        id = 'angular.' + id; -        break; -      case 'api': -      case 'cookbook': -      case 'guide': -      case 'intro': -      case 'tutorial': -        break; -      default: -        id = section + '.' + id; -        section = 'intro'; -    } -    var newUrl = section + '/' + (id || 'index'); -    console.log('WARNING:', 'found old style url', url, 'at', this.file, this.line, -        'converting to', newUrl); -    return newUrl; + +    // remove this after +    return this.section + '/' + url;    },    markdown: function (text) { @@ -126,16 +115,13 @@ Doc.prototype = {          text = text.replace(/{@link\s+([^\s}]+)\s*([^}]*?)\s*}/g,            function(_all, url, title){              var isFullUrl = url.match(IS_URL), -                // FIXME(vojta) angular link could be api.angular now with sections -                isAngular = url.match(IS_ANGULAR); +                // FIXME(vojta) angular link could be api/angular now with sections +                isAngular = url.match(IS_ANGULAR), +                absUrl = isFullUrl ? url : self.convertUrlToAbsolute(url); -            if (!isFullUrl) { -              // TODO(vojta) there could be relative link, but not angular -              // do we want to store all links (and check even the full links like http://github.com ? -              self.links.push(self.sectionHuristic(url)); -            } +            if (!isFullUrl) self.links.push(absUrl); -            return '<a href="' + (isFullUrl ? '' + url : '#!' + self.sectionHuristic(url)) + '">' +            return '<a href="' + (isFullUrl ? '' + url : '#!' + absUrl) + '">'                + (isAngular ? '<code>' : '')                + (title || url).replace(/\n/g, ' ')                + (isAngular ? '</code>' : '') | 
