Skip to content
This repository
Browse code

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
Tom Ward authored August 27, 2011
1  bin/rocco
@@ -41,6 +41,7 @@ ARGV.options { |o|
41 41
   o.on("-c", "--comment-chars=CHARS") { |chars| options[:comment_chars] = Regexp.escape(chars) }
42 42
   o.on("-t", "--template=TEMPLATE") { |template| options[:template_file] = template }
43 43
   o.on("-d", "--docblocks") { options[:docblocks] = true }
  44
+  o.on("-s", "--stylesheet=STYLESHEET") { |stylesheet| options[:stylesheet] = stylesheet }
44 45
   o.on_tail("-h", "--help") { usage($stdout, 0) }
45 46
   o.parse!
46 47
 } or abort_with_note
8  lib/rocco.rb
@@ -71,6 +71,9 @@
71 71
 #   when rendering the final, highlighted file via Mustache.  _Defaults
72 72
 #   to `nil` (that is, Mustache will use `./lib/rocco/layout.mustache`)_.
73 73
 #
  74
+# * `:stylesheet`, which specifies the css stylesheet to use for each
  75
+#   rendered template.  _Defaults to `http://jashkenas.github.com/docco/resources/docco.css`
  76
+#   (the original docco stylesheet)
74 77
 class Rocco
75 78
   VERSION = '0.8.1'
76 79
 
@@ -91,7 +94,8 @@ def initialize(filename, sources=[], options={}, &block)
91 94
     defaults = {
92 95
       :language      => 'ruby',
93 96
       :comment_chars => '#',
94  
-      :template_file => nil
  97
+      :template_file => nil,
  98
+      :stylesheet => 'http://jashkenas.github.com/docco/resources/docco.css'
95 99
     }
96 100
     @options = defaults.merge(options)
97 101
 
@@ -148,7 +152,7 @@ def initialize(filename, sources=[], options={}, &block)
148 152
   # Generate HTML output for the entire document.
149 153
   require 'rocco/layout'
150 154
   def to_html
151  
-    Rocco::Layout.new(self, @options[:template_file]).render
  155
+    Rocco::Layout.new(self, @options[:stylesheet], @options[:template_file]).render
152 156
   end
153 157
 
154 158
   # Helper Functions
2  lib/rocco/layout.mustache
@@ -3,7 +3,7 @@
3 3
 <head>
4 4
   <meta http-equiv="content-type" content="text/html;charset=utf-8">
5 5
   <title>{{ title }}</title>
6  
-  <link rel="stylesheet" href="http://jashkenas.github.com/docco/resources/docco.css">
  6
+  <link rel="stylesheet" href="{{ stylesheet }}">
7 7
 </head>
8 8
 <body>
9 9
 <div id='container'>
7  lib/rocco/layout.rb
@@ -4,8 +4,9 @@
4 4
 class Rocco::Layout < Mustache
5 5
   self.template_path = "#{File.dirname(__FILE__)}/.."
6 6
 
7  
-  def initialize(doc, file=nil)
  7
+  def initialize(doc, stylesheet, file=nil)
8 8
     @doc = doc
  9
+    @stylesheet = stylesheet
9 10
     if not file.nil?
10 11
       Rocco::Layout.template_file = file
11 12
     end
@@ -15,6 +16,10 @@ def title
15 16
     File.basename(@doc.file)
16 17
   end
17 18
 
  19
+  def stylesheet
  20
+    @stylesheet
  21
+  end
  22
+
18 23
   def file
19 24
     @doc.file
20 25
   end
23  test/test_stylesheet.rb
... ...
@@ -0,0 +1,23 @@
  1
+require File.expand_path('../helper', __FILE__)
  2
+
  3
+class RoccoStylesheetTests < Test::Unit::TestCase
  4
+  def test_default_stylesheet
  5
+    r = Rocco.new( 'file.rb', [ 'file.rb'] ) {
  6
+      "# Content"
  7
+    }
  8
+    html = r.to_html
  9
+    assert(
  10
+      html.include?('<link rel="stylesheet" href="http://jashkenas.github.com/docco/resources/docco.css">')
  11
+    )
  12
+  end
  13
+
  14
+  def test_custom_stylesheet
  15
+    r = Rocco.new( 'file.rb', [ 'file.rb'], :stylesheet => 'http://example.com/custom.css' ) {
  16
+      "# Content"
  17
+    }
  18
+    html = r.to_html
  19
+    assert(
  20
+      html.include?('<link rel="stylesheet" href="http://example.com/custom.css">')
  21
+    )
  22
+  end
  23
+end

0 notes on commit 6bc7152

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