~ubuntu-branches/ubuntu/karmic/chef/karmic

« back to all changes in this revision

Viewing changes to chef-server/tasks/doc.thor

  • Committer: Bazaar Package Importer
  • Author(s): Joshua Timberman
  • Date: 2009-08-12 12:18:48 UTC
  • Revision ID: james.westby@ubuntu.com-20090812121848-yl38hpd7nfsl51xz
Tags: upstream-0.7.8
ImportĀ upstreamĀ versionĀ 0.7.8

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
$: << File.join("doc")
 
2
require 'rubygems'
 
3
require 'rdoc/rdoc'
 
4
require 'fileutils'
 
5
require 'erb'
 
6
 
 
7
module Merb
 
8
  
 
9
  class GemNotFoundException < Exception
 
10
  end
 
11
  
 
12
  module DocMethods
 
13
    def setup_gem_path
 
14
      if File.directory?(gems_dir = File.join(File.dirname(__FILE__), 'gems'))
 
15
        $BUNDLE = true; Gem.clear_paths; Gem.path.unshift(gems_dir)
 
16
      end
 
17
    end
 
18
    
 
19
    def get_more
 
20
      libs = []
 
21
      more_library = find_library("merb-more")
 
22
      File.open("#{more_library}/lib/merb-more.rb").read.each_line do |line|
 
23
        if line['require']
 
24
          libs << line.gsub("require '", '').gsub("'\n", '')
 
25
        end
 
26
      end
 
27
      return libs
 
28
    end
 
29
    
 
30
    def generate_documentation(file_list, destination, arguments = [])
 
31
      output_dir = File.join("/../doc", "rdoc", destination)
 
32
      FileUtils.rm_rf(output_dir)
 
33
      
 
34
      arguments += [
 
35
        "--fmt", "merb",
 
36
        "--op", output_dir
 
37
      ]
 
38
      RDoc::RDoc.new.document(arguments + file_list)
 
39
      AdvancedDoc.new.index
 
40
    end
 
41
    
 
42
    def find_library(directory_snippet)
 
43
      gem_dir = nil
 
44
      Gem.path.find do |path|
 
45
        dir = Dir.glob("#{path}/gems/#{directory_snippet}*") 
 
46
        dir.empty? ? false : gem_dir = dir.last
 
47
      end
 
48
      raise GemNotFoundException if gem_dir.nil?
 
49
      return gem_dir
 
50
    end
 
51
    
 
52
    def get_file_list(directory_snippet)
 
53
      gem_dir = find_library(directory_snippet)
 
54
      files = Dir.glob("#{gem_dir}/**/lib/**/*.rb")
 
55
      files += ["#{gem_dir}/README"] if File.exists?("#{gem_dir}/README")
 
56
      return  files
 
57
    end
 
58
  end
 
59
  
 
60
  class AdvancedDoc < Thor
 
61
    
 
62
    group 'core'
 
63
    include DocMethods
 
64
    
 
65
    def initialize
 
66
      super
 
67
      setup_gem_path
 
68
    end
 
69
    
 
70
    desc 'index', "Regenerate the index file for your framework documentation"
 
71
    def index
 
72
      @directories = Dir.entries(File.join(File.dirname(__FILE__) + "/../", "doc", "rdoc"))
 
73
      @directories.delete(".")
 
74
      @directories.delete("..")
 
75
      @directories.delete("generators")
 
76
      @directories.delete("index.html")
 
77
      index_template = File.read(File.join("doc", "rdoc", "generators", "template", "merb", "index.html.erb"))
 
78
      
 
79
      File.open(File.join("doc", "rdoc", "index.html"), "w") do |file|
 
80
        file.write(ERB.new(index_template).result(binding))
 
81
      end
 
82
    end
 
83
    
 
84
    desc 'plugins', 'Generate the rdoc for each merb-plugins seperatly'
 
85
    def plugins
 
86
      libs = ["merb_activerecord", "merb_builder", "merb_jquery", "merb_laszlo", "merb_parts", "merb_screw_unit", "merb_sequel", "merb_stories", "merb_test_unit"]
 
87
      
 
88
      libs.each do |lib|
 
89
        options[:gem] = lib
 
90
        gem
 
91
      end
 
92
    end
 
93
    
 
94
    desc 'more', 'Generate the rdoc for each merb-more gem seperatly'
 
95
    def more
 
96
      libs = get_more
 
97
      libs.each do |lib|
 
98
        options[:gem] = lib
 
99
        gem
 
100
      end
 
101
    end
 
102
    
 
103
    desc 'core', 'Generate the rdoc for merb-core'
 
104
    def core
 
105
      options[:gem] = "merb-core"
 
106
      gem
 
107
    end
 
108
    
 
109
    desc 'gem', 'Generate the rdoc for a specific gem'
 
110
    method_options "--gem" => :required
 
111
    def gem
 
112
      file_list = get_file_list(options[:gem])
 
113
      readme = File.join(find_library("merb-core"), "README")
 
114
      generate_documentation(file_list, options[:gem], ["-m", readme])
 
115
    rescue GemNotFoundException
 
116
      puts "Can not find the gem in the gem path #{options[:gem]}"
 
117
    end
 
118
    
 
119
  end
 
120
  
 
121
  class Doc < Thor
 
122
    
 
123
    include DocMethods
 
124
    
 
125
    def initialize
 
126
      super
 
127
      setup_gem_path
 
128
      
 
129
    end
 
130
    
 
131
    desc 'stack', 'Generate the rdoc for merb-core, merb-more merged together'
 
132
    def stack
 
133
      libs = ["merb"]
 
134
            
 
135
      file_list = []
 
136
      libs.each do |gem_name|
 
137
        begin
 
138
          file_list += get_file_list(gem_name)
 
139
        rescue GemNotFoundException
 
140
          puts "Could not find #{gem_name} in #{Gem.path}.  Continuing with out it."
 
141
        end
 
142
      end
 
143
      readme = File.join(find_library("merb"), "README")
 
144
      generate_documentation(file_list, "stack", ["-m", readme])
 
145
    end
 
146
    
 
147
  end
 
148
  
 
149
end
 
 
b'\\ No newline at end of file'