Skip to content

Commit

Permalink
Use the asset pipeline when possible
Browse files Browse the repository at this point in the history
  • Loading branch information
mike-burns committed Sep 13, 2012
1 parent 3a986d5 commit 5e9046a
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 9 deletions.
44 changes: 37 additions & 7 deletions README.md
Expand Up @@ -6,17 +6,44 @@ Paul Revere

Simple announcement plugin to include "one off" style announcements in Rails web apps.

Install
-------
Install with the asset pipeline (Rails 3.1+, asset pipeline enabled)
--------------------------------------------------------------------

Install as normal in your Gemfile:

gem 'paul_revere'

Run the generator to create the migration and copy the javascript file into public:
Run the generator to create the migration:

rails generate paul_revere

Add the announcement JS to `app/assets/javascripts/application.js`:

//= require announcements

Run the migration:

rake db:migrate && rake db:migrate:redo

Install without the asset pipeline (Rails 3.0 or asset pipeline disabled)
---------------------------------------------------------------------------

Install as normal in your Gemfile:

gem 'paul_revere'

Run the generator to create the migration and copy the JavaScript file into public:

rails generate paul_revere

Add the announcement JS to your layout, such as `app/views/layouts/application.html.erb`:

<%= javascript_include_tag 'announcements' %>

Run the migration:

rake db:migrate && rake db:migrate:redo

Usage
-----

Expand All @@ -31,9 +58,13 @@ Paul Revere provides...
So the flow would be...

* Install the gem
* Add `helper :announcements` either to application_controller.rb or to the specific controllers where you want to make the announcement helpers available
* Use those partials in the correct places in your view code and mailer view code where you want announcements to show up
* When you want to make an announcement, use the rails console to create a new Announcement record
* Use those partials in the correct places in your view code and mailer view code where you want announcements to show up:

<%= render 'announcements/announcement_for_all' %>

* When you want to make an announcement, use the Rails console to create a new `Announcement` record:

Announcement.create!(body: 'This Web site is shutting down because you refuse to pay')

Beastie Boys Lyrics
-------------------
Expand Down Expand Up @@ -104,7 +135,6 @@ His boy had beef and he got dropped
Mike D. grabbed the money M.C.A. snatched the gold
I grabbed two girlies and a beer that's cold.


Credits
-------

Expand Down
File renamed without changes.
22 changes: 20 additions & 2 deletions lib/generators/paul_revere/paul_revere_generator.rb
Expand Up @@ -4,11 +4,29 @@ class PaulRevereGenerator < Rails::Generators::Base
include Rails::Generators::Migration
extend ActiveRecord::Generators::Migration

desc "Put the javascript and migration in place"
desc "Put the JavaScript and migration in place"
source_root File.join(File.dirname(__FILE__), "templates")

def install
copy_file "announcements.js", "public/javascripts/announcements.js"
copy_javascript if needs_js_copied?
migration_template "migration.rb", "db/migrate/create_announcements.rb"
end

private

def copy_javascript
copy_file File.join(javascript_path, 'announcements.js'), js_destination
end

def javascript_path
File.join(%w(.. .. .. .. app assets javascripts))
end

def needs_js_copied?
::Rails.version < '3.1' || !::Rails.application.config.assets.enabled
end

def js_destination
'public/javascripts/announcements.js'
end
end

0 comments on commit 5e9046a

Please sign in to comment.