Watch Static Files, Convert them to Database Records (Mongoid, ActiveRecord, etc.)
Ruby
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
lib/guard
spec
.gitignore
.rspec
MIT-LICENSE
README.md
Rakefile
guard-post.gemspec

README.md

GuardPost

Watch Static Files, Convert them to Database Records (Mongoid, ActiveRecord, etc.).

Install

gem install guard-post
guard init post

Usage

This just tells you when a file has changed. You can use this for blogging with post-modern, which just reads a Markdown file with a YAML header (like in Jekyll), and syntax highlights the content (and executes inline Haml so you can use Haml in markdown for things like tables). Here's an example:

Guardfile

# :update => callback, :rails => true|false (loads current development rails env if so)
guard "post", :update => lambda { |file| Post.save_from_file!(file) } do
  watch(%r{^app/documents/(.+\.md)})
end

Example Model

# app/models/post.rb
class Post
  include Mongoid::Document

  field :title
  field :tags, :type => Array
  field :content

  def save_from_file!(path)
    attributes  = PostModern.read(path)
    post        = Post.where(:file => attributes[:file]).first

    if post.present?
      post.update_attributes(attributes)
    else
      post = Post.create(attributes)
    end

    post
  end
end

This way, whenever you save a markdown file, you can render the content and save it to some database, making static files dynamic.


MIT License. © 2011 Lance Pollard. Free to use for whatever.