Skip to content
Browse files

doc updates

  • Loading branch information...
1 parent cd4e5c4 commit 0310468f158e7b4122ca695345b42b2e5845e30e Dale Campbell committed Apr 19, 2009
Showing with 69 additions and 4 deletions.
  1. +1 −0 .gitignore
  2. +1 −1 app/models/page.rb
  3. +7 −0 lib/corrupt.rb
  4. +2 −1 lib/corrupt/framework/controller.rb
  5. +4 −2 lib/corrupt/generators/app.rb
  6. +6 −0 lib/corrupt/system.rb
  7. +48 −0 tasks/doc.rake
View
1 .gitignore
@@ -3,5 +3,6 @@
config/app_config.yml
coverage/
db/*.sqlite3
+doc/api/
log/*.log
tmp/
View
2 app/models/page.rb
@@ -1,4 +1,4 @@
-# This is an application model and will get loaded into the
+# This is an example application model and will get loaded into the
# global namespace. Corrupt uses DataMapper by default,
# however, a model can be any Ruby class.
class Page
View
7 lib/corrupt.rb
@@ -40,29 +40,36 @@ def self.to_version
private
+ # Points to the root of the current Corrupt application.
def self.app_root
# FIXME: This is most certainly wrong. Dir.pwd should probably not be used here.
ENV['CORRUPT_APP'] || File.join(Dir.pwd, 'app')
end
+ # Returns the Corrupt::Config instance.
def self.config
Corrupt::Config
end
+ # Path to the application configuration file.
def self.config_file
ENV['CORRUPT_CONFIG'] || Corrupt.app_root + '/../config/app_config.yml'
end
+ # The current Corrupt environment (development, production, etc.)
+ # Defaults to 'development'.
def self.env
ENV['CORRUPT_ENV'] || 'development'
end
+ # Returns the logger instance.
def self.log
@log ||= Logger.new("#{Corrupt.app_root}/../log/#{Corrupt.env}.log")
@log.level = (Corrupt.env == 'production' ? Logger::WARN : Logger::DEBUG)
@log
end
+ # Returns the root path of the Corrupt library.
def self.root
ENV['CORRUPT_ROOT'] || File.expand_path(File.dirname(__FILE__) + '/..')
end
View
3 lib/corrupt/framework/controller.rb
@@ -16,6 +16,7 @@ def content=(new_content)
end
# Return the headers for the response.
+ # TODO: Save the header hash and allow setting of custom keys.
def headers
{ 'Content-Length' => content.size.to_s,
'Content-Type' => 'text/html' }
@@ -32,7 +33,7 @@ def return_response(status = 200)
[status, headers, content]
end
- # Set the template file to be rendered.
+ # Set the template file to be rendered or return the Corrupt::Template object.
def template(file = nil)
@template ||= Corrupt::Template.new(file)
end
View
6 lib/corrupt/generators/app.rb
@@ -4,7 +4,6 @@ module Generators
# Generator to create a new Corrupt application.
class App
- # A list of directories to create when making a new application.
DIRS = [
'app',
'app/controllers',
@@ -28,7 +27,6 @@ class App
'tmp',
]
- # A list of files to copy for a new application.
FILES = [
'config.ru',
'Rakefile',
@@ -68,6 +66,8 @@ def initialize(path)
private
+ # This method is responsible for running the generator methods
+ # (creating directories, copying files, etc.).
def setup_app!
Dir.mkdir(@path) unless File.exists?(@path)
create_directories
@@ -76,12 +76,14 @@ def setup_app!
$stdout.puts "Application created in: #{@path}"
end
+ # Create a directory for each entry in +DIRS+.
def create_directories
DIRS.each do |dir|
Dir.mkdir(File.join(@path, dir))
end
end
+ # Copy each +FILES+ entry, preserving the path.
def copy_files
FILES.each do |file|
base_file = File.expand_path(File.join(Corrupt.root, file))
View
6 lib/corrupt/system.rb
@@ -21,10 +21,12 @@ def boot!
private
+ # Setup the Corrupt::Config instance.
def load_app_config
Corrupt::Config.setup(Corrupt.config_file)
end
+ # Load any application controllers.
def load_controllers
app_controller = "#{Corrupt.app_root}/controllers/app_controller.rb"
controllers = Dir["#{Corrupt.app_root}/controllers/*.rb"].sort
@@ -36,17 +38,21 @@ def load_controllers
end
end
+ # Load any application models.
def load_models
models = Dir["#{Corrupt.app_root}/models/*.rb"].sort
models.each do |model|
require model
end
end
+ # Load the application <tt>/config/routes.rb</tt>.
def prepare_router
load File.expand_path(Corrupt.app_root + '/../config/routes.rb')
end
+ # Setup the database connection.
+ # TODO: This should only be ran if the application uses a database.
def setup_database
database = File.join(Corrupt.app_root, '..', Corrupt::Config['database'])
DataMapper.setup(:default, "sqlite3:///#{database}")
View
48 tasks/doc.rake
@@ -0,0 +1,48 @@
+APP_ROOT = File.join(File.dirname(__FILE__), '..')
+
+desc 'Generate API documentation'
+task :doc do
+ Rake::Task['doc:api'].invoke
+end
+
+namespace :doc do
+ task :setup_rdoc do
+ @file_list = FileList[ "#{File.join(APP_ROOT, 'README')}",
+ "#{APP_ROOT}/app/**/*.rb",
+ "#{APP_ROOT}/lib/**/*.rb" ]
+ # Substitute APP_ROOT with a dot. Makes for a better index in the generated docs.
+ @files = @file_list.collect {|f| f.gsub(/#{APP_ROOT}/, '.')}
+ @options = %W[
+ --all
+ --inline-source
+ --line-numbers
+ --op #{File.join(APP_ROOT, 'doc', 'api')}
+ --title 'Corrupt API Documentation'
+ ]
+ # Generate a diagram, yes/no?
+ @options << '-d' if RUBY_PLATFORM !~ /win32/ && `which dot` =~ /\/dot/ && !ENV['NODOT']
+ end
+
+ task :api => [:setup_rdoc] do
+ run_rdoc(@options, @files)
+ end
+
+ desc 'Remove generated API documentation'
+ task :clear do
+ sh "rm -rf #{File.join(APP_ROOT, 'doc', 'api')}"
+ end
+
+ desc 'Rebuild API documentation'
+ task :rebuild do
+ Rake::Task['doc:clear'].invoke
+ Rake::Task['doc:api'].invoke
+ end
+end
+
+private
+
+def run_rdoc(options, files)
+ options = options.join(' ') if options.is_a? Array
+ files = files.join(' ') if files.is_a? Array
+ sh "rdoc #{options} #{files}"
+end

0 comments on commit 0310468

Please sign in to comment.
Something went wrong with that request. Please try again.