Module: Slideshow::HeadersFilter
- Included in:
- Gen
- Defined in:
- lib/slideshow/filters/headers_filter.rb
Instance Method Summary collapse
Instance Method Details
#leading_headers(content_with_headers) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/slideshow/filters/headers_filter.rb', line 6 def leading_headers( content_with_headers ) # todo: lets user override headers with command line options # that is, lets you override options using commandline switch # read source document; split off optional header from source # strip leading optional headers (key/value pairs) including optional empty lines read_headers = true content = "" keys = [] # track header keys for stats content_with_headers.each_line do |line| if read_headers && line =~ /^\s*(\w[\w-]*)[ \t]*:[ \t]*(.*)/ key = $1.downcase value = $2.strip keys << key logger.debug " adding header: key=>#{key}< value=>#{value}<" headers.put( key, value ) elsif line =~ /^\s*$/ content << line unless read_headers else read_headers = false content << line end end puts " Reading #{keys.length} headers: #{keys.join(', ')}..." content end |