Permalink
Browse files

* Fail partially removed.

  • Loading branch information...
1 parent b9bd256 commit 8c85a395c210fcb354c40a2048c47ef17b4c7887 Erik Hollensbe committed Jul 8, 2010
View
@@ -2,3 +2,8 @@ desc "builds the gem"
task :gem do
system %(gem build hanna.gemspec)
end
+
+# probably should replace this
+task :install => [:gem] do
+ sh "gem install hanna*.gem"
+end
View
@@ -8,7 +8,7 @@ Gem::Specification.new do |gem|
gem.summary = "An RDoc template that scales"
gem.description = "Hanna is an RDoc implemented in Haml, making its source clean and maintainable. It's built with simplicity, beauty and ease of browsing in mind."
- gem.files = Dir['Rakefile', '{bin,lib,rails,spec}/**/*', 'README*', 'LICENSE*'] & `git ls-files`.split("\n")
+ gem.files = Dir['Rakefile', '{bin,lib,rails,spec}/**/*', 'README*', 'LICENSE*']
gem.executables = Dir['bin/*'].map { |f| File.basename(f) }
gem.add_dependency 'rdoc', Hanna::RDOC_VERSION_REQUIREMENT
@@ -21,4 +21,4 @@ Gem::Specification.new do |gem|
gem.has_rdoc = false
gem.rubyforge_project = nil
-end
+end
View
@@ -4,45 +4,255 @@
# Tony Strauss (http://github.com/DesigningPatterns)
# Michael Granger <ged@FaerieMUD.org>, who had maintained the original RDoc template
+require 'pathname'
require 'haml'
require 'sass'
-require 'rdoc/generator/html'
-require 'hanna/template_page_patch'
+require 'rdoc/rdoc'
+require 'rdoc/generator/darkfish'
+#require 'hanna/template_page_patch'
+require 'hanna/version' unless ::Hanna
-module RDoc::Generator::HTML::HANNA
- class << self
- def dir
- @dir ||= File.join File.dirname(__FILE__), 'template_files'
+class RDoc::Generator::Hanna
+ STYLE = 'styles.sass'
+ INDEX = 'index.haml'
+ LAYOUT = 'layout.haml'
+ CLASS_PAGE = 'page.haml'
+ FILE_INDEX = 'file_index.haml'
+ CLASS_INDEX = 'class_index.haml'
+ METHOD_INDEX = 'method_index.haml'
+ FILE_PAGE = CLASS_PAGE
+ CLASS_DIR = 'classes'
+ FILE_DIR = 'files'
+
+ INDEX_OUT = 'index.html'
+ FILE_INDEX_OUT = 'fr_file_index.html'
+ CLASS_INDEX_OUT = 'fr_class_index.html'
+ METHOD_INDEX_OUT = 'fr_method_index.html'
+ STYLE_OUT = File.join('css', 'style.css')
+
+ # EPIC CUT AND PASTE TIEM NAO -- GG
+ RDoc::RDoc.add_generator( self )
+
+ def self::for( options )
+ new( options )
+ end
+
+ def initialize( options )
+ @options = options
+
+ template = 'hanna'
+
+ @templatedir = Pathname.new File.join(File.expand_path(File.dirname(__FILE__)), 'template_files')
+
+ @files = nil
+ @classes = nil
+ @methods = nil
+ @modsort = nil
+
+ @basedir = Pathname.pwd.expand_path
+ end
+
+ def generate( top_levels )
+ @outputdir = Pathname.new( @options.op_dir ).expand_path( @basedir )
+
+ @files = top_levels.sort
+ @classes = RDoc::TopLevel.all_classes_and_modules.sort
+ @methods = @classes.map { |m| m.method_list }.flatten.sort
+ @modsort = get_sorted_module_list( @classes )
+
+ # Now actually write the output
+ write_static_files
+ generate_indexes
+ generate_class_files
+ generate_file_files
+
+ rescue StandardError => err
+ p [ err.class.name, err.message, err.backtrace.join("\n ") ]
+ raise
+ end
+
+ def write_static_files
+ css_dir = outjoin('css')
+
+ unless File.directory?(css_dir)
+ FileUtils.mkdir css_dir
end
- def read(*names)
- content = names.inject('') { |all, name| all << File.read(File.join(dir, name)) }
- extension = names.first =~ /\.(\w+)$/ && $1
+ File.open(File.join(css_dir, 'style.css'), 'w') { |f| f << Sass::Engine.new(File.read(templjoin(STYLE))).to_css }
+ end
+
+ # FIXME refactor
+ def generate_indexes
+ @main_page_uri = @files.find { |f| f.name == @options.main_page }.path
+ File.open(outjoin(INDEX_OUT), 'w') { |f| f << haml_file(templjoin(INDEX)).to_html(binding) }
+
+ file_index = haml_file(templjoin(FILE_INDEX))
+
+ values = {
+ :files => @files,
+ :stylesheet => STYLE_OUT,
+ :list_title => "File Index"
+ }
+
+ File.open(outjoin(FILE_INDEX_OUT), 'w') { |f| f << with_layout(values) { file_index.to_html(binding, values) } }
+
+ class_index = haml_file(templjoin(CLASS_INDEX))
+
+ values = {
+ :classes => @classes,
+ :stylesheet => STYLE_OUT,
+ :list_title => "Class Index"
+ }
+
+ File.open(outjoin(CLASS_INDEX_OUT), 'w') { |f| f << with_layout(values) { class_index.to_html(binding, values) } }
+
+ method_index = haml_file(templjoin(METHOD_INDEX))
+
+ p @methods
+
+ values = {
+ :methods => @methods,
+ :stylesheet => STYLE_OUT,
+ :list_title => "Method Index"
+ }
+
+ File.open(outjoin(METHOD_INDEX_OUT), 'w') { |f| f << with_layout(values) { method_index.to_html(binding, values) } }
+ end
+
+ def generate_file_files
+ file_page = haml_file(templjoin(FILE_PAGE))
+
+ # FIXME non-Ruby files
+ @files.each do |file|
+ path = Pathname.new(file.path)
+ stylesheet = Pathname.new(STYLE_OUT).relative_path_from(path.dirname)
+
+ values = {
+ :file => file,
+ :stylesheet => stylesheet,
+ :classmod => nil,
+ :title => file.base_name,
+ :list_title => nil
+ }
+
+ result = with_layout(values) { file_page.to_html(binding, :values => values) { file.description } }
+
+ # FIXME XXX sanity check
+ dir = path.dirname
+ unless File.directory? dir
+ FileUtils.mkdir_p dir
+ end
- Hanna::TemplateHelpers.silence_warnings do
- case extension
- when 'sass'
- Sass::Engine.new(content)
- when 'haml'
- Haml::Engine.new(content, :format => :html4, :filename => names.join(','))
+ File.open(outjoin(file.path), 'w') { |f| f << result }
+ end
+ end
+
+ def with_layout(values)
+ layout = haml_file(templjoin(LAYOUT))
+ layout.to_html(binding, :values => values) { yield }
+ end
+
+ # probably should bring in nokogiri/libxml2 to do this right.. not sure if
+ # it's worth it.
+ def frame_link(content)
+ content.gsub(%r!<a href="http://[^>]*>!).each do |tag|
+ a_tag, rest = tag.split(' ', 2)
+ rest.gsub!(/target="[^"]*"/, '')
+ a_tag + ' target="_top" ' + rest
+ end
+ end
+
+ def class_dir
+ CLASS_DIR
+ end
+
+ def file_dir
+ FILE_DIR
+ end
+
+ def method_missing(sym, *args)
+ p [sym, args]
+ end
+
+ def h(html)
+ CGI::escapeHTML(html)
+ end
+
+ # XXX may my sins be not visited upon my sons.
+ def render_class_tree(entries, parent=nil)
+ namespaces = { }
+
+ entries.sort.inject('') do |out, klass|
+ unless namespaces[klass.full_name]
+ if parent
+ text = '<span class="parent">%s::</span>%s' % [parent.full_name, klass.name]
else
- content
+ text = klass.name
end
+
+ out << '<li>'
+
+ out << link_to(text, File.join(CLASS_DIR, klass.full_name.split('::')) + '.html')
+
+ if subentries = @classes.select { |x| x.full_name =~ /^#{klass.full_name}::/ }
+ subentries.each { |x| namespaces[x.full_name] = true }
+ out << "\n<ol>" + render_class_tree(subentries, klass) + "\n</ol>"
+ end
+
+ out << '</li>'
end
+
+ out
+ end
+ end
+
+ def build_javascript_search_index(entries)
+ result = "var search_index = [\n"
+ entries.each do |entry|
+ method_name = entry.name
+ module_name = entry.parent_name
+ # FIXME link
+ html = link_to_method(entry, '')
+ result << " { method: '#{method_name.downcase}', " +
+ "module: '#{module_name.downcase}', " +
+ "html: '#{html}' },\n"
end
+ result << "]"
+ result
end
- STYLE = read('styles.sass')
+ def link_to(text, url = nil, classname = nil)
+ class_attr = classname ? ' class="%s"' % classname : ''
- CLASS_PAGE = read('page.haml')
- FILE_PAGE = CLASS_PAGE
- METHOD_LIST = read('method_list.haml', 'sections.haml')
+ if url
+ %[<a target="docwin" href="#{url}"#{class_attr}>#{text}</a>]
+ elsif classname
+ %[<span#{class_attr}>#{text}</span>]
+ else
+ text
+ end
+ end
- FR_INDEX_BODY = BODY = read('layout.haml')
+ # +method_text+ is in the form of "ago (ActiveSupport::TimeWithZone)".
+ def link_to_method(entry, url = nil, classname = nil)
+ method_name = entry.pretty_name
+ module_name = entry.parent_name
+ link_to %Q(<span class="method_name">#{h method_name}</span> <span class="module_name">(#{h module_name})</span>), url, classname
+ end
+
+ #########
+ protected
+ #########
- FILE_INDEX = read('file_index.haml')
- CLASS_INDEX = read('class_index.haml')
- METHOD_INDEX = read('method_index.haml')
+ def outjoin(name)
+ File.join(@outputdir, name)
+ end
- INDEX = read('index.haml')
+ def templjoin(name)
+ File.join(@templatedir, name)
+ end
+
+ def haml_file(file)
+ Haml::Engine.new(File.read(file), :format => :html4)
+ end
end
View
@@ -1,42 +1,43 @@
-require 'hanna/version'
-require 'rake'
-require 'rake/rdoctask'
+require 'rdoc/rdoc'
+require 'hanna'
+gem 'rdoc'
+require 'rdoc/task'
-Rake::RDocTask.class_eval do
+class Hanna::Task < RDoc::Task
# don't allow it
undef :external=, :template=
# Create the tasks defined by this task lib.
def define
- @template = 'hanna'
- options << '--format=html'
+ options << '-f hanna'
# inline source and UTF-8 are defaults:
options << '--inline-source' unless options.include? '--inline-source' or options.include? '-S'
options << '--charset=UTF-8' if options.grep(/^(--charset\b|-c\b)/).empty?
+
+ super
+ #desc "Build the HTML documentation"
+ #task name
- desc "Build the HTML documentation"
- task name
-
- desc "Force a rebuild of the RDOC files"
- task paste("re", name) => [paste("clobber_", name), name]
+ #desc "Force a rebuild of the RDOC files"
+ #task paste("re", name) => [paste("clobber_", name), name]
- desc "Remove rdoc products"
- task paste("clobber_", name) do
- rm_r rdoc_dir rescue nil
- end
+ #desc "Remove rdoc products"
+ #task paste("clobber_", name) do
+ #rm_r rdoc_dir rescue nil
+ #end
- task :clobber => [paste("clobber_", name)]
+ #task :clobber => [paste("clobber_", name)]
- directory @rdoc_dir
- task name => [rdoc_target]
- file rdoc_target => @rdoc_files + [Rake.application.rakefile] do
- rm_r @rdoc_dir rescue nil
- Hanna::require_rdoc
- require 'rdoc/rdoc'
+ #directory @rdoc_dir
+ #task name => [rdoc_target]
+ #file rdoc_target => @rdoc_files + [Rake.application.rakefile] do
+ #rm_r @rdoc_dir rescue nil
+ #Hanna::require_rdoc
+ #require 'rdoc/rdoc'
- RDoc::RDoc.new.document(option_list + @rdoc_files)
- end
- return self
+ #RDoc::RDoc.new.document(option_list + @rdoc_files)
+ #end
+ #return self
end
end
@@ -1,3 +1,3 @@
%h1= values[:list_title]
%ol#index-entries.classes
- = render_class_tree make_class_tree(values[:entries])
+ = render_class_tree values[:classes].select { |x| x.full_name !~ /::/ }
@@ -2,10 +2,10 @@
- any_hidden = false
%ol#index-entries{ :class => 'files' }
- - for entry in values[:entries]
- - hide = entry[:name] =~ /\.rb$/
+ - values[:files].each do |file|
+ - hide = file.name =~ /\.rb$/
- any_hidden = true if hide
- %li{ :class => hide ? 'other' : nil }= link_to entry[:name], entry[:href]
+ %li{ :class => hide ? 'other' : nil }= link_to file.name, file.path
- if any_hidden
%li
Oops, something went wrong.

0 comments on commit 8c85a39

Please sign in to comment.