Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 145 lines (115 sloc) 3.189 kb
d9d744d @tenderlove initial commit
authored
1 require 'rdoc/generator'
2 require 'rdoc/rdoc'
3 require 'paddle'
4 require 'erb'
5 require 'md5'
6 require 'fileutils'
7
8 class RDoc::Generator::Paddle
9 RDoc::RDoc.add_generator self
10
11 TEMPLATE_DIR = File.expand_path(
12 File.join(File.dirname(__FILE__), '..', '..', 'templates'))
1a4f628 @tenderlove copying images. woo
authored
13 IMAGE_DIR = File.expand_path(
14 File.join(File.dirname(__FILE__), '..', '..', 'images'))
d9d744d @tenderlove initial commit
authored
15
16 class << self
17 alias :for :new
18 end
19
20 def initialize options
21 @options = options
22 @class_dir = nil
23 @file_dir = nil
24 @odir = Pathname.new(options.op_dir).expand_path(Pathname.pwd)
25 @fh = nil
26 @files = nil
27 end
28
29 def generate top_levels
30 @files = top_levels
37b3d60 @tenderlove escaping stuff
authored
31 @classes = RDoc::TopLevel.all_classes_and_modules.reject { |x|
32 x.name =~ /[<>]/
33 }
d9d744d @tenderlove initial commit
authored
34
35 FileUtils.mkdir_p(File.join(@odir, class_dir))
36
37 emit_mimetype
38 emit_meta_inf
39 emit_cover
40 emit_title
41 emit_opf
42 emit_toc
43 emit_classfiles
1a4f628 @tenderlove copying images. woo
authored
44 copy_images
d9d744d @tenderlove initial commit
authored
45 end
46
47 def class_dir
48 '/doc'
49 end
50
51 def title
52 @options.title
53 end
54
55 def identifier
d27b6e3 @tenderlove using md5 for the identifier
authored
56 MD5.hexdigest title
d9d744d @tenderlove initial commit
authored
57 end
58
59 private
37b3d60 @tenderlove escaping stuff
authored
60 def h string
61 string.strip.gsub(/<pre>\s*<\/pre>/, '').gsub(/&/, '&amp;').gsub(/<</, '&lt;&lt;')
62 end
63
1a4f628 @tenderlove copying images. woo
authored
64 def copy_images
65 imgs = File.join @odir, 'images'
66 FileUtils.mkdir_p imgs
67
68 FileUtils.cp File.join(IMAGE_DIR, 'ruby.png'), imgs
69 end
70
d9d744d @tenderlove initial commit
authored
71 def emit_meta_inf
72 meta_inf = File.join @odir, 'META-INF'
73 FileUtils.mkdir_p meta_inf
74
75 FileUtils.cp File.join(TEMPLATE_DIR, 'container.xml'), meta_inf
76 end
77
78 def emit_mimetype
79 File.open(File.join(@odir, 'mimetype'), 'wb') do |f|
80 f.write 'application/epub+zip'
81 end
82 end
83
84 def emit_cover
85 template = ERB.new File.read(File.join(TEMPLATE_DIR, 'cover.html.erb')),
86 nil, '<>'
87
88 File.open(File.join(@odir, class_dir, 'cover.html'), 'wb') do |f|
89 f.write template.result binding
90 end
91 end
92
93 def emit_title
94 template = ERB.new File.read(File.join(TEMPLATE_DIR, 'title.html.erb')),
95 nil, '<>'
96
97 File.open(File.join(@odir, class_dir, 'title.html'), 'wb') do |f|
98 f.write template.result binding
99 end
100 end
101
102 def emit_classfiles
103 @classes.each do |klass|
7d11fbf @tenderlove adding methods and style
authored
104 klass_methods = []
105 instance_methods = []
106
107 klass.method_list.each do |method|
108 next if 'private' == method.visibility.to_s
109 if method.type == 'class'
110 klass_methods << method
111 else
112 instance_methods << method
113 end
114 end
115
d9d744d @tenderlove initial commit
authored
116 template = ERB.new File.read(File.join(TEMPLATE_DIR, 'classfile.html.erb')),
117 nil, '<>'
118
119 FileUtils.mkdir_p(File.dirname(File.join(@odir, klass.path)))
120
121 File.open(File.join(@odir, klass.path), 'wb') do |f|
122 f.write template.result binding
123 end
124 end
125 end
126
127 def emit_opf
128 template = ERB.new File.read(File.join(TEMPLATE_DIR, 'content.opf.erb')),
129 nil, '<>'
130
131 File.open(File.join(@odir, 'content.opf'), 'wb') do |f|
132 f.write template.result binding
133 end
134 end
135
136 def emit_toc
137 template = ERB.new File.read(File.join(TEMPLATE_DIR, 'toc.ncx.erb')),
138 nil, '<>'
139
140 File.open(File.join(@odir, 'toc.ncx'), 'wb') do |f|
141 f.write template.result binding
142 end
143 end
144 end
Something went wrong with that request. Please try again.