Class: TranscribableGenerator

Inherits:
ActiveRecord::Generators::Base
  • Object
show all
Includes:
Transcribable
Defined in:
lib/generators/transcribable_generator.rb

Constant Summary

Constants included from Transcribable

Transcribable::VERSION

Instance Method Summary collapse

Methods included from Transcribable

new_columns, table, transcribable_attrs

Instance Method Details

#copy_filesObject



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/generators/transcribable_generator.rb', line 27

def copy_files
  # Copies the migration template to db/migrate.
  if Transcribable.new_columns && Transcribable.new_columns.length > 0
    @migration_name = "add_#{Transcribable.new_columns.keys.join("_and_")}_to_transcriptions"
    migration_template 'migration_add_columns.rb', "db/migrate/#{@migration_name}.rb"
  elsif !ActiveRecord::Base.connection.tables.include?("transcriptions")
    migration_template 'migration.rb', 'db/migrate/create_transcriptions_table.rb'
  end
  
  # controller
  template 'controller.rb', 'app/controllers/transcriptions_controller.rb'
  
  # model
  template 'model.rb', 'app/models/transcription.rb'

  # views
  template 'views/layouts/simple_frame.html.erb', 'app/views/layouts/simple_frame.html.erb'
  template 'views/_form.html.erb', 'app/views/transcriptions/_form.html.erb'
  template 'views/new.html.erb', 'app/views/transcriptions/new.html.erb'

  # assets
  template 'assets/stylesheets/simple_frame.css', 'app/assets/stylesheets/simple_frame.css'

  # config
  template 'config/documentcloud.yml', 'config/documentcloud.yml'

  # routes
  route "resources :transcriptions, :only => [:new, :create]"
  route "resources :#{@table.to_sym}, :only => [:index, :show]"
  route "root :to => \"#{@table}#index\""
end

#new_columnsObject



23
24
25
# File 'lib/generators/transcribable_generator.rb', line 23

def new_columns
  Transcribable.new_columns
end

#tableObject



15
16
17
# File 'lib/generators/transcribable_generator.rb', line 15

def table
  @table = Transcribable.table
end

#transcribable_attrsObject



19
20
21
# File 'lib/generators/transcribable_generator.rb', line 19

def transcribable_attrs
  Transcribable.transcribable_attrs
end