From c7a91ffff1ae32d1d795433eb1b916509a39cd65 Mon Sep 17 00:00:00 2001 From: Hannah Wolfe Date: Wed, 18 Sep 2013 19:49:10 +0100 Subject: [PATCH] Removing FancyFirstChar plugin - requires removal of most of the plugin tests --- content/plugins/FancyFirstChar/index.js | 101 -------------- content/plugins/README.md | 3 + core/test/unit/plugins_spec.js | 173 +----------------------- 3 files changed, 4 insertions(+), 273 deletions(-) delete mode 100644 content/plugins/FancyFirstChar/index.js create mode 100644 content/plugins/README.md diff --git a/content/plugins/FancyFirstChar/index.js b/content/plugins/FancyFirstChar/index.js deleted file mode 100644 index 39b8557bef..0000000000 --- a/content/plugins/FancyFirstChar/index.js +++ /dev/null @@ -1,101 +0,0 @@ -var util = require('util'), - _ = require('underscore'), - fancifyPlugin, - whiteSpace = [ - '', - ' ', - '\t', - '\n', - '\r' - ]; - -fancifyPlugin = { - - // Fancify a single post body - fancify: function (originalContent) { - var newContent, - firstCharIndex = 0, - firstChar, - getIndexOfNextCharacter = function (beginFrom) { - var currIndex = beginFrom, - nextChar; - - nextChar = originalContent.substr(currIndex, 1); - while (_.contains(whiteSpace, nextChar) && currIndex !== originalContent.length) { - currIndex += 1; - nextChar = originalContent.substr(currIndex, 1); - } - - return currIndex; - }, - getAfterNextClosingTag = function (beginFrom) { - return originalContent.indexOf('>', beginFrom) + 1; - }; - - // Skip any leading white space until we get a character - firstCharIndex = getIndexOfNextCharacter(firstCharIndex); - - firstChar = originalContent.substr(firstCharIndex, 1); - while (firstChar === '<') { - // Get after the close of the tag - firstCharIndex = getAfterNextClosingTag(firstCharIndex); - - // Skip any white space until we get a character - firstCharIndex = getIndexOfNextCharacter(firstCharIndex); - - // Grab the character - firstChar = originalContent.substr(firstCharIndex, 1); - } - - // Do nothing if we found no characters - if (firstCharIndex === originalContent.length) { - return originalContent; - } - - newContent = originalContent.substr(0, firstCharIndex); - newContent += ''; - newContent += originalContent.substr(firstCharIndex, 1); - newContent += ''; - newContent += originalContent.substr(firstCharIndex + 1, originalContent.length - firstCharIndex - 1); - - return newContent; - }, - - // Fancify a collection of posts - fancifyPosts: function (posts) { - var self = this; - - if (_.isArray(posts)) { - _.each(posts, function (post) { - post.html = self.fancify(post.html); - }); - } else if (posts.hasOwnProperty('html')) { - posts.html = this.fancify(posts.html); - } - - return posts; - }, - - install: function () { - - }, - - uninstall: function () { - - }, - - // Registers the prePostsRender filter to alter the html. - activate: function (ghost) { - ghost.registerFilter('prePostsRender', this.fancifyPosts); - }, - - // Unregister any filters. - deactivate: function (ghost) { - ghost.unregisterFilter("prePostsRender", this.fancifyPosts); - } -}; - -// Ensure our this context in the important methods -_.bindAll(fancifyPlugin, "fancifyPosts", "fancify", "activate", "deactivate"); - -module.exports = fancifyPlugin; \ No newline at end of file diff --git a/content/plugins/README.md b/content/plugins/README.md new file mode 100644 index 0000000000..c8faafb4a4 --- /dev/null +++ b/content/plugins/README.md @@ -0,0 +1,3 @@ +# Content / Plugins + +Coming soon, Ghost plugins will appear here \ No newline at end of file diff --git a/core/test/unit/plugins_spec.js b/core/test/unit/plugins_spec.js index 480a837387..0129c0cfbf 100644 --- a/core/test/unit/plugins_spec.js +++ b/core/test/unit/plugins_spec.js @@ -9,8 +9,7 @@ var testUtils = require('./testUtils'), // Stuff we are testing plugins = require('../../server/plugins'), GhostPlugin = plugins.GhostPlugin, - loader = require('../../server/plugins/loader'), - FancyFirstChar = require('../../../content/plugins/FancyFirstChar'); + loader = require('../../server/plugins/loader'); describe('Plugins', function () { @@ -60,174 +59,4 @@ describe('Plugins', function () { _.isFunction(plugin.deactivate).should.equal(true); }); }); - - describe('loader', function () { - - // TODO: These depend heavily on the FancyFirstChar plugin being present. - - it('can load FancyFirstChar by name and unload', function (done) { - var fancyPlugin = require("../../../content/plugins/FancyFirstChar"), - fakeGhost = { - registerFilter: function () { return; }, - unregisterFilter: function () { return; } - }, - installMock = sinon.stub(fancyPlugin, "install"), - uninstallMock = sinon.stub(fancyPlugin, "uninstall"), - registerMock = sinon.stub(fakeGhost, "registerFilter"), - unregisterMock = sinon.stub(fakeGhost, "unregisterFilter"); - - loader.installPluginByName("FancyFirstChar", fakeGhost).then(function (loadedPlugin) { - - should.exist(loadedPlugin); - - installMock.called.should.equal(true); - - loadedPlugin.activate(fakeGhost); - - // Registers the filter - registerMock.called.should.equal(true); - - loadedPlugin.deactivate(fakeGhost); - - // Unregisters the filter - unregisterMock.called.should.equal(true); - - loadedPlugin.uninstall(fakeGhost); - - done(); - }, done); - }); - }); - - it("can initialize an array of plugins", function (done) { - - var fakeGhost = { - registerFilter: sandbox.stub(), - unregisterFilter: sandbox.stub() - }, - installSpy = sinon.spy(loader, "installPluginByName"), - activateSpy = sinon.spy(loader, "activatePluginByName"); - - plugins.init(fakeGhost, ["FancyFirstChar"]).then(function (loadedPlugins) { - should.exist(loadedPlugins); - should.exist(loadedPlugins["FancyFirstChar"]); - - installSpy.called.should.equal(true); - activateSpy.called.should.equal(true); - - var api = require("../../server/api"); - - return api.settings.read("installedPlugins").then(function (setting) { - should.exist(setting); - - setting.value.should.equal('["FancyFirstChar"]'); - - done(); - }); - }, done); - }); - - describe("FancyFirstChar", function () { - - it("has install and uninstall handlers", function () { - should.exist(FancyFirstChar.install); - should.exist(FancyFirstChar.uninstall); - }); - - it("activates and deactivates properly", function () { - var fakeGhost = { - registerFilter: sandbox.stub(), - unregisterFilter: sandbox.stub() - }; - - FancyFirstChar.activate(fakeGhost); - - fakeGhost.registerFilter.called.should.equal(true); - - FancyFirstChar.deactivate(fakeGhost); - - fakeGhost.unregisterFilter.called.should.equal(true); - }); - - it("fancifies simple text", function () { - var original = "Some text to fancify", - expect = 'Some text to fancify', - result; - - result = FancyFirstChar.fancify(original); - - result.should.equal(expect); - }); - - it("fancifies in single tag", function () { - var original = "

Some text to fancify

", - expect = '

Some text to fancify

', - result; - - result = FancyFirstChar.fancify(original); - - result.should.equal(expect); - }); - - it("fancifies in nested tag", function () { - var original = "

Some text to fancify

", - expect = '

Some text to fancify

', - result; - - result = FancyFirstChar.fancify(original); - - result.should.equal(expect); - }); - - it("fancifies in nested nested tag", function () { - var original = "

Some text to fancify

", - expect = '

Some text to fancify

', - result; - - result = FancyFirstChar.fancify(original); - - result.should.equal(expect); - }); - - it("fancifies with tags before first text", function () { - var original = "
Kitteh

Some text to fancify

", - expect = "
Kitteh

Some text to fancify

", - result; - - result = FancyFirstChar.fancify(original); - - result.should.equal(expect); - }); - - it("does nothing if no text found", function () { - var original = "
Kitteh
", - expect = "
Kitteh
", - result; - - result = FancyFirstChar.fancify(original); - - result.should.equal(expect); - }); - - it("skips leading white space", function () { - var original = "\n\t

Some text to fancify

", - expect = '\n\t

Some text to fancify

', - result; - - result = FancyFirstChar.fancify(original); - - result.should.equal(expect); - }); - - it("skips white space in inner tags", function () { - var original = "\n\t

\n\t\t Some text to fancify

", - expect = '\n\t

\n\t\t Some text to fancify

', - result; - - result = FancyFirstChar.fancify(original); - - result.should.equal(expect); - }); - }); - }); \ No newline at end of file