Permalink
Browse files

rocco: link to original source URL (if any)

  • Loading branch information...
1 parent 94eb7ba commit f205833fa23c3fcb0d05880cfc250f9b3c18b5e9 @mislav committed Aug 22, 2010
Showing with 22 additions and 5 deletions.
  1. +8 −4 app.rb
  2. +8 −0 rocco_ext.rb
  3. +6 −1 templates/rocco.mustache
View
@@ -20,6 +20,10 @@ def email_link(email)
"<a href='mailto:#{email}'>#{email}</a>"
end
+ def link_to(text, path)
+ "<a href='#{path}'>#{text}</a>"
+ end
+
def redirect_to(code)
redirect "/#{code.slug}"
end
@@ -43,9 +47,9 @@ def html_attributes(hash)
}.join('')
end
- def rocco(filename = default_title, options = {}, &block)
+ def rocco(options = {}, &block)
options = settings.rocco.merge(options)
- Rocco.new(filename, [], options, &block).to_html
+ Rocco.new(default_title, [], options, &block).to_html
rescue Racc::ParseError
status 500
@message = "There was a parse error when trying to process Ruby code"
@@ -90,7 +94,7 @@ def sass_with_caching(name)
get '/f/:name' do
code = ExplainRuby::Code.from_test_fixture(params[:name])
- rocco(code.url) { code.to_s }
+ rocco(:url => code.url) { code.to_s }
end
get '/f/:name/sexp' do
@@ -111,5 +115,5 @@ def sass_with_caching(name)
code = ExplainRuby::Code.find params[:captures][0]
halt 404 unless code
etag code.md5
- rocco { code.to_s }
+ rocco(:url => code.url) { code.to_s }
end
View
@@ -10,6 +10,14 @@
def highlight_style
@doc.options[:uv_style]
end
+
+ def url
+ @doc.options[:url]
+ end
+
+ def url?
+ !!url
+ end
end
Rocco.class_eval do
@@ -23,7 +23,12 @@
<table cellspacing=0 cellpadding=0>
<thead>
<tr>
- <th class=docs><h1>{{ title }}</h1></th>
+ <th class=docs>
+ <h1>{{ title }}</h1>
+ {{#url?}}
+ <p>Code from: <a href="{{ url }}">{{ url }}</a></p>
+ {{/url?}}
+ </th>
<th class=code></th>
</tr>
</thead>

0 comments on commit f205833

Please sign in to comment.