Permalink
Browse files

switch rocco from pygments to ultraviolet

  • Loading branch information...
1 parent e0974a0 commit 133deb6cdf2f365dab2b92553aeb0107e4c77b23 @mislav committed Aug 21, 2010
Showing with 455 additions and 207 deletions.
  1. +1 −0 Gemfile
  2. +8 −0 Gemfile.lock
  3. +13 −10 app.rb
  4. +37 −0 rocco_ext.rb
  5. +1 −1 templates/layout.mustache
  6. +3 −3 templates/rocco.mustache
  7. +96 −0 views/_dawn.sass
  8. +45 −0 views/_idle.sass
  9. +57 −0 views/_lazy.sass
  10. +184 −0 views/_pygments.sass
  11. +6 −193 views/docco.sass
  12. +4 −0 views/layout.rb
View
@@ -7,6 +7,7 @@ gem 'mustache'
gem 'ruby2ruby'
gem 'rocco'
gem 'nokogiri'
+gem 'ultraviolet'
group :development do
gem 'mongrel'
View
@@ -13,6 +13,8 @@ GEM
gem_plugin (>= 0.2.3)
mustache (0.11.2)
nokogiri (1.4.3.1)
+ oniguruma (1.1.0)
+ plist (3.1.0)
rack (1.2.1)
rake (0.8.7)
rdiscount (1.6.5)
@@ -30,6 +32,11 @@ GEM
rack (>= 1.0)
sinatra (1.0)
rack (>= 1.0)
+ textpow (0.10.1)
+ oniguruma (>= 1.1.0)
+ plist (>= 3.0.0)
+ ultraviolet (0.10.2)
+ textpow (>= 0.10.0)
PLATFORMS
ruby
@@ -45,3 +52,4 @@ DEPENDENCIES
ruby2ruby
shotgun
sinatra
+ ultraviolet
View
@@ -6,9 +6,7 @@
require 'mustache/sinatra'
set :mustache, { :templates => './templates', :views => './views' }
-require 'rocco'
-Rocco::Layout.template_path = Sinatra::Application.mustache[:templates]
-Rocco::Layout.template_name = 'rocco'
+require 'rocco_ext'
helpers do
def email_link(email)
@@ -46,7 +44,7 @@ def html_attributes(hash)
end
def rocco(filename = default_title, options = {}, &block)
- options = {:comment_chars => '>'}.update(options)
+ options = settings.rocco.merge(options)
Rocco.new(filename, [], options, &block).to_html
rescue Racc::ParseError
status 500
@@ -57,6 +55,14 @@ def rocco(filename = default_title, options = {}, &block)
def default_title
"Explain Ruby"
end
+
+ def sass_with_caching(name)
+ time = ::File.mtime ::File.join(settings.views, "#{name}.sass")
+ expires 500, :public, :must_revalidate if settings.environment == :production
+ last_modified time
+ content_type 'text/css'
+ sass name
+ end
end
get '/' do
@@ -78,9 +84,8 @@ def default_title
end
get '/f/:name' do
- # content_type 'text/plain'
file = File.open("./fixtures/#{params[:name]}.rb")
- rocco(file.path) { insert_explanations ruby2ruby(file) }
+ rocco(file.path) { ExplainRuby::Code.new(file.read, file.path).to_s }
end
get '/f/:name/sexp' do
@@ -90,11 +95,9 @@ def default_title
end
get '/chunky.css' do
- content_type 'text/css'
- sass :style
+ sass_with_caching :style
end
get '/docco.css' do
- content_type 'text/css'
- sass :docco
+ sass_with_caching :docco
end
View
@@ -0,0 +1,37 @@
+require 'uv'
+require 'rocco'
+
+set :rocco, { :comment_chars => '>', :uv_style => 'dawn' }
+
+Rocco::Layout.template_path = Sinatra::Application.mustache[:templates]
+Rocco::Layout.template_name = 'rocco'
+
+Rocco::Layout.class_eval do
+ def highlight_style
+ @doc.options[:uv_style]
+ end
+end
+
+Rocco.class_eval do
+ attr_reader :options
+
+ alias pygments_highlight highlight
+
+ def highlight(blocks)
+ docs_blocks, code_blocks = blocks
+
+ markdown = docs_blocks.join("\n\n##### DIVIDER\n\n")
+ docs_html = Markdown.new(markdown, :smart).
+ to_html.
+ split(/\n*<h5>DIVIDER<\/h5>\n*/m)
+
+ all_code = code_blocks.join("\n\n# DIVIDER\n\n")
+ code_html = Uv.parse(all_code, 'xhtml', 'ruby', false, options[:uv_style])
+
+ code_html = code_html.
+ split(%r{\n*<span class="Comment"><span class="Comment">#</span> DIVIDER</span>\n*}).
+ each { |code| code.gsub!(%r{\s*<pre class="\w+">|</pre>}, '') }
+
+ docs_html.zip(code_html)
+ end
+end
@@ -5,7 +5,7 @@
<link rel="stylesheet" href="/chunky.css" type="text/css">
</head>
-<body>
+<body class="{{ highlight_style }}">
<div id='container'>
<div id="background"></div>
{{{ yield }}}
@@ -5,8 +5,8 @@
<title>{{ title }}</title>
<link rel="stylesheet" href="/docco.css">
</head>
-<body>
-<div id='container'>
+<body class="{{ highlight_style }}">
+<div id="container">
<div id="background"></div>
{{#sources?}}
<div id="jump_to">
@@ -37,7 +37,7 @@
{{{ docs }}}
</td>
<td class=code>
- <div class='highlight'><pre>{{{ code }}}</pre></div>
+ <pre>{{{ code }}}</pre>
</td>
</tr>
{{/sections}}
View
@@ -0,0 +1,96 @@
+// $dawn_background: #F5F5F5
+$dawn_background: desaturate(#f5f5ff, 30%)
+
+.dawn
+ #background, td.code, th.code
+ background-color: $dawn_background
+ border-left: 1px solid darken($dawn_background, 10%)
+
+ pre
+ color: #080808
+
+ .MetaSeparator
+ font-weight: bold
+ background-color: #DCDCDC
+ color: #19356D
+ .SupportVariable
+ color: #234A97
+ .Constant
+ font-weight: bold
+ color: #811F24
+ .EmbeddedSource
+ background-color: #829AC2
+ .StringRegexpConstantCharacterEscape
+ font-weight: bold
+ color: #811F24
+ .Support
+ color: #691C97
+ .MarkupList
+ color: #693A17
+ .Storage
+ color: #A71D5D
+ font-style: italic
+ .line-numbers
+ background-color: #7496CF
+ color: #000000
+ .StringConstant
+ font-weight: bold
+ color: #696969
+ .MarkupUnderline
+ text-decoration: underline
+ color: #080808
+ .MarkupHeading
+ font-weight: bold
+ color: #19356D
+ .SupportConstant
+ color: #B4371F
+ .MarkupQuote
+ background-color: #C5C5C5
+ color: #0B6125
+ font-style: italic
+ .StringRegexpSpecial
+ font-weight: bold
+ color: #CF5628
+ .InvalidIllegal
+ background-color: #B52A1D
+ color: #F8F8F8
+ font-style: italic
+ .MarkupDeleted
+ color: #B52A1D
+ .MarkupRaw
+ background-color: #C5C5C5
+ color: #234A97
+ .SupportFunction
+ color: #693A17
+ .PunctuationSeparator
+ color: #794938
+ .StringRegexp
+ color: #CF5628
+ .StringEmbeddedSource
+ background-color: #829AC2
+ color: #080808
+ .MarkupLink
+ color: #234A97
+ font-style: italic
+ .MarkupBold
+ font-weight: bold
+ color: #080808
+ .StringVariable
+ color: #234A97
+ .String
+ color: #0B6125
+ .Keyword
+ color: #794938
+ .MarkupItalic
+ color: #080808
+ font-style: italic
+ .InvalidDeprecated
+ font-weight: bold
+ color: #B52A1D
+ .Variable
+ color: #234A97
+ .Entity
+ color: #BF4F24
+ .Comment
+ color: #5A525F
+ font-style: italic
View
@@ -0,0 +1,45 @@
+$idle_background: white
+
+.idle
+ #background, td.code, th.code
+ background-color: $idle_background
+ border-left: 1px solid darken($idle_background, 10%)
+
+ pre
+ color: black
+
+ .InheritedClass
+ .TypeName
+ color: #21439C
+ .Number
+ .LibraryVariable
+ color: #A535AE
+ .Storage
+ color: #FF5600
+ .line-numbers
+ background-color: #BAD6FD
+ color: #000000
+ .StringInterpolation
+ color: #990000
+ .TagName
+ .LibraryConstant
+ color: #A535AE
+ .FunctionArgument
+ .BuiltInConstant
+ color: #A535AE
+ .Invalid
+ background-color: #990000
+ color: #FFFFFF
+ .LibraryClassType, .LibraryFunction
+ color: #A535AE
+ .TagAttribute
+ .Keyword
+ color: #FF5600
+ .UserDefinedConstant
+ .String
+ color: #00A33F
+ .FunctionName
+ color: #21439C
+ .Variable
+ .Comment
+ color: #919191
View
@@ -0,0 +1,57 @@
+$lazy_background: white
+
+.lazy
+ #background, td.code, th.code
+ background-color: $lazy_background
+ border-left: 1px solid darken($lazy_background, 10%)
+
+ pre
+ color: black
+
+ .OcamlInfixFPOperator
+ text-decoration: underline
+ .OcamlInfixOperator
+ color: #3B5BB5
+ .MetaFunctionCallPy
+ color: #3E4558
+ .Superclass
+ color: #3B5BB5
+ font-style: italic
+ .LatexEntity
+ color: #D62A28
+ .Constant
+ color: #3B5BB5
+ .OcamlFPConstant
+ text-decoration: underline
+ .Support
+ color: #3B5BB5
+ .OcamlOperator
+ color: #000000
+ .line-numbers
+ background-color: #E3FC8D
+ color: #000000
+ .StringInterpolation
+ color: #671EBB
+ .InvalidIllegal
+ background-color: #9D1E15
+ color: #F8F8F8
+ .OcamlVariant
+ color: #7F90AA
+ .MetaTag
+ color: #3A4A64
+ .OcamlPrefixFPOperator
+ text-decoration: underline
+ .OcamlPrefixOperator
+ color: #3B5BB5
+ .String
+ color: #409B1C
+ .Keyword
+ color: #FF7800
+ .InvalidDeprecated
+ color: #990000
+ font-style: italic
+ .Variable
+ .Entity
+ color: #3B5BB5
+ .Comment
+ color: #8C868F
Oops, something went wrong.

0 comments on commit 133deb6

Please sign in to comment.