Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

* Fail partially removed.

  • Loading branch information...
commit 8c85a395c210fcb354c40a2048c47ef17b4c7887 1 parent b9bd256
Erik Hollensbe authored
View
5 Rakefile
@@ -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
4 hanna.gemspec
@@ -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
260 lib/hanna/hanna.rb
@@ -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
51 lib/hanna/rdoctask.rb
@@ -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
View
2  lib/hanna/template_files/class_index.haml
@@ -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 !~ /::/ }
View
6 lib/hanna/template_files/file_index.haml
@@ -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
View
6 lib/hanna/template_files/index.haml
@@ -1,11 +1,11 @@
!!! Frameset
%html{ "xml:lang" => "en", :lang => "en", :xmlns => "http://www.w3.org/1999/xhtml" }
%head
- %title= values[:title]
- %meta{ :content => "text/html; charset=#{values[:charset]}", "http-equiv" => "Content-Type" }
+ %title= @options.title
+ %meta{ :content => "text/html; charset=#{@options.charset}", "http-equiv" => "Content-Type" }
%frameset{ :cols => "20%, *", :border => "1", :frameborder => "1", :bordercolor => "gray" }
%frameset{ :rows => "15%, 35%, 50%" }
%frame{ :name => "Files", :title => "Files", :src => "fr_file_index.html" }
%frame{ :name => "Classes", :src => "fr_class_index.html" }
%frame{ :name => "Methods", :src => "fr_method_index.html" }
- %frame{ :name => "docwin", :src => values[:initial_page] }=""
+ %frame{ :name => "docwin", :src => @main_page_uri }=""
View
4 lib/hanna/template_files/layout.haml
@@ -3,8 +3,8 @@
%html{ :lang => "en" }
%head
%title= values[:title]
- %meta{ 'http-equiv' => "Content-Type", :content => "text/html; charset=#{values[:charset]}" }
- %link{ :rel => "stylesheet", :href => values[:style_url], :type => "text/css", :media => "screen" }
+ %meta{ 'http-equiv' => "Content-Type", :content => "text/html; charset=#{@options.charset}" }
+ %link{ :rel => "stylesheet", :href => values[:stylesheet], :type => "text/css", :media => "screen" }
- unless index
:javascript
function popupCode(url) {
View
11 lib/hanna/template_files/method_index.haml
@@ -1,13 +1,14 @@
%h1= values[:list_title]
%script{:type => 'text/javascript'}
- = read("prototype-1.6.0.3.js")
- = build_javascript_search_index(values[:entries])
- = read("method_search.js")
+ = File.read(File.join(@templatedir, "prototype-1.6.0.3.js"))
+ = build_javascript_search_index(values[:methods])
+ = File.read(File.join(@templatedir, "method_search.js"))
%form{:onsubmit => 'return performSearch()'}
%input{:type => 'text', :id => 'search', :class => 'untouched', :value => 'Enter search terms...'}
%ol#search-results{ :class => 'methods', :style => 'display: none' }
%ol#index-entries{ :class => 'methods' }
- - for entry in values[:entries]
- %li= link_to_method entry[:name], entry[:href]
+ - values[:methods].each do |entry|
+ -# FIXME link
+ %li= link_to_method entry, ''
View
20 lib/hanna/template_files/page.haml
@@ -1,13 +1,13 @@
- file_page = !values[:classmod]
-- title_in_description = values[:description] && values[:description] =~ /^\s*<h1>/m
+- title_in_description = values[:file].description && values[:file].description =~ /^\s*<h1>/m
.header
- title = capture_haml do
- if file_page
- = values[:short_name]
+ = values[:file].name
- else
%span.type= values[:classmod]
- = values[:full_name]
+ = values[:file].path
- if title_in_description
.name= title
- else
@@ -15,9 +15,9 @@
- if file_page
.paths
- = values[:full_path]
- - if values[:cvsurl]
- == (#{link_to 'view online', values[:cvsurl]})
+ = values[:file].path
+ -#- if values[:cvsurl]
+ -#== (#{link_to 'view online', values[:cvsurl]})
- else
%ol.paths
- values[:infiles].each_with_index do |file, index|
@@ -29,7 +29,7 @@
%li
%a.show{ :href => '#', :onclick => 'this.parentNode.parentNode.className += " expanded"; this.parentNode.removeChild(this); return false' } show all
- - if values[:parent] then
+ - if values[:file].respond_to?(:parent) then
.parent
Parent:
%strong= link_to values[:parent], values[:par_url]
@@ -40,11 +40,11 @@
%span.datetime= values[:dtm_modified]
#content
- - if values[:diagram]
- #diagram= values[:diagram]
+ -#- if values[:diagram]
+ -##diagram= values[:diagram]
#text
- if values[:description]
#description~ sanitize_code_blocks values[:description]
- = yield
+ = frame_link yield
View
6 lib/hanna/template_page_patch.rb
@@ -32,7 +32,7 @@ def write_html_on(io, values)
private
- def get_binding(values = nil)
- binding
- end
+ def get_binding(values = nil)
+ binding
+ end
end
View
2  lib/hanna/version.rb
@@ -3,7 +3,7 @@ module Hanna
VERSION = '0.1.13'
# The version of RDoc that Hanna should use
- RDOC_VERSION = '2.3.0'
+ RDOC_VERSION = '2.5.9'
RDOC_VERSION_REQUIREMENT = "~> #{RDOC_VERSION}"
# Load the correct version of RDoc
View
1  lib/rdoc/discover.rb
@@ -0,0 +1 @@
+require 'hanna'

0 comments on commit 8c85a39

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