smartgen_syntaxhighlighter 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +4 -0
- data/.rspec +3 -0
- data/Gemfile +11 -0
- data/Gemfile.lock +59 -0
- data/LICENSE +20 -0
- data/README.md +48 -0
- data/Rakefile +7 -0
- data/lib/smartgen_syntaxhighlighter.rb +1 -0
- data/lib/smartgen_syntaxhighlighter/all.rb +2 -0
- data/lib/smartgen_syntaxhighlighter/markdown.rb +3 -0
- data/lib/smartgen_syntaxhighlighter/pre_processor.rb +48 -0
- data/lib/smartgen_syntaxhighlighter/textile.rb +3 -0
- data/lib/smartgen_syntaxhighlighter/version.rb +5 -0
- data/smartgen_syntaxhighlighter.gemspec +24 -0
- data/spec/lib/pre_processor_spec.rb +46 -0
- metadata +106 -0
data/.gitignore
ADDED
data/.rspec
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
smartgen_syntaxhighlighter (0.1.0)
|
5
|
+
smartgen
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: http://rubygems.org/
|
9
|
+
specs:
|
10
|
+
RedCloth (4.2.3)
|
11
|
+
activesupport (3.0.3)
|
12
|
+
archive-tar-minitar (0.5.2)
|
13
|
+
bluecloth (2.0.10)
|
14
|
+
columnize (0.3.2)
|
15
|
+
diff-lcs (1.1.2)
|
16
|
+
i18n (0.5.0)
|
17
|
+
linecache (0.43)
|
18
|
+
linecache19 (0.5.11)
|
19
|
+
ruby_core_source (>= 0.1.4)
|
20
|
+
rspec (2.4.0)
|
21
|
+
rspec-core (~> 2.4.0)
|
22
|
+
rspec-expectations (~> 2.4.0)
|
23
|
+
rspec-mocks (~> 2.4.0)
|
24
|
+
rspec-core (2.4.0)
|
25
|
+
rspec-expectations (2.4.0)
|
26
|
+
diff-lcs (~> 1.1.2)
|
27
|
+
rspec-mocks (2.4.0)
|
28
|
+
ruby-debug (0.10.4)
|
29
|
+
columnize (>= 0.1)
|
30
|
+
ruby-debug-base (~> 0.10.4.0)
|
31
|
+
ruby-debug-base (0.10.4)
|
32
|
+
linecache (>= 0.3)
|
33
|
+
ruby-debug-base19 (0.11.24)
|
34
|
+
columnize (>= 0.3.1)
|
35
|
+
linecache19 (>= 0.5.11)
|
36
|
+
ruby_core_source (>= 0.1.4)
|
37
|
+
ruby-debug19 (0.11.6)
|
38
|
+
columnize (>= 0.3.1)
|
39
|
+
linecache19 (>= 0.5.11)
|
40
|
+
ruby-debug-base19 (>= 0.11.19)
|
41
|
+
ruby_core_source (0.1.4)
|
42
|
+
archive-tar-minitar (>= 0.5.2)
|
43
|
+
smartgen (0.0.1)
|
44
|
+
RedCloth (>= 4.2.3)
|
45
|
+
activesupport (>= 2.3.5)
|
46
|
+
bluecloth (>= 2.0.9)
|
47
|
+
i18n (>= 0.5.0)
|
48
|
+
thor (>= 0.14.6)
|
49
|
+
thor (0.14.6)
|
50
|
+
|
51
|
+
PLATFORMS
|
52
|
+
ruby
|
53
|
+
|
54
|
+
DEPENDENCIES
|
55
|
+
rspec (>= 2.3.0)
|
56
|
+
ruby-debug
|
57
|
+
ruby-debug19
|
58
|
+
smartgen
|
59
|
+
smartgen_syntaxhighlighter!
|
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2010 Vicente Mundim
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
Smartgen Syntaxhighlighter
|
2
|
+
==========================
|
3
|
+
|
4
|
+
Adds support to use Alex Gorbatchev's Syntax Highlighter [plugin](http://alexgorbatchev.com/SyntaxHighlighter/) with smartgen.
|
5
|
+
|
6
|
+
## How it works?
|
7
|
+
|
8
|
+
Basically it creates a pre processor that substitute any of the following tags with proper _pre_ tags:
|
9
|
+
|
10
|
+
- ruby
|
11
|
+
- js
|
12
|
+
- javascript
|
13
|
+
- shell
|
14
|
+
- bash
|
15
|
+
- html
|
16
|
+
- xml
|
17
|
+
- as3
|
18
|
+
- plain
|
19
|
+
|
20
|
+
## Using
|
21
|
+
|
22
|
+
To use it with default settings, add gem to your gemspec:
|
23
|
+
|
24
|
+
gem 'smartgen_syntaxhighlighter'
|
25
|
+
|
26
|
+
And then require all engines pre processors after smartgen:
|
27
|
+
|
28
|
+
require 'smartgen'
|
29
|
+
require 'smartgen_syntaxhighlighter/all'
|
30
|
+
|
31
|
+
If you want to use it just for textile files:
|
32
|
+
|
33
|
+
require 'smartgen'
|
34
|
+
require 'smartgen_syntaxhighlighter/textile'
|
35
|
+
|
36
|
+
or for markdown files:
|
37
|
+
|
38
|
+
require 'smartgen'
|
39
|
+
require 'smartgen_syntaxhighlighter/markdown'
|
40
|
+
|
41
|
+
## Customizing
|
42
|
+
|
43
|
+
If you need to customize options, the you'll need to register the pre processor yourself:
|
44
|
+
|
45
|
+
require 'smartgen'
|
46
|
+
require 'smartgen_syntaxhighlighter/pre_processor'
|
47
|
+
|
48
|
+
Smartgen::Engine::Textile.register(SyntaxhighlighterPreProcessor.new(:gutter => true, :toolbar => true))
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
# require 'smartgen_syntaxhighlighter/all' to register pre processor with default options
|
@@ -0,0 +1,48 @@
|
|
1
|
+
class SyntaxhighlighterPreProcessor
|
2
|
+
attr_reader :options
|
3
|
+
|
4
|
+
def initialize(opts={})
|
5
|
+
@enclose_with_tag = opts.delete(:enclose_with_tag)
|
6
|
+
@options = merge_with_defaults(opts)
|
7
|
+
end
|
8
|
+
|
9
|
+
def process(body)
|
10
|
+
body.gsub(%r{<(ruby|js|javascript|shell|bash|html|xml|as3|plain)>(.*?)</\1>}m) do |match|
|
11
|
+
escaped_code = ERB::Util.h($2)
|
12
|
+
|
13
|
+
options[:brush] = case $1
|
14
|
+
when 'ruby', 'plain', 'as3', 'shell', 'bash', 'xml'
|
15
|
+
$1
|
16
|
+
when 'js', 'javascript'
|
17
|
+
'js; html-script: true'
|
18
|
+
when 'html'
|
19
|
+
'xml' # html is understood, but there are .xml rules in the CSS
|
20
|
+
else
|
21
|
+
'plain'
|
22
|
+
end
|
23
|
+
|
24
|
+
%{#{enclose_start_tag}<pre class="#{to_class_attribute}">#{escaped_code}</pre>#{enclose_end_tag}}
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
def enclose_start_tag
|
30
|
+
"<#{@enclose_with_tag}>" if @enclose_with_tag
|
31
|
+
end
|
32
|
+
|
33
|
+
def enclose_end_tag
|
34
|
+
"</#{@enclose_with_tag}>" if @enclose_with_tag
|
35
|
+
end
|
36
|
+
|
37
|
+
def to_class_attribute
|
38
|
+
sorted_options.map { |key, value| "#{key}: #{value}" }.join('; ')
|
39
|
+
end
|
40
|
+
|
41
|
+
def sorted_options
|
42
|
+
options.sort { |first_pair, second_pair| first_pair[0].to_s <=> second_pair[0].to_s }
|
43
|
+
end
|
44
|
+
|
45
|
+
def merge_with_defaults(opts)
|
46
|
+
{ :gutter => false, :toolbar => false }.merge(opts)
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "smartgen_syntaxhighlighter/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "smartgen_syntaxhighlighter"
|
7
|
+
s.version = Smartgen::Syntaxhighlighter::VERSION
|
8
|
+
s.platform = Gem::Platform::RUBY
|
9
|
+
s.authors = ["Vicente Mundim"]
|
10
|
+
s.email = ["vicente.mundim"]
|
11
|
+
s.homepage = ""
|
12
|
+
s.summary = %q{Adds Syntax Highlighter support for smartgen}
|
13
|
+
s.description = %q{Use Syntax Highlighter plugin when generating files with smartgen}
|
14
|
+
|
15
|
+
s.rubyforge_project = "smartgen_syntaxhighlighter"
|
16
|
+
|
17
|
+
s.files = `git ls-files`.split("\n")
|
18
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
19
|
+
s.require_paths = ["lib"]
|
20
|
+
|
21
|
+
s.add_dependency "smartgen"
|
22
|
+
|
23
|
+
s.add_development_dependency "rspec", ">= 2.3.0"
|
24
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.unshift(File.join(File.dirname(__FILE__), "..", "lib"))
|
3
|
+
require 'rspec'
|
4
|
+
require 'smartgen_syntaxhighlighter/pre_processor'
|
5
|
+
|
6
|
+
describe SyntaxhighlighterPreProcessor do
|
7
|
+
['ruby', 'plain', 'as3', 'shell', 'bash', 'xml'].each do |language|
|
8
|
+
def body(language)
|
9
|
+
"<#{language}>some code here</#{language}>"
|
10
|
+
end
|
11
|
+
|
12
|
+
it "should replace '<#{language}>' tags with proper <pre> tags and brush" do
|
13
|
+
subject.process(body(language)).should == "<pre class=\"brush: #{language}; gutter: false; toolbar: false\">some code here</pre>"
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
['js', 'javascript'].each do |language|
|
18
|
+
def body(language)
|
19
|
+
"<#{language}>some code here</#{language}>"
|
20
|
+
end
|
21
|
+
|
22
|
+
it "should replace '<#{language}>' tags with proper <pre> tags and 'js' brush, adding 'html-script: true' option" do
|
23
|
+
subject.process(body(language)).should == "<pre class=\"brush: js; html-script: true; gutter: false; toolbar: false\">some code here</pre>"
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should use 'xml' when rendering 'html' tags" do
|
28
|
+
subject.process("<html>some code here</html>").should == "<pre class=\"brush: xml; gutter: false; toolbar: false\">some code here</pre>"
|
29
|
+
end
|
30
|
+
|
31
|
+
context "with options" do
|
32
|
+
subject { SyntaxhighlighterPreProcessor.new :toolbar => true, :gutter => true }
|
33
|
+
|
34
|
+
it "should use given options" do
|
35
|
+
subject.process("<ruby>some code here</ruby>").should == "<pre class=\"brush: ruby; gutter: true; toolbar: true\">some code here</pre>"
|
36
|
+
end
|
37
|
+
|
38
|
+
context "with enclose_with_tag option" do
|
39
|
+
subject { SyntaxhighlighterPreProcessor.new :enclose_with_tag => 'my_tag' }
|
40
|
+
|
41
|
+
it "should enclose language tag with given tag" do
|
42
|
+
subject.process("<ruby>some code here</ruby>").should == "<my_tag><pre class=\"brush: ruby; gutter: false; toolbar: false\">some code here</pre></my_tag>"
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
metadata
ADDED
@@ -0,0 +1,106 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: smartgen_syntaxhighlighter
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 1
|
8
|
+
- 0
|
9
|
+
version: 0.1.0
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- Vicente Mundim
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2011-01-24 00:00:00 -02:00
|
18
|
+
default_executable:
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: smartgen
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
none: false
|
25
|
+
requirements:
|
26
|
+
- - ">="
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
segments:
|
29
|
+
- 0
|
30
|
+
version: "0"
|
31
|
+
type: :runtime
|
32
|
+
version_requirements: *id001
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: rspec
|
35
|
+
prerelease: false
|
36
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
37
|
+
none: false
|
38
|
+
requirements:
|
39
|
+
- - ">="
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
segments:
|
42
|
+
- 2
|
43
|
+
- 3
|
44
|
+
- 0
|
45
|
+
version: 2.3.0
|
46
|
+
type: :development
|
47
|
+
version_requirements: *id002
|
48
|
+
description: Use Syntax Highlighter plugin when generating files with smartgen
|
49
|
+
email:
|
50
|
+
- vicente.mundim
|
51
|
+
executables: []
|
52
|
+
|
53
|
+
extensions: []
|
54
|
+
|
55
|
+
extra_rdoc_files: []
|
56
|
+
|
57
|
+
files:
|
58
|
+
- .gitignore
|
59
|
+
- .rspec
|
60
|
+
- Gemfile
|
61
|
+
- Gemfile.lock
|
62
|
+
- LICENSE
|
63
|
+
- README.md
|
64
|
+
- Rakefile
|
65
|
+
- lib/smartgen_syntaxhighlighter.rb
|
66
|
+
- lib/smartgen_syntaxhighlighter/all.rb
|
67
|
+
- lib/smartgen_syntaxhighlighter/markdown.rb
|
68
|
+
- lib/smartgen_syntaxhighlighter/pre_processor.rb
|
69
|
+
- lib/smartgen_syntaxhighlighter/textile.rb
|
70
|
+
- lib/smartgen_syntaxhighlighter/version.rb
|
71
|
+
- smartgen_syntaxhighlighter.gemspec
|
72
|
+
- spec/lib/pre_processor_spec.rb
|
73
|
+
has_rdoc: true
|
74
|
+
homepage: ""
|
75
|
+
licenses: []
|
76
|
+
|
77
|
+
post_install_message:
|
78
|
+
rdoc_options: []
|
79
|
+
|
80
|
+
require_paths:
|
81
|
+
- lib
|
82
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
83
|
+
none: false
|
84
|
+
requirements:
|
85
|
+
- - ">="
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
segments:
|
88
|
+
- 0
|
89
|
+
version: "0"
|
90
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
91
|
+
none: false
|
92
|
+
requirements:
|
93
|
+
- - ">="
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
segments:
|
96
|
+
- 0
|
97
|
+
version: "0"
|
98
|
+
requirements: []
|
99
|
+
|
100
|
+
rubyforge_project: smartgen_syntaxhighlighter
|
101
|
+
rubygems_version: 1.3.7
|
102
|
+
signing_key:
|
103
|
+
specification_version: 3
|
104
|
+
summary: Adds Syntax Highlighter support for smartgen
|
105
|
+
test_files:
|
106
|
+
- spec/lib/pre_processor_spec.rb
|