Advertisement
Guest User

Untitled

a guest
Jan 30th, 2015
202
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.75 KB | None | 0 0
  1. ##
  2. # <doc topic="Example with spaces">
  3. # Thats by the way doc example.
  4. # It uses *markdown* as markup.
  5. # </doc>
  6. #
  7. def scandoc file
  8. doc_start_rx = /(.+)(<doc( topic=\"(.+)\")?>)/
  9. doc_end_rx = /(.+)(<\/doc>)/
  10.  
  11. File.open(file) do |file|
  12. file.each_line.inject({docs: [], current: nil, indent: nil}) do |docs, line|
  13.  
  14. docs[:docs] << docs[:current] if line =~ doc_end_rx
  15. docs[:current] = nil if line =~ doc_end_rx
  16.  
  17. docs[:current][:doc] << line.gsub(docs[:indent], "") unless docs[:current].nil?
  18.  
  19. docs[:current] = {doc: [], topic: line[doc_start_rx, 4]} if line =~ doc_start_rx
  20. docs[:indent] = line[doc_start_rx, 1] if line =~ doc_start_rx
  21.  
  22. docs
  23. end[:docs]
  24. end
  25. end
  26.  
  27. ##
  28. # <doc>
  29. # Just run
  30. # </doc>
  31. puts (scandoc __FILE__)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement