Skip to content

rantecki/docpad-plugin-associatedfiles

 
 

Repository files navigation

Associated Files Plugin for DocPad

Build Status NPM version Dependency Status Development Dependency Status
Gittip donate button Flattr donate button PayPayl donate button BitCoin donate button

This plugin streamlines finding associated files for a particular document in DocPad, which is useful for:

  • getting images for a gallery
  • getting downloads for an article
  • etc. etc.

Install

docpad install associatedfiles

Usage

The way it works is by looking into src/files/associated-files/#{document.associatedFilesDirectory or document.basename} for files. Where associatedFilesDirectory is set in your document's meta data, and if it doesn't exist it will use the document's basename (e.g. the basename of my-holiday-2012.html.eco is my-holiday-2012). Any files inside that path will be associated to your document, and retrieveable by @getDocument().getAssociatedFiles()

Lets see how this works, we have the document src/documents/my-holiday-2012.html.eco:

---
title: My Holiday in 2012
---

<h2>Here are some great photos from our trip</h2>

<% for file in @getDocument().getAssociatedFiles().toJSON(): %>
<p>
	<h3><%= file.title or file.name %></h3>
	<img src="<%= file.url %>" title="<%= file.title or file.name %>" />
</p>
<% end %>

Then we will stick a few images inside our path: src/files/associated-files/my-holiday-2012. And we'll end up with the rendered result:

<h2>Here are some great photos from our trip</h2>

<p>
	<h3>sweet-sweet-beach.jpg</h3>
	<img src="/associated-files/my-holiday-2012/sweet-sweet-beach.jpg" title="sweet-sweet-beach.jpg" />
</p>

<p>
	<h3>sweet-sweet-icecream.jpg</h3>
	<img src="/associated-files/my-holiday-2012/sweet-sweet-icecream.jpg" title="sweet-sweet-icecream.jpg" />
</p>

Ins't that cool?

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.

Backers

Maintainers

These amazing people are maintaining this project:

Sponsors

No sponsors yet! Will you be the first?

Gittip donate button Flattr donate button PayPayl donate button BitCoin donate button

Contributors

These amazing people have contributed code to this project:

Become a contributor!

License

Licensed under the incredibly permissive MIT license

Copyright © Bevry Pty Ltd [email protected] (http://bevry.me)

About

DocPad plugin that fetches any associated files for our particular document

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • CoffeeScript 98.8%
  • JavaScript 1.2%