From 5d8877d079e40d24bea647af21162edf01b400ca Mon Sep 17 00:00:00 2001 From: Benjamin Lupton Date: Fri, 6 Apr 2012 20:01:34 +1000 Subject: [PATCH] v4.1.0. Feedr plugin now exposes feedr.feeds instead of feeds. Feedr, Partials and Cachr plugins gain README.md and History.md files. Exchange data is now moved to the docpad-extras repo. Fixed broken balupton.docpad skeleton repo url. --- History.md | 7 +- lib/docpad.coffee | 216 ++++++++++-------- lib/exchange/plugins/cachr/History.md | 4 + lib/exchange/plugins/cachr/README.md | 44 ++++ lib/exchange/plugins/feedr/History.md | 7 + lib/exchange/plugins/feedr/README.md | 68 ++++++ .../plugins/feedr/feedr.plugin.coffee | 5 +- lib/exchange/plugins/feedr/package.json | 8 +- lib/exchange/plugins/partials/History.md | 4 + lib/exchange/plugins/partials/README.md | 31 +++ lib/interfaces/console.coffee | 3 +- package.json | 2 +- 12 files changed, 292 insertions(+), 107 deletions(-) create mode 100644 lib/exchange/plugins/cachr/History.md create mode 100644 lib/exchange/plugins/cachr/README.md create mode 100644 lib/exchange/plugins/feedr/History.md create mode 100644 lib/exchange/plugins/feedr/README.md create mode 100644 lib/exchange/plugins/partials/History.md create mode 100644 lib/exchange/plugins/partials/README.md diff --git a/History.md b/History.md index 60b643af..4479e3d2 100644 --- a/History.md +++ b/History.md @@ -1,5 +1,10 @@ ## History +- v4.1.0 April 6, 2012 + - [Feedr Plugin](https://github.com/bevry/docpad/tree/master/lib/exchange/plugins/feedr) now exposes `@feedr.feeds` to the `templateData` instead of `@feeds` + - Exchange data now moved to the [docpad-extras](https://github.com/bevry/docpad-extras) repository + - Fixed broken `balupton.docpad` skeleton repo url + - v4.0.3 April 6, 2012 - Added support for partials, with the new [Partials Plugin](https://github.com/bevry/docpad/tree/master/lib/exchange/plugins/partials) - Added support for caching remote assets, with the new [Cachr Plugin](https://github.com/bevry/docpad/tree/master/lib/exchange/plugins/cachr) @@ -24,7 +29,7 @@ - When an error occurs we will send an error report back to DocPad using [AirBrake](http://airbrake.io/) - To turn this off, set `reportErrors` in your docpad configuration to `false` - Files, Documents, Layouts and Partials are now proper "models" and are now found in the `lib/models` directory - - Moved out some unstable or not as popular plugins to the [DocPad-Extra](https://github.com/bevry/docpad-extra) repository, plugins moved are: + - Moved out some unstable or not as popular plugins to the [docpad-extras](https://github.com/bevry/docpad-extras) repository, plugins moved are: - Admin - Authenticate - AutoUpdate diff --git a/lib/docpad.coffee b/lib/docpad.coffee index 66771e38..db0624d0 100644 --- a/lib/docpad.coffee +++ b/lib/docpad.coffee @@ -82,6 +82,9 @@ class DocPad extends EventSystem # Loaded plugins indexed by name loadedPlugins: {} + # A listing of all the available extensions for DocPad + exchange: {} + # ----------------------------- # Paths @@ -103,51 +106,8 @@ class DocPad extends EventSystem # ----------------------------- - # Exchange - - ### - Exchange Configuration - Still to be decided how it should function for now. - Eventually it will be loaded from: - - a remote url upon initialization - - then stored in ~/.docpad/exchange.json - Used to: - - store the information of available extensions for docpad - ### - exchange: - # Plugins - plugins: {} + # Configuration - # Skeletons - skeletons: - 'kitchensink.docpad': - branch: 'docpad-3.x' - repo: 'git://github.com/bevry/kitchensink.docpad.git' - description: 'The entire kitchensink to showcase everything that docpad is capable of.' - 'canvas.docpad': - branch: 'docpad-3.x' - repo: 'git://github.com/bevry/canvas.docpad.git' - description: 'The bare minimum to get started, with a few bundled client-side libraries to make it easier.' - 'balupton.docpad': - branch: '2012' - repo: 'git://github.com:balupton/balupton.docpad.git' - description: 'The personal website/blog of Benjamin Lupton, the creator of DocPad.' - 'deckpad': - branch: 'master' - repo: 'git://github.com/calvinmetcalf/deckpad.git' - description: 'Build rich HTML5 presentations with DocPad.' - 'nodechat.docpad': - branch: 'master' - repo: 'git://github.com/balupton/nodechat.docpad.git' - description: ''' - A local chat application built with DocPad, Socket.io and Backbone.js. - NOTE: To run nodechat you must use `coffee server.coffee` instead of `docpad run` - ''' - - # Themes - themes: {} - - ### Instance Configuration Loaded from: @@ -171,6 +131,9 @@ class DocPad extends EventSystem # Plugin directories to load loadPlugins: [] + # Where to fetch the exchange information from + exchangeUrl: 'https://raw.github.com/bevry/docpad-extras/master/exchange.json' + # ----------------------------- # Website Paths @@ -286,6 +249,7 @@ class DocPad extends EventSystem @slowPlugins = {} @foundPlugins = {} @loadedPlugins = {} + @exchange = {} # Clean the models @cleanModels() @@ -322,6 +286,55 @@ class DocPad extends EventSystem getDebugging: -> return @getLogLevel() is 7 + # Get Exchange + # Get the exchange data + # Requires internet access + # next(err,exchange) + getExchange: (next) -> + # Check if it is stored locally + return next(null,@exchange) unless _.isEmpty(@exchange) + + # Otherwise fetch it from the exchangeUrl + @loadJsonUrl @config.exchangeUrl, (err,parsedData) -> + return next(err) if err + @exchange = parsedData + return next(null,parsedData) + + # Chain + @ + + # Get Skeletons + # Get all the available skeletons for us and their details + # next(err,skeletons) + getSkeletons: (next) -> + @getExchange (err,exchange) -> + return next(err) if err + skeletons = exchange.skeletons + return next(null,skeletons) + @ + + # Get Skeleton + # Returns a skeleton's details + # next(err,skeletonDetails) + getSkeleton: (skeletonId,next) -> + @getSkeletons (err,skeletons) -> + return next(err) if err + skeletonDetails = skeletons[skeletonId] + return next(null,skeletonDetails) + @ + + # Load a json url + # next(err,parsedData) + loadJsonUrl: (jsonUrl,next) -> + # Read the url using balUtil + balUtil.readPath jsonUrl, (err,data) -> + return next(err) if err + parsedData = JSON.parse(data.toString()) + return next(null,parsedData) + + # Chain + @ + # Load a json path # next(err,parsedData) loadJsonPath: (jsonPath,next) -> @@ -493,59 +506,63 @@ class DocPad extends EventSystem docpad = @ logger = @logger debugging = @getDebugging() - skeletonDetails = @exchange.skeletons[skeletonId] or {} packagePath = path.join(destinationPath, 'package.json') - # Initialize a Git Repository - # Requires internet access - # next(err) - initGitRepo = (next) -> - commands = [ - command: docpad.config.gitPath - args: ['init'] - , - command: docpad.config.gitPath - args: ['remote','add','skeleton',skeletonDetails.repo] - , - command: docpad.config.gitPath - args: ['fetch','skeleton'] - , - command: docpad.config.gitPath - args: ['pull','skeleton',skeletonDetails.branch] - , - command:docpad.config.gitPath - args: ['submodule','init'] - , - command: docpad.config.gitPath - args: ['submodule','update','--recursive'] - ] - logger.log 'debug', "Initializing git pull for the skeleton #{skeletonId}" - balUtil.spawn commands, {cwd:destinationPath,output:debugging}, (err,results) -> - # Check - if err - logger.log 'debug', results - return next(err) - - # Complete - logger.log 'debug', "Initialized git pull for the skeleton #{skeletonId}" - return next() - - # Log - logger.log 'info', "Initializing the skeleton #{skeletonId} to #{destinationPath}" - - # Check if the skeleton path already exists - balUtil.ensurePath destinationPath, (err) -> + # Grab the skeletonDetails + @getSkeleton skeletonId, (err,skeletonDetails) -> # Check - return tasks.exit(err) if err - # Initalize the git repository - initGitRepo (err) -> - return next(err) if err - # And initialize and node modules we may have - docpad.initNodeModules destinationPath, (err) -> - return next(err) if err - logger.log 'info', "Initialized the skeleton #{skeletonId} to #{destinationPath}" + return next(err) if err + + # Initialize a Git Repository + # Requires internet access + # next(err) + initGitRepo = (next) -> + commands = [ + command: docpad.config.gitPath + args: ['init'] + , + command: docpad.config.gitPath + args: ['remote','add','skeleton',skeletonDetails.repo] + , + command: docpad.config.gitPath + args: ['fetch','skeleton'] + , + command: docpad.config.gitPath + args: ['pull','skeleton',skeletonDetails.branch] + , + command:docpad.config.gitPath + args: ['submodule','init'] + , + command: docpad.config.gitPath + args: ['submodule','update','--recursive'] + ] + logger.log 'debug', "Initializing git pull for the skeleton #{skeletonId}" + balUtil.spawn commands, {cwd:destinationPath,output:debugging}, (err,results) -> + # Check + if err + logger.log 'debug', results + return next(err) + + # Complete + logger.log 'debug', "Initialized git pull for the skeleton #{skeletonId}" return next() + # Log + logger.log 'info', "Initializing the skeleton #{skeletonId} to #{destinationPath}" + + # Check if the skeleton path already exists + balUtil.ensurePath destinationPath, (err) -> + # Check + return tasks.exit(err) if err + # Initalize the git repository + initGitRepo (err) -> + return next(err) if err + # And initialize and node modules we may have + docpad.initNodeModules destinationPath, (err) -> + return next(err) if err + logger.log 'info', "Initialized the skeleton #{skeletonId} to #{destinationPath}" + return next() + # Chain @ @@ -1620,7 +1637,6 @@ class DocPad extends EventSystem {opts,next} = @getActionArgs(opts,next) docpad = @ logger = @logger - skeletons = @exchange.skeletons skeletonId = @config.skeleton destinationPath = @config.rootPath selectSkeletonCallback = opts.selectSkeletonCallback or null @@ -1659,11 +1675,15 @@ class DocPad extends EventSystem if skeletonId useSkeleton() else - # Provide selection to the interface - selectSkeletonCallback skeletons, (err,_skeletonId) -> - return fatal(err) if err - skeletonId = _skeletonId - useSkeleton() + # Get the available skeletons + docpad.getSkeletons (err,skeletons) -> + # Check + return complete(err) if err + # Provide selection to the interface + selectSkeletonCallback skeletons, (err,_skeletonId) -> + return fatal(err) if err + skeletonId = _skeletonId + useSkeleton() # Chain @ diff --git a/lib/exchange/plugins/cachr/History.md b/lib/exchange/plugins/cachr/History.md new file mode 100644 index 00000000..aa1b45ec --- /dev/null +++ b/lib/exchange/plugins/cachr/History.md @@ -0,0 +1,4 @@ +## History + +- v0.1.0 March 23, 2012 + - Initial working version for [Benjamin Lupton's Website](https://github.com/balupton/balupton.docpad) \ No newline at end of file diff --git a/lib/exchange/plugins/cachr/README.md b/lib/exchange/plugins/cachr/README.md new file mode 100644 index 00000000..748494dc --- /dev/null +++ b/lib/exchange/plugins/cachr/README.md @@ -0,0 +1,44 @@ +# Cachr Plugin for DocPad + +This plugin caches remote resources locally. + + +## Usage + +To use, simply wrap any url you want to cache locally within the exposed `@cachr(url)` function inside your templates. + +- [CoffeeKup](http://coffeekup.org/) example: + + ``` coffeescript + img src:'http://somewebsite.com/someimage.gif' + ``` + + would become: + + ``` coffeescript + img src:@cachr('http://somewebsite.com/someimage.gif') + ``` + +- [Eco](https://github.com/sstephenson/eco) example: + + ``` coffeescript + + ``` + + would become: + + ``` coffeescript + + ``` + + + +## History + +You can discover the history inside the `History.md` file + + +## License + +Licensed under the [MIT License](http://creativecommons.org/licenses/MIT/) +
Copyright © 2012 [Bevry Pty Ltd](http://bevry.me) \ No newline at end of file diff --git a/lib/exchange/plugins/feedr/History.md b/lib/exchange/plugins/feedr/History.md new file mode 100644 index 00000000..2b5085d0 --- /dev/null +++ b/lib/exchange/plugins/feedr/History.md @@ -0,0 +1,7 @@ +## History + +- v0.2.0 April 6, 2012 + - Now exposes `@feedr.feeds` to the `templateData` instead of `@feeds` + +- v0.1.0 March 23, 2012 + - Initial working version for [Benjamin Lupton's Website](https://github.com/balupton/balupton.docpad) \ No newline at end of file diff --git a/lib/exchange/plugins/feedr/README.md b/lib/exchange/plugins/feedr/README.md new file mode 100644 index 00000000..ffa95c41 --- /dev/null +++ b/lib/exchange/plugins/feedr/README.md @@ -0,0 +1,68 @@ +# Feedr Plugin for DocPad + +This plugin is able to pull in remote json and xml feeds, convert them to JSON data, and expose them to `@feedr.feeds[feednName]` for your templates. + + +## Usage + +### Setup + +First we have to tell Feedr which feeds it should retrieve, you can do this by adding the following to your website's `package.json` file: + +``` json +"docpad": { + "plugins": { + "feedr": { + "feeds": { + "twitter": { + "url": "https://api.twitter.com/1/statuses/user_timeline.json?screen_name=balupton&count=20&include_entities=true&include_rts=true" + }, + "someOtherFeedName": { + "url": "someOtherFeedUrl" + } + } + } + } +} +``` + +### Rendering + +Then inside your templates, we would do something like the following to render the items: + +- Using [CoffeeKup](http://coffeekup.org/) + + ``` coffeescript + ul -> + for tweet in @feedr.feeds.twitter + continue if tweet.in_reply_to_user_id + li datetime: tweet.created_at, -> + a href: "https://twitter.com/#!/#{tweet.user.screen_name}/status/#{tweet.id_str}", title: "View on Twitter", -> + tweet.text + ``` + +- Using [Eco](https://github.com/sstephenson/eco) + + ``` coffeescript + + ``` + + +## History + +You can discover the history inside the `History.md` file + + +## License + +Licensed under the [MIT License](http://creativecommons.org/licenses/MIT/) +
Copyright © 2012 [Bevry Pty Ltd](http://bevry.me) \ No newline at end of file diff --git a/lib/exchange/plugins/feedr/feedr.plugin.coffee b/lib/exchange/plugins/feedr/feedr.plugin.coffee index 1e660ac1..de166321 100644 --- a/lib/exchange/plugins/feedr/feedr.plugin.coffee +++ b/lib/exchange/plugins/feedr/feedr.plugin.coffee @@ -18,7 +18,8 @@ module.exports = (BasePlugin) -> # Prepare feedr = @ feeds = @config.feeds or {} - templateData.feeds = {} + templateData.feedr = + feeds: {} # Tasks tasks = new balUtil.Group (err) -> @@ -29,7 +30,7 @@ module.exports = (BasePlugin) -> tasks.push -> feedr.readFeed feedName, feedData, (err,body) -> return tasks.complete(err) if err - templateData.feeds[feedName] = body + templateData.feedr.feeds[feedName] = body return tasks.complete(err) # Async diff --git a/lib/exchange/plugins/feedr/package.json b/lib/exchange/plugins/feedr/package.json index ffb3e800..6875950f 100644 --- a/lib/exchange/plugins/feedr/package.json +++ b/lib/exchange/plugins/feedr/package.json @@ -1,6 +1,6 @@ { "name": "docpad-feedr", - "version": "0.1.0", + "version": "0.2.0", "description": "Adds support for reading feeds to DocPad", "homepage": "https://github.com/bevry/docpad", "keywords": [ @@ -14,9 +14,9 @@ "json" ], "author": { - "name": "Benjamin Lupton", - "email": "b@lupton.cc", - "url": "http://balupton.com" + "name": "Bevry Pty Ltd", + "email": "us@bevry.me", + "url": "http://bevry.me" }, "maintainers": [ { diff --git a/lib/exchange/plugins/partials/History.md b/lib/exchange/plugins/partials/History.md new file mode 100644 index 00000000..8b2092f5 --- /dev/null +++ b/lib/exchange/plugins/partials/History.md @@ -0,0 +1,4 @@ +## History + +- v0.1.0 March 31, 2012 + - Initial working version for [Benjamin Lupton's Website](https://github.com/balupton/balupton.docpad) \ No newline at end of file diff --git a/lib/exchange/plugins/partials/README.md b/lib/exchange/plugins/partials/README.md new file mode 100644 index 00000000..7448d017 --- /dev/null +++ b/lib/exchange/plugins/partials/README.md @@ -0,0 +1,31 @@ +# Partials Plugin for DocPad + +This plugin provides DocPad with Partials. Partials are documents which can be inserted into other documents, and are also passed by the docpad rendering engine. + + +## Usage + +### Setup + +To use, first create the `src/partials` directory, and place any partials you want to use in there. + +Then in our templates we will be exposed with the `@partial(filename,data)` function. The `data` argument is optional, and can be used to send custom data to the partial's `templateData`. + + +### Example + +For instance we could create the file `src/partials/hello.html.md` which contains `**Hello <%=@name or 'World'%>**`. + +We could then render it by using `<%=@partial('hello.html.coffee')%>` to get back `Hello World` or with `<%=@partial('hello.html.coffee',{name:'Apprentice'})%>` to get back `Hello Apprentice`. + + + +## History + +You can discover the history inside the `History.md` file + + +## License + +Licensed under the [MIT License](http://creativecommons.org/licenses/MIT/) +
Copyright © 2012 [Bevry Pty Ltd](http://bevry.me) \ No newline at end of file diff --git a/lib/interfaces/console.coffee b/lib/interfaces/console.coffee index 2d49c99b..95e3b1a7 100644 --- a/lib/interfaces/console.coffee +++ b/lib/interfaces/console.coffee @@ -146,9 +146,10 @@ class ConsoleInterface ''' for own skeletonId, skeleton of skeletons ids.push(skeletonId) + skeletonDescription = skeleton.description.replace(/\n/g,'\n\t') console.log """ \t#{cliColor.bold(skeletonId)} - \t#{skeleton.description} + \t#{skeletonDescription} """ diff --git a/package.json b/package.json index 5c4f672a..c35a0352 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "docpad", - "version": "4.0.3", + "version": "4.1.0", "description": "DocPad is a language agnostic document management system. This means you write your website as documents, in whatever language you wish, and DocPad will handle the compiling, templates and layouts for you. For static documents it will generate static files, for dynamic documents it'll re-render them on each request. You can utilise DocPad by itself, or use it as a module your own custom system. It's pretty cool, and well worth checking out. We love it.", "homepage": "https://github.com/bevry/docpad", "keywords": [