Screencast: Syntax Highlighting
Syntax Highlighting wird die visuelle Aufbereitung von Source-Code genant. Die meisten Texteditoren unterstützen Syntax Highlighting, aber auch Web wird gerne darauf zurückgegriffen um Quellcode lesbarer zu machen. Ryan zeigt diese Woche wie man in Ruby/Rails-Applikationen um Syntax Highlighting bereichern kann.
Download:
Download (30.9 MB, 9:09)
Alternativer Download für iPod & Apple TV (24.4 MB, 9:09)
Resourcen:
Quellcode:
<%= textilize(coderay(@article.content)) %>
# config/environment.rb
config.gem "coderay"
config.gem "RedCloth"
# application_helper.rb
def coderay(text)
text.gsub(/\<code( lang="(.+?)")?\>(.+?)\<\/code\>/m) do
content_tag("notextile", CodeRay.scan($3, $2).div(:css => :class))
end
end
# syntax_benchmark.rb
require "rubygems"
require "benchmark"
require "coderay"
require "uv"
path = __FILE__
content = File.read(__FILE__)
# run it once to initialize
CodeRay.scan("print 'hello'", "ruby").div(:css => :class)
Uv.parse("print 'test'", "xhtml", "ruby", true, "amy")
Benchmark.bm(11) do |b|
b.report("coderay") do
50.times { CodeRay.scan(content, "ruby").div(:css => :class) }
end
b.report("ultraviolet") do
50.times { Uv.parse(content, "xhtml", "ruby", true, "amy") }
end
b.report("pygments") do
50.times { `pygmentize -f html "#{path}"` }
end
end
.CodeRay {
background-color: #232323;
border: 1px solid black;
font-family: 'Courier New', 'Terminal', monospace;
color: #E6E0DB;
padding: 3px 5px;
overflow: auto;
font-size: 12px;
margin: 12px 0;
}
.CodeRay pre {
margin: 0px;
padding: 0px;
}
.CodeRay .an { color:#E7BE69 } /* html attribute */
.CodeRay .c { color:#BC9358; font-style: italic; } /* comment */
.CodeRay .ch { color:#509E4F } /* escaped character */
.CodeRay .cl { color:#FFF } /* class */
.CodeRay .co { color:#FFF } /* constant */
.CodeRay .fl { color:#A4C260 } /* float */
.CodeRay .fu { color:#FFC56D } /* function */
.CodeRay .gv { color:#D0CFFE } /* global variable */
.CodeRay .i { color:#A4C260 } /* integer */
.CodeRay .il { background:#151515 } /* inline code */
.CodeRay .iv { color:#D0CFFE } /* instance variable */
.CodeRay .pp { color:#E7BE69 } /* doctype */
.CodeRay .r { color:#CB7832 } /* keyword */
.CodeRay .rx { color:#A4C260 } /* regex */
.CodeRay .s { color:#A4C260 } /* string */
.CodeRay .sy { color:#6C9CBD } /* symbol */
.CodeRay .ta { color:#E7BE69 } /* html tag */
.CodeRay .pc { color:#6C9CBD } /* boolean */
Eingestellt am 29.03.2010 um 12:48
Kategorie: Tutorials
Suchen auf rubyonrails.de
Tags
2.0 ActiveRecord Ajax Authentication Buch Capistrano Controller Enterprise Event Formulare Gewinnspiel Grundlagen IDE irb jQuery Kochbuch Konferenz MySQL OReilly Passenger Phusion Plugin PragProgs Rails Rails 3 Rails 3.1 RailsWayCon Release Release Candidate Routing Ruby RubyGems rubyonrails.de Ryan Bates Scaffolding Screencast Script-Tip Security Test Tools Tutorial Upgrade Video Views WindowsAktuelle Artikel
- Screencast: JSON Dokumente mit Jbuilder erstellen
- Rails 3.2.1 veröffentlicht
- Screencast: Upgrade auf Rails 3.2
- Ruby on Rails 3.2
- Screencast: Private Pub für Realtime-Events
- Screencast: Pretty URLs mit FriendlyId
- Screencast: HTML Emails mit Rails verschicken
- Screencast: Einstieg in die Rails-Entwicklung
- Frohe Weihnachten!
- Screencast: Arbeit an der Konsole mit ZSH
Artikel Archiv
- January 2012
- December 2011
- November 2011
- October 2011
- September 2011
- August 2011
- July 2011
- June 2011
- May 2011
- April 2011
- March 2011
- February 2011
- January 2011
- December 2010
- November 2010
- October 2010
- September 2010
- August 2010
- July 2010
- June 2010
- May 2010
- April 2010
- March 2010
- February 2010
- January 2010
- December 2009
- November 2009
- October 2009
- September 2009
- August 2009
- July 2009
- May 2009
- April 2009
- March 2009
- February 2009
- December 2008
- November 2008
- August 2008
- July 2008
- June 2008
- May 2008
- March 2008
- February 2008
- January 2008
- December 2007
- November 2007
- October 2007
- September 2007
Aktuelle Rails Version + Abhängigkeiten:
Gem rails-3.0.0actionmailer (= 3.0.0, runtime)
actionpack (= 3.0.0, runtime)
activerecord (= 3.0.0, runtime)
activeresource (= 3.0.0, runtime)
activesupport (= 3.0.0, runtime)
bundler (~> 1.0.0, runtime)
railties (= 3.0.0, runtime)
Rails auf Rubyforge
Rails auf Github
