Class: DocFace::Base
- Inherits:
-
Object
- Object
- DocFace::Base
- Defined in:
- lib/docface/base.rb
Instance Method Summary collapse
- #all_the_things ⇒ Object
- #assets ⇒ Object
- #build(file, content) ⇒ Object
- #build_index(path) ⇒ Object
- #cleanup(h) ⇒ Object
- #cli ⇒ Object
-
#initialize ⇒ Base
constructor
A new instance of Base.
- #parse(files, directory) ⇒ Object
- #write_index(content) ⇒ Object
Constructor Details
#initialize ⇒ Base
Returns a new instance of Base.
10 11 12 13 14 15 16 17 |
# File 'lib/docface/base.rb', line 10 def initialize cli @troll = FileTroll.new @writer = Writer.new @parser = Parser.new @short_files = Array.new all_the_things end |
Instance Method Details
#all_the_things ⇒ Object
19 20 21 22 23 24 25 26 27 28 |
# File 'lib/docface/base.rb', line 19 def all_the_things @directory.each do |dir| files = @troll.troll(dir) parse(files,dir) end @index_hash = @troll.index_hash(@short_files) cleanup(@index_hash) assets write_index(build_index("templates/index.erb")) end |
#assets ⇒ Object
56 57 58 |
# File 'lib/docface/base.rb', line 56 def assets @writer.assets(File.join(File.dirname(__FILE__),"../../public"),"#{@output_dir}/public") end |
#build(file, content) ⇒ Object
50 51 52 53 54 |
# File 'lib/docface/base.rb', line 50 def build(file,content) file = File.join(@output_dir,file).gsub(/\.md|.MD|.markdown|.mdown/,".html") directory = File.dirname(file) @writer.write(directory,file,content) end |
#build_index(path) ⇒ Object
60 61 62 63 |
# File 'lib/docface/base.rb', line 60 def build_index(path) r = ERB.new(File.read(File.join(File.dirname(__FILE__),path))) r.result(binding) end |
#cleanup(h) ⇒ Object
69 70 71 72 73 |
# File 'lib/docface/base.rb', line 69 def cleanup(h) return true if h.empty? h.find_all{|k,v|h[k]=nil if v.is_a?(Hash)&&cleanup(v)} false end |
#cli ⇒ Object
30 31 32 33 34 35 36 37 38 |
# File 'lib/docface/base.rb', line 30 def cli @cli = Cli.opts @directory = @cli[:dir] @page_attributes = { :title => @cli[:title] || "DocFace", :summary => @cli[:summary] || "" } @output_dir = @cli[:output] ? @cli[:output] : "#{Dir.pwd}/docface" end |
#parse(files, directory) ⇒ Object
40 41 42 43 44 45 46 47 48 |
# File 'lib/docface/base.rb', line 40 def parse(files,directory) files.each do |file| content = @parser.to_html(File.read(file)) dir = directory.gsub(directory.split('/').last, "") file = file.gsub(dir, "") @short_files << file build(file,content) end end |
#write_index(content) ⇒ Object
65 66 67 |
# File 'lib/docface/base.rb', line 65 def write_index(content) @writer.write(@output_dir,"#{@output_dir}/index.html",content) end |