From 9dbe33f6bb089e7531168701dc0b8748dc734580 Mon Sep 17 00:00:00 2001 From: Geoff Kimball Date: Mon, 14 Dec 2015 11:21:24 -0800 Subject: [PATCH] Remove docs JS utilities now covered by the foundation-docs library --- lib/buildSearch.js | 140 ------------------------------- lib/escape.js | 3 - lib/handlebars.js | 204 --------------------------------------------- lib/marked.js | 35 -------- 4 files changed, 382 deletions(-) delete mode 100644 lib/buildSearch.js delete mode 100644 lib/escape.js delete mode 100644 lib/handlebars.js delete mode 100644 lib/marked.js diff --git a/lib/buildSearch.js b/lib/buildSearch.js deleted file mode 100644 index 0b59cf0b6..000000000 --- a/lib/buildSearch.js +++ /dev/null @@ -1,140 +0,0 @@ -// This function builds a search result library out of a map of components created by Supercollider, the documentation generator. - -var format = require('string-template'); -var fs = require('fs'); -var path = require('path'); -var escape = require('./escape'); - -// Path to write the search terms file to -var outputFolder = path.join(process.cwd(), '_build/data'); -var outputPath = path.join(outputFolder, 'search.json'); - -// Links to old Foundation versions -var oldFoundations = { - '2': '2.2.1', - '3': '3.2.5', - '4': '4.3.2', - '5': '5.5.3' -} - -// Search results are pre-sorted by type -// The important thing is that pages and components are shown first, because that's what people search for most often -var sortOrder = ['page', 'component', 'sass variable', 'sass mixin', 'sass function', 'js class', 'js function', 'js plugin option', 'js event']; - -module.exports = buildSearch; - -// Builds a JSON object of search results out of a list of components and writes it to a file. -// @param {Object} data - Supercollider-generated object of components to use. -// @param {Function} cb - Callback to run when finished writing to disk. -function buildSearch(data, cb) { - var tree = []; - - // Add results for old Foundation documentation - for (var i in oldFoundations) { - // lol - var index = (i > 3) ? '/index.html' : '/'; - - tree.push({ - type: 'page', - name: 'Foundation ' + i, - description: 'Documentation for Foundation v' + oldFoundations[i], - link: 'http://foundation.zurb.com/sites/docs/v/' + oldFoundations[i] + index, - tags: ['old', 'previous'] - }) - } - - // Each item in "data" is a page or component - for (var i in data) { - var item = data[i]; - var link = path.relative('docs/pages', item.fileName).replace('md', 'html'); - var type = 'page'; - - if (item.sass || item.js) { - type = 'component'; - } - if (item.library) { - type = 'library'; - } - - // Add the page itself as a search result - tree.push({ - type: type, - name: item.title, - description: item.description, - link: link, - tags: item.tags || [] - }); - - // Add Sass variables, mixins, and functions as search results - if (item.sass) { - var sassItems = [].concat(item.sass.variable || [], item.sass.mixin || [], item.sass.function || []); - - for (var j in sassItems) { - var name = sassItems[j].context.name; - var type = sassItems[j].context.type; - var description = sassItems[j].description.replace('\n', ''); - var hash = '#'; - - if (type === 'variable') { - name = '$' + name; - hash += 'sass-variables'; - } - - if (type === 'mixin' || type === 'function') { - hash += escape(name); - name = name + '()'; - } - - tree.push({ - name: name, - type: 'sass ' + type, - description: description, - link: link + hash - }); - } - } - - // Add JavaScript classes, functions, events, and plugin options as search results - if (item.js) { - var jsItems = [].concat(item.js.class || [], item.js.function || [], item.js.event || [], item.js.member || []); - - for (var k in jsItems) { - var name = jsItems[k].name; - var type = jsItems[k].kind; - var description = jsItems[k].description.replace('\n', ''); - var hash = '#js-' + type.replace('plugin ', '') + 's'; - - if (type === 'class') { - name = 'Foundation.' + name; - hash = hash.slice(0, -1) - } - - if (type === 'member') { - type = 'plugin option' - } - - if (type === 'function') { - name = jsItems[k].meta.code.name.replace('prototype.', ''); - hash = '#' + name.split('.')[1]; - name += '()'; - } - - tree.push({ - type: 'js ' + type, - name: name, - description: description, - link: link + hash - }); - } - } - } - - // Re-order search results to show pages and components first, then Sass/JS items - tree = tree.sort(function(a, b) { - return sortOrder.indexOf(a.type) - sortOrder.indexOf(b.type); - }); - - // Write the search file to disk - if (!fs.existsSync(outputFolder)) fs.mkdirSync(outputFolder) - fs.writeFile(outputPath, JSON.stringify(tree, null, ' '), cb); -} diff --git a/lib/escape.js b/lib/escape.js deleted file mode 100644 index be1ffc40a..000000000 --- a/lib/escape.js +++ /dev/null @@ -1,3 +0,0 @@ -module.exports = function(text) { - return text.toLowerCase().replace(/[^\w]+/g, '-'); -} diff --git a/lib/handlebars.js b/lib/handlebars.js deleted file mode 100644 index 394036e4f..000000000 --- a/lib/handlebars.js +++ /dev/null @@ -1,204 +0,0 @@ -var marked = require('marked'); -var multiline = require('multiline'); -var handlebars = require('handlebars'); -var hljs = require('highlight.js'); -var format = require('string-template'); -var querystring = require('querystring'); -var escape = require('./escape'); - -var ISSUE_TEXT = multiline(function() {/* -**How can we reproduce this bug?** - -1. Step one -2. Step two -3. Step three - -**What did you expect to happen?** - -**What happened instead?** - -**Test case** - -Give us a link to a [CodePen](http://codepen.io) or [JSFiddle](http://jsfiddle.net) that recreates the issue. -*/}); - -// Converts Markdown to HTML -handlebars.registerHelper('md', function(text) { - return marked(text); -}); - -// Creates a heading with an anchor link -handlebars.registerHelper('heading', function(level, anchor, options) { - // Allow for optional second parameter - if (typeof anchor === 'object') { - options = anchor; - anchor = options.fn(this); - } - - var escapedText = escape(anchor); - var magellan = (level === 2) ? format(' data-magellan-target="{0}"', [escapedText]) : ''; - - return format('{2}', [level, escapedText, options.fn(this), magellan]); -}); - -// Escapes a string for use as a URL hash -handlebars.registerHelper('escape', function(text) { - return escape(text || ''); -}); - -// Capitalizes the first letter of a string -handlebars.registerHelper('toUpper', function(str) { - return str[0].toUpperCase() + str.slice(1); -}); - -// Makes an entire string lowercase -handlebars.registerHelper('toLower', function(str) { - if (typeof str === 'undefined') str = ''; - return str.toLowerCase(); -}); - -// Formats a mixin using a SassDoc mixin object to look like this: -// @include mixinName($param, $param) { } -handlebars.registerHelper('writeMixin', function(mixin) { - var name = mixin['context']['name']; - var params = mixin['parameter']; - - var str = '@include '; - str += name; - - if (params) str += '('; - - for (var i in params) { - str += '$' + params[i]['name'] + ', '; - } - - if (params) str = str.slice(0, -2) + ')'; - - if (typeof mixin.content === 'string') { - str += ' { }'; - } - else { - str += ';' - } - - str = hljs.highlight('scss', str).value; - - return str; -}); - -// Formats a function using a SassDoc function object to look like this: -// function($param, $param) -handlebars.registerHelper('writeFunction', function(func) { - var name = func['context']['name']; - var params = func['parameter']; - - var str = ''; - str += name + '('; - - for (var i in params) { - str += '$' + params[i]['name'] + ', '; - } - if (params) str = str.slice(0, -2); - str += ')'; - - str = hljs.highlight('scss', str).value; - - return str; -}); - -// Formats a variable declaration using a SassDoc variable object to look like this: -// $name: $value; -handlebars.registerHelper('writeVariable', function(variable) { - var name = variable['context']['name']; - var value = variable['context']['value']; - var str = '$' + name + ': ' + value + ';'; - str = hljs.highlight('scss', str).value; - - return str; -}); - -// Adds an external link, pulled from a SassDock @link annotation. -handlebars.registerHelper('externalLink', function(link) { - if (!link) return ''; - - return format('

Learn more: {1}

', [link[0].url, link[0].caption]); -}); - -// Format Sass variable types to read "x or y or z" -handlebars.registerHelper('sassTypes', function(types) { - if (typeof types === 'undefined') return ''; - - var types = types.replace(' ', '').split('|'); - var output = ''; - - for (var i in types) { - output += types[i] + ' or '; - } - - return output.slice(0, -4); -}); - -// Format a Sass value to pretty-print a map, or "None" if there's no value -handlebars.registerHelper('sassValue', function(value) { - if (typeof value === 'undefined') return 'None'; - - if (value[0] === '(' && value[value.length - 1] === ')') { - value = value.slice(1, -1).split(',').join('
'); - } - - return value; -}); - -handlebars.registerHelper('jsModuleName', function(value) { - return value.replace('module:', '') + '.js'; -}); - -handlebars.registerHelper('editLink', function(value) { - return format('https://github.com/zurb/foundation-sites/edit/develop/{0}', [value.replace('.html', '.md')]); -}); - -handlebars.registerHelper('issueLink', function(name) { - return 'https://github.com/zurb/foundation-sites/issues/new?' + querystring.stringify({ - title: format('[{0}] ISSUE NAME HERE', [name]), - body: ISSUE_TEXT - }); -}); - -handlebars.registerHelper('sourceLink', function(files) { - var output = ''; - var text = { - 'sass': 'Sass', - 'js': 'JavaScript' - } - var both = files.sass && files.js; - - for (var i in files) { - var module = files[i]; - if (typeof module === 'string') module = [module]; - module = module.filter(function(val) { - return val[0] !== '!'; - }).map(function(val) { - if (val.indexOf('*') > -1) { - val = val.split('*')[0]; - } - return val; - })[0]; - output += format('
  • {1}
  • ', [ - 'https://github.com/zurb/foundation-sites/tree/master/' + module, - (both ? 'View ' + text[i] + ' Source' : 'View Source') - ]); - } - - return output; -}); - -handlebars.registerHelper('filter', function(item, options) { - if (item.access === 'private' || item.alias) return ''; - return options.fn(this); -}); - -handlebars.registerHelper('raw', function(content) { - return content.fn(this); -}); - -module.exports = handlebars; diff --git a/lib/marked.js b/lib/marked.js deleted file mode 100644 index 14a10518a..000000000 --- a/lib/marked.js +++ /dev/null @@ -1,35 +0,0 @@ -var escape = require('./escape') -var marked = require('marked'); -var format = require('string-template'); -var hljs = require('highlight.js'); - -var mdRenderer = new marked.Renderer(); - -// Adds an anchor link to each heading created -mdRenderer.heading = function(text, level) { - var escapedText = escape(text); - var magellan = (level === 2) ? format(' data-magellan-target="{0}"', [escapedText]) : ''; - - return format('{2}', [level, escapedText, text, magellan]); -} - -// Adds special formatting to each code block created -// If the language is suffixed with "_example", the raw HTML is printed after the code sample, creating a live example. -mdRenderer.code = function(code, language) { - var extraOutput = ''; - - if (typeof language === 'undefined') language = 'html'; - - // If the language is *_example, live code will print out along with the sample - if (language.match(/_example$/)) { - extraOutput = format('\n\n
    {0}
    ', [code]); - language = language.replace(/_example$/, ''); - } - - var renderedCode = hljs.highlight(language, code).value; - var output = format('
    {1}
    ', [language, renderedCode]); - - return output + extraOutput; -} - -module.exports = mdRenderer; -- 2.47.2