-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 5125857
Showing
7 changed files
with
148 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
.yardoc | ||
doc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
Copyright (c) 2010 Ørjan Blom <blom@blom.tv> | ||
|
||
Permission to use, copy, modify, and distribute this software for any | ||
purpose with or without fee is hereby granted, provided that the above | ||
copyright notice and this permission notice appear in all copies. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
haml-coderay | ||
============ | ||
|
||
[CodeRay][1] filter for [Haml][2]. Specify [language][3] to highlight | ||
with an exclamation point followed by the language name: | ||
|
||
:coderay | ||
!ruby | ||
|
||
if true | ||
puts "hello" | ||
end | ||
|
||
:coderay | ||
!xml | ||
|
||
<foo> | ||
<bar>...</bar> | ||
</foo> | ||
|
||
The default encoder and encoder options are `:div` and `{}`, | ||
repectively, and are accessible through the following variables: | ||
|
||
Haml::Filters::CodeRay.encoder | ||
Haml::Filters::CodeRay.encoder_options | ||
|
||
[1]: http://coderay.rubychan.de/ | ||
[2]: http://haml-lang.com/ | ||
[3]: http://coderay.rubychan.de/doc/classes/CodeRay/Scanners.html |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
require "rubygems" | ||
require "rake" | ||
require "yard" | ||
require "spec/rake/spectask" | ||
require "lib/haml-coderay" | ||
|
||
task :default => :spec | ||
|
||
Spec::Rake::SpecTask.new "spec" do |t| | ||
t.spec_opts << "--color --format nested" | ||
t.spec_files = FileList["spec/*_spec.rb"] | ||
end | ||
|
||
YARD::Rake::YardocTask.new do |t| | ||
t.files = %w(lib/**/*.rb) | ||
t.options = %w(-mmarkdown -rREADME.md -odoc) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
Gem::Specification.new do |spec| | ||
spec.name = "haml-coderay" | ||
spec.version = "0.0.0" | ||
spec.summary = "CodeRay filter for Haml" | ||
spec.description = "Adds a CodeRay syntax highlighting filter to Haml" | ||
spec.author = "Ørjan Blom" | ||
spec.email = "blom@blom.tv" | ||
spec.homepage = "http://github.com/blom/haml-coderay" | ||
spec.files = %w(LICENSE README.md lib/haml-coderay.rb) | ||
|
||
spec.add_dependency "haml" | ||
spec.add_dependency "coderay" | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
require "haml" | ||
|
||
# CodeRay filter for Haml. Specify language to highlight with an exclamation | ||
# point followed by the language name. | ||
# | ||
# @example Ruby | ||
# | ||
# :coderay | ||
# !ruby | ||
# | ||
# if true | ||
# puts "hello" | ||
# end | ||
# | ||
# @example XML | ||
# | ||
# :coderay | ||
# !xml | ||
# | ||
# <foo> | ||
# <bar>...</bar> | ||
# </foo> | ||
module Haml::Filters::CodeRay | ||
include Haml::Filters::Base | ||
lazy_require "coderay" | ||
|
||
class << self | ||
# CodeRay encoder (_default_: `:div`). | ||
attr_accessor :encoder | ||
|
||
# Coderay encoder options (_default_: `{}`). | ||
attr_accessor :encoder_options | ||
end | ||
self.encoder = :div | ||
self.encoder_options = {} | ||
|
||
# @param [String] text text to render | ||
def render(text) | ||
text.sub!(/\A\S*!(\S+)\s+/, '') | ||
::CodeRay.scan(text, $1.downcase.to_sym). | ||
send(encoder, encoder_options) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
require "rubygems" | ||
require "lib/haml-coderay" | ||
|
||
describe Haml::Filters::CodeRay do | ||
describe :encoder do | ||
subject { Haml::Filters::CodeRay.encoder } | ||
specify { should == :div } | ||
end | ||
|
||
describe :encoder_options do | ||
subject { Haml::Filters::CodeRay.encoder_options } | ||
specify { should == {} } | ||
end | ||
end | ||
|
||
describe Haml::Filters.defined["coderay"], %<["coderay"]> do | ||
it { should == Haml::Filters::CodeRay } | ||
end | ||
|
||
describe Haml::Engine do | ||
it "should accept :coderay" do | ||
Haml::Engine.new(":coderay\n !xml\n ."). | ||
render.should be_a String | ||
end | ||
|
||
it "should not accept :coderay without language specifier" do | ||
lambda { | ||
Haml::Engine.new(":coderay\n xml\n .").render | ||
}.should raise_exception(NoMethodError, /downcase.*nil/) | ||
end | ||
end |