Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

tumblr-theme-parser

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

tumblr-theme-parser - npm Package Compare versions

Comparing version 0.0.1 to 1.0.0

120

lib/index.js
// Generated by CoffeeScript 1.8.0
(function() {
var cheerio, compile, parse, transformKeysRecursive;
var MIXINS, cheerio, clone, compile, parse, transformKeysRecursive,
__indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; };

@@ -9,2 +10,17 @@ parse = require('./parser').parse;

clone = require('lodash.clone');
MIXINS = {
likebutton: function(data, _arg) {
var color, size;
color = _arg.color, size = _arg.size;
return parse("<div class=\"like_button\" data-post-id=\"" + data.attributes["post-id"] + "\" id=\"like_button_" + data.attributes["post-id"] + "\">\n <iframe id=\"like_iframe_" + data.attributes["post-id"] + "\" src=\"http://assets.tumblr.com/assets/html/like_iframe.html?_v=1af0c0fbf0ad9b4dc38445698d099106#name={Name}&amp;post_id=" + data.attributes["post-id"] + "&amp;color=" + color + "&amp;rk=" + data.attributes.rk + "\" scrolling=\"no\" width=\"14\" height=\"14\" frameborder=\"0\" class=\"like_toggle\" allowTransparency=\"true\"></iframe>\n</div>");
},
reblogbutton: function(data, _arg) {
var color, size;
color = _arg.color, size = _arg.size;
return ["<a href=\"" + data.attributes.reblog_url + "\" class=\"reblog_button\" style=\"display: block; width:" + size + "px; height:" + size + "px;\">\n <svg width=\"100%\" height=\"100%\" viewBox=\"0 0 21 21\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" fill=\"" + color + "\">\n <path d=\"M5.01092527,5.99908429 L16.0088498,5.99908429 L16.136,9.508 L20.836,4.752 L16.136,0.083 L16.1360004,3.01110845 L2.09985349,3.01110845 C1.50585349,3.01110845 0.979248041,3.44726568 0.979248041,4.45007306 L0.979248041,10.9999998 L3.98376463,8.30993634 L3.98376463,6.89801007 C3.98376463,6.20867902 4.71892527,5.99908429 5.01092527,5.99908429 Z\"></path>\n <path d=\"M17.1420002,13.2800293 C17.1420002,13.5720293 17.022957,14.0490723 16.730957,14.0490723 L4.92919922,14.0490723 L4.92919922,11 L0.5,15.806 L4.92919922,20.5103758 L5.00469971,16.9990234 L18.9700928,16.9990234 C19.5640928,16.9990234 19.9453125,16.4010001 19.9453125,15.8060001 L19.9453125,9.5324707 L17.142,12.203\"></path>\n </svg>\n</a>"];
}
};
transformKeysRecursive = function(obj, fn) {

@@ -31,6 +47,7 @@ var e, i, output, _i, _len, _ref;

compile = function(text, data) {
var $, ast, compileBlock, i, key, metaTags, output, post, tag, type, v, _i, _j, _k, _len, _len1, _ref, _ref1;
var $, ast, compileBlock, i, key, metaTags, post, result, tag, type, v, _i, _j, _k, _len, _len1, _ref, _ref1;
if (data == null) {
data = {};
}
data = clone(data);
$ = cheerio.load(text);

@@ -69,36 +86,46 @@ metaTags = $('meta');

});
output = '';
compileBlock = function(ast, data) {
var blockName, blockType, context, element, invert, value, _k, _l, _len2, _len3, _ref1, _ref2, _results;
_results = [];
for (_k = 0, _len2 = ast.length; _k < _len2; _k++) {
element = ast[_k];
compileBlock = function(ast, data, searchParentScope) {
var compileElement, element, output, searchScope, _k, _len2;
searchScope = function(type, tagName) {
var value, _k, _len2, _ref1;
key = (type === '' ? tagName : "" + type + ":" + tagName);
value = data[key];
if ((value == null) && type === 'if') {
_ref1 = Object.keys(data);
for (_k = 0, _len2 = _ref1.length; _k < _len2; _k++) {
key = _ref1[_k];
if (tagName === key.replace(/\s/g, '').replace(/^[a-z]+:/, '')) {
value = data[key];
break;
}
}
}
if ((value == null) && (searchParentScope != null)) {
value = searchParentScope(type, tagName);
}
if (type === '' && __indexOf.call(Object.keys(MIXINS), tagName) >= 0) {
return MIXINS[tagName].bind(this, value);
}
return value;
};
compileElement = function(element) {
var blockName, blockType, context, invert, out, value, _k, _len2, _ref1;
if (typeof element === 'string') {
_results.push(output += element);
return element;
} else if (element.type !== 'block') {
type = element.type;
if (type === '') {
value = data[element.tagName];
if (value != null) {
_results.push(output += value);
value = searchScope(element.type, element.tagName);
if (value != null) {
if (typeof value === 'function') {
return compileBlock(value(element.attributes), data, searchScope);
} else {
_results.push(console.warn("Variable \"" + element.tagName + "\" is undefined"));
return value;
}
} else {
_results.push(output += data["" + type + ":" + element.tagName]);
console.warn("Variable \"" + key + "\" is undefined");
return '';
}
} else {
_ref1 = (element.tagName.slice(0, 5) === 'ifnot' ? ['if', "" + element.tagName.slice(5), true] : element.tagName.slice(0, 2) === 'if' ? ['if', "" + element.tagName.slice(2), false] : ['block', "" + element.tagName, false]), blockType = _ref1[0], blockName = _ref1[1], invert = _ref1[2];
value = data["" + blockType + ":" + blockName];
value = searchScope(blockType, blockName);
if (blockType === 'if') {
if (value == null) {
_ref2 = Object.keys(data);
for (_l = 0, _len3 = _ref2.length; _l < _len3; _l++) {
key = _ref2[_l];
if (blockName === key.replace(/\s/g, '').replace(/^[a-z]+:/, '')) {
value = data[key];
break;
}
}
}
if ((value != null) && value !== '') {

@@ -116,32 +143,33 @@ if (typeof value !== 'boolean') {

if (typeof value === 'boolean' && value) {
_results.push(compileBlock(element.contents, data));
return compileBlock(element.contents, data, searchScope);
} else if (Array.isArray(value)) {
_results.push((function() {
var _len4, _m, _results1;
_results1 = [];
for (_m = 0, _len4 = value.length; _m < _len4; _m++) {
context = value[_m];
_results1.push(compileBlock(element.contents, context));
}
return _results1;
})());
out = '';
for (_k = 0, _len2 = value.length; _k < _len2; _k++) {
context = value[_k];
out += compileBlock(element.contents, context, searchScope);
}
return out;
} else if (typeof value === 'object') {
_results.push(compileBlock(element.contents, value));
return compileBlock(element.contents, value, searchScope);
} else {
_results.push(void 0);
return '';
}
}
};
output = '';
for (_k = 0, _len2 = ast.length; _k < _len2; _k++) {
element = ast[_k];
output += compileElement(element);
}
return _results;
return output;
};
ast = parse(text);
compileBlock(ast, data);
output = output.split('\n');
for (i = _k = 0, _ref1 = output.length; 0 <= _ref1 ? _k < _ref1 : _k > _ref1; i = 0 <= _ref1 ? ++_k : --_k) {
output[i] = output[i].trimRight();
result = compileBlock(ast, data).split('\n');
for (i = _k = 0, _ref1 = result.length; 0 <= _ref1 ? _k < _ref1 : _k > _ref1; i = 0 <= _ref1 ? ++_k : --_k) {
result[i] = result[i].trimRight();
}
output = output.filter(function(val, i, arr) {
result = result.filter(function(val, i, arr) {
return !(val === '' && arr[i - 1] === '');
});
return output.join('\n');
return result.join('\n');
};

@@ -148,0 +176,0 @@

@@ -52,4 +52,4 @@ module.exports = (function() {

peg$c14 = { type: "literal", value: "=\"", description: "\"=\\\"\"" },
peg$c15 = /^[0-9]/,
peg$c16 = { type: "class", value: "[0-9]", description: "[0-9]" },
peg$c15 = /^[a-zA-Z0-9]/,
peg$c16 = { type: "class", value: "[a-zA-Z0-9]", description: "[a-zA-Z0-9]" },
peg$c17 = "\"",

@@ -56,0 +56,0 @@ peg$c18 = { type: "literal", value: "\"", description: "\"\\\"\"" },

{
"name": "tumblr-theme-parser",
"description": "parse and compile tumblr themes",
"version": "0.0.1",
"version": "1.0.0",
"author": "Sean Lang <slang800@gmail.com>",

@@ -11,3 +11,4 @@ "bin": {

"argparse": "^1.0.2",
"cheerio": "^0.19.0"
"cheerio": "^0.19.0",
"lodash.clone": "^3.0.2"
},

@@ -31,2 +32,3 @@ "devDependencies": {

"main": "lib",
"repository": "git://github.com/slang800/tumblr-theme-parser.git",
"scripts": {

@@ -33,0 +35,0 @@ "test": "mocha"

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc