Class: IPT::README::Formatter

Inherits:
Object
  • Object
show all
Defined in:
lib/ipt/readme.rb

Constant Summary collapse

PATTERN =
"README.{text,textile,rdoc,md,markdown}"
FORMATTER =
[MarkdownFormatter, TextileFormatter, RdocFormatter]

Instance Method Summary collapse

Constructor Details

#initialize(root_dir) ⇒ Formatter

Returns a new instance of Formatter.



80
81
82
# File 'lib/ipt/readme.rb', line 80

def initialize(root_dir)
  @dir = root_dir
end

Instance Method Details

#find_formatter(file) ⇒ Object



88
89
90
91
92
93
94
95
96
# File 'lib/ipt/readme.rb', line 88

def find_formatter(file)
  ext = file.split(/\./).last
  FORMATTER.each do |f|
    if f.supports(ext)
      return f
    end 
  end
  PlainFormatter # Default formatter
end

#find_readmeObject



84
85
86
# File 'lib/ipt/readme.rb', line 84

def find_readme
  Dir["#{@dir}/#{PATTERN}"].first
end

#to_htmlObject



98
99
100
101
102
103
104
105
106
107
# File 'lib/ipt/readme.rb', line 98

def to_html
  readme_file = find_readme
  if readme_file && File.file?(readme_file)
    File.open("readme.html", "w") do |f|
      f << find_formatter(readme_file).new.to_html(IO.readlines(readme_file).join)
    end
  else
    puts "No #{PATTERN}s file could be found."
  end
end