Browse files

Going back to generators instead of Rake tasks for copying stylesheet…

…s and config files, because Rake tasks are not detected in Rails gem plugins (partially reverts 852751b).

* nuked the stylesheets rake task in favor of the old generator
* nuked the config rake task in favor of a new generator
* updated gemspec to match new files
  • Loading branch information...
1 parent 10d7da5 commit 2526d2c126cd246de3a792565e5496ef8f22a25b @justinfrench committed Oct 11, 2009
View
8 README.textile
@@ -79,7 +79,7 @@ RDoc documentation _should_ be automatically generated after each commit and mad
h2. Installation
-You can (and should) get it as a gem:
+You can and should get it as a gem:
<pre>
gem install justinfrench-formtastic
@@ -93,12 +93,14 @@ And then add it as a dependency in your environment.rb file:
:source => 'http://gems.github.com'
</pre>
-If you're a little more old school, install it as a plugin:
+Run the generator to add a (commented out) Formtastic config file to your app's config/initializers/:
<pre>
- ./script/plugin install git://github.com/justinfrench/formtastic.git
+ ./script/generate formtastic_config
</pre>
+See also "What about Stylesheets?"
+
h2. Usage
View
5 formtastic.gemspec
@@ -17,6 +17,11 @@ Gem::Specification.new do |s|
"MIT-LICENSE",
"README.textile",
"Rakefile",
+ "generators/formtastic_config/formtastic_config_generator.rb",
+ "generators/formtastic_config/templates/formtastic.rb",
+ "generators/form/form_generator.rb",
+ "generators/form/templates/view__form.html.erb",
+ "generators/form/templates/view__form.html.haml",
"generators/formtastic_stylesheets/formtastic_stylesheets_generator.rb",
"generators/formtastic_stylesheets/templates/formtastic.css",
"generators/formtastic_stylesheets/templates/formtastic_changes.css",
View
20 generators/formtastic_config/formtastic_config_generator.rb
@@ -0,0 +1,20 @@
+class FormtasticConfigGenerator < Rails::Generator::Base
+
+ def initialize(*runtime_args)
+ super
+ end
+
+ def manifest
+ record do |m|
+ m.directory File.join('config', 'initializers')
+ m.template 'formtastic.rb', File.join('config', 'initializers', 'formtastic.rb')
+ end
+ end
+
+ protected
+
+ def banner
+ %{Usage: #{$0} #{spec.name}\nCopies a (commented out) sample Formtastic config file into config/initializers/formtastic.rb}
+ end
+
+end
View
0 config/initializers/formtastic.rb → ...formtastic_config/templates/formtastic.rb
File renamed without changes.
View
21 generators/formtastic_stylesheets/formtastic_stylesheets_generator.rb
@@ -0,0 +1,21 @@
+class FormtasticStylesheetsGenerator < Rails::Generator::Base
+
+ def initialize(*runtime_args)
+ super
+ end
+
+ def manifest
+ record do |m|
+ m.directory File.join('public', 'stylesheets')
+ m.template 'formtastic.css', File.join('public', 'stylesheets', 'formtastic.css')
+ m.template 'formtastic_changes.css', File.join('public', 'stylesheets', 'formtastic_changes.css')
+ end
+ end
+
+ protected
+
+ def banner
+ %{Usage: #{$0} #{spec.name}\nCopies formtastic.css and formtastic_changes.css to public/}
+ end
+
+end
View
0 public/stylesheets/formtastic.css → ...stic_stylesheets/templates/formtastic.css
File renamed without changes.
View
0 public/stylesheets/formtastic_changes.css → ...lesheets/templates/formtastic_changes.css
File renamed without changes.
View
47 tasks/formtastic_tasks.rake
@@ -1,47 +0,0 @@
-# coding: utf-8
-
-namespace :formtastic do
-
- GEM_ROOT = File.join(File.dirname(__FILE__), '..').freeze
-
- task :setup do
- Rake::Task['formtastic:generate:config'].invoke
- Rake::Task['formtastic:generate:stylesheets'].invoke
- end
-
- namespace :generate do
-
- desc "Generate Formtastic-initializer (configration)."
- task :config do
- config_file = File.join(GEM_ROOT, 'config', 'initializers', 'formtastic.rb')
- to_file = File.join(Rails.root, 'config', 'initializers', 'formtastic.rb')
-
- FileUtils.cp(config_file, to_file)
-
- if File.exist?(to_file)
- puts "[formtastic]: Generated initializer: #{to_file}"
- else
- puts "[formtastic]: ERROR: Failed to generate initializer \"#{File.basename(to_file)}\". Hint: Try with sudo."
- end
- end
-
- desc "Generate Formtastic-stylesheets."
- task :stylesheets do
- stylesheet_files = Dir.glob(File.join(GEM_ROOT, 'public', 'stylesheets', '*.css'))
- to_path = File.join(Rails.public_path, 'stylesheets')
-
- FileUtils.cp(stylesheet_files, to_path)
-
- stylesheet_files.each do |file|
- to_file = File.join(to_path, File.basename(file))
- if File.exist?(to_file)
- puts "[formtastic]: Generated stylesheet: #{to_file}"
- else
- puts "[formtastic]: ERROR: Failed to generate stylesheet \"#{File.basename(file)}\". Hint: Try with sudo."
- end
- end
- end
-
- end
-
-end

0 comments on commit 2526d2c

Please sign in to comment.