Class: Tap::Generator::Generators::Root

Inherits:
Base
  • Object
show all
Defined in:
lib/tap/generator/generators/root.rb

Overview

:startdoc::generator a basic tap directory structure

Generates a tap root directory structure. Use the switches to turn on or off the creation of various files:

project
|- MIT-LICENSE
|- README
|- Rakefile
|- lib
|- project.gemspec
|- tap.yml
`- test
    `- tap_test_helper.rb

Instance Attribute Summary

Attributes inherited from Base

#prompt_in, #prompt_out, #template_dir

Instance Method Summary collapse

Methods inherited from Base

#action, #directories, #directory, #file, #initialize, #iterate, #log_relative, #on, #path, #process, #set, #template, #template_files

Constructor Details

This class inherits a constructor from Tap::Generator::Base

Instance Method Details

#manifest(m, root, project_name = nil) ⇒ Object

::args ROOT, PROJECT_NAME=basename(ROOT)



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/tap/generator/generators/root.rb', line 38

def manifest(m, root, project_name=nil)
  r = Tap::Root.new(File.expand_path(root, destination_root))
  project_name = File.basename(r.root) if project_name == nil
  
  m.directory r.root
  m.directory r['lib']
  m.directory r['test']
  
  template_files do |source, target|
    case
    when File.directory?(source)
      m.directory r[target]
      next
    when source =~ /gemspec$/
      locals = gemspec.config.to_hash.merge(
        :project_name => project_name, 
        :license => license,
        :history => history
      )
      m.template r[project_name + '.gemspec'], source, locals
      next
    when source =~ /Rakefile$/
      next unless rakefile
    when source =~ /Rapfile$/
      next unless rapfile
    when source =~ /MIT-LICENSE$/
      next unless license
    end
    
    m.template r[target], source, :project_name => project_name, :license => license
  end
  
  m.file(r['History']) if history
  m.file(r['tap.yml']) do |file|
    Configurable::Utils.dump(Tap::Env.configurations, file) do |key, config|
      # get the description
      desc = config.attributes[:desc]
      doc = desc.to_s
      doc = desc.comment if doc.empty?
      
      # wrap as lines
      lines = Lazydoc::Utils.wrap(doc, 78).collect {|line| "# #{line}"}
      lines << "" unless lines.empty?
      
      # setup formatting
      default = config.default
      leader = key == 'root' || default == nil ? '# ' : ''
      config = YAML.dump({key => default})[5..-1].strip.gsub(/\n+/, "\n#{leader}")
      "#{lines.join("\n")}#{leader}#{config}\n\n"
    end if env
  end
end