Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

add code highlighting

  • Loading branch information...
commit a5f6e3929f2fab7b8325611e39e12feb83fe0315 1 parent ee250fd
@joshbuddy joshbuddy authored
View
6 Gemfile
@@ -5,3 +5,9 @@ source "http://rubygems.org"
gem "rake"
gem "sinatra"
gem "rdiscount"
+gem 'rack-codehighlighter'
+gem 'coderay'
+
+group :development do
+ gem "shotgun"
+end
View
16 Gemfile.lock
@@ -1,21 +1,31 @@
GEM
remote: http://rubygems.org/
specs:
+ coderay (1.0.0)
+ nokogiri (1.5.0)
rack (1.3.4)
+ rack-codehighlighter (0.5.0)
+ nokogiri (>= 1.4.1)
+ rack (>= 1.0.0)
rack-protection (1.1.4)
rack
rake (0.9.2)
rdiscount (1.6.8)
+ shotgun (0.9)
+ rack (>= 1.0)
sinatra (1.3.1)
- rack (>= 1.3.4, ~> 1.3)
- rack-protection (>= 1.1.2, ~> 1.1)
- tilt (>= 1.3.3, ~> 1.3)
+ rack (~> 1.3, >= 1.3.4)
+ rack-protection (~> 1.1, >= 1.1.2)
+ tilt (~> 1.3, >= 1.3.3)
tilt (1.3.3)
PLATFORMS
ruby
DEPENDENCIES
+ coderay
+ rack-codehighlighter
rake
rdiscount
+ shotgun
sinatra
View
7 config.ru
@@ -1,8 +1,13 @@
# -*- ruby -*-
-require './railsbridge'
+require 'rack/codehighlighter'
+require 'coderay'
+
use Rack::ShowExceptions
use Rack::ShowStatus
use Rack::Static, :urls => ["/css", "/img"], :root => "public"
+use Rack::Codehighlighter, :coderay, :element => "pre.code", :pattern => /\A\s*:::(\w+)\s*\n/
+
+require './railsbridge'
run RailsBridge
View
1  lessons/03.yaml
@@ -39,6 +39,7 @@ content: |
Add this to a file called ~/.irbrc:
<pre class="code">
+ :::ruby
class Object
def pim inherited = false
self.class.public_instance_methods(inherited).sort -
View
6 lessons/13.yaml
@@ -13,7 +13,8 @@ steps: |
Edit app/models/topic.rb so that it looks like this:
<pre class="code">
- class Topic < ActiveRecord::Base
+ :::ruby
+ class Topic &lt; ActiveRecord::Base
has_many :votes
end
</pre>
@@ -21,7 +22,8 @@ steps: |
Edit app/models/vote.rb so that it looks like this:
<pre class="code">
- class Vote < ActiveRecord::Base
+ :::ruby
+ class Vote &lt; ActiveRecord::Base
belongs_to :topic
end
</pre>
View
5 lessons/14.yaml
@@ -9,6 +9,7 @@ steps: |
Edit `app/views/topics/index.html.erb` so that the bottom loop looks like this:
<pre class="code">
+ :::erb
&lt;% @topics.each do |topic| %>
&lt;tr>
&lt;td>&lt;%= topic.title %>&lt;/td>
@@ -25,7 +26,8 @@ steps: |
Add the following method to `Vote` in `app/controllers/votes_controller.rb`:
<pre class="code">
- class VotesControllerTest < ActionController::TestCase
+ :::ruby
+ class VotesControllerTest &lt; ActionController::TestCase
def create
topic = Topic.find(params[:topic_id])
vote = topic.votes.build
@@ -43,6 +45,7 @@ explanation: |
First we added this line to `app/views/topics/index.html.erb`
<pre class="code">
+ :::erb
&lt;td>&lt;%= link_to '+1', votes_path(:topic_id => topic.id), :method => :post %>&lt;/td>
</pre>
View
1  lessons/16.yaml
@@ -23,6 +23,7 @@ steps: |
done the last few lines should look like this:
<pre class="code">
+ :::ruby
# This is a legacy wild controller route that's not recommended for RESTful applications.
# Note: This route will make all actions in every controller accessible via GET requests.
# match ':controller(/:action(/:id(.:format)))'
View
3  lessons/17.yaml
@@ -15,6 +15,7 @@ steps: |
method (it looks like this):
<pre class="code">
+ :::ruby
def create
@topic = Topic.new(params[:topic])
@@ -33,12 +34,14 @@ steps: |
Change the line:
<pre class="code">
+ :::ruby
format.html { redirect_to @topic, :notice => 'Topic was successfully created.' }
</pre>
so that the file looks like this:
<pre class="code">
+ :::ruby
def create
@topic = Topic.new(params[:topic])
View
7 lessons/18.yaml
@@ -14,12 +14,14 @@ steps: |
like this:
<pre class="code">
+ :::erb
&lt;td>&lt;%= topic.description %>&lt;/td>
</pre>
Also delete the line that looks like this:
<pre class="code">
+ :::erb
&lt;th>Description&lt;/th>
</pre>
@@ -29,24 +31,28 @@ steps: |
line:
<pre class="code">
+ :::erb
&lt;td>&lt;%= topic.title %>&lt;/td>
</pre>
with this:
<pre class="code">
+ :::erb
&lt;td>&lt;%= link_to topic.title, topic %>&lt;/td>
</pre>
explanation: |
<pre class="code">
+ :::erb
&lt;td><%= topic.description %>&lt;/td>
</pre>
This line was getting the description using .description and just printing it out
<pre class="code">
+ :::erb
&lt;th>Description&lt;/th>
</pre>
@@ -57,6 +63,7 @@ explanation: |
<pre class="code">
+ :::erb
&lt;td><%= link_to topic.title, topic %>&lt;/td>
</pre>
View
4 lessons/19.yaml
@@ -16,6 +16,7 @@ steps: |
Open `app/views/topics/index.html.erb` and remove these two lines:
<pre class="code">
+ :::erb
&lt;td>&lt;%= link_to 'Show', topic %>&lt;/td>
&lt;td>&lt;%= link_to 'Edit', edit_topic_path(topic) %>&lt;/td>
</pre>
@@ -23,14 +24,13 @@ steps: |
Change the line with the word 'Destroy' to this:
<pre class="code">
+ :::erb
&lt;td>&lt;%= link_to 'Delete', topic, :confirm => 'Are you sure?', :method => :delete %>&lt;/td>
</pre>
Now save your file and try reloading in your browser to see the changes.
explanation: |
-
* The two links we removed were show and edit. We did this because the title now links to the show page and from the show page you can reach the edit page.
* The second change we made was to make the link text 'Delete' instead of destroy.
-
View
85 public/css/railsbridge.css
@@ -54,3 +54,88 @@ h2 { font-size: 3.0em; padding: 0; margin: 0 }
h3 { font-size: 2.0em; padding: 0; margin: 0 0 0.5em 0 }
h4 { font-size: 1.5em; padding: 0; margin: 0 }
+
+/* Code ray css */
+
+.CodeRay { background: white; padding: 10px }
+
+.CodeRay .line-numbers a:target { color: blue !important; }
+.CodeRay .line-numbers .highlighted { color: red !important; }
+.CodeRay .line-numbers .highlighted a { color: red !important; }
+.CodeRay span.line-numbers { padding: 0px 4px; }
+.CodeRay .line { display: block; float: left; width: 100%; }
+.CodeRay .code { width: 100%; }
+.CodeRay .code pre { overflow: auto; }
+
+.CodeRay .debug { color: white !important; background: blue !important; }
+
+.CodeRay .annotation { color:#007 }
+.CodeRay .attribute-name { color:#b48 }
+.CodeRay .attribute-value { color:#700 }
+.CodeRay .binary { color:#509 }
+.CodeRay .char .content { color:#D20 }
+.CodeRay .char .delimiter { color:#710 }
+.CodeRay .char { color:#D20 }
+.CodeRay .class { color:#B06; font-weight:bold }
+.CodeRay .class-variable { color:#369 }
+.CodeRay .color { color:#0A0 }
+.CodeRay .comment { color:#777 }
+.CodeRay .comment .char { color:#444 }
+.CodeRay .comment .delimiter { color:#444 }
+.CodeRay .complex { color:#A08 }
+.CodeRay .constant { color:#036; font-weight:bold }
+.CodeRay .decorator { color:#B0B }
+.CodeRay .definition { color:#099; font-weight:bold }
+.CodeRay .delimiter { color:black }
+.CodeRay .directive { color:#088; font-weight:bold }
+.CodeRay .doc { color:#970 }
+.CodeRay .doc-string { color:#D42; font-weight:bold }
+.CodeRay .doctype { color:#34b }
+.CodeRay .entity { color:#800; font-weight:bold }
+.CodeRay .error { color:#F00; background-color:#FAA }
+.CodeRay .escape { color:#666 }
+.CodeRay .exception { color:#C00; font-weight:bold }
+.CodeRay .float { color:#60E }
+.CodeRay .function { color:#06B; font-weight:bold }
+.CodeRay .global-variable { color:#d70 }
+.CodeRay .hex { color:#02b }
+.CodeRay .imaginary { color:#f00 }
+.CodeRay .include { color:#B44; font-weight:bold }
+.CodeRay .inline { background-color: hsla(0,0%,0%,0.07); color: black }
+.CodeRay .inline-delimiter { font-weight: bold; color: #666 }
+.CodeRay .instance-variable { color:#33B }
+.CodeRay .integer { color:#00D }
+.CodeRay .key .char { color: #60f }
+.CodeRay .key .delimiter { color: #404 }
+.CodeRay .key { color: #606 }
+.CodeRay .keyword { color:#080; font-weight:bold }
+.CodeRay .label { color:#970; font-weight:bold }
+.CodeRay .local-variable { color:#963 }
+.CodeRay .namespace { color:#707; font-weight:bold }
+.CodeRay .octal { color:#40E }
+.CodeRay .operator { }
+.CodeRay .predefined { color:#369; font-weight:bold }
+.CodeRay .predefined-constant { color:#069 }
+.CodeRay .predefined-type { color:#0a5; font-weight:bold }
+.CodeRay .preprocessor { color:#579 }
+.CodeRay .pseudo-class { color:#00C; font-weight:bold }
+.CodeRay .regexp .content { color:#808 }
+.CodeRay .regexp .delimiter { color:#404 }
+.CodeRay .regexp .modifier { color:#C2C }
+.CodeRay .regexp { background-color:hsla(300,100%,50%,0.06); }
+.CodeRay .reserved { color:#080; font-weight:bold }
+.CodeRay .shell .content { color:#2B2 }
+.CodeRay .shell .delimiter { color:#161 }
+.CodeRay .shell { background-color:hsla(120,100%,50%,0.06); }
+.CodeRay .string .char { color: #b0b }
+.CodeRay .string .content { color: #D20 }
+.CodeRay .string .delimiter { color: #710 }
+.CodeRay .string .modifier { color: #E40 }
+.CodeRay .string { background-color:hsla(0,100%,50%,0.05); }
+.CodeRay .symbol .content { color:#A60 }
+.CodeRay .symbol .delimiter { color:#630 }
+.CodeRay .symbol { color:#A60 }
+.CodeRay .tag { color:#070 }
+.CodeRay .type { color:#339; font-weight:bold }
+.CodeRay .value { color: #088; }
+.CodeRay .variable { color:#037 }
Please sign in to comment.
Something went wrong with that request. Please try again.