Plant

Dont just seed, plant.

This gem allows you to define your content in yaml files, then to be loaded into the database by a rake task. You then get source control on your yml files, with the flexibility of being able to use a databse searching engine to search for content.

Installation

Add to your gem file:

gem 'plant'

run bundle install

Then copy the migrations over and run them rake plant:install:migrations rake db:migrate

Usage

Add your content to app/content/any/path/blah.yml, plant will pick up on any yml files in app/content.

With some content added run: rake plant:seed

You can run this as many times as you like and the content will be replaced with tah in your yaml file.

No to output it onto your page, simply use the helper:

= plant_content_for('any.path.blah.key', { scenario: current_user })

You can pass any argument as the scenario argument, plant will call .scenario on it. So if you define a method in your user model called scenario, this will be appended to the node search string:

  class User
     def scenario
        'fish'
     end
  end

=> plant_content_for('red.buses', scenario: current_user) will return the content for 'red.buses.fish' if it exists, if not will return 'red.buses' or 'red.buses.main'

Interpolation

When defining content that needs a parameter, you can use standard ruby interpolation i.e. #name but with SINGLE quotes, otherwise the interpolation will be injected at yaml load time, which will be nil, rather than at run time. If a content is defined as: sample: foo: 'Say hello to #name' Calling plant_content_for('sample.foo', name: 'George') will return 'Say hello to George'

HTML

If you want to include HTML in your content, you can. But when outputing on to the page, you need to pass in html_safe. => plant_content_for('sample.link', html_safe: true)

Capistrano

To work with capistrano include: require 'capistrano/plant' in your Capfile. This is not tested yet. Otherwise take a look at lib/capistrano/tasks/plant.rake on how to run rake task on deploy

Development

To get started, clone the repo and run bundle install. This will get all the stuff that you need. Then a simple bundle exec guard will start the guard runner, which watches on rubocop and specs. If you add functionality, please add tests.

Before pushing back to the repo, make sure that all tests pass.

Future features / Wish list

  • Use git to find diffs so don't have to load all content every time
  • Allow only build certain yml files in rake task
  • integration with Guard (after yml)