Method: Mdoc::Document#initialize
- Defined in:
- lib/mdoc/document.rb
#initialize(path) ⇒ Document
rubocop:disable MethodLength
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 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/mdoc/document.rb', line 14 def initialize(path) if path.is_a?(String) @file = path path = File.new(@file, 'r:bom|utf-8') end # initialize performed processor list @performed = {} position = nil # before meta, :meta, :body, :between, :pandoc_header , = [], '' , @body = Meta.new, '' path.each do |line| # puts position.to_s + line if position line.chomp! if line.match(/^\s*$/) next if position.nil? || position == :between else position = :body if position == :between end if line.match(/^\%?\s*\-{3,}\s*$/) # meta headers position = :between if position == :meta position = :meta unless position next elsif line.match(/^\%\s*/) position = :pandoc_header if position.nil? else position = :body unless position # if position == :pandoc_header end if position == :pandoc_header << line.gsub(/^\%\s*/, '') position = :between if .size >= 3 end << line << "\n" if position == :meta @body << line << "\n" if position == :body end .load() if .size > 0 if .size > 0 .title, ., .date = [0 .. 2] end # source meta holds meta information from source file only = .dup end |