Class: EventCalendarGenerator

Inherits:
Rails::Generators::Base
  • Object
show all
Includes:
Rails::Generators::Migration
Defined in:
lib/generators/event_calendar/event_calendar_generator.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.next_migration_number(dirname) ⇒ Object

FIXME: Should be proxied to ActiveRecord::Generators::Base Implement the required interface for Rails::Generators::Migration.



84
85
86
87
88
89
90
# File 'lib/generators/event_calendar/event_calendar_generator.rb', line 84

def self.next_migration_number(dirname) #:nodoc:
  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

#controller_class_nameObject



54
55
56
# File 'lib/generators/event_calendar/event_calendar_generator.rb', line 54

def controller_class_name
  "#{@controller_name}_controller".classify
end

#controller_nameObject



58
59
60
# File 'lib/generators/event_calendar/event_calendar_generator.rb', line 58

def controller_name
  controller_class_name.underscore
end

#do_itObject



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/generators/event_calendar/event_calendar_generator.rb', line 16

def do_it
  say "Adding an all_day column", :yellow if options[:use_all_day]
  say "Adding a color column", :yellow if options[:use_color]

  if options[:use_jquery]
    say "Using JQuery for scripting", :yellow
    copy_file 'jq_javascript.js', "public/javascripts/event_calendar.js"
  else
    say "Using Prototype for scripting", :yellow
    copy_file 'javascript.js', "public/javascripts/event_calendar.js"
  end

  copy_file "stylesheet.css", "public/stylesheets/event_calendar.css"

  unless options.static_only?
    template "model.rb.erb", "app/models/#{model_name}.rb"
    template "controller.rb.erb", "app/controllers/#{controller_name}.rb"
    empty_directory "app/views/#{view_name}"
    template "view.html.erb", File.join("app/views/#{view_name}/index.html.erb")
    template "helper.rb.erb", "app/helpers/#{helper_name}.rb"
    migration_template "migration.rb.erb", "db/migrate/create_#{table_name}.rb"
    route "match '/#{view_name}(/:year(/:month))' => '#{view_name}#index', :as => :#{named_route_name}, :constraints => {:year => /\\d{4}/, :month => /\\d{1,2}/}"
  end

end

#helper_class_nameObject



62
63
64
# File 'lib/generators/event_calendar/event_calendar_generator.rb', line 62

def helper_class_name
  "#{@controller_name}_helper".classify
end

#helper_nameObject



66
67
68
# File 'lib/generators/event_calendar/event_calendar_generator.rb', line 66

def helper_name
  helper_class_name.underscore
end

#model_class_nameObject



42
43
44
# File 'lib/generators/event_calendar/event_calendar_generator.rb', line 42

def model_class_name
  @model_name.classify
end

#model_nameObject



46
47
48
# File 'lib/generators/event_calendar/event_calendar_generator.rb', line 46

def model_name
  model_class_name.underscore
end

#named_route_nameObject



74
75
76
77
78
79
80
# File 'lib/generators/event_calendar/event_calendar_generator.rb', line 74

def named_route_name
  if view_name.include?("/")
    view_name.split("/").join("_")
  else
    view_name
  end
end

#table_nameObject



70
71
72
# File 'lib/generators/event_calendar/event_calendar_generator.rb', line 70

def table_name
  model_name.pluralize
end

#view_nameObject



50
51
52
# File 'lib/generators/event_calendar/event_calendar_generator.rb', line 50

def view_name
  @controller_name.underscore
end