Class: Cdoc::CDoc
- Inherits:
-
Object
- Object
- Cdoc::CDoc
- Defined in:
- lib/cdoc.rb
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.
- #sidebar_section(headers) ⇒ Object
Constructor Details
Instance Attribute Details
#docstring ⇒ Object
Returns the value of attribute docstring.
119 120 121 |
# File 'lib/cdoc.rb', line 119 def docstring @docstring end |
#files ⇒ Object
Returns the value of attribute files.
119 120 121 |
# File 'lib/cdoc.rb', line 119 def files @files end |
Instance Method Details
#extract_documentation(file) ⇒ Object
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 186 187 188 189 190 191 192 193 |
# File 'lib/cdoc.rb', line 153 def extract_documentation(file) begin lines = File.readlines(file) rescue => e puts "#{e.class}: Error reading file #{file}. Skip" return end docs = [] doclines = [] 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?('#') doclines << line.strip.sub('#', '') else recording = false docs << doclines.join("\n") doclines = [] end end end if recording && (doclines.length != 0) recording = false docs << doclines.join("\n") doclines = [] end docs end |
#generate ⇒ Object
133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 |
# File 'lib/cdoc.rb', line 133 def generate @doc.title('Chillr API Documentaion') @file_groups = files.group_by { |f| File.basename(f, '_controller.rb') } @sidebar = (@file_groups.keys) @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 |
#sidebar_section(headers) ⇒ Object
127 128 129 130 131 |
# File 'lib/cdoc.rb', line 127 def (headers) headers.each do |title| title.capitalize end end |