Class: FrameyGenerator
- Inherits:
-
Rails::Generators::Base
- Object
- Rails::Generators::Base
- FrameyGenerator
- Includes:
- Rails::Generators::Migration
- Defined in:
- lib/rails/generators/framey/framey_generator.rb
Class Method Summary collapse
Instance Method Summary collapse
- #add_route ⇒ Object
- #copy_controllers ⇒ Object
- #copy_initializer_file ⇒ Object
- #copy_models ⇒ Object
- #copy_public_files ⇒ Object
- #copy_views ⇒ Object
-
#create_migration_file ⇒ Object
Every method that is declared below will be automatically executed when the generator is run.
Class Method Details
.next_migration_number(dirname) ⇒ Object
:nodoc:
14 15 16 17 18 19 20 |
# File 'lib/rails/generators/framey/framey_generator.rb', line 14 def self.next_migration_number(dirname) #:nodoc: if ActiveRecord::Base. Time.now.utc.strftime("%Y%m%d%H%M%S") else "%.3d" % (current_migration_number(dirname) + 1) end end |
.source_root ⇒ Object
10 11 12 |
# File 'lib/rails/generators/framey/framey_generator.rb', line 10 def self.source_root sources = File.join(File.dirname(__FILE__), 'templates') end |
Instance Method Details
#add_route ⇒ Object
88 89 90 91 92 93 94 95 96 |
# File 'lib/rails/generators/framey/framey_generator.rb', line 88 def add_route videos_text = 'namespace :framey do resources :videos, :only => [ :index, :show, :new], :controller => "videos" end' callback_test = 'post "/framey/callback" => "framey/videos#callback"' route(videos_text) route(callback_test) end |
#copy_controllers ⇒ Object
74 75 76 |
# File 'lib/rails/generators/framey/framey_generator.rb', line 74 def copy_controllers copy_file 'videos_controller.rb', 'app/controllers/framey/videos_controller.rb' end |
#copy_initializer_file ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/rails/generators/framey/framey_generator.rb', line 45 def copy_initializer_file if self.api_key and self.api_secret f = File.open File.join(File.dirname(__FILE__), 'templates', 'initializer.rb') initializer = f.read; f.close initializer.gsub!(/API_KEY_VALUE/, self.api_key) initializer.gsub!(/API_SECRET_VALUE/, self.api_secret) tmp = File.open "tmp/~initializer_ready.rb", "w" tmp.write initializer tmp.close copy_file '../../../tmp/~initializer_ready.rb', 'config/initializers/framey.rb' remove_file 'tmp/~initializer_ready.rb' else copy_file 'initializer.rb', 'config/initializers/framey.rb' end end |
#copy_models ⇒ Object
78 79 80 |
# File 'lib/rails/generators/framey/framey_generator.rb', line 78 def copy_models copy_file 'video.rb', 'app/models/framey/video.rb' end |
#copy_public_files ⇒ Object
82 83 84 85 |
# File 'lib/rails/generators/framey/framey_generator.rb', line 82 def copy_public_files copy_file 'javascripts/swfobject.js', 'public/javascripts/swfobject.js' copy_file 'stylesheets/framey.css', 'public/stylesheets/framey.css' end |
#copy_views ⇒ Object
67 68 69 70 71 72 |
# File 'lib/rails/generators/framey/framey_generator.rb', line 67 def copy_views copy_file 'index.html.erb', 'app/views/framey/videos/index.html.erb' copy_file 'new.html.erb', 'app/views/framey/videos/new.html.erb' copy_file 'show.html.erb', 'app/views/framey/videos/show.html.erb' copy_file 'framey.html.erb', 'app/views/layouts/framey.html.erb' end |
#create_migration_file ⇒ Object
Every method that is declared below will be automatically executed when the generator is run
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/rails/generators/framey/framey_generator.rb', line 25 def create_migration_file f = File.open File.join(File.dirname(__FILE__), 'templates', 'schema.rb') schema = f.read; f.close schema.gsub!(/ActiveRecord::Schema.*\n/, '') schema.gsub!(/^end\n*$/, '') f = File.open File.join(File.dirname(__FILE__), 'templates', 'migration.rb') migration = f.read; f.close migration.gsub!(/SCHEMA_AUTO_INSERTED_HERE/, schema) tmp = File.open "tmp/~migration_ready.rb", "w" tmp.write migration tmp.close migration_template '../../../tmp/~migration_ready.rb', 'db/migrate/create_framey_tables.rb' remove_file 'tmp/~migration_ready.rb' end |