Each framework pattern can have help now.

This commit is contained in:
Chris Eppstein 2009-11-01 15:26:58 -08:00
parent 9ae53ac72e
commit 8bcdd7360d
2 changed files with 37 additions and 0 deletions

View File

@ -21,6 +21,15 @@ Available commands:
end end
banner << "\n" banner << "\n"
end end
banner << "\nAvailable Frameworks & Patterns:\n\n"
Compass::Frameworks::ALL.each do |framework|
banner << " * #{framework.name}\n"
framework.template_directories.each do |pattern|
banner << " - #{framework.name}/#{pattern}\n"
end
end
opts.banner = banner opts.banner = banner
super super
@ -53,6 +62,8 @@ Available commands:
$command = options[:help_command] $command = options[:help_command]
puts Compass::Commands[options[:help_command]].usage puts Compass::Commands[options[:help_command]].usage
$command = "help" $command = "help"
elsif Compass::Frameworks.template_exists? options[:help_command]
puts Compass::Frameworks.template_usage(options[:help_command])
else else
raise OptionParser::ParseError, "No such command: #{options[:help_command]}" raise OptionParser::ParseError, "No such command: #{options[:help_command]}"
end end

View File

@ -15,6 +15,9 @@ module Compass
@templates_directory = options[:templates_directory] || File.join(path, 'templates') @templates_directory = options[:templates_directory] || File.join(path, 'templates')
@stylesheets_directory = options[:stylesheets_directory] || File.join(path, 'stylesheets') @stylesheets_directory = options[:stylesheets_directory] || File.join(path, 'stylesheets')
end end
def template_directories
Dir.glob(File.join(templates_directory, "*")).map{|f| File.basename(f)}
end
end end
def register(name, *arguments) def register(name, *arguments)
@ -47,6 +50,29 @@ module Compass
end end
end end
def template_exists?(template)
framework_name, template = template.split(%r{/}, 2)
template ||= "project"
if framework = self[framework_name]
return File.directory?(File.join(framework.templates_directory, template))
end
false
end
def template_usage(template)
framework_name, template = template.split(%r{/}, 2)
framework = self[framework_name]
template ||= "project"
usage_file = File.join(framework.templates_directory, template, "USAGE.markdown")
if File.exists?(usage_file)
File.read(usage_file)
else
<<-END.gsub(/^ {8}/, '')
No Usage!
END
end
end
end end
end end