Class: Docme
- Inherits:
-
Object
- Object
- Docme
- Defined in:
- lib/docme.rb
Instance Method Summary collapse
- #engage ⇒ Object
-
#initialize(path, is_verbose = nil, style = nil, index = nil, page_erb = nil) ⇒ Docme
constructor
A new instance of Docme.
- #make_home ⇒ Object
- #render_css ⇒ Object
- #render_docs ⇒ Object
- #render_index ⇒ Object
- #scan_docs ⇒ Object
Constructor Details
#initialize(path, is_verbose = nil, style = nil, index = nil, page_erb = nil) ⇒ Docme
Returns a new instance of Docme.
11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/docme.rb', line 11 def initialize(path, is_verbose = nil, style = nil, index = nil, page_erb = nil) @path = path @pages = [] @is_verbose = is_verbose @style = style @index = index @page_erb = page_erb puts '+ docme will parse: '.color(:cyan) + @path if @is_verbose make_home end |
Instance Method Details
#engage ⇒ Object
24 25 26 27 28 29 30 |
# File 'lib/docme.rb', line 24 def engage make_home scan_docs render_docs render_index render_css end |
#make_home ⇒ Object
32 33 34 35 36 37 38 39 40 41 |
# File 'lib/docme.rb', line 32 def make_home # create the directory where the site will be stored if Dir.exist?('docme_site') clean_directory('docme_site', @is_verbose) else puts "+ Setting up docme's living arrangements.".color(:cyan) if @is_verbose Dir.mkdir('docme_site') puts ' - Woohoo! docme has a home!' if @is_verbose end end |
#render_css ⇒ Object
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/docme.rb', line 89 def render_css puts '+ docme is styling'.color(:cyan) if @is_verbose if @style.nil? template = File.read(File.join(File.dirname(__FILE__), 'templates/style.erb')) else template = File.read(File.join(Dir.pwd, @style)) end renderer = ERB.new(template) File.open('style.css', 'w+') do |f| f.write(renderer.result(binding)) end # add page to docme dir FileUtils.mv('style.css', 'docme_site/style.css') puts '+ styling completed'.color(:cyan) if @is_verbose end |
#render_docs ⇒ Object
59 60 61 62 63 64 65 |
# File 'lib/docme.rb', line 59 def render_docs puts '+ docme generated the following pages: '.color(:cyan) if @is_verbose @pages.each do |page_object| page_object.render_site(@pages, @page_erb) puts ' - ' + page_object.name if @is_verbose end end |
#render_index ⇒ Object
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/docme.rb', line 67 def render_index puts '+ docme is creating the index'.color(:cyan) if @is_verbose if @index.nil? template = File.read(File.join(File.dirname(__FILE__), 'templates/index.erb')) else template = File.read(File.join(Dir.pwd, @index)) end renderer = ERB.new(template) File.open('site_index.html', 'w+') do |f| f.write(renderer.result(binding)) end # add page to docme dir FileUtils.mv('site_index.html', 'docme_site/site_index.html') puts '+ index created'.color(:cyan) if @is_verbose end |
#scan_docs ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/docme.rb', line 43 def scan_docs puts '+ docme scanning: '.color(:cyan) + @path if @is_verbose # if a directory was provided if File.directory?(@path) @pages.concat parse_directory(@path, @is_verbose) else # if a single file was provided @pages.push(parse_file(@path, @is_verbose)) end end |