class Asciibuild::Extensions::ConcatBlock

Public Instance Methods

process(parent, reader, attrs) click to toggle source
# File lib/asciibuild/extensions.rb, line 127
def process parent, reader, attrs
  doctitle = parent.document.attributes["doctitle"]
  body = reader.read

  puts ""
  puts "#{doctitle} > #{parent.title} > #{attrs['title']}"
  puts (">" * 80)

  fname = if not include_section?(parent, attrs)
    if parent.document.attributes["error"]
      puts "Section \"#{parent.title}\" skipped due to previous error."
      attrs['title'] = 'icon:pause-circle[role=red] ' + attrs['title'] + " (previous error)"
    else
      sections = parent.document.attributes["sections"].split(/,[ ]*/)
      puts "Section \"#{parent.title}\" skipped. Does not match #{sections}."
      attrs['title'] = 'icon:pause-circle[role=yellow] ' + attrs['title']
    end
    false
  else
    attrs["file"]
  end

  if fname
    if not parent.document.attributes["#{parent.title} #{fname}"]
      open(fname, 'w') do |f|
        f.write("")
      end
      parent.document.attributes["#{parent.title} #{fname}"] = true
    end

    open(fname, 'a') do |f|
      f.write(body + "\n")
    end
    puts body
  end

  puts ("<" * 80)

  create_open_block parent, ["----", body, "----"], attrs
end