Skip to content

Commit

Permalink
Update the install destination of javascript to use vendor
Browse files Browse the repository at this point in the history
It is not possible to configure the Rails application to not use the
asset pipeline in newer versions of Rails, so that setting has been
removed.

Additionally, we can install the javascript provided by the gem into the
vendor directory in the Rails app, so that the user can customize it if
needed.
  • Loading branch information
mjankowski committed Feb 24, 2015
1 parent 4eaabbc commit 6233f14
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
12 changes: 4 additions & 8 deletions lib/generators/paul_revere/paul_revere_generator.rb
Expand Up @@ -7,26 +7,22 @@ class PaulRevereGenerator < Rails::Generators::Base
source_root File.join(File.dirname(__FILE__), "templates")

def install
copy_javascript if needs_js_copied?
copy_javascript
migration_template "migration.rb", "db/migrate/create_announcements.rb"
end

private

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

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

def needs_js_copied?
!::Rails.application.config.assets.enabled
end

def js_destination
'public/javascripts/announcements.js'
def javascript_destination
"vendor/assets/javascripts/announcements.js"
end

def self.next_migration_number(dirname)
Expand Down
15 changes: 14 additions & 1 deletion spec/lib/generators/paul_revere/paul_revere_generator_spec.rb
Expand Up @@ -11,7 +11,7 @@
run_generator
end

specify do
it "installs the migrations" do
expect(destination_root).to have_structure {
directory "db" do
directory "migrate" do
Expand All @@ -24,4 +24,17 @@
}
end

it "installs the javascript" do
expect(destination_root).to have_structure {
directory "vendor" do
directory "assets" do
directory "javascripts" do
file "announcements.js" do
contains "hideAnnouncement"
end
end
end
end
}
end
end

0 comments on commit 6233f14

Please sign in to comment.