kaminari--kaminari/lib/generators/kaminari/views_generator.rb

41 lines
1.4 KiB
Ruby
Raw Normal View History

module Kaminari
module Generators
2011-02-09 10:24:20 +00:00
class ViewsGenerator < Rails::Generators::NamedBase
2011-02-07 02:32:27 +00:00
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".'
2011-02-09 10:24:20 +00:00
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.
2011-02-09 11:07:26 +00:00
google: Looks googlish! (note that this is just an example...)
2011-02-09 22:42:49 +00:00
Try with this option :window => 10, :outer_window => -1
2011-02-09 20:28:50 +00:00
github: A very simple one with only "Older" and "Newer" links.
2011-02-09 10:24:20 +00:00
BANNER
end
desc ''
def copy_views
2011-02-07 02:32:27 +00:00
Dir.glob(filename_pattern).map {|f| File.basename f}.each do |f|
2011-02-09 10:24:20 +00:00
copy_file File.join([template_name.presence, f].compact), "app/views/kaminari/#{f}"
2011-02-07 02:32:27 +00:00
end
end
private
2011-02-09 10:24:20 +00:00
def template_name
(f = file_name.downcase) == 'default' ? '' : f
end
2011-02-07 02:32:27 +00:00
def filename_pattern
2011-02-09 10:24:20 +00:00
File.join self.class.source_root, template_name, "*.html.#{options[:template_engine].try(:to_s).try(:downcase) || 'erb'}"
end
end
end
end