New: Introducing PHP and Composer Support.Read the Announcement
Socket
Book a DemoInstallSign in
Socket

docpad-plugin-mongodb

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

docpad-plugin-mongodb

Import your mongodb collections to DocPad collections

Source
npmnpm
Version
2.2.0
Version published
Weekly downloads
1
-75%
Maintainers
1
Weekly downloads
 
Created
Source

EXPERIMENTAL MongoDB Importer Plugin for DocPad

Build Status NPM version Dependency Status Development Dependency Status Gittip donate button

Import MongoDB collections into DocPad collections.

Inspired by https://github.com/simonh1000/docpad-plugin-mongo and based on https://github.com/docpad/docpad-plugin-tumblr/

Install

docpad install mongodb

Configuration

Simple example

Add the following to your docpad configuration file via:

plugins:
  mongodb:
    collections: [
      connectionString: "mongodb://localhost/blog" # format is "mongodb://username:password@hostname:port/dbname?options"
      collectionName: "posts"
      relativeDirPath: "blog"
      extension: ".html"
      sort: date: 1 # newest first
      meta:
        layout: "blogpost"
    ]

Fancy example

plugins:
  mongodb:
    collectionDefaults:
      connectionString: "mongodb://localhost/blog" # format is "mongodb://username:password@hostname:port/dbname?options"

    collections: [
      {
        # connectionString is imported from the defaults
        collectionName: "posts"
        relativeDirPath: "blog"
        extension: '.html.eco'
        sort: date: 1 # newest first
        injectDocumentHelper: (document) ->
          document.setMeta(
            layout: 'default'
            tags: (document.get('tags') or []).concat(['post'])
            data: """
              <%- @partial('post/'+@document.tumblr.type, @extend({}, @document, @document.tumblr)) %>
              """
          )
      },

      {
        collectionName: "comments"
        extension: '.html.markup'
        sort: date: -1 #oldest first
        meta:
          write: false
      },

      {
        connectionString: "mongodb://localhost/stats"
        collectionName: "stats"
        extension: ".json"
      }
    ]

Config details:

Each configuration object in collections inherits defalt values from collectionDefaults and then from the built-in defaults:

  connectionString: process.env.MONGOLAB_URI || process.env.MONGOHQ_URL || "mongodb://localhost/localdev"
  relativeDirPath: null # defaults to collectionName
  extension: ".json"
  injectDocumentHelper: null
  collectionName: "mongodb"
  meta: {}

The default directory for where the imported documents will go inside is the collectionName. You can override this using the relativeDirPath plugin config option.

The default content for the imported documents is JSON data. You can can customise this with the injectDocumentHelper plugin configuration option which is a function that takes in a single Document Model.

If you would like to render a template, add a layout, and change the extension, you can this with the eco and partials plugins and following collection configuration:

extension: '.html.eco'
injectDocumentHelper: (document) ->
  document.setMeta(
    layout: 'default'
    tags: (document.get('tags') or []).concat(['post'])
    data: """
			<%- @partial('post/'+@document.tumblr.type, @extend({}, @document, @document.tumblr)) %>
			"""
  )

The sort field is passed as the comparator to Query Engine which tries it as a MongoDB-style sort first and then a Backbone.js comparator second.

Creating a File Listing

As imported documents are just like normal documents, you can also list them just as you would other documents. Here is an example of a index.html.eco file that would output the titles and links to all the blog posts from the simple example above:

<h2>Blog:</h2>
<ul><% for post in @getCollection('posts').toJSON(): %>
	<li>
		<a href="<%= post.url %>"><%= post.title %></a>
	</li>
<% end %></ul>

History

Discover the change history by heading on over to the HISTORY.md file.

Contribute

Discover how you can contribute by heading on over to the CONTRIBUTING.md file.

License

Licensed under the incredibly permissive MIT license

Copyright © Bevry Pty Ltd us@bevry.me (http://bevry.me)

Keywords

docpad

FAQs

Package last updated on 21 Oct 2014

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts