Skip to content

Commit

Permalink
Add a stylesheet option to build docs using an alternative css styles…
Browse files Browse the repository at this point in the history
…heet.

Use `rocco -s "http://example.com/style.css"` to use a different stylesheet to the default docco one.
  • Loading branch information
tomafro committed Aug 27, 2011
1 parent b31be06 commit 6bc7152
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 4 deletions.
1 change: 1 addition & 0 deletions bin/rocco
Expand Up @@ -41,6 +41,7 @@ ARGV.options { |o|
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("-d", "--docblocks") { options[:docblocks] = true }
o.on("-s", "--stylesheet=STYLESHEET") { |stylesheet| options[:stylesheet] = stylesheet }
o.on_tail("-h", "--help") { usage($stdout, 0) }
o.parse!
} or abort_with_note
Expand Down
8 changes: 6 additions & 2 deletions lib/rocco.rb
Expand Up @@ -71,6 +71,9 @@
# when rendering the final, highlighted file via Mustache. _Defaults
# to `nil` (that is, Mustache will use `./lib/rocco/layout.mustache`)_.
#
# * `:stylesheet`, which specifies the css stylesheet to use for each
# rendered template. _Defaults to `http://jashkenas.github.com/docco/resources/docco.css`
# (the original docco stylesheet)
class Rocco
VERSION = '0.8.1'

Expand All @@ -91,7 +94,8 @@ def initialize(filename, sources=[], options={}, &block)
defaults = {
:language => 'ruby',
:comment_chars => '#',
:template_file => nil
:template_file => nil,
:stylesheet => 'http://jashkenas.github.com/docco/resources/docco.css'
}
@options = defaults.merge(options)

Expand Down Expand Up @@ -148,7 +152,7 @@ def initialize(filename, sources=[], options={}, &block)
# Generate HTML output for the entire document.
require 'rocco/layout'
def to_html
Rocco::Layout.new(self, @options[:template_file]).render
Rocco::Layout.new(self, @options[:stylesheet], @options[:template_file]).render
end

# Helper Functions
Expand Down
2 changes: 1 addition & 1 deletion lib/rocco/layout.mustache
Expand Up @@ -3,7 +3,7 @@
<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8">
<title>{{ title }}</title>
<link rel="stylesheet" href="http://jashkenas.github.com/docco/resources/docco.css">
<link rel="stylesheet" href="{{ stylesheet }}">
</head>
<body>
<div id='container'>
Expand Down
7 changes: 6 additions & 1 deletion lib/rocco/layout.rb
Expand Up @@ -4,8 +4,9 @@
class Rocco::Layout < Mustache
self.template_path = "#{File.dirname(__FILE__)}/.."

def initialize(doc, file=nil)
def initialize(doc, stylesheet, file=nil)
@doc = doc
@stylesheet = stylesheet
if not file.nil?
Rocco::Layout.template_file = file
end
Expand All @@ -15,6 +16,10 @@ def title
File.basename(@doc.file)
end

def stylesheet
@stylesheet
end

def file
@doc.file
end
Expand Down
23 changes: 23 additions & 0 deletions test/test_stylesheet.rb
@@ -0,0 +1,23 @@
require File.expand_path('../helper', __FILE__)

class RoccoStylesheetTests < Test::Unit::TestCase
def test_default_stylesheet
r = Rocco.new( 'file.rb', [ 'file.rb'] ) {
"# Content"
}
html = r.to_html
assert(
html.include?('<link rel="stylesheet" href="http://jashkenas.github.com/docco/resources/docco.css">')
)
end

def test_custom_stylesheet
r = Rocco.new( 'file.rb', [ 'file.rb'], :stylesheet => 'http://example.com/custom.css' ) {
"# Content"
}
html = r.to_html
assert(
html.include?('<link rel="stylesheet" href="http://example.com/custom.css">')
)
end
end

0 comments on commit 6bc7152

Please sign in to comment.