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.
Constructor Details
#initialize ⇒ CDoc
Returns a new instance of CDoc.
121 122 123 124 125 |
# File 'lib/cdoc.rb', line 121 def initialize @files = Rake::FileList.new('app/controllers/**/*.rb') @files = @files.select { |file| file.end_with?('_controller.rb') } @doc = DocString.new end |
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
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/cdoc.rb', line 145 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
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 |
# File 'lib/cdoc.rb', line 127 def generate @doc.title('Chillr API Documentaion') @file_groups = files.group_by { |f| File.basename(f, '_controller.rb') } @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 |