From 389d4879da4aa620ee95d789b19ff9be44eb730a Mon Sep 17 00:00:00 2001 From: Peter Bacon Darwin Date: Wed, 12 Feb 2014 22:47:42 +0000 Subject: chore(doc-gen): new docs chore(doc-gen): implement dgeni --- docs/app/src/directives.js | 35 +++++ docs/app/src/docs.js | 128 ++++++++++++++++++ docs/app/src/errors.js | 62 +++++++++ docs/app/src/examples.js | 266 ++++++++++++++++++++++++++++++++++++++ docs/app/src/navigationService.js | 24 ++++ docs/app/src/search.js | 149 +++++++++++++++++++++ docs/app/src/tutorials.js | 58 +++++++++ docs/app/src/versions.js | 15 +++ 8 files changed, 737 insertions(+) create mode 100644 docs/app/src/directives.js create mode 100644 docs/app/src/docs.js create mode 100644 docs/app/src/errors.js create mode 100644 docs/app/src/examples.js create mode 100644 docs/app/src/navigationService.js create mode 100644 docs/app/src/search.js create mode 100644 docs/app/src/tutorials.js create mode 100644 docs/app/src/versions.js (limited to 'docs/app/src') diff --git a/docs/app/src/directives.js b/docs/app/src/directives.js new file mode 100644 index 00000000..15bef69b --- /dev/null +++ b/docs/app/src/directives.js @@ -0,0 +1,35 @@ +angular.module('directives', []) + +.directive('code', function() { + return { restrict:'E', terminal: true }; +}) + +/** + * backToTop Directive + * @param {Function} $anchorScroll + * + * @description Ensure that the browser scrolls when the anchor is clicked + */ +.directive('backToTop', ['$anchorScroll', function($anchorScroll) { + return function link(scope, element) { + element.on('click', function(event) { + scope.$apply($anchorScroll); + }); + }; +}]) + + +.directive('code', function() { + return { + restrict: 'E', + terminal: true, + compile: function(element) { + var linenums = element.hasClass('linenum') || element.parent()[0].nodeName === 'PRE'; + var match = /lang-(\S)+/.exec(element.className); + var lang = match && match[1]; + var html = element.html(); + element.html(window.prettyPrintOne(html, lang, linenums)); + } + }; +}); + diff --git a/docs/app/src/docs.js b/docs/app/src/docs.js new file mode 100644 index 00000000..5f9543d6 --- /dev/null +++ b/docs/app/src/docs.js @@ -0,0 +1,128 @@ +angular.module('docsApp', [ + 'ngRoute', + 'ngCookies', + 'ngSanitize', + 'ngAnimate', + 'versionsData', + 'pagesData', + 'directives', + 'errors', + 'examples', + 'search', + 'tutorials', + 'versions', + 'bootstrap', + 'bootstrapPrettify', + 'ui.bootstrap.dropdown' +]) + + +.config(function($locationProvider) { + $locationProvider.html5Mode(true).hashPrefix('!'); +}) + + +.controller('DocsController', function($scope, $rootScope, $location, $window, $cookies, NG_PAGES, NG_NAVIGATION, NG_VERSION) { + + $scope.fold = function(url) { + if(url) { + $scope.docs_fold = '/notes/' + url; + if(/\/build/.test($window.location.href)) { + $scope.docs_fold = '/build/docs' + $scope.docs_fold; + } + window.scrollTo(0,0); + } + else { + $scope.docs_fold = null; + } + }; + var OFFLINE_COOKIE_NAME = 'ng-offline', + INDEX_PATH = /^(\/|\/index[^\.]*.html)$/; + + + /********************************** + Publish methods + ***********************************/ + + $scope.navClass = function(navItem) { + return { + active: navItem.href && this.currentPage.path, + 'nav-index-section': navItem.type === 'section' + }; + }; + + $scope.afterPartialLoaded = function() { + $window._gaq.push(['_trackPageview', $location.path()]); + }; + + /** stores a cookie that is used by apache to decide which manifest ot send */ + $scope.enableOffline = function() { + //The cookie will be good for one year! + var date = new Date(); + date.setTime(date.getTime()+(365*24*60*60*1000)); + var expires = "; expires="+date.toGMTString(); + var value = angular.version.full; + document.cookie = OFFLINE_COOKIE_NAME + "="+value+expires+"; path=" + $location.path; + + //force the page to reload so server can serve new manifest file + window.location.reload(true); + }; + + + + /********************************** + Watches + ***********************************/ + + + $scope.$watch(function docsPathWatch() {return $location.path(); }, function docsPathWatchAction(path) { + // Strip off leading slash + if ( path.charAt(0)==='/' ) { + path = path.substr(1); + } + var currentPage = $scope.currentPage = NG_PAGES[path]; + + if ( currentPage ) { + $scope.currentArea = currentPage && NG_NAVIGATION[currentPage.area]; + var pathParts = currentPage.path.split('/'); + var breadcrumb = $scope.breadcrumb = []; + var breadcrumbPath = ''; + angular.forEach(pathParts, function(part) { + breadcrumbPath += part; + breadcrumb.push({ name: (NG_PAGES[breadcrumbPath]&&NG_PAGES[breadcrumbPath].name) || part, url: breadcrumbPath }); + breadcrumbPath += '/'; + }); + } else { + $scope.currentArea = null; + $scope.breadcrumb = []; + } + }); + + /********************************** + Initialize + ***********************************/ + + $scope.versionNumber = angular.version.full; + $scope.version = angular.version.full + " " + angular.version.codeName; + $scope.subpage = false; + $scope.offlineEnabled = ($cookies[OFFLINE_COOKIE_NAME] == angular.version.full); + $scope.futurePartialTitle = null; + $scope.loading = 0; + $scope.URL = URL; + $scope.$cookies = $cookies; + + $cookies.platformPreference = $cookies.platformPreference || 'gitUnix'; + + if (!$location.path() || INDEX_PATH.test($location.path())) { + $location.path('/api').replace(); + } + + // bind escape to hash reset callback + angular.element(window).on('keydown', function(e) { + if (e.keyCode === 27) { + $scope.$apply(function() { + $scope.subpage = false; + }); + } + }); +}); diff --git a/docs/app/src/errors.js b/docs/app/src/errors.js new file mode 100644 index 00000000..b91cfb81 --- /dev/null +++ b/docs/app/src/errors.js @@ -0,0 +1,62 @@ +angular.module('errors', ['ngSanitize']) + +.filter('errorLink', ['$sanitize', function ($sanitize) { + var LINKY_URL_REGEXP = /((ftp|https?):\/\/|(mailto:)?[A-Za-z0-9._%+-]+@)\S*[^\s\.\;\,\(\)\{\}<>]/g, + MAILTO_REGEXP = /^mailto:/, + STACK_TRACE_REGEXP = /:\d+:\d+$/; + + var truncate = function (text, nchars) { + if (text.length > nchars) { + return text.substr(0, nchars - 3) + '...'; + } + return text; + }; + + return function (text, target) { + var targetHtml = target ? ' target="' + target + '"' : ''; + + if (!text) return text; + + return $sanitize(text.replace(LINKY_URL_REGEXP, function (url) { + if (STACK_TRACE_REGEXP.test(url)) { + return url; + } + + // if we did not match ftp/http/mailto then assume mailto + if (!/^((ftp|https?):\/\/|mailto:)/.test(url)) url = 'mailto:' + url; + + return '' + + truncate(url.replace(MAILTO_REGEXP, ''), 60) + + ''; + })); + }; +}]) + + +.directive('errorDisplay', ['$location', 'errorLinkFilter', function ($location, errorLinkFilter) { + var interpolate = function (formatString) { + var formatArgs = arguments; + return formatString.replace(/\{\d+\}/g, function (match) { + // Drop the braces and use the unary plus to convert to an integer. + // The index will be off by one because of the formatString. + var index = +match.slice(1, -1); + if (index + 1 >= formatArgs.length) { + return match; + } + return formatArgs[index+1]; + }); + }; + + return { + link: function (scope, element, attrs) { + var search = $location.search(), + formatArgs = [attrs.errorDisplay], + i; + + for (i = 0; angular.isDefined(search['p'+i]); i++) { + formatArgs.push(search['p'+i]); + } + element.html(errorLinkFilter(interpolate.apply(null, formatArgs), '_blank')); + } + }; +}]); \ No newline at end of file diff --git a/docs/app/src/examples.js b/docs/app/src/examples.js new file mode 100644 index 00000000..44dd98f1 --- /dev/null +++ b/docs/app/src/examples.js @@ -0,0 +1,266 @@ +angular.module('examples', []) + +.directive('sourceEdit', function(getEmbeddedTemplate) { + return { + template: '
' + + '' + + ' Edit' + + '' + + '' + + '
', + scope: true, + controller: function($scope, $attrs, openJsFiddle, openPlunkr) { + var sources = { + module: $attrs.sourceEdit, + deps: read($attrs.sourceEditDeps), + html: read($attrs.sourceEditHtml), + css: read($attrs.sourceEditCss), + js: read($attrs.sourceEditJs), + json: read($attrs.sourceEditJson), + unit: read($attrs.sourceEditUnit), + scenario: read($attrs.sourceEditScenario) + }; + $scope.fiddle = function(e) { + e.stopPropagation(); + openJsFiddle(sources); + }; + $scope.plunkr = function(e) { + e.stopPropagation(); + openPlunkr(sources); + }; + } + }; + + function read(text) { + var files = []; + angular.forEach(text ? text.split(' ') : [], function(refId) { + // refId is index.html-343, so we need to strip the unique ID when exporting the name + files.push({name: refId.replace(/-\d+$/, ''), content: getEmbeddedTemplate(refId)}); + }); + return files; + } +}) + + +.factory('angularUrls', function($document) { + var urls = {}; + + angular.forEach($document.find('script'), function(script) { + var match = script.src.match(/^.*\/(angular[^\/]*\.js)$/); + if (match) { + urls[match[1].replace(/(\-\d.*)?(\.min)?\.js$/, '.js')] = match[0]; + } + }); + + return urls; +}) + + +.factory('formPostData', function($document) { + return function(url, fields) { + var form = angular.element('
'); + angular.forEach(fields, function(value, name) { + var input = angular.element(''); + input.attr('value', value); + form.append(input); + }); + $document.find('body').append(form); + form[0].submit(); + form.remove(); + }; +}) + + +.factory('prepareDefaultAppModule', function() { + return function(content) { + var deps = []; + angular.forEach(content.deps, function(file) { + if(file.name == 'angular-animate.js') { + deps.push('ngAnimate'); + } + }); + + var moduleName = 'App'; + return { + module : moduleName, + script : "angular.module('" + moduleName + "', [" + + (deps.length ? "'" + deps.join("','") + "'" : "") + "]);\n\n" + }; + }; +}) + +.factory('prepareEditorAssetTags', function(angularUrls) { + return function(content, options) { + options = options || {}; + var includeLocalFiles = options.includeLocalFiles; + var html = makeScriptTag(angularUrls['angular.js']); + + var allFiles = [].concat(content.js, content.css, content.html, content.json); + angular.forEach(content.deps, function(file) { + if (file.name !== 'angular.js') { + var isLocal = false; + for(var i=0;i\n'; + } + + function makeCssLinkTag(src) { + return '\n'; + } + }; +}) + + +.factory('openPlunkr', function(templateMerge, formPostData, prepareEditorAssetTags, prepareDefaultAppModule) { + return function(content) { + var hasRouting = false; + angular.forEach(content.deps, function(file) { + hasRouting = hasRouting || file.name == 'angular-route.js'; + }); + var indexHtmlContent = '\n' + + '\n' + + ' \n' + + '{{scriptDeps}}'; + + if(hasRouting) { + indexHtmlContent += '\n'; + } + + indexHtmlContent += '\n' + + ' \n\n' + + '{{indexContents}}\n\n' + + ' \n' + + '\n'; + + indexProp = { + module: content.module, + scriptDeps: prepareEditorAssetTags(content, { includeLocalFiles : true }), + indexContents: content.html[0].content + }; + + var allFiles = [].concat(content.js, content.css, content.html, content.json); + + if(!content.module) { + var moduleData = prepareDefaultAppModule(content); + indexProp.module = moduleData.module; + + var found = false; + angular.forEach(content.js, function(file) { + if(file.name == 'script.js') { + file.content = moduleData.script + file.content; + found = true; + } + }); + if(!found) { + indexProp.scriptDeps += '\n'; + allFiles.push({ + name : 'script.js', + content : moduleData.script + }); + } + } + + var postData = {}; + + angular.forEach(allFiles, function(file, index) { + if (file.content && file.name != 'index.html') { + postData['files[' + file.name + ']'] = file.content; + } + }); + + postData['files[index.html]'] = templateMerge(indexHtmlContent, indexProp); + postData['tags[]'] = "angularjs"; + + postData.private = true; + postData.description = 'AngularJS Example Plunkr'; + + formPostData('http://plnkr.co/edit/?p=preview', postData); + }; +}) + +.factory('openJsFiddle', function(templateMerge, formPostData, prepareEditorAssetTags, prepareDefaultAppModule) { + var HTML = '
\n{{html:2}}
', + CSS = ' \n' + + '{{head:0}}