Permalink
Browse files

Making a new 'right_rails' generator

  • Loading branch information...
1 parent 46e1348 commit 639c2258d2e0f5e74e9079db2683a3baa07e7142 @MadRabbit committed Nov 10, 2011
Showing with 37 additions and 1 deletion.
  1. +1 −1 README.rdoc
  2. +36 −0 lib/generators/right_rails/right_rails_generator.rb
View
@@ -29,7 +29,7 @@ Just add the following into your +Gemfile+
If you're on Rails < 3.1 then run the +right_rails+ generator
- script/generate right_rails
+ rails g right_rails
If you're using Rails 3.1 with the pipeline assets handler, then you
can require things in your +application.js+ file
@@ -0,0 +1,36 @@
+#
+# Copies all the javascripts in place and updates them if necessary
+#
+# Kudos to Jose Fernández (http://github.com/magec)
+#
+class RightRailsGenerator < Rails::Generators::Base
+
+ def manifest
+ source_path = File.dirname(__FILE__)
+ images_path = "#{source_path}/../../../vendor/assets/images/rightjs-ui"
+ javascripts_path = "#{source_path}/../../../vendor/assets/javascripts"
+
+ # copying the javascript javascript files
+ directory javascripts_path , "public/javascripts"
+
+ # copying the images in place
+ directory images_path, "public/images/rightjs-ui"
+
+ # patching up the JS files to use images from 'pubic/images'
+ Dir['public/javascripts/right/*.js'].each do |filename|
+ old_content = File.read(filename)
+ new_content = old_content.gsub("url(/assets/rightjs-ui/", "url(/images/rightjs-ui/")
+
+ if old_content != new_content
+ File.open(filename, "w") do |f|
+ f.write new_content
+ end
+ end
+ end
+ end
+
+ def banner
+ "Usage: #{$0} right_rails"
+ end
+
+end

0 comments on commit 639c225

Please sign in to comment.