Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ##
- # <doc topic="Example with spaces">
- # Thats by the way doc example.
- # It uses *markdown* as markup.
- # </doc>
- #
- def scandoc file
- doc_start_rx = /(.+)(<doc( topic=\"(.+)\")?>)/
- doc_end_rx = /(.+)(<\/doc>)/
- File.open(file) do |file|
- file.each_line.inject({docs: [], current: nil, indent: nil}) do |docs, line|
- docs[:docs] << docs[:current] if line =~ doc_end_rx
- docs[:current] = nil if line =~ doc_end_rx
- docs[:current][:doc] << line.gsub(docs[:indent], "") unless docs[:current].nil?
- docs[:current] = {doc: [], topic: line[doc_start_rx, 4]} if line =~ doc_start_rx
- docs[:indent] = line[doc_start_rx, 1] if line =~ doc_start_rx
- docs
- end[:docs]
- end
- end
- ##
- # <doc>
- # Just run
- # </doc>
- puts (scandoc __FILE__)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement