Browse files

adding an episode generator

  • Loading branch information...
1 parent 1f19d3e commit 32bebb5750515c70075bfba83295ff99d8010da5 @ryanb committed Jun 21, 2008
Showing with 65 additions and 2 deletions.
  1. +0 −2 .gitignore
  2. +3 −0 generators/episode/USAGE
  3. +31 −0 generators/episode/episode_generator.rb
  4. +3 −0 generators/episode/templates/README.erb
  5. +14 −0 script/destroy
  6. +14 −0 script/generate
View
2 .gitignore
@@ -1,2 +0,0 @@
-.DS_Store
-._*
View
3 generators/episode/USAGE
@@ -0,0 +1,3 @@
+Example:
+
+ script/generate episode 115 "This is the Episode Name"
View
31 generators/episode/episode_generator.rb
@@ -0,0 +1,31 @@
+class EpisodeGenerator < RubiGen::Base
+ attr_accessor :episode_number, :episode_name
+
+ def initialize(runtime_args, runtime_options = {})
+ super
+ usage if @args.length != 2
+
+ @episode_number = @args[0]
+ @episode_name = @args[1]
+ end
+
+ def manifest
+ record do |m|
+ m.directory "episode-#{episode_number}"
+ m.template "README.erb", "#{folder}/README"
+ end
+ end
+
+ def folder
+ "episode-#{episode_number}"
+ end
+
+ protected
+ def banner
+ <<-EOS
+Creates an episode folder structure given number and name.
+
+USAGE: #{$0} #{spec.name} [number] [name]
+EOS
+ end
+end
View
3 generators/episode/templates/README.erb
@@ -0,0 +1,3 @@
+Railscasts Episode #<%= episode_number %>: <%= episode_name %>
+
+http://railscasts.com/episodes/<%= episode_number %>
View
14 script/destroy
@@ -0,0 +1,14 @@
+#!/usr/bin/env ruby
+APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
+
+begin
+ require 'rubigen'
+rescue LoadError
+ require 'rubygems'
+ require 'rubigen'
+end
+require 'rubigen/scripts/destroy'
+
+ARGV.shift if ['--help', '-h'].include?(ARGV[0])
+RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit]
+RubiGen::Scripts::Destroy.new.run(ARGV)
View
14 script/generate
@@ -0,0 +1,14 @@
+#!/usr/bin/env ruby
+APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
+
+begin
+ require 'rubigen'
+rescue LoadError
+ require 'rubygems'
+ require 'rubigen'
+end
+require 'rubigen/scripts/generate'
+
+ARGV.shift if ['--help', '-h'].include?(ARGV[0])
+RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit]
+RubiGen::Scripts::Generate.new.run(ARGV)

0 comments on commit 32bebb5

Please sign in to comment.