class Creq::DocWriter

Public Class Methods

call(req, stream = $stdout) click to toggle source
# File lib/creq/doc_writer.rb, line 9
def self.call(req, stream = $stdout)
  writer = new(req.is_a?(Array)? req.first.root : req.root)
  writer.write(req.inject([], :<<), stream)
end

Public Instance Methods

text(r) click to toggle source
# File lib/creq/doc_writer.rb, line 19
def text(r)
  [title(r), attributes(r), body(r)]
  .select{|i| !i.empty?}.join("\n\n")
end
write(req, stream) click to toggle source
Calls superclass method Creq::Writer#write
# File lib/creq/doc_writer.rb, line 14
def write(req, stream)
  req.delete_at(0)
  super(req, stream)
end

Protected Instance Methods

attributes(r) click to toggle source
# File lib/creq/doc_writer.rb, line 33
def attributes(r)
  return "" if r.user_attributes.empty? || r[:skip_meta]
  t = ["Attribute | Value", "--------- | -----"]
  r.user_attributes.inject(t){|s, (k, v)| s << "#{k} | #{v}"}
  t.join("\n")
end
body(r) click to toggle source
# File lib/creq/doc_writer.rb, line 40
def body(r)
  bodycp = String.new(r.body)
  return "" if bodycp.empty?
  r.links.each{|l| bodycp.gsub!("[[#{l}]]", link(l))}
  bodycp
end
title(r) click to toggle source
# File lib/creq/doc_writer.rb, line 26
def title(r)
  t = ['#' * r.level]
  t << "[#{r.id}]" unless r[:skip_meta]
  t << r.title
  t.join(' ')
end
url(id) click to toggle source
# File lib/creq/doc_writer.rb, line 53
def url(id)
  id.downcase
    .gsub(/[^A-Za-z0-9]/, '-')
    .gsub(/(-){2,}/, '-')
end