From 2cbc4ea976fd940ae7bb19adb94cdbe172f96a01 Mon Sep 17 00:00:00 2001 From: Tarrant Date: Wed, 27 Nov 2013 16:01:32 +1100 Subject: [PATCH 1/2] Bugfix to settings $.extend The $.extend was the wrong way round, never allowing a user to override the sassdoc.json path --- viewer/js/lib/sassdoc.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/viewer/js/lib/sassdoc.js b/viewer/js/lib/sassdoc.js index 77bb670..33287a2 100644 --- a/viewer/js/lib/sassdoc.js +++ b/viewer/js/lib/sassdoc.js @@ -9,9 +9,9 @@ 'mixins' : 1, 'privates' : -1 }, - settings = $.extend(window.Sassdoc.settings, { + settings = $.extend({ docs: 'sassdoc.json' - }), + }, window.Sassdoc.settings || {}), sources = {}, showIt; @@ -451,4 +451,4 @@ }); }); }; -})(window, document, jQuery); \ No newline at end of file +})(window, document, jQuery); From 8b5ad81e1cc4cdf005cafc5efea0c175bf1ab35e Mon Sep 17 00:00:00 2001 From: Tarrant Date: Wed, 27 Nov 2013 16:37:06 +1100 Subject: [PATCH 2/2] Support custom template directory via settings --- viewer/js/lib/sassdoc.js | 115 ++++++++++++++++++++------------------- 1 file changed, 58 insertions(+), 57 deletions(-) diff --git a/viewer/js/lib/sassdoc.js b/viewer/js/lib/sassdoc.js index 33287a2..242d23b 100644 --- a/viewer/js/lib/sassdoc.js +++ b/viewer/js/lib/sassdoc.js @@ -2,18 +2,19 @@ window.Sassdoc || (window.Sassdoc = {}); window.Sassdoc.init = function() { var sassdoc, - rendered = 0, - templates = ['nav', 'toc', 'view'], - filters = { - 'functions' : 1, - 'mixins' : 1, - 'privates' : -1 - }, - settings = $.extend({ - docs: 'sassdoc.json' - }, window.Sassdoc.settings || {}), - sources = {}, - showIt; + rendered = 0, + templates = ['nav', 'toc', 'view'], + filters = { + 'functions' : 1, + 'mixins' : 1, + 'privates' : -1 + }, + settings = $.extend({ + docs: 'sassdoc.json', + templatePath: 'tmpl' + }, window.Sassdoc.settings || {}), + sources = {}, + showIt; Array.prototype.remove = function(from, to) { var rest = this.slice((to || from) + 1 || this.length); @@ -46,8 +47,8 @@ function query(name){ var q = unescape(window.location.search) + '&', - regex = new RegExp('.*?[&\\?]' + name + '=(.*?)&.*'), - val = q.replace(regex, "$1"); + regex = new RegExp('.*?[&\\?]' + name + '=(.*?)&.*'), + val = q.replace(regex, "$1"); return val == q ? undefined : val; } @@ -57,11 +58,11 @@ $.extend(settings, { docs: query('docs') }); - break; + break; case 'target': default: parseTarget(window.location.hash.replace('#', '')); - break; + break; } } @@ -78,12 +79,12 @@ data.methods = []; for(var category in sassdoc) { var toc = {}, - methods = sassdoc[category], - normCategory = category.replace(/[ \:\.\/\\]/g,'-'); - tocMethods = []; + methods = sassdoc[category], + normCategory = category.replace(/[ \:\.\/\\]/g,'-'); + tocMethods = []; for(var key in methods ) { var method = $.extend({}, methods[key]), - signature = []; + signature = []; // if it begins with an underscore, it assume it's private method['private'] == method['private'] || /^_.*/.test(key); // if this isn't a private method, use hyphens instead of underscores @@ -97,8 +98,8 @@ function getAcceptableValues(description) { var pattern = /.*\[(.*|.*)\].*/, - match = description.match(pattern), - values = match ? match[1].replace(/\|/g, ' | ') : false; + match = description.match(pattern), + values = match ? match[1].replace(/\|/g, ' | ') : false; return values; } @@ -122,28 +123,28 @@ switch(p) { case 'see': /* TODO: this doesn't work correctly yet, need to improve the regex - var global = patterns[p].g, - individual = patterns[p].i; - description = description.replace(individual, function(match, unit) { - return ''+match+''; - }); - */ - break; + var global = patterns[p].g, + individual = patterns[p].i; + description = description.replace(individual, function(match, unit) { + return ''+match+''; + }); + */ + break; case 'link': description = description.replace(patterns[p], function(match, unit) { return ''+match+''; }); - break; + break; case 'email': description = description.replace(patterns[p], function(match, unit) { return ''+match+''; }); - break; + break; default: description = description.replace(patterns[p], function(match, unit) { return ''+match+''; }); - break; + break; } } return description; @@ -189,7 +190,7 @@ } if(method.usage) { var usage = method.usage, - replacer = (method.mixin ? '@include ': ''); + replacer = (method.mixin ? '@include ': ''); function removeIndex(array, index) { var rest = array.slice((to || from) + 1 || array.length); array.length = from < 0 ? array.length + from : from; @@ -248,7 +249,7 @@ } function getTemplate(tmpl) { - $.ajax('tmpl/'+tmpl+'.tmpl', { + $.ajax(settings.templatePath+'/'+tmpl+'.tmpl', { success: function(html) { render(tmpl, html); } @@ -263,11 +264,11 @@ } $(function() { var $toc = $('#tmpl-toc'), - $view = $('#tmpl-view'), - $nav = $('#tmpl-nav'), - $body = $('body'), - $win = $(window), - $revealed = $(); + $view = $('#tmpl-view'), + $nav = $('#tmpl-nav'), + $body = $('body'), + $win = $(window), + $revealed = $(); showIt = function(action, what, other, source, e, preserve) { what = what.replace('#',''); @@ -288,13 +289,13 @@ $body.addClass('hide-all-categories'); $revealed = $('.reveal, .is-category-'+what).addClass('reveal'); } - break; + break; case 'source': // if there's a source viewer, use it, otherwise if(settings.source_viewer && (/^(http(s?)):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?$/i).test(settings.source_viewer)) { var h = $win.height() - 81, - $iframe = $('