Skip to content

nfriedly/docpad-plugin-mongo

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

MongoDB plugin

Add to docpad.coffee

# Define the DocPad Configuration
docpadConfig = {

	[...]

	plugins:

		mongo:
			hostname: 'mongodb://...:...@troup.mongohq.com:10044/'
			# hostname: 'mongodb://localhost/'
			user: ...
			pass: ...
			database: 'app22118608'		
			collection: 'gigs',
			customSchema:
				town: String,
				date: { type: Date, default: Date.now },
				location: String,
				link: String		
			queryArr: [
				name: "futuregigs"
				predicate: {"date": {$gte: new Date()}}
			,
				name: "pastgigs"
				predicate: {"date": {$lt: new Date()}}
			]
}

# Export the DocPad Configuration
module.exports = docpadConfig

Example of usage in eco file, note the extra hidden input element that tells the server which predicate to use to rewrite all the content of (it will delete everything matching the predicate first and then insert the data sent from the client).

<% zero_pad = (x) -> if x < 10 then '0'+x else ''+x %>
<input type='hidden' id='queryName' value='futuregigs'>
<% if @gigs.length: %>
	<% for gig in @futuregigs: %>
		<% mString = gig.date.getFullYear() %>
		<% mString += "-"+ zero_pad (gig.date.getMonth() + 1) %>
		<% mString += "-"+ zero_pad gig.date.getDate() %>
		<div class="gig-entry">
			<input type="hidden" name="_id" value="<%= gig._id %>">
			<input type="date" name="date" width="20" value="<%- mString %>">
			<input type="textarea" name="location" value="<%= gig.location %>">
			<input type="textarea" name="town" value="<%= gig.town %>">
			<input type="textarea" name="link" value="<%= gig.link %>">
		</div>
	<% end %>
<% end %>

About

Forked to fix a couple of bugs, but I ended up creating a new plugin to replace it:

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published