public
Description: Merb Plugins: Even more modules to hook up your Merb installation
Homepage: http://www.merbivore.com
Clone URL: git://github.com/wycats/merb-plugins.git
merb-plugins / merb_stories / rspec_generators / story / story_generator.rb
100644 51 lines (41 sloc) 1.567 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
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
41
42
43
44
45
46
47
48
49
50
51
class StoryGenerator < Merb::GeneratorBase
  
  attr_reader :story_name, :story_path, :step_name, :path_levels, :full_story_path
  
  def initialize(runtime_args, runtime_options = {})
    @base = File.dirname(__FILE__)
    super
    name = runtime_args.shift.split "/"
    @story_name = name.pop
    @story_path = name.empty? ? nil : name.join("/")
    @step_name = @story_path.nil? ? @story_name : (@story_path.gsub("/", "_") + "_" + @story_name)
    @path_levels = @story_path.nil? ? 0 : @story_path.split("/").size
    @full_story_path = @story_path.nil? ? @story_name : File.join(@story_path, @story_name)
  end
 
  def manifest
    record do |m|
      @m = m
      @assigns = {
                    :story_name => self.story_name,
                    :story_path => self.story_path,
                    :step_name => self.step_name,
                    :path_levels => self.path_levels,
                    :full_story_path => self.full_story_path
                  }
                  
      if( !File.exists?('stories/stories/all.rb') ) # So it doesn't get destroyed when you do a destroy script
        m.dependency "merb_story_setup", [""]
      end
      
      m.directory File.join("stories", "stories", self.story_path) unless self.story_path.nil?
      
      copy_dirs
      copy_files
 
    end
  end
 
  protected
    def banner
      <<-EOS
Creates a stub for a rSpec text story spec in merb.
 
USAGE: #{$0} #{spec.name} my_story"
 
EXAMPLE:
#{$0} #{spec.name} my_story
#{$0} #{spec.name} story_group/specific_story
EOS
  end
end