Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add a stylesheet option to build docs using an alternative css styles…

…heet.

Use `rocco -s "http://example.com/style.css"` to use a different stylesheet to the default docco one.
  • Loading branch information...
commit 6bc71526baa9f7fd982ba5412096af9e380003a7 1 parent b31be06
@tomafro tomafro authored
View
1  bin/rocco
@@ -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
View
8 lib/rocco.rb
@@ -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'
@@ -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)
@@ -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
View
2  lib/rocco/layout.mustache
@@ -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'>
View
7 lib/rocco/layout.rb
@@ -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
@@ -15,6 +16,10 @@ def title
File.basename(@doc.file)
end
+ def stylesheet
+ @stylesheet
+ end
+
def file
@doc.file
end
View
23 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
Please sign in to comment.
Something went wrong with that request. Please try again.