Class: Caseadilla::ScaffoldGenerator

Inherits:
Rails::Generators::NamedBase
  • Object
show all
Includes:
CaseadillaHelper, Rails::Generators::Migration
Defined in:
lib/generators/caseadilla/scaffold/scaffold_generator.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from CaseadillaHelper

#caseadilla_check_box, #caseadilla_check_box_group, #caseadilla_collection_check_boxes, #caseadilla_collection_select, #caseadilla_color_field, #caseadilla_custom_field, #caseadilla_date_field, #caseadilla_date_select, #caseadilla_datetime_field, #caseadilla_datetime_local_field, #caseadilla_datetime_select, #caseadilla_email_field, #caseadilla_file_field, #caseadilla_format_date, #caseadilla_format_datetime, #caseadilla_format_time, #caseadilla_generate_page_title, #caseadilla_get_access_level_array, #caseadilla_get_access_level_text, #caseadilla_get_footer_string, #caseadilla_get_full_version_string, #caseadilla_get_short_version_string, #caseadilla_hidden_field, #caseadilla_month_field, #caseadilla_no_yes_label, #caseadilla_number_field, #caseadilla_pagination_details, #caseadilla_password_field, #caseadilla_radio_button, #caseadilla_radio_button_group, #caseadilla_range_field, #caseadilla_search_field, #caseadilla_select, #caseadilla_show_icon, #caseadilla_show_row_icon, #caseadilla_sort_link, #caseadilla_table_cell_link, #caseadilla_table_cell_no_link, #caseadilla_telephone_field, #caseadilla_text_area, #caseadilla_text_area_wysiwym, #caseadilla_text_field, #caseadilla_time_field, #caseadilla_time_select, #caseadilla_time_zone_select, #caseadilla_url_field, #caseadilla_week_field, #caseadilla_yes_no_label

Class Method Details

.next_migration_number(dirname) ⇒ Object


12
13
14
15
16
17
18
# File 'lib/generators/caseadilla/scaffold/scaffold_generator.rb', line 12

def self.next_migration_number dirname
  if ActiveRecord::Base.timestamped_migrations
    Time.now.utc.strftime("%Y%m%d%H%M%S")
  else
    "%.3d" % (current_migration_number(dirname) + 1)
  end
end

Instance Method Details

#generate_filesObject


20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/generators/caseadilla/scaffold/scaffold_generator.rb', line 20

def generate_files
  @plural_route = (plural_name != singular_name) ? plural_name : "#{plural_name}_index"
  @read_only = options[:read_only]
  @no_index = options[:no_index]

  template 'controller.rb', "app/controllers/caseadilla/#{plural_name}_controller.rb"
  template 'views/index.html.erb', "app/views/caseadilla/#{plural_name}/index.html.erb" unless @no_index
  template 'views/show.html.erb', "app/views/caseadilla/#{plural_name}/show.html.erb"
  template 'views/new.html.erb', "app/views/caseadilla/#{plural_name}/new.html.erb" unless @read_only
  template 'views/_form.html.erb', "app/views/caseadilla/#{plural_name}/_form.html.erb"
  template 'views/_table.html.erb', "app/views/caseadilla/#{plural_name}/_table.html.erb"

  add_namespace_to_routes
  add_to_routes
  add_to_navigation unless @no_index

  if options[:create_model]
    template 'model.rb', "app/models/#{singular_name}.rb"
    migration_template 'migration.rb', "db/migrate/create_#{plural_name}.rb"
  end
end