Skip to content
Browse files

Adding CLI argument `template`

In v0.5, the Mustache template is hardcoded as
`./lib/rocco/layout.mustache`.  This makes it quite difficult to
style generated content as one must edit the layout file inside the
gem itself to make changes.

I propose leaving that file as a sensible default, but allowing the user
to specify an absolute or relative (to the current working directory)
path to a mustach template of her choosing.  That's implemented in this
commit.
  • Loading branch information...
1 parent e57b208 commit bb8fcb9ef0e63281b9b46104d40bbd5adb1cf07a @mikewest mikewest committed
Showing with 13 additions and 2 deletions.
  1. +2 −0 bin/rocco
  2. +7 −1 lib/rocco.rb
  3. +4 −1 lib/rocco/layout.rb
View
2 bin/rocco
@@ -7,6 +7,7 @@
#/ -c, --comment-chars=<chars>
#/ The string to recognize as a comment marker
#/ -o, --output=<dir> Directory where generated HTML files are written
+#/ -t, --template=<path> The file to use as template when rendering HTML
#/ --help Show this help message
require 'optparse'
@@ -37,6 +38,7 @@ ARGV.options { |o|
o.on("-o", "--output=DIR") { |dir| output_dir = dir }
o.on("-l", "--language=LANG") { |lang| options[:language] = lang }
o.on("-c", "--comment-chars=CHARS") { |chars| options[:comment_chars] = Regexp.escape(chars) }
+ o.on("-t", "--template=TEMPLATE") { |template| options[:template_file] = template }
o.on_tail("-h", "--help") { usage($stdout, 0) }
o.parse!
} or abort_with_note
View
8 lib/rocco.rb
@@ -82,10 +82,12 @@ def initialize(filename, sources=[], options={}, &block)
defaults = {
:language => 'ruby',
:comment_chars => '#',
+ :template_file => nil
}
@options = defaults.merge(options)
@sources = sources
@comment_pattern = Regexp.new("^\\s*#{@options[:comment_chars]}")
+ @template_file = @options[:template_file]
@sections = highlight(split(parse(@data)))
end
@@ -102,10 +104,14 @@ def initialize(filename, sources=[], options={}, &block)
# for building an index of other files.
attr_reader :sources
+ # An absolute path to a file that ought be used as a template for the
+ # HTML-rendered documentation.
+ attr_reader :template_file
+
# Generate HTML output for the entire document.
require 'rocco/layout'
def to_html
- Rocco::Layout.new(self).render
+ Rocco::Layout.new(self, @template_file).render
end
#### Internal Parsing and Highlighting
View
5 lib/rocco/layout.rb
@@ -3,8 +3,11 @@
class Rocco::Layout < Mustache
self.template_path = File.dirname(__FILE__)
- def initialize(doc)
+ def initialize(doc, file=nil)
@doc = doc
+ if not file.nil?
+ Rocco::Layout.template_file = file
+ end
end
def title

0 comments on commit bb8fcb9

Please sign in to comment.
Something went wrong with that request. Please try again.