diff --git a/LICENSE.md b/LICENSE.md index 44c92998..5ddaac8a 100644 --- a/LICENSE.md +++ b/LICENSE.md @@ -93,28 +93,12 @@ http://www.sitepen.com/blog/2010/03/02/commonjs-utilities/ Licensed under the MIT license. -Mustache.js Templates +Simple JavaScript Templating ------------------- -Mustache is -Copyright (c) 2009 Chris Wanstrath (Ruby) -Copyright (c) 2010 Jan Lehnardt (JavaScript) +Simple JavaScript Templating is +Copyright (c) John Resig - http://ejohn.org/ -Permission is hereby granted, free of charge, to any person obtaining -a copy of this software and associated documentation files (the -"Software"), to deal in the Software without restriction, including -without limitation the rights to use, copy, modify, merge, publish, -distribute, sublicense, and/or sell copies of the Software, and to -permit persons to whom the Software is furnished to do so, subject to -the following conditions: - -The above copyright notice and this permission notice shall be -included in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. \ No newline at end of file +Licensed under the MIT license. + +http://ejohn.org/blog/javascript-micro-templating/ \ No newline at end of file diff --git a/modules/jsdoc/doclet.js b/modules/jsdoc/doclet.js index 1217b580..a1147ff3 100644 --- a/modules/jsdoc/doclet.js +++ b/modules/jsdoc/doclet.js @@ -214,17 +214,19 @@ return o; } - Doclet.prototype.isInner = function() { - var access = this.tagValue('access'); + Doclet.prototype.getAccess = function() { + var attrib = this.tagValue('attrib'); - if (!access) { - return false; + if (!attrib) { + return ''; } - else if (typeof access === 'string') { - return (access === 'inner'); + else if (typeof attrib === 'string' && ['inner', 'static', 'instance'].indexOf(attrib) > -1) { + return attrib; } else { - return (access.indexOf('inner') > -1); + if (attrib.indexOf('instance') > -1) { return 'instance'; } + else if (attrib.indexOf('inner') > -1) { return 'inner'; } + else if (attrib.indexOf('static') > -1) { return 'static'; } } } @@ -285,8 +287,8 @@ for (var i = 0; i < tags.length; i++) { tagAbout = tagDictionary.lookUp(tags[i].name); - if (tagAbout.setsDocletAccess) { - tags[tags.length] = parse_tag.fromText('access '+tags[i].name); + if (tagAbout.setsDocletAttrib) { + tags[tags.length] = parse_tag.fromText('attrib '+tags[i].name); } if (tagAbout.impliesTag) { // TODO allow a template string? diff --git a/modules/jsdoc/name.js b/modules/jsdoc/name.js index 4500a2ca..dc2e55b3 100644 --- a/modules/jsdoc/name.js +++ b/modules/jsdoc/name.js @@ -18,6 +18,7 @@ currentModule = moduleName; } + var attribModes = { '.':'static', '~':'inner', '#':'instance' }; /** Calculates the path, memberof and name values. @method resolve @@ -29,37 +30,53 @@ name = doclet.tagValue('name') || '', memberof = doclet.tagValue('memberof') || '', path, - shortname, + attrib, prefix; // only keep the first word of the first tagged name - name = name.split(/\s+/g)[0]; + name = name.split(/\s+/g)[0]; // TODO allow spaces in quoted names? if (currentModule) { name = name.replace(/^exports\.(?=.+$)/, currentModule + '.'); } - name = name.replace(/\.prototype\.?/g, '#'); + path = name = name.replace(/\.prototype\.?/g, '#'); - path = shortname = name; - - if (memberof) { + if (memberof) { // @memberof tag given // like @name foo.bar, @memberof foo if (name.indexOf(memberof) === 0) { - path = name; - [prefix, name] = exports.shorten(name); + [prefix, attrib, name] = exports.shorten(name); + } + else { // like @name bar, @memberof foo + if ( /([.~#])$/.test(memberof) ) { // like @memberof foo# or @memberof foo~ + path = memberof + name; + attrib = RegExp.$1; + if (name) { doclet.addTag('attrib', attribModes[attrib]); } + } + else { + attrib = doclet.getAccess(); + + if (!attrib) { + attrib = 'static'; // default attrib is static + if (name) { doclet.addTag('attrib', 'static'); } + path = memberof + '.' + name; + } + else { + path = memberof + (attrib === 'inner'? '~':'#') + name; + } + } } } else if (isa !== 'file') { - [memberof, name] = exports.shorten(name); + [prefix, attrib, name] = exports.shorten(name); - if (memberof) { - // memberof ends with a ~ means it's an inner symbol - /^(.+?)(~)?$/.test(memberof); - var nameImpliesInner = (RegExp.$2 === '~'); - - if (memberof) { doclet.setTag('memberof', RegExp.$1); } // side effect: modifies RegExp.$2 - if (nameImpliesInner) { doclet.addTag('access', 'inner'); } + if (prefix) { + doclet.setTag('memberof', prefix); + if (name) { doclet.addTag('attrib', attribModes[attrib]); } + } + else if (name) { + // global symbol + doclet.addTag('attrib', 'global'); } } @@ -76,8 +93,8 @@ if (name) doclet.setTag('name', name); - if (memberof && name.indexOf(memberof) !== 0) { - path = memberof + (/[#~]$/.test(memberof)? '' : '.') + ns + name; + if (!path && memberof && name.indexOf(memberof) !== 0) { + path = memberof + (attrib? attrib : '') + ns + name; } else if (ns) { path = ns + name }; @@ -88,24 +105,25 @@ return path; } + exports.shorten = function(path) { // quoted strings in a path are atomic var atoms = [], - cursor = 0; + attrib; // ., ~, or # + path = path.replace(/(".+?")/g, function($) { - //$ = $.slice(1, -1); // trim quotes? - var token = '@{' + atoms.length + '}@'; atoms.push($); return token; }); var shortname = path.split(/([#.~])/).pop(), - splitOn = RegExp.$1, + splitOn = RegExp.$1 || '.', + attrib = splitOn, splitAt = path.lastIndexOf(splitOn), prefix = (splitOn && splitAt !== -1)? path.slice(0, splitAt) : ''; - if (splitOn === '#' || splitOn === '~') { prefix = prefix + splitOn; } + //if (splitOn === '#' || splitOn === '~') { prefix = prefix + splitOn; } // restore quoted strings back again for (var i = 0, leni = atoms.length; i < leni; i++) { @@ -113,7 +131,7 @@ shortname = shortname.replace('@{'+i+'}@', atoms[i]); } - return [prefix, shortname]; + return [prefix, attrib, shortname]; } /** @@ -149,7 +167,7 @@ enclosingDoc = exports.docFromNode(enclosing); if (enclosingDoc) { - if (enclosingDoc.isInner()) memberof = ''; // inner functions have `this` scope of global + if (enclosingDoc.getAccess() === 'inner') memberof = ''; // inner functions have `this` scope of global else memberof = enclosingDoc.tagValue('path'); } else { diff --git a/modules/jsdoc/schema.js b/modules/jsdoc/schema.js index f5e20744..c818dada 100644 --- a/modules/jsdoc/schema.js +++ b/modules/jsdoc/schema.js @@ -38,10 +38,10 @@ exports.jsdocSchema = { "maxItems": 1, "enum": ["constructor", "module", "event", "namespace", "method", "property", "enum", "class", "interface", "constant", "file"] }, - "access": { + "attrib": { "type": "string", "maxItems": 1, - "enum": ["private", "protected", "public"] + "enum": ["private", "protected", "public", "global", "static", "instance", "readonly"] }, "type": { "type": "array", diff --git a/modules/jsdoc/tagdictionary.js b/modules/jsdoc/tagdictionary.js index 317b400b..7f4d13e6 100644 --- a/modules/jsdoc/tagdictionary.js +++ b/modules/jsdoc/tagdictionary.js @@ -57,7 +57,7 @@ setsDocletIsa : false, // the name of this tag is used to define the doclet's isa property setsDocletDesc : false, setsDocletName : false, // this tag can be used to name the doclet - setsDocletAccess : false, // the name of this tag becomes the access of the doclet + setsDocletAttrib : false, // the name of this tag becomes the attribute of the doclet setsDocletType : false, // the type of this tag becomes th type of the doclet setsDocletDocspace: false, // the name of this tag becomes the docspace for the doclet name, like "event:" canHaveType : false, // this tag can have a {type} @@ -269,11 +269,11 @@ canHavePdesc: true }); - /** Syntax: @access - @property {TagDefinition} access + /** Syntax: @attrib + @property {TagDefinition} attrib @memberOf module:jsdoc/tagdictionary.tagDefinitions */ - new TagDefinition('access', { + new TagDefinition('attrib', { isExported: true }); @@ -282,7 +282,7 @@ @memberOf module:jsdoc/tagdictionary.tagDefinitions */ new TagDefinition('private', { - setsDocletAccess: true + setsDocletAttrib: true }); /** Syntax: @protected @@ -290,7 +290,7 @@ @memberOf module:jsdoc/tagdictionary.tagDefinitions */ new TagDefinition('protected', { - setsDocletAccess: true + setsDocletAttrib: true }); /** Syntax: @readonly @@ -298,7 +298,7 @@ @memberOf module:jsdoc/tagdictionary.tagDefinitions */ new TagDefinition('readonly', { - setsDocletAccess: true + setsDocletAttrib: true }); /** Syntax: @inner @@ -306,7 +306,31 @@ @memberOf module:jsdoc/tagdictionary.tagDefinitions */ new TagDefinition('inner', { - setsDocletAccess: true + setsDocletAttrib: true + }); + + /** Syntax: @static + @property {TagDefinition} static + @memberOf module:jsdoc/tagdictionary.tagDefinitions + */ + new TagDefinition('static', { + setsDocletAttrib: true + }); + + /** Syntax: @global + @property {TagDefinition} global + @memberOf module:jsdoc/tagdictionary.tagDefinitions + */ + new TagDefinition('global', { + setsDocletAttrib: true + }); + + /** Syntax: @instance + @property {TagDefinition} instance + @memberOf module:jsdoc/tagdictionary.tagDefinitions + */ + new TagDefinition('instance', { + setsDocletAttrib: true }); /** Syntax: @public @@ -314,7 +338,7 @@ @memberOf module:jsdoc/tagdictionary.tagDefinitions */ new TagDefinition('public', { - setsDocletAccess: true + setsDocletAttrib: true }); /** Syntax: @exception|throws diff --git a/templates/default/publish.js b/templates/default/publish.js index 5089b5f8..2901964e 100644 --- a/templates/default/publish.js +++ b/templates/default/publish.js @@ -1,26 +1,107 @@ (function() { -load(BASEDIR + '/templates/lib/janl/mustache.js'); +//// include your template engine of choice + /** + Apply template formatting to some data. + @function tmpl + @param {string} templateFilepath + @param {Object} data + @return {string} + */ + load(BASEDIR + '/templates/lib/resig/tmpl.js'); -publish = function(docs, opts) { - docs.doc.filter(function($) { - $.desc = linkify($.desc); - $.path = "" + $.path + ''; - }); - var template = readFile(BASEDIR + '/templates/default/tmpl/index.html'); - print(Mustache.to_html(template, docs)); -} - -function linkify(text) { - if (typeof text === 'string') { - return text.replace(/\{@link\s+(.+?)(:? (.+?))?\}/gi, function(str, p1, p2, offset, s) { - return "" + (p2 || p1) + ''; - }); +//// define a global publish function, will be called by JSDoc + /** + Generate the output from the documentation data collected by JSDoc. + @function publish + @param {module:jsdoc/docset.doclets} docs + @param {Object} opts + */ + publish = function(docs, opts) { + /** + Turn JSDOC {@link}s into usable HTML links. + @ignore For internal use only. + @function linkify + @param {string} text Containing {@link}s presumably. + @return {string} The text with tags instead. + */ + function linkify(text) { + if (typeof text === 'string') { + return text.replace(/\{@link\s+(.+?)(:? (.+?))?\}/gi, function(str, p1, p2, offset, s) { + return "" + (p2 || p1) + ''; + }); + } } -} + + function getDoc(docpath) { + var i = docs.doc.length; + while (i--) { + if (docs.doc[i].path === docpath) { + return docs.doc[i]; + } + } + } + + + function docpathToUri(docpath) { + var page, doc, uri; + if (uri = docpathToUri.cache[docpath]) { return uri; } + + doc = getDoc(docpath); + if (doc && doc.memberof) { +//print('=doc.memberof is '+doc.memberof); + uri = 'doc' + makeFileNameSafe(doc.memberof)+'.html#'+doc.name; + } + else { +//print('~doc.path is '+doc.path); + uri = 'doc' + makeFileNameSafe(doc.path)+'.html'; + } + + return uri; + } + docpathToUri.cache = {}; + + function makeFileNameSafe(docpath) { + return hash(docpath); + } + makeFileNameSafe.id = 0; + + function hash(str) { + //if ( typeof(hash.crc) === 'undefined' ) { + hash.crc = 0; + //} + var x = 0; + var y = 0; + + hash.crc = hash.crc ^ (-1); + for( var i = 0, iTop = str.length; i < iTop; i++ ) { + y = ( hash.crc ^ str.charCodeAt( i ) ) & 0xFF; + x = '0x' + hash.table.substr( y * 9, 8 ); + hash.crc = ( hash.crc >>> 8 ) ^ x; + } + + return hash.crc ^ (-1); + } + hash.table = "00000000 77073096 EE0E612C 990951BA 076DC419 706AF48F E963A535 9E6495A3 0EDB8832 79DCB8A4 E0D5E91E 97D2D988 09B64C2B 7EB17CBD E7B82D07 90BF1D91 1DB71064 6AB020F2 F3B97148 84BE41DE 1ADAD47D 6DDDE4EB F4D4B551 83D385C7 136C9856 646BA8C0 FD62F97A 8A65C9EC 14015C4F 63066CD9 FA0F3D63 8D080DF5 3B6E20C8 4C69105E D56041E4 A2677172 3C03E4D1 4B04D447 D20D85FD A50AB56B 35B5A8FA 42B2986C DBBBC9D6 ACBCF940 32D86CE3 45DF5C75 DCD60DCF ABD13D59 26D930AC 51DE003A C8D75180 BFD06116 21B4F4B5 56B3C423 CFBA9599 B8BDA50F 2802B89E 5F058808 C60CD9B2 B10BE924 2F6F7C87 58684C11 C1611DAB B6662D3D 76DC4190 01DB7106 98D220BC EFD5102A 71B18589 06B6B51F 9FBFE4A5 E8B8D433 7807C9A2 0F00F934 9609A88E E10E9818 7F6A0DBB 086D3D2D 91646C97 E6635C01 6B6B51F4 1C6C6162 856530D8 F262004E 6C0695ED 1B01A57B 8208F4C1 F50FC457 65B0D9C6 12B7E950 8BBEB8EA FCB9887C 62DD1DDF 15DA2D49 8CD37CF3 FBD44C65 4DB26158 3AB551CE A3BC0074 D4BB30E2 4ADFA541 3DD895D7 A4D1C46D D3D6F4FB 4369E96A 346ED9FC AD678846 DA60B8D0 44042D73 33031DE5 AA0A4C5F DD0D7CC9 5005713C 270241AA BE0B1010 C90C2086 5768B525 206F85B3 B966D409 CE61E49F 5EDEF90E 29D9C998 B0D09822 C7D7A8B4 59B33D17 2EB40D81 B7BD5C3B C0BA6CAD EDB88320 9ABFB3B6 03B6E20C 74B1D29A EAD54739 9DD277AF 04DB2615 73DC1683 E3630B12 94643B84 0D6D6A3E 7A6A5AA8 E40ECF0B 9309FF9D 0A00AE27 7D079EB1 F00F9344 8708A3D2 1E01F268 6906C2FE F762575D 806567CB 196C3671 6E6B06E7 FED41B76 89D32BE0 10DA7A5A 67DD4ACC F9B9DF6F 8EBEEFF9 17B7BE43 60B08ED5 D6D6A3E8 A1D1937E 38D8C2C4 4FDFF252 D1BB67F1 A6BC5767 3FB506DD 48B2364B D80D2BDA AF0A1B4C 36034AF6 41047A60 DF60EFC3 A867DF55 316E8EEF 4669BE79 CB61B38C BC66831A 256FD2A0 5268E236 CC0C7795 BB0B4703 220216B9 5505262F C5BA3BBE B2BD0B28 2BB45A92 5CB36A04 C2D7FFA7 B5D0CF31 2CD99E8B 5BDEAE1D 9B64C2B0 EC63F226 756AA39C 026D930A 9C0906A9 EB0E363F 72076785 05005713 95BF4A82 E2B87A14 7BB12BAE 0CB61B38 92D28E9B E5D5BE0D 7CDCEFB7 0BDBDF21 86D3D2D4 F1D4E242 68DDB3F8 1FDA836E 81BE16CD F6B9265B 6FB077E1 18B74777 88085AE6 FF0F6A70 66063BCA 11010B5C 8F659EFF F862AE69 616BFFD3 166CCF45 A00AE278 D70DD2EE 4E048354 3903B3C2 A7672661 D06016F7 4969474D 3E6E77DB AED16A4A D9D65ADC 40DF0B66 37D83BF0 A9BCAE53 DEBB9EC5 47B2CF7F 30B5FFE9 BDBDF21C CABAC28A 53B39330 24B4A3A6 BAD03605 CDD70693 54DE5729 23D967BF B3667A2E C4614AB8 5D681B02 2A6F2B94 B40BBE37 C30C8EA1 5A05DF1B 2D02EF8D"; -function symbolnameToLinkname(symbolName) { - return symbolName; -} + // turn symbol paths into anchors + docs.doc.filter(function($) { + $.desc = linkify($.desc); + }); + + var template = BASEDIR + '/templates/default/tmpl/index.html'; + print( tmpl(template, docs) ); + } + +//// export some utilities to the template + /** + Return the first line of the given description text. + @method tmpl.summarize + @param {string} desc + @return {string} + */ + tmpl.summarize = function(desc) { + return /(.*)/.test(desc), RegExp.$1; + } })(); \ No newline at end of file diff --git a/templates/default/tmpl/index.html b/templates/default/tmpl/index.html index c6548793..5ed0b363 100644 --- a/templates/default/tmpl/index.html +++ b/templates/default/tmpl/index.html @@ -29,11 +29,13 @@

All Symbols

+<% if (doc.length) { %>
    -{{#doc}} -
  • {{{isa}}} {{{path}}} - {{{desc}}}
  • -{{/doc}} + <% for ( var i = 0; i < doc.length; i++ ) { %> +
  • {<%= doc[i].isa %>} <%= doc[i].path %> - <%= tmpl.summarize(doc[i].desc) %>
  • + <% } %>
+<% } %> \ No newline at end of file diff --git a/templates/lib/janl/mustache.js b/templates/lib/janl/mustache.js deleted file mode 100644 index 8d9f1289..00000000 --- a/templates/lib/janl/mustache.js +++ /dev/null @@ -1,324 +0,0 @@ -/* - mustache.js — Logic-less templates in JavaScript - - See http://mustache.github.com/ for more info. -*/ - -var Mustache = function() { - var Renderer = function() {}; - - Renderer.prototype = { - otag: "{{", - ctag: "}}", - pragmas: {}, - buffer: [], - pragmas_implemented: { - "IMPLICIT-ITERATOR": true - }, - context: {}, - - render: function(template, context, partials, in_recursion) { - // reset buffer & set context - if(!in_recursion) { - this.context = context; - this.buffer = []; // TODO: make this non-lazy - } - - // fail fast - if(!this.includes("", template)) { - if(in_recursion) { - return template; - } else { - this.send(template); - return; - } - } - - template = this.render_pragmas(template); - var html = this.render_section(template, context, partials); - if(in_recursion) { - return this.render_tags(html, context, partials, in_recursion); - } - - this.render_tags(html, context, partials, in_recursion); - }, - - /* - Sends parsed lines - */ - send: function(line) { - if(line != "") { - this.buffer.push(line); - } - }, - - /* - Looks for %PRAGMAS - */ - render_pragmas: function(template) { - // no pragmas - if(!this.includes("%", template)) { - return template; - } - - var that = this; - var regex = new RegExp(this.otag + "%([\\w-]+) ?([\\w]+=[\\w]+)?" + - this.ctag); - return template.replace(regex, function(match, pragma, options) { - if(!that.pragmas_implemented[pragma]) { - throw({message: - "This implementation of mustache doesn't understand the '" + - pragma + "' pragma"}); - } - that.pragmas[pragma] = {}; - if(options) { - var opts = options.split("="); - that.pragmas[pragma][opts[0]] = opts[1]; - } - return ""; - // ignore unknown pragmas silently - }); - }, - - /* - Tries to find a partial in the curent scope and render it - */ - render_partial: function(name, context, partials) { - name = this.trim(name); - if(!partials || partials[name] === undefined) { - throw({message: "unknown_partial '" + name + "'"}); - } - if(typeof(context[name]) != "object") { - return this.render(partials[name], context, partials, true); - } - return this.render(partials[name], context[name], partials, true); - }, - - /* - Renders inverted (^) and normal (#) sections - */ - render_section: function(template, context, partials) { - if(!this.includes("#", template) && !this.includes("^", template)) { - return template; - } - - var that = this; - // CSW - Added "+?" so it finds the tighest bound, not the widest - var regex = new RegExp(this.otag + "(\\^|\\#)\\s*(.+)\\s*" + this.ctag + - "\n*([\\s\\S]+?)" + this.otag + "\\/\\s*\\2\\s*" + this.ctag + - "\\s*", "mg"); - - // for each {{#foo}}{{/foo}} section do... - return template.replace(regex, function(match, type, name, content) { - var value = that.find(name, context); - if(type == "^") { // inverted section - if(!value || that.is_array(value) && value.length === 0) { - // false or empty list, render it - return that.render(content, context, partials, true); - } else { - return ""; - } - } else if(type == "#") { // normal section - if(that.is_array(value)) { // Enumerable, Let's loop! - return that.map(value, function(row) { - return that.render(content, that.create_context(row), - partials, true); - }).join(""); - } else if(that.is_object(value)) { // Object, Use it as subcontext! - return that.render(content, that.create_context(value), - partials, true); - } else if(typeof value === "function") { - // higher order section - return value.call(context, content, function(text) { - return that.render(text, context, partials, true); - }); - } else if(value) { // boolean section - return that.render(content, context, partials, true); - } else { - return ""; - } - } - }); - }, - - /* - Replace {{foo}} and friends with values from our view - */ - render_tags: function(template, context, partials, in_recursion) { - // tit for tat - var that = this; - - var new_regex = function() { - return new RegExp(that.otag + "(=|!|>|\\{|%)?([^\\/#\\^]+?)\\1?" + - that.ctag + "+", "g"); - }; - - var regex = new_regex(); - var tag_replace_callback = function(match, operator, name) { - switch(operator) { - case "!": // ignore comments - return ""; - case "=": // set new delimiters, rebuild the replace regexp - that.set_delimiters(name); - regex = new_regex(); - return ""; - case ">": // render partial - return that.render_partial(name, context, partials); - case "{": // the triple mustache is unescaped - return that.find(name, context); - default: // escape the value - return that.escape(that.find(name, context)); - } - }; - var lines = template.split("\n"); - for(var i = 0; i < lines.length; i++) { - lines[i] = lines[i].replace(regex, tag_replace_callback, this); - if(!in_recursion) { - this.send(lines[i]); - } - } - - if(in_recursion) { - return lines.join("\n"); - } - }, - - set_delimiters: function(delimiters) { - var dels = delimiters.split(" "); - this.otag = this.escape_regex(dels[0]); - this.ctag = this.escape_regex(dels[1]); - }, - - escape_regex: function(text) { - // thank you Simon Willison - if(!arguments.callee.sRE) { - var specials = [ - '/', '.', '*', '+', '?', '|', - '(', ')', '[', ']', '{', '}', '\\' - ]; - arguments.callee.sRE = new RegExp( - '(\\' + specials.join('|\\') + ')', 'g' - ); - } - return text.replace(arguments.callee.sRE, '\\$1'); - }, - - /* - find `name` in current `context`. That is find me a value - from the view object - */ - find: function(name, context) { - name = this.trim(name); - - // Checks whether a value is thruthy or false or 0 - function is_kinda_truthy(bool) { - return bool === false || bool === 0 || bool; - } - - var value; - if(is_kinda_truthy(context[name])) { - value = context[name]; - } else if(is_kinda_truthy(this.context[name])) { - value = this.context[name]; - } - - if(typeof value === "function") { - return value.apply(context); - } - if(value !== undefined) { - return value; - } - // silently ignore unkown variables - return ""; - }, - - // Utility methods - - /* includes tag */ - includes: function(needle, haystack) { - return haystack.indexOf(this.otag + needle) != -1; - }, - - /* - Does away with nasty characters - */ - escape: function(s) { - s = String(s === null ? "" : s); - return s.replace(/&(?!\w+;)|["<>\\]/g, function(s) { - switch(s) { - case "&": return "&"; - case "\\": return "\\\\"; - case '"': return '\"'; - case "<": return "<"; - case ">": return ">"; - default: return s; - } - }); - }, - - // by @langalex, support for arrays of strings - create_context: function(_context) { - if(this.is_object(_context)) { - return _context; - } else { - var iterator = "."; - if(this.pragmas["IMPLICIT-ITERATOR"]) { - iterator = this.pragmas["IMPLICIT-ITERATOR"].iterator; - } - var ctx = {}; - ctx[iterator] = _context; - return ctx; - } - }, - - is_object: function(a) { - return a && typeof a == "object"; - }, - - is_array: function(a) { - return Object.prototype.toString.call(a) === '[object Array]'; - }, - - /* - Gets rid of leading and trailing whitespace - */ - trim: function(s) { - return s.replace(/^\s*|\s*$/g, ""); - }, - - /* - Why, why, why? Because IE. Cry, cry cry. - */ - map: function(array, fn) { - if (typeof array.map == "function") { - return array.map(fn); - } else { - var r = []; - var l = array.length; - for(var i = 0; i < l; i++) { - r.push(fn(array[i])); - } - return r; - } - } - }; - - return({ - name: "mustache.js", - version: "0.3.0-dev", - - /* - Turns a template and view into HTML - */ - to_html: function(template, view, partials, send_fun) { - var renderer = new Renderer(); - if(send_fun) { - renderer.send = send_fun; - } - renderer.render(template, view, partials); - if(!send_fun) { - return renderer.buffer.join("\n"); - } - } - }); -}(); \ No newline at end of file diff --git a/templates/lib/resig/tmpl.js b/templates/lib/resig/tmpl.js new file mode 100644 index 00000000..9eb47715 --- /dev/null +++ b/templates/lib/resig/tmpl.js @@ -0,0 +1,34 @@ +// Based on Simple JavaScript Templating +// By John Resig - http://ejohn.org/ - MIT Licensed +// see: http://ejohn.org/blog/javascript-micro-templating/ +// modified to run on Rhino +(function(){ + var cache = {}; + + this.tmpl = function tmpl(/** templatefilename | templatesrc */str, data){ // templatefilename not contain `<` + var fn = str.indexOf('<') === -1 ? + cache[str] = cache[str] || tmpl(readFile(str)) : + + // Generate a reusable function that will serve as a template + // generator (and which will be cached). + new Function("obj", + "var p=[],print=function(){p.push.apply(p,arguments);};" + + + // Introduce the data as local variables using with(){} + "with(obj){p.push('" + + + // Convert the template into pure JavaScript + str + .replace(/[\r\t\n]/g, " ") + .split("<%").join("\t") + .replace(/((^|%>)[^\t]*)'/g, "$1\r") + .replace(/\t=(.*?)%>/g, "',$1,'") + .split("\t").join("');") + .split("%>").join("p.push('") + .split("\r").join("\\'") + + "');}return p.join('');"); + + // Provide some basic currying to the user + return data ? fn( data ) : fn; + }; +})(); \ No newline at end of file diff --git a/test/samples/jsdoc_test.js b/test/samples/jsdoc_test.js index fd3932a5..e2aab399 100644 --- a/test/samples/jsdoc_test.js +++ b/test/samples/jsdoc_test.js @@ -67,7 +67,7 @@ function Hexagon(sideLength) { /** - * This is an unattached (static) function that adds two integers together. + * This is an unattached (static) function that adds two integers together using {@link Shape#getClassName}. * @function * @param {int} One The first number to add * @param {int} Two The second number to add diff --git a/test/tests/07_jsdoc_resolvefunc.js b/test/tests/07_jsdoc_resolvefunc.js index 50a6a01f..94f45c38 100644 --- a/test/tests/07_jsdoc_resolvefunc.js +++ b/test/tests/07_jsdoc_resolvefunc.js @@ -67,8 +67,8 @@ expect(doclet.name).to(eql, 'inner'); expect(doclet).to(have_property, 'path'); expect(doclet.path).to(eql, 'Foo~inner'); - expect(doclet).to(have_property, 'access'); - expect(doclet.access).to(eql, 'inner'); + expect(doclet).to(have_property, 'attrib'); + expect(doclet.attrib).to(eql, 'inner'); }); }); @@ -81,8 +81,8 @@ expect(doclet.name).to(eql, 'deep'); expect(doclet).to(have_property, 'path'); expect(doclet.path).to(eql, 'Foo~inner~deep'); - expect(doclet).to(have_property, 'access'); - expect(doclet.access).to(eql, 'inner'); + expect(doclet).to(have_property, 'attrib'); + expect(doclet.attrib).to(eql, 'inner'); }); }); diff --git a/test/tests/14_tag_member.js b/test/tests/14_tag_member.js index 257fad7d..a50245c5 100644 --- a/test/tests/14_tag_member.js +++ b/test/tests/14_tag_member.js @@ -67,6 +67,58 @@ }); }); + describe('A doclet with a property tag and a member tag and an inner tag', function() { + it('should have an `isa` property set to "property"', function() { + var doclet = doclets[4]; + expect(doclet).to(have_property, 'isa'); + expect(doclet.isa).to(eql, 'property'); + }); + + it('should have a `name` property set to the given name"', function() { + var doclet = doclets[4]; + expect(doclet).to(have_property, 'name'); + expect(doclet.name).to(eql, 'bish'); + }); + + it('should have a `memberof` property set to the given member name', function() { + var doclet = doclets[4]; + expect(doclet).to(have_property, 'memberof'); + expect(doclet.memberof).to(eql, 'bar'); + }); + + it('should have a `path` property set to the memberof~name', function() { + var doclet = doclets[4]; + expect(doclet).to(have_property, 'path'); + expect(doclet.path).to(eql, 'bar~bish'); + }); + }); + + describe('A doclet with a property tag and a member tag and an instance access tag', function() { + it('should have an `isa` property set to "property"', function() { + var doclet = doclets[5]; + expect(doclet).to(have_property, 'isa'); + expect(doclet.isa).to(eql, 'property'); + }); + + it('should have a `name` property set to the given name"', function() { + var doclet = doclets[5]; + expect(doclet).to(have_property, 'name'); + expect(doclet.name).to(eql, 'bosh'); + }); + + it('should have a `memberof` property set to the given member name', function() { + var doclet = doclets[5]; + expect(doclet).to(have_property, 'memberof'); + expect(doclet.memberof).to(eql, 'bar'); + }); + + it('should have a `path` property set to the memberof~name', function() { + var doclet = doclets[5]; + expect(doclet).to(have_property, 'path'); + expect(doclet.path).to(eql, 'bar#bosh'); + }); + }); + }); })(); @@ -85,5 +137,17 @@ @property bah @member bar */ + + /** + @inner + @property bish + @member bar + */ + + /** + @attrib instance + @property bosh + @member bar + */ })(); \ No newline at end of file