Skip to content

Nodebuilder #54

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
.DS_Store
.DS_Store
node_modules
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ If you'd like to **add a new snippet**: Take a look at an existing snippet: http

If you'd like to **modify an existing snippet**: Feel free to make improvements to an existing snippet. Do not worry about rebuilding index.html, just make sure the README looks good and I will rebuild the site before pushing up changes.

If you'd like to **modify the HTML**: Be sure to change template.html, not index.html (it is autogenerated). By running `rake build`, you can preview changes. No need to include the autogenerated file in a pull request, I will rebuild it before pushing up changes.
If you'd like to **modify the HTML**: Be sure to change template.html, not index.html (it is autogenerated). By running `./build.js`, you can preview changes. No need to include the autogenerated file in a pull request, I will rebuild it before pushing up changes.
53 changes: 0 additions & 53 deletions Rakefile

This file was deleted.

91 changes: 91 additions & 0 deletions build.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
#!/usr/bin/env node

var marked = require('marked');
var glob = require('glob');
var path = require('path');
var fs = require('fs');

var snippetsFolder = './snippets',
templatePath = './template.html',
githubProjectPage = 'https://github.com/bgrins/devtools-snippets';

// use highlight.js
marked.setOptions({
highlight: function (code) {
return require('highlight.js').highlightAuto(code).value;
}
});


function build() {
var links = [];
var json = {
snippets: []
};
var html = '';
glob(snippetsFolder + "/**/*.js", {}, function (er, files) {

files.forEach(function(filePath) {

var filename = path.basename(filePath, path.extname(filePath)),
foldername = path.basename(path.dirname(filePath)),
readmePath = path.dirname(filePath) + '/README.md',
snippetCode = fs.readFileSync(filePath).toString(),
readmeHTML = marked(fs.readFileSync(readmePath).toString()),
// we need to escape $ for javascript replace function
codeHTML = marked('```js\n' + snippetCode.replace(/\$/g, '$$$$') + '```');

// create heading with correct links
var newHeading = "<h3>" +
"<a href='" + githubProjectPage + "/tree/master/snippets/" + foldername + "/" + filename + ".js'>" +
filename + ".js</a> " +
"<small style='float:right'>" +
"<a href='snippets/" + foldername + "/" + filename + ".js'>(view raw)</a>" +
"</small>" +
"</h3>\n\n";

// replace heading with links + wrap
readmeHTML = "<div class='snippet'>" + readmeHTML.replace(/<h3.*<\/h3>/, newHeading) + "</div>";
readmeHTML = readmeHTML.replace(new RegExp('"' + filename, "g"), "\"snippets/" + foldername + "/" + filename );

// wrap doc + code
var snippetHTML = "<div class='snippet-wrapper' id='" + filename + "'>" +
readmeHTML +
codeHTML +
"</div>";

// add to global HTML
html += snippetHTML;

// add link for the TOC
links.push("<li><a href='#" + filename + "'>" + filename + "</a></li>");

// add to the JSON
json.snippets.push({
"name": filename,
"content": snippetCode
});

});

// fill the tempalte blocks
var template = fs.readFileSync(templatePath).toString();
template = template.replace('<!-- REPLACELINKS -->', links.join('\n'));
template = template.replace('<!-- REPLACE -->', html);

fs.writeFile('index.html', template, function (err) {
if (err) throw err;
console.log('[+] index.html updated');
});

fs.writeFile('snippets.json', JSON.stringify(json, null, ' '), function (err) {
if (err) throw err;
console.log('[+] snippets.json updated');
});

});

}


build();
152 changes: 152 additions & 0 deletions docs/highlight-default.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
/*

Original style from softwaremaniacs.org (c) Ivan Sagalaev <[email protected]>

*/

.hljs {
display: block;
overflow-x: auto;
padding: 0.5em;
background: #f0f0f0;
-webkit-text-size-adjust: none;
}

.hljs,
.hljs-subst,
.hljs-tag .hljs-title,
.nginx .hljs-title {
color: black;
}

.hljs-string,
.hljs-title,
.hljs-constant,
.hljs-parent,
.hljs-tag .hljs-value,
.hljs-rules .hljs-value,
.hljs-preprocessor,
.hljs-pragma,
.haml .hljs-symbol,
.ruby .hljs-symbol,
.ruby .hljs-symbol .hljs-string,
.hljs-template_tag,
.django .hljs-variable,
.smalltalk .hljs-class,
.hljs-addition,
.hljs-flow,
.hljs-stream,
.bash .hljs-variable,
.apache .hljs-tag,
.apache .hljs-cbracket,
.tex .hljs-command,
.tex .hljs-special,
.erlang_repl .hljs-function_or_atom,
.asciidoc .hljs-header,
.markdown .hljs-header,
.coffeescript .hljs-attribute {
color: #800;
}

.smartquote,
.hljs-comment,
.hljs-annotation,
.diff .hljs-header,
.hljs-chunk,
.asciidoc .hljs-blockquote,
.markdown .hljs-blockquote {
color: #888;
}

.hljs-number,
.hljs-date,
.hljs-regexp,
.hljs-literal,
.hljs-hexcolor,
.smalltalk .hljs-symbol,
.smalltalk .hljs-char,
.go .hljs-constant,
.hljs-change,
.lasso .hljs-variable,
.makefile .hljs-variable,
.asciidoc .hljs-bullet,
.markdown .hljs-bullet,
.asciidoc .hljs-link_url,
.markdown .hljs-link_url {
color: #080;
}

.hljs-label,
.hljs-javadoc,
.ruby .hljs-string,
.hljs-decorator,
.hljs-filter .hljs-argument,
.hljs-localvars,
.hljs-array,
.hljs-attr_selector,
.hljs-important,
.hljs-pseudo,
.hljs-pi,
.haml .hljs-bullet,
.hljs-doctype,
.hljs-deletion,
.hljs-envvar,
.hljs-shebang,
.apache .hljs-sqbracket,
.nginx .hljs-built_in,
.tex .hljs-formula,
.erlang_repl .hljs-reserved,
.hljs-prompt,
.asciidoc .hljs-link_label,
.markdown .hljs-link_label,
.vhdl .hljs-attribute,
.clojure .hljs-attribute,
.asciidoc .hljs-attribute,
.lasso .hljs-attribute,
.coffeescript .hljs-property,
.hljs-phony {
color: #88f;
}

.hljs-keyword,
.hljs-id,
.hljs-title,
.hljs-built_in,
.css .hljs-tag,
.hljs-javadoctag,
.hljs-phpdoc,
.hljs-dartdoc,
.hljs-yardoctag,
.smalltalk .hljs-class,
.hljs-winutils,
.bash .hljs-variable,
.apache .hljs-tag,
.hljs-type,
.hljs-typename,
.tex .hljs-command,
.asciidoc .hljs-strong,
.markdown .hljs-strong,
.hljs-request,
.hljs-status {
font-weight: bold;
}

.asciidoc .hljs-emphasis,
.markdown .hljs-emphasis {
font-style: italic;
}

.nginx .hljs-built_in {
font-weight: normal;
}

.coffeescript .javascript,
.javascript .xml,
.lasso .markup,
.tex .hljs-formula,
.xml .javascript,
.xml .vbscript,
.xml .css,
.xml .hljs-cdata {
opacity: 0.5;
}
Loading