Class: Mdoc::Document
- Inherits:
-
Object
- Object
- Mdoc::Document
- Extended by:
- Forwardable
- Defined in:
- lib/mdoc/document.rb,
lib/mdoc/document/kramdown.rb
Direct Known Subclasses
Defined Under Namespace
Classes: Kramdown
Constant Summary collapse
- LOOP_MAX =
99
Instance Attribute Summary collapse
-
#body ⇒ Object
Returns the value of attribute body.
-
#file ⇒ Object
Returns the value of attribute file.
-
#meta ⇒ Object
Returns the value of attribute meta.
-
#out_file ⇒ Object
Returns the value of attribute out_file.
-
#performed ⇒ Object
Returns the value of attribute performed.
-
#smeta ⇒ Object
Returns the value of attribute smeta.
-
#tpl_file ⇒ Object
Returns the value of attribute tpl_file.
Instance Method Summary collapse
-
#apply!(pn) ⇒ Object
apply processors by processor name (if corresponding processor) class defined.
-
#initialize(path) ⇒ Document
constructor
rubocop:disable MethodLength.
Constructor Details
#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 , = [], '' @meta, @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 @meta.load() if .size > 0 if .size > 0 @meta.title, @meta., @meta.date = [0 .. 2] end # source meta holds meta information from source file only @smeta = @meta.dup end |
Instance Attribute Details
#body ⇒ Object
Returns the value of attribute body.
9 10 11 |
# File 'lib/mdoc/document.rb', line 9 def body @body end |
#file ⇒ Object
Returns the value of attribute file.
9 10 11 |
# File 'lib/mdoc/document.rb', line 9 def file @file end |
#meta ⇒ Object
Returns the value of attribute meta.
9 10 11 |
# File 'lib/mdoc/document.rb', line 9 def @meta end |
#out_file ⇒ Object
Returns the value of attribute out_file.
9 10 11 |
# File 'lib/mdoc/document.rb', line 9 def out_file @out_file end |
#performed ⇒ Object
Returns the value of attribute performed.
9 10 11 |
# File 'lib/mdoc/document.rb', line 9 def performed @performed end |
#smeta ⇒ Object
Returns the value of attribute smeta.
9 10 11 |
# File 'lib/mdoc/document.rb', line 9 def @smeta end |
#tpl_file ⇒ Object
Returns the value of attribute tpl_file.
9 10 11 |
# File 'lib/mdoc/document.rb', line 9 def tpl_file @tpl_file end |
Instance Method Details
#apply!(pn) ⇒ Object
apply processors by processor name (if corresponding processor) class defined. rubocop:disable MethodLength
68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/mdoc/document.rb', line 68 def apply!(pn) prc = Mdoc.get_processor(pn) if performed[prc] if prc.new.repeatable? prc.new.process! self performed[prc] += 1 # error if performed too many times (prevent dead loop) raise "loop max reached: #{prc}" if performed[prc] > LOOP_MAX end else # not performed prc.new.process! self performed[prc] = 1 end end |