UNPKG

chocolate

Version:

A full stack Node.js web framework built using Coffeescript

229 lines (209 loc) 10.7 kB
// Generated by CoffeeScript 1.12.6 (function() { var Chocodown, Doccolate, Highlight, _module, docco_template, ext, generate, generate_html, get_language, highlight, highlight_end, highlight_start, l, languages, options, parse, path, template; Highlight = require('./highlight'); Chocodown = require('./chocodown'); path = { extname: function(path) { var items, result; items = path.split('.'); result = items.slice(-1)[0]; if (items.length > 1) { return '.' + result; } else { return result; } }, basename: function(path) { var items; items = path.split('/'); return items.slice(-1)[0]; } }; languages = { '.coffee': { name: 'coffeescript', symbol: '#', symbol_close: '' }, '.js': { name: 'javascript', symbol: '//', symbol_close: '' }, '.json': { name: 'javascript', symbol: '//', symbol_close: '' }, '.html': { name: 'xml', symbol: '/* ', symbol_close: ' */' }, '.css': { name: 'css', symbol: '/* ', symbol_close: ' */' }, '.rb': { name: 'ruby', symbol: '#', symbol_close: '' }, '.py': { name: 'python', symbol: '#', symbol_close: '' }, '.markdown': { name: 'markdown', symbol: '', symbol_close: '' }, '.md': { name: 'markdown', symbol: '', symbol_close: '' }, '.chocodown': { name: 'markdown', symbol: '', symbol_close: '' }, '.cd': { name: 'markdown', symbol: '', symbol_close: '' }, '.chocokup': { name: 'coffeescript', symbol: '', symbol_close: '' }, '.ck': { name: 'coffeescript', symbol: '', symbol_close: '' } }; for (ext in languages) { l = languages[ext]; l.comment_matcher = new RegExp('^\\s*' + l.symbol.replace('*', '\\*') + '\\s?'); l.comment_filter = new RegExp('(^#![/]|^\\s*#[\\{|\\w])'); l.divider_text = '\n' + l.symbol + 'DIVIDER' + l.symbol_close + '\n'; l.divider_html = new RegExp('\\n*<span class="comment">' + l.symbol.replace('*', '\\*') + 'DIVIDER' + l.symbol_close.replace('*', '\\*') + '<\\/span>\\n*'); } get_language = function(source) { return languages[path.extname(source)]; }; parse = function(source, code) { var code_text, docs_text, has_code, j, language, len, line, lines, save, sections; language = get_language(source); lines = code.split('\n'); sections = []; has_code = docs_text = code_text = ''; save = function(docs, code) { return sections.push({ docs_text: docs, code_text: code }); }; for (j = 0, len = lines.length; j < len; j++) { line = lines[j]; if (line.match(language.comment_matcher) && !line.match(language.comment_filter)) { if (has_code) { save(docs_text, code_text); has_code = docs_text = code_text = ''; } docs_text += line.replace(language.comment_matcher, '') + '\n'; } else { has_code = true; code_text += line + '\n'; } } save(docs_text, code_text); return sections; }; highlight_start = '<div class="highlight"><pre>'; highlight_end = '</pre></div>'; generate_html = function(source, sections) { var code_width, doc_max_width, doc_min_width, html, title; title = path.basename(source); doc_min_width = '450px'; doc_max_width = '450px'; code_width = '100%'; return html = docco_template({ title: title, sections: sections, css_class: options.css_class, style: options.default_style, doc_min_width: doc_min_width, doc_max_width: doc_max_width, code_width: code_width }); }; highlight = function(source, sections) { var code, fragments, i, j, language, len, result, results, section; language = get_language(source); code = ((function() { var j, len, results; results = []; for (j = 0, len = sections.length; j < len; j++) { section = sections[j]; results.push(section.code_text); } return results; })()).join(language.divider_text); result = Highlight.highlight(language.name, code).value; fragments = result.split(language.divider_html); results = []; for (i = j = 0, len = sections.length; j < len; i = ++j) { section = sections[i]; section.code_html = highlight_start + fragments[i] + highlight_end; results.push(section.docs_html = new Chocodown.converter().makeHtml(section.docs_text)); } return results; }; generate = function(source, code) { var e, hihilighted, html, sections; switch (path.extname(source)) { case '.txt': return html = '<pre>' + code + '</pre>'; case '.html': return html = code; case '.markdown': case '.md': case '.chocodown': case '.cd': return html = new Chocodown.converter().makeHtml(code); case '.chocokup': case '.ck': try { return html = new Chocodown.Chocokup.Panel(code).render(); } catch (error) { e = error; return html = e.message; } break; default: sections = parse(source, code); hihilighted = highlight(source, sections); return html = generate_html(source, sections); } }; options = { css_class: 'dl-s-default', default_style: ".dl-s-default {color: #252519;}\n.dl-s-default a {color: #444;}\n\n.dl-s-default .keyword {color: #954121;}\n.dl-s-default .comment {color: #a50;}\n.dl-s-default .number {color: #164;}\n.dl-s-default .literal {color: sienna;}\n.dl-s-default .string {color: #219161;}\n.dl-s-default .regexp {color: #f50;}\n.dl-s-default .function {color: #30a;}\n.dl-s-default .title {color: #00c;}\n.dl-s-default .params {color: #a0a;}\n.dl-s-default .variable {color: #19469D;}\n.dl-s-default .property {color: #19469D;}\n.dl-s-default .error {color: red;}\n \n.dl-s-default .tag {color: #170;}\n.dl-s-default .id {color: #085;}\n.dl-s-default .class {color: #05a;}\n.dl-s-default .at_rule {color: #f50;}\n.dl-s-default .attr_selector {color: black;}\n.dl-s-default .pseudo {color: black;}\n.dl-s-default .rules {color: black;}\n.dl-s-default .value {color: black;}\n.dl-s-default .hexcolor {color: black;}\n.dl-s-default .important {color: black;}" }; Doccolate = { generate: generate, options: options }; _module = typeof window !== "undefined" && window !== null ? window : module; _module[_module.exports != null ? "exports" : "Doccolate"] = Doccolate; template = function(str) { return new Function('obj', 'var p=[],print=function(){p.push.apply(p,arguments);};' + 'with(obj){p.push(\'' + str.replace(/[\r\t\n]/g, " ").replace(/'(?=[^<]*%>)/g, "\t").split("'").join("\\'").split("\t").join("'").replace(/<%=(.+?)%>/g, "',$1,'").split('<%').join("');").split('%>').join("p.push('") + "');}return p.join('');"); }; docco_template = template("<style>\n <%= style %>\n\n /*--------------------- Layout and Typography ----------------------------*/\n\n #docco_container {\n font-family: \"Palatino Linotype\", \"Book Antiqua\", Palatino, FreeSerif, serif;\n color: #252519;\n \n position: absolute;\n top: 0;\n left: 0;\n }\n \n #docco_container p {\n margin: 0 0 15px 0;\n }\n \n #docco_container h1, \n #docco_container h2, \n #docco_container h3, \n #docco_container h4, \n #docco_container h5, \n #docco_container h6 {\n margin: 0px 0 15px 0;\n }\n\n \n #docco_container h1 {\n margin-top: 40px;\n }\n\n #docco_background {\n position: absolute;\n top: 0; left: 525px; right: 0; bottom: 0;\n background: #f5f5ff;\n border-left: 1px solid #e5e5ee;\n z-index: -1;\n }\n \n td.docco_docs, th.docco_docs {\n max-width: <%= doc_max_width %>;\n min-width: <%= doc_min_width %>;\n min-height: 5px;\n padding: 0px 25px 1px 50px;\n overflow-x: hidden;\n vertical-align: top;\n text-align: left;\n font-family: \"Palatino Linotype\", \"Book Antiqua\", Palatino, FreeSerif, serif;\n font-size: 15px;\n line-height: 20px;\n }\n .docco_docs pre {\n margin: 15px 0 15px;\n padding-left: 15px;\n color: darkSlateGray;\n font-size: 12px;\n line-height: 15px;\n }\n .docco_docs tt, .docco_docs code {\n background: #f8f8ff;\n border: 1px solid #dedede;\n padding: 0 0.2em;\n display: inline-block;\n }\n .docco_docs p tt, .docco_docs p code {\n font-size: 12px;\n }\n .docco_pilwrap {\n position: relative;\n }\n .docco_pilcrow {\n font: 12px Arial;\n text-decoration: none;\n color: #454545;\n position: absolute;\n top: 3px; left: -20px;\n padding: 1px 2px;\n opacity: 0;\n -webkit-transition: opacity 0.2s linear;\n }\n td.docco_docs:hover .docco_pilcrow {\n opacity: 1;\n }\n td.docco_code, th.docco_code {\n padding: 0px 15px 16px 25px;\n width: <%= code_width %>;\n vertical-align: top;\n background: #f5f5ff;\n border-left: 1px solid #e5e5ee; \n }\n #.docco_container pre, #.docco_container tt, #.docco_container code {\n font-size: 12px; line-height: 18px;\n font-family: Menlo, Monaco, Consolas, \"Lucida Console\", monospace;\n margin: 0; padding: 0;\n }\n</style>\n \n<div id=\"docco_container\" class=\"<%= css_class %>\">\n <div id=\"docco_background\"></div>\n <table cellpadding=\"0\" cellspacing=\"0\">\n <% if (title != '') { %>\n <thead>\n <tr>\n <th class=\"docco_docs\">\n <h1>\n <%= title %>\n </h1>\n </th>\n <th class=\"docco_code\">\n </th>\n </tr>\n </thead>\n <% } %>\n <tbody>\n <% for (var i=0, l=sections.length; i<l; i++) { %>\n <% var section = sections[i]; %>\n <tr id=\"docco_section-<%= i + 1 %>\">\n <td class=\"docco_docs\">\n <div class=\"docco_pilwrap\">\n <a class=\"docco_pilcrow\" href=\"#docco_section-<%= i + 1 %>\">&#182;</a>\n </div>\n <%= section.docs_html %>\n </td>\n <td class=\"docco_code\">\n <%= section.code_html %>\n </td>\n </tr>\n <% } %>\n </tbody>\n </table>\n</div>"); }).call(this);