Class: RDoc::Generator::Hanna
- Inherits:
-
Object
- Object
- RDoc::Generator::Hanna
- Defined in:
- lib/hanna.rb
Overview
Hanna version of RDoc::Generator
Defined Under Namespace
Modules: LabelListTable Classes: ERB
Constant Summary collapse
- STYLE =
'styles.css'- LAYOUT =
'layout.erb'- INDEX_PAGE =
'index.erb'- CLASS_PAGE =
'page.erb'- METHOD_LIST_PAGE =
'method_list.erb'- FILE_PAGE =
CLASS_PAGE- SECTIONS_PAGE =
'sections.erb'- FILE_INDEX =
'file_index.erb'- CLASS_INDEX =
'class_index.erb'- METHOD_INDEX =
'method_index.erb'- 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')
- METHOD_SEARCH_JS =
"method_search.js"- DESCRIPTION =
'RDoc generator designed with simplicity, beauty and ease of browsing in mind'
Class Method Summary collapse
-
.setup_options(options) ⇒ Object
:nocov: For RDoc >= 6.13.1.
Instance Method Summary collapse
-
#class_dir ⇒ Object
:nocov: For RDoc < 6.13.
- #classfile(klass) ⇒ Object
- #erb_template(file) ⇒ Object
- #file_dir ⇒ Object
- #frame_link(content) ⇒ Object
- #generate ⇒ Object
- #generate_class_files ⇒ Object
- #generate_file_files ⇒ Object
- #generate_index(outfile, templfile, index_name, values) ⇒ Object
- #generate_indexes ⇒ Object
-
#h(html) ⇒ Object
:nocov:.
-
#initialize(store, options) ⇒ Hanna
constructor
A new instance of Hanna.
- #link_to(text, url) ⇒ Object
- #link_to_method(entry, url) ⇒ Object
- #outjoin(name) ⇒ Object
- #render_class_tree(entries, prefix = nil, out = String.new) ⇒ Object
- #templjoin(name) ⇒ Object
- #with_layout(values) ⇒ Object
- #write_static_files ⇒ Object
Constructor Details
#initialize(store, options) ⇒ Hanna
Returns a new instance of Hanna.
54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/hanna.rb', line 54 def initialize( store, ) @options = @store = store @templatedir = Pathname.new File.('../hanna/template_files', __FILE__) @files = nil @classes = nil @methods = nil @attributes = nil @basedir = Pathname.pwd. end |
Class Method Details
Instance Method Details
#class_dir ⇒ Object
:nocov: For RDoc < 6.13
202 203 204 |
# File 'lib/hanna.rb', line 202 def class_dir CLASS_DIR end |
#classfile(klass) ⇒ Object
253 254 255 |
# File 'lib/hanna.rb', line 253 def classfile(klass) Pathname.new(File.join(CLASS_DIR, klass.full_name.split('::')) + '.html') end |
#erb_template(file) ⇒ Object
281 282 283 |
# File 'lib/hanna.rb', line 281 def erb_template(file) ERB.new(File.read(file)) end |
#file_dir ⇒ Object
206 207 208 |
# File 'lib/hanna.rb', line 206 def file_dir FILE_DIR end |
#frame_link(content) ⇒ Object
192 193 194 195 196 197 198 |
# File 'lib/hanna.rb', line 192 def frame_link(content) content.gsub(%r!<a[ \n]href="https?://[^>]*>!).each do |tag| a_tag, rest = tag.split(' ', 2) rest.gsub!(/target="[^"]*"/, '') a_tag + ' target="_top" ' + rest end end |
#generate ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/hanna.rb', line 68 def generate @outputdir = Pathname.new( @options.op_dir ).( @basedir ) @files = @store.all_files.sort @classes = @store.all_classes_and_modules.sort @methods = @classes.map {|m| m.method_list }.flatten.sort @attributes = @classes.map(&:attributes).flatten.sort # Now actually write the output write_static_files generate_indexes generate_class_files generate_file_files end |
#generate_class_files ⇒ Object
141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 |
# File 'lib/hanna.rb', line 141 def generate_class_files class_page = erb_template(templjoin(CLASS_PAGE)) method_list_page = erb_template(templjoin(METHOD_LIST_PAGE)) sections_page = erb_template(templjoin(SECTIONS_PAGE)) @classes.each do |klass| outfile = classfile(klass) stylesheet = Pathname.new(STYLE_OUT).relative_path_from(outfile.dirname) sections = {} klass.each_section do |section, constants, attributes| method_types = [] alias_types = [] klass.methods_by_type(section).each do |type, visibilities| visibilities.each do |visibility, methods| aliases, methods = methods.partition{|x| x.is_alias_for} method_types << ["#{visibility.to_s.capitalize} #{type.to_s.capitalize}", methods.sort] unless methods.empty? alias_types << ["#{visibility.to_s.capitalize} #{type.to_s.capitalize}", aliases.sort] unless aliases.empty? end end sections[section] = {:constants=>constants, :attributes=>attributes, :method_types=>method_types, :alias_types=>alias_types} end values = { :file => klass.path, :entry => klass, :stylesheet => stylesheet, :classmod => klass.type, :title => klass.full_name, :list_title => nil, :description => klass.description, :sections => sections } result = with_layout(values) do h = {:values => values} class_page.to_html(binding, h) do method_list_page.to_html(binding, h) + sections_page.to_html(binding, h) end end dir = outfile.dirname FileUtils.mkdir_p dir File.binwrite(outfile, result) end end |
#generate_file_files ⇒ Object
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 |
# File 'lib/hanna.rb', line 111 def generate_file_files file_page = erb_template(templjoin(FILE_PAGE)) method_list_page = erb_template(templjoin(METHOD_LIST_PAGE)) @files.each do |file| path = Pathname.new(file.path) stylesheet = Pathname.new(STYLE_OUT).relative_path_from(path.dirname) values = { :file => file, :entry => file, :stylesheet => stylesheet, :classmod => nil, :title => file.base_name, :list_title => nil, :description => file.description } result = with_layout(values) do file_page.to_html(binding, :values => values) do method_list_page.to_html(binding, values) end end dir = path.dirname FileUtils.mkdir_p dir File.binwrite(outjoin(file.path), result) end end |
#generate_index(outfile, templfile, index_name, values) ⇒ Object
100 101 102 103 104 105 106 107 108 109 |
# File 'lib/hanna.rb', line 100 def generate_index(outfile, templfile, index_name, values) values.merge!({ :stylesheet => STYLE_OUT, :list_title => "#{index_name} Index" }) index = erb_template(templjoin(templfile)) File.binwrite(outjoin(outfile), with_layout(values){index.to_html(binding, values)}) end |
#generate_indexes ⇒ Object
89 90 91 92 93 94 95 96 97 98 |
# File 'lib/hanna.rb', line 89 def generate_indexes @main_page_uri = @files.find { |f| f.name == @options.main_page }.path rescue '' File.binwrite(outjoin(INDEX_OUT), erb_template(templjoin(INDEX_PAGE)).to_html(binding)) generate_index(FILE_INDEX_OUT, FILE_INDEX, 'File', { :files => @files}) generate_index(CLASS_INDEX_OUT, CLASS_INDEX, 'Class', { :classes => @classes }) generate_index(METHOD_INDEX_OUT, METHOD_INDEX, 'Method', { :methods => @methods, :attributes => @attributes }) File.binwrite(outjoin(METHOD_SEARCH_JS), File.binread(templjoin(METHOD_SEARCH_JS))) end |
#h(html) ⇒ Object
:nocov:
211 212 213 |
# File 'lib/hanna.rb', line 211 def h(html) CGI::escapeHTML(html.to_s) end |
#link_to(text, url) ⇒ Object
243 244 245 |
# File 'lib/hanna.rb', line 243 def link_to(text, url) %[<a href="#{url}">#{text}</a>] end |
#link_to_method(entry, url) ⇒ Object
247 248 249 250 251 |
# File 'lib/hanna.rb', line 247 def link_to_method(entry, url) method_name = entry.pretty_name rescue entry.name module_name = entry.parent_name rescue entry.name link_to %Q(<span class="method_name" value="#{entry.name}">#{h method_name}</span> <span class="module_name">(#{h module_name})</span>), url end |
#outjoin(name) ⇒ Object
257 258 259 |
# File 'lib/hanna.rb', line 257 def outjoin(name) File.join(@outputdir, name) end |
#render_class_tree(entries, prefix = nil, out = String.new) ⇒ Object
215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 |
# File 'lib/hanna.rb', line 215 def render_class_tree(entries, prefix=nil, out=String.new) namespaces = { } entries.sort.each do |klass| full_name = klass.full_name next if namespaces[full_name] class_prefix = "#{full_name}::" subentries = @classes.select{|c| c.full_name.start_with?(class_prefix)} subentries.each { |x| namespaces[x.full_name] = true } text = prefix ? (prefix + klass.name) : klass.name link = link_to(text, classfile(klass)) if subentries.empty? out << "<span class=\"class-link\">" << link << "</span>\n" else out << '<details' out << ' open' if full_name.count(':') == 0 out << '><summary>' << link << "</summary>\n" render_class_tree(subentries, "<span class=\"parent\">#{full_name}::</span>", out) out << "</details>" end end out end |
#templjoin(name) ⇒ Object
261 262 263 |
# File 'lib/hanna.rb', line 261 def templjoin(name) File.join(@templatedir, name) end |
#with_layout(values) ⇒ Object
187 188 189 190 |
# File 'lib/hanna.rb', line 187 def with_layout(values) layout = erb_template(templjoin(LAYOUT)) layout.to_html(binding, :values => values) { yield } end |
#write_static_files ⇒ Object
83 84 85 86 87 |
# File 'lib/hanna.rb', line 83 def write_static_files css_dir = outjoin('css') FileUtils.mkdir_p css_dir File.binwrite(File.join(css_dir, 'style.css'), File.read(templjoin(STYLE))) end |