Sha256: d3f9e105377942011f68fe7f09afe26e9ea8f9ab0a6a29f2118d145a18ff3248
Contents?: true
Size: 1.23 KB
Versions: 2
Compression:
Stored size: 1.23 KB
Contents
module Dash class ResourceGenerator < Rails::Generators::NamedBase source_root File.expand_path('../templates', __FILE__) def add_route insert_into_file 'config/routes.rb', :after => /namespace :dash(.*)/ do "\n\n resources :#{table_name}" end end def add_scope insert_into_file "app/models/#{singular_name}.rb", :after => /class #{singular_name.camelize}(.*)/ do "\n\n scope :filter, lambda { |filter| where('', :filter => \"%\#{filter.present? ? filter.downcase : ''}%\") }" end end def add_menu insert_into_file 'app/views/layouts/dash.html.haml', :before => /(.*)#session(.*)/ do "#{' ' * 16}%li\n" + "#{' ' * 18}%a{ :href => main_app.url_for(:controller => 'dash/#{table_name}', :action => 'index'), :title => #{singular_name.camelize}.model_name.human(:count => 2) }\n" + "#{' ' * 20}= #{singular_name.camelize}.model_name.human(:count => 2)\n" end end def create_templates template 'resource.erb', "app/controllers/dash/#{table_name}_controller.rb" template 'form.erb', "app/views/dash/#{table_name}/form.html.haml" template 'index.erb', "app/views/dash/#{table_name}/index.html.haml" end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
rails_dash-0.0.6 | lib/generators/dash/resource_generator.rb |
rails_dash-0.0.5 | lib/generators/dash/resource_generator.rb |