haml-coderay 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +13 -0
- data/README.md +28 -0
- data/lib/haml-coderay.rb +54 -0
- metadata +123 -0
data/LICENSE
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
Copyright (c) 2010 Ørjan Blom <blom@blom.tv>
|
2
|
+
|
3
|
+
Permission to use, copy, modify, and distribute this software for any
|
4
|
+
purpose with or without fee is hereby granted, provided that the above
|
5
|
+
copyright notice and this permission notice appear in all copies.
|
6
|
+
|
7
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
8
|
+
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
9
|
+
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
10
|
+
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
11
|
+
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
12
|
+
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
13
|
+
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
haml-coderay
|
2
|
+
============
|
3
|
+
|
4
|
+
[CodeRay][1] filter for [Haml][2]. Specify which [language][3] to
|
5
|
+
highlight with a shebang followed by the language name:
|
6
|
+
|
7
|
+
:coderay
|
8
|
+
#!ruby
|
9
|
+
|
10
|
+
if true
|
11
|
+
puts "hello"
|
12
|
+
end
|
13
|
+
|
14
|
+
The default [encoder][4] and encoder options are `:div` and `{}`,
|
15
|
+
respectively, and they are accessible as:
|
16
|
+
|
17
|
+
Haml::Filters::CodeRay.encoder
|
18
|
+
Haml::Filters::CodeRay.encoder_options
|
19
|
+
|
20
|
+
Installation
|
21
|
+
------------
|
22
|
+
|
23
|
+
gem install haml-coderay
|
24
|
+
|
25
|
+
[1]: http://coderay.rubychan.de/
|
26
|
+
[2]: http://haml-lang.com/
|
27
|
+
[3]: http://coderay.rubychan.de/doc/classes/CodeRay/Scanners.html
|
28
|
+
[4]: http://coderay.rubychan.de/doc/classes/CodeRay/Encoders.html
|
data/lib/haml-coderay.rb
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
require "haml"
|
2
|
+
|
3
|
+
# CodeRay filter for Haml. Specify which language to highlight with a shebang
|
4
|
+
# followed by the language name.
|
5
|
+
#
|
6
|
+
# @example Ruby
|
7
|
+
#
|
8
|
+
# :coderay
|
9
|
+
# #!ruby
|
10
|
+
#
|
11
|
+
# if true
|
12
|
+
# puts "hello"
|
13
|
+
# end
|
14
|
+
#
|
15
|
+
# @see http://haml-lang.com/docs/yardoc/Haml/Filters.html
|
16
|
+
# @see http://coderay.rubychan.de/doc/classes/CodeRay/Scanners.html
|
17
|
+
module Haml::Filters::CodeRay
|
18
|
+
include Haml::Filters::Base
|
19
|
+
lazy_require "coderay"
|
20
|
+
|
21
|
+
defined?(self::VERSION) ||
|
22
|
+
VERSION = "0.0.1".freeze
|
23
|
+
|
24
|
+
@encoder = :div
|
25
|
+
@encoder_options = {}
|
26
|
+
|
27
|
+
class << self
|
28
|
+
# Encoder (_default_: `:div`).
|
29
|
+
#
|
30
|
+
# @see http://coderay.rubychan.de/doc/classes/CodeRay/Encoders.html
|
31
|
+
attr_accessor :encoder
|
32
|
+
|
33
|
+
# Encoder options (_default_: `{}`).
|
34
|
+
#
|
35
|
+
# @see http://coderay.rubychan.de/doc/classes/CodeRay/Encoders.html
|
36
|
+
attr_accessor :encoder_options
|
37
|
+
end
|
38
|
+
|
39
|
+
# Prepares the text for passing to `::CodeRay.scan`.
|
40
|
+
#
|
41
|
+
# @param [String] text
|
42
|
+
# @return [Array<String, Symbol>] code and language
|
43
|
+
def prepare(text)
|
44
|
+
[ text.sub(/\A\s*#!(\S+)\s*\n+/, ""), $1.downcase.to_sym ]
|
45
|
+
end
|
46
|
+
|
47
|
+
# @param [String] text text to render
|
48
|
+
# @return [String] rendered text
|
49
|
+
#
|
50
|
+
# @see http://coderay.rubychan.de/doc/classes/CodeRay.html#M000008
|
51
|
+
def render(text)
|
52
|
+
::CodeRay.scan(*prepare(text)).send(encoder, encoder_options)
|
53
|
+
end
|
54
|
+
end
|
metadata
ADDED
@@ -0,0 +1,123 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: haml-coderay
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
version: 0.0.1
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- "\xC3\x98rjan Blom"
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2010-04-03 00:00:00 +02:00
|
18
|
+
default_executable:
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: coderay
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - ">="
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
segments:
|
28
|
+
- 0
|
29
|
+
version: "0"
|
30
|
+
type: :runtime
|
31
|
+
version_requirements: *id001
|
32
|
+
- !ruby/object:Gem::Dependency
|
33
|
+
name: haml
|
34
|
+
prerelease: false
|
35
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - ">="
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
segments:
|
40
|
+
- 0
|
41
|
+
version: "0"
|
42
|
+
type: :runtime
|
43
|
+
version_requirements: *id002
|
44
|
+
- !ruby/object:Gem::Dependency
|
45
|
+
name: mg
|
46
|
+
prerelease: false
|
47
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
48
|
+
requirements:
|
49
|
+
- - ">="
|
50
|
+
- !ruby/object:Gem::Version
|
51
|
+
segments:
|
52
|
+
- 0
|
53
|
+
version: "0"
|
54
|
+
type: :development
|
55
|
+
version_requirements: *id003
|
56
|
+
- !ruby/object:Gem::Dependency
|
57
|
+
name: rspec
|
58
|
+
prerelease: false
|
59
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
60
|
+
requirements:
|
61
|
+
- - ">="
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
segments:
|
64
|
+
- 0
|
65
|
+
version: "0"
|
66
|
+
type: :development
|
67
|
+
version_requirements: *id004
|
68
|
+
- !ruby/object:Gem::Dependency
|
69
|
+
name: yard
|
70
|
+
prerelease: false
|
71
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
segments:
|
76
|
+
- 0
|
77
|
+
version: "0"
|
78
|
+
type: :development
|
79
|
+
version_requirements: *id005
|
80
|
+
description: Adds a CodeRay syntax highlighting filter to Haml
|
81
|
+
email: blom@blom.tv
|
82
|
+
executables: []
|
83
|
+
|
84
|
+
extensions: []
|
85
|
+
|
86
|
+
extra_rdoc_files: []
|
87
|
+
|
88
|
+
files:
|
89
|
+
- lib/haml-coderay.rb
|
90
|
+
- LICENSE
|
91
|
+
- README.md
|
92
|
+
has_rdoc: true
|
93
|
+
homepage: http://github.com/blom/haml-coderay
|
94
|
+
licenses: []
|
95
|
+
|
96
|
+
post_install_message:
|
97
|
+
rdoc_options: []
|
98
|
+
|
99
|
+
require_paths:
|
100
|
+
- lib
|
101
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
102
|
+
requirements:
|
103
|
+
- - ">="
|
104
|
+
- !ruby/object:Gem::Version
|
105
|
+
segments:
|
106
|
+
- 0
|
107
|
+
version: "0"
|
108
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
109
|
+
requirements:
|
110
|
+
- - ">="
|
111
|
+
- !ruby/object:Gem::Version
|
112
|
+
segments:
|
113
|
+
- 0
|
114
|
+
version: "0"
|
115
|
+
requirements: []
|
116
|
+
|
117
|
+
rubyforge_project:
|
118
|
+
rubygems_version: 1.3.6
|
119
|
+
signing_key:
|
120
|
+
specification_version: 3
|
121
|
+
summary: CodeRay filter for Haml
|
122
|
+
test_files: []
|
123
|
+
|