Skip to content

Commit

Permalink
* Transformer for embedding figures (interactive JavaScript widgets) …
Browse files Browse the repository at this point in the history
…in blog posts
  • Loading branch information
joehewitt committed Oct 29, 2011
1 parent 1eceee0 commit 08c63a7
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 6 deletions.
28 changes: 22 additions & 6 deletions lib/Blog.js
Expand Up @@ -40,7 +40,6 @@ function Blog(conf, cb) {

this._assignConf(conf);

this.reload = aggregate(this.reload);
this.reload(cb);
}

Expand All @@ -55,6 +54,20 @@ function subclass(cls, supercls, proto) {
}

subclass(Blog, events.EventEmitter, {
useApp: function(app) {
this.app = app;

if (app) {
this._findContent(_.bind(function() {
this.contentPaths.forEach(function(contentPath) {
if (contentPath.all) {
app.paths.unshift(contentPath.path);
}
});
}, this));
}
},

rssRoute: function(numberOfPosts) {
var rssRoute = syndicate.route(this, numberOfPosts);
if (this.cache) {
Expand Down Expand Up @@ -212,7 +225,7 @@ subclass(Blog, events.EventEmitter, {
}, this), 50);
},

reload: function(cb) {
reload: aggregate(function(cb) {
if (!this.isInvalid) {
if (cb) cb(0);
return;
Expand Down Expand Up @@ -324,11 +337,11 @@ subclass(Blog, events.EventEmitter, {
}
}
}, cb, this));
},
}),

normalizeURL: function(URL) {
if (this.normalizeCallback) {
return this.normalizeCallback(URL);
normalizeURL: function(URL, type) {
if (this.app) {
return this.app.normalizeURL(URL, type);
} else {
return URL;
}
Expand Down Expand Up @@ -618,6 +631,9 @@ subclass(Blog, events.EventEmitter, {
var ImageTransformer = require('./ImageTransformer').ImageTransformer;
this.addTransform(new ImageTransformer());

var FigureTransformer = require('./FigureTransformer').FigureTransformer;
this.addTransform(new FigureTransformer());

// XXXjoe Not yet implemented
// if (conf.facebook) {
// var FacebookTransformer = require('./FacebookTransformer').FacebookTransformer;
Expand Down
31 changes: 31 additions & 0 deletions lib/FigureTransformer.js
@@ -0,0 +1,31 @@

var _ = require('underscore');
var path = require('path');
var fs = require('fs');
var abind = require('dandy/errors').abind;
var ibind = require('dandy/errors').ibind;

// ************************************************************************************************

function FigureTransformer() {
}
exports.FigureTransformer = FigureTransformer;

FigureTransformer.prototype = {
pattern: /^figure:(.*?)\/(.*?)$/,

transform: function(post, projectName, figureName, url, title, alt, query, cb) {
if (!projectName || !figureName) { cb(new Error("Invalid figure URL")); return; }

var divClass = "figure-" + projectName + "-" + figureName;

var timestamp = '';
if (timestamp) {
projectName += '@' + timestamp;
}

var tag = '<div class="figure" require="' + projectName + '" figure="' + figureName + '">' + alt + '</div>';

cb(0, {content: tag});
}
};

0 comments on commit 08c63a7

Please sign in to comment.