Skip to content

Commit

Permalink
the generator is Named now
Browse files Browse the repository at this point in the history
  • Loading branch information
amatsuda committed Feb 9, 2011
1 parent 1a06de2 commit 54b4e0f
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions lib/generators/kaminari/views_generator.rb
Original file line number Diff line number Diff line change
@@ -1,20 +1,36 @@
module Kaminari
module Generators
class ViewsGenerator < Rails::Generators::Base
class ViewsGenerator < Rails::Generators::NamedBase
source_root File.expand_path('../../../../app/views/kaminari', __FILE__)

class_option :template_engine, :type => :string, :aliases => '-e', :desc => 'Template engine for the views. Available options are "erb" and "haml".'

desc 'Copies all paginator partials to your application.'
def self.banner
<<-BANNER.chomp
rails g kaminari:views THEME [options]
Copies all paginator partial templates to your application.
You can choose a template THEME by specifying one from the list below:
default: The default one.
This one is used internally while you don't override the partials.
BANNER
end

desc ''
def copy_views
Dir.glob(filename_pattern).map {|f| File.basename f}.each do |f|
copy_file f, "app/views/kaminari/#{f}"
copy_file File.join([template_name.presence, f].compact), "app/views/kaminari/#{f}"
end
end

private
def template_name
(f = file_name.downcase) == 'default' ? '' : f
end

def filename_pattern
File.join self.class.source_root, "*.html.#{options[:template_engine] || 'erb'}"
File.join self.class.source_root, template_name, "*.html.#{options[:template_engine].try(:to_s).try(:downcase) || 'erb'}"
end
end
end
Expand Down

0 comments on commit 54b4e0f

Please sign in to comment.