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.
10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/docme.rb', line 10 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: ' + @path if @is_verbose make_home end |
Instance Method Details
#engage ⇒ Object
23 24 25 26 27 28 29 |
# File 'lib/docme.rb', line 23 def engage make_home scan_docs render_docs render_index render_css end |
#make_home ⇒ Object
31 32 33 34 35 36 37 38 39 40 |
# File 'lib/docme.rb', line 31 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." if @is_verbose Dir.mkdir('docme_site') puts ' - Woohoo! docme has a home!' if @is_verbose end end |
#render_css ⇒ Object
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/docme.rb', line 88 def render_css puts '+ docme is styling' 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' if @is_verbose end |
#render_docs ⇒ Object
58 59 60 61 62 63 64 |
# File 'lib/docme.rb', line 58 def render_docs puts '+ docme generated the following pages: ' 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
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/docme.rb', line 66 def render_index puts '+ docme is creating the index' 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' if @is_verbose end |
#scan_docs ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/docme.rb', line 42 def scan_docs puts '+ docme scanning: ' + @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 |