Browse files

Add generator option to override all of the things.

  • Loading branch information...
1 parent e07c95f commit 55a06a9387d6d98abba2f9110b928724e5aa729b @jasoncodes jasoncodes committed Jun 12, 2011
View
11 lib/generators/postmarkdown/override_generator.rb
@@ -3,38 +3,39 @@ class OverrideGenerator < Rails::Generators::Base
desc File.read(File.expand_path('../usage/override.txt', __FILE__))
source_root File.expand_path('../../../../app', __FILE__)
+ class_option :all, :type => :boolean, :group => :override, :desc => 'Override all of the things'
class_option :views, :type => :boolean, :group => :override, :desc => 'Override the Post views'
class_option :model, :type => :boolean, :group => :override, :desc => 'Override the Post model'
class_option :controller, :type => :boolean, :group => :override, :desc => 'Override the Posts controller'
class_option :theme, :type => :boolean, :group => :override, :desc => 'Override the layout and stylesheet'
def check_class_options
- if options.views.blank? && options.model.blank? && options.controller.blank? && options.theme.blank?
+ if options.blank?
exec 'rails g postmarkdown:override --help'
exit
end
end
def override_views
- if options.views
+ if options.views || options.all
directory 'views/posts', 'app/views/posts'
end
end
def override_model
- if options.model
+ if options.model || options.all
copy_file 'models/post.rb', 'app/models/post.rb'
end
end
def override_controller
- if options.controller
+ if options.controller || options.all
copy_file 'controllers/posts_controller.rb', 'app/controllers/posts_controller.rb'
end
end
def override_theme
- if options.theme
+ if options.theme || options.all
directory 'views/layouts', 'views/layouts'
directory '../public/stylesheets', 'public/stylesheets'
end
View
1 lib/generators/postmarkdown/usage/override.txt
@@ -2,6 +2,7 @@ Description:
This generator will override either the Post model, controller or views.
Examples:
+ $ rails generate postmarkdown:override --all # overrides all of the things
$ rails generate postmarkdown:override --controller # overrides file `app/controllers/posts_controller.rb`
$ rails generate postmarkdown:override --model # overrides file `app/models/post.rb`
$ rails generate postmarkdown:override --views # overrides all files in directory `app/views/posts/`
View
1 readme.md
@@ -49,6 +49,7 @@ Open `http://localhost:3000/posts` in your browser and you should be able to nav
The easiest way to customize the Postmarkdown functionality or appearance is by using the override generator. This generator can copy files from the Postmarkdown core and place them into your Rails app. For example:
+ $ rails generate postmarkdown:override --all # overrides all of the things
$ rails generate postmarkdown:override --controller # overrides `app/controllers/posts_controller.rb`
$ rails generate postmarkdown:override --model # overrides `app/models/post.rb`
$ rails generate postmarkdown:override --views # overrides all files in directory `app/views/posts/`

0 comments on commit 55a06a9

Please sign in to comment.