Class: Cdoc::CDoc
Instance Attribute Summary collapse
-
#docstring ⇒ Object
Returns the value of attribute docstring.
-
#files ⇒ Object
Returns the value of attribute files.
Instance Method Summary collapse
- #extract_documentation(file) ⇒ Object
- #generate ⇒ Object
-
#initialize ⇒ CDoc
constructor
A new instance of CDoc.
Methods included from Helpers
Constructor Details
Instance Attribute Details
#docstring ⇒ Object
Returns the value of attribute docstring.
175 176 177 |
# File 'lib/cdoc.rb', line 175 def docstring @docstring end |
#files ⇒ Object
Returns the value of attribute files.
175 176 177 |
# File 'lib/cdoc.rb', line 175 def files @files end |
Instance Method Details
#extract_documentation(file) ⇒ Object
205 206 207 208 209 210 211 212 213 214 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 242 243 |
# File 'lib/cdoc.rb', line 205 def extract_documentation(file) begin lines = File.readlines(file) rescue => e puts "#{e.class}: Error reading file #{file}. Skip" return end sections = [] section_doc_lines = [] recording = false lines.each do |line| if !recording && (line.strip == '#doc') recording = true next end if recording line = line.strip if line.empty? next elsif line.start_with?('#') section_doc_lines << line.strip.sub('#', '') else recording = false sections << section_doc_lines.join("\n") section_doc_lines = [] end end end if recording && (section_doc_lines.length != 0) sections << section_doc_lines.join("\n") end sections end |
#generate ⇒ Object
183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 |
# File 'lib/cdoc.rb', line 183 def generate @doc.title(ENV['TITLE'] || 'Chillr API Documentaion') file_groups = files.group_by { |f| File.basename(f, '_controller.rb') } # Generates sidebar @doc.(file_groups.keys) # Generates body file_groups.each do |group, files| @doc.section(group.capitalize) files.each do |file| docs = extract_documentation(file) docs.each do |doc| @doc.subsection(doc) end end end @doc.finish end |