coderay_bash 0.1.3 → 0.2.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/README.md CHANGED
@@ -17,4 +17,9 @@ Bash scanner for highlighting scripts with CodeRay
17
17
 
18
18
  <%= @body %>
19
19
 
20
+ ### Types
21
+
22
+ * `:bash`
23
+ * `:erb_bash` -- erb code in bash strings
24
+
20
25
  For more information see [CodeRay web pages](http://coderay.rubychan.de/)
data/Rakefile CHANGED
@@ -5,10 +5,16 @@
5
5
  $KCODE='UTF8'
6
6
 
7
7
  require 'rake/gempackagetask'
8
+ require 'rake/testtask'
8
9
  require 'rake/clean'
9
10
 
10
11
  CLEAN << "coverage" << "pkg" << "README.html" << "CHANGELOG.html"
11
12
 
12
- task :default => [:gem]
13
+ task :default => [:test, :gem]
13
14
  Rake::GemPackageTask.new(eval(File.read("coderay_bash.gemspec"))) {|pkg|}
14
15
 
16
+ Rake::TestTask.new(:test) do |t|
17
+ t.pattern = File.join(File.dirname(__FILE__), 'test/test.rb')
18
+ t.verbose = true
19
+ end
20
+
data/coderay_bash.gemspec CHANGED
@@ -13,7 +13,7 @@ spec = Gem::Specification.new do |s|
13
13
  s.email = "pejuko@gmail.com"
14
14
  s.authors = ["Petr Kovar"]
15
15
  s.name = 'coderay_bash'
16
- s.version = '0.1.3'
16
+ s.version = '0.2.0'
17
17
  s.date = Time.now.strftime("%Y-%m-%d")
18
18
  s.add_dependency('coderay', '< 1.0')
19
19
  s.require_path = 'lib'
@@ -23,7 +23,7 @@ spec = Gem::Specification.new do |s|
23
23
  This gem was tested with coderay 0.9.3 and won't work with coderay from svn.
24
24
  EOF
25
25
  s.description = <<EOF
26
- This gem was tested with coderay 0.9.3 and won't work with coderay from svn.
26
+ Bash highlighting for coderay. This gem was tested with coderay 0.9.3 and won't work with coderay >= 1.0.
27
27
  EOF
28
28
  end
29
29
 
@@ -49,10 +49,15 @@ module Scanners
49
49
  add(VARIABLES, :pre_type).
50
50
  add(BASH_VARIABLES, :pre_type)
51
51
 
52
- def scan_tokens tokens, options
52
+ attr_reader :state, :quote
53
+
54
+ def initialize(*args)
55
+ super(*args)
56
+ @state = :initial
57
+ @quote = nil
58
+ end
53
59
 
54
- state = :initial
55
- quote = nil
60
+ def scan_tokens tokens, options
56
61
 
57
62
  until eos?
58
63
  kind = match = nil
@@ -62,7 +67,7 @@ module Scanners
62
67
  next
63
68
  end
64
69
 
65
- if state == :initial
70
+ if @state == :initial
66
71
  if match = scan(/\A#!.*/)
67
72
  kind = :directive
68
73
  elsif match = scan(/#.*/)
@@ -74,10 +79,10 @@ module Scanners
74
79
  elsif match = scan(/;/)
75
80
  kind = :delimiter
76
81
  elsif match = scan(/(?:"|`)/)
77
- state = :quote
78
- quote = match
79
- tokens << [:open, :string] if quote == '"'
80
- tokens << [:open, :shell] if quote == '`'
82
+ @state = :quote
83
+ @quote = match
84
+ tokens << [:open, :string] if @quote == '"'
85
+ tokens << [:open, :shell] if @quote == '`'
81
86
  tokens << [match, :delimiter]
82
87
  next
83
88
  elsif match = scan(/'[^']*'/)
@@ -149,15 +154,15 @@ module Scanners
149
154
  kind = :error
150
155
  match = ">>>>>#{match}<<<<<"
151
156
  end
152
- elsif state == :quote
157
+ elsif @state == :quote
153
158
  if (match = scan(/\\.?/))
154
159
  kind = :content
155
- elsif match = scan(/#{quote}/)
160
+ elsif match = scan(/#{@quote}/)
156
161
  tokens << [match, :delimiter]
157
- tokens << [:close, :string] if quote == '"'
158
- tokens << [:close, :shell] if quote == "`"
159
- quote = nil
160
- state = :initial
162
+ tokens << [:close, :string] if @quote == '"'
163
+ tokens << [:close, :shell] if @quote == "`"
164
+ @quote = nil
165
+ @state = :initial
161
166
  next
162
167
  #kind = :symbol
163
168
  elsif match = scan(PRE_CONSTANTS)
@@ -165,11 +170,11 @@ module Scanners
165
170
  elsif match = scan(/ \$\{?[A-Za-z_][A-Za-z_\d]*\}? /x)
166
171
  kind = IDENT_KIND[match]
167
172
  kind = :instance_variable if kind == :ident
168
- elsif (quote == '`') and (match = scan(/\$"/))
173
+ elsif (@quote == '`') and (match = scan(/\$"/))
169
174
  kind = :content
170
- elsif (quote == '"') and (match = scan(/\$`/))
175
+ elsif (@quote == '"') and (match = scan(/\$`/))
171
176
  kind = :content
172
- elsif match = scan(/[^#{quote}\$\\]+/)
177
+ elsif match = scan(/[^#{@quote}\$\\]+/)
173
178
  kind = :content
174
179
  else match = scan(/.+/)
175
180
  # this shouldn't be
@@ -0,0 +1,18 @@
1
+ # Scanner for Bash
2
+ # Author: spam+github@codez.ch
3
+ require 'coderay/scanners/rhtml'
4
+
5
+ module CodeRay
6
+ module Scanners
7
+ class ErbBash < RHTML
8
+ register_for :erb_bash
9
+
10
+ protected
11
+ def setup
12
+ super
13
+ # Scan Bash instead of HTML template
14
+ @html_scanner = CodeRay.scanner :bash, :tokens => @tokens, :keep_tokens => true
15
+ end
16
+ end
17
+ end
18
+ end
data/lib/coderay_bash.rb CHANGED
@@ -1,3 +1,6 @@
1
1
  require 'coderay'
2
- path = File.join File.expand_path(File.dirname(__FILE__)), "coderay/scanners/bash.rb"
3
- require path
2
+
3
+ path = File.join File.expand_path(File.dirname(__FILE__))
4
+
5
+ require File.join(path, "coderay/scanners/bash.rb")
6
+ require File.join(path, "coderay/scanners/erb_bash.rb")
metadata CHANGED
@@ -1,13 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: coderay_bash
3
3
  version: !ruby/object:Gem::Version
4
- hash: 29
5
4
  prerelease: false
6
5
  segments:
7
6
  - 0
8
- - 1
9
- - 3
10
- version: 0.1.3
7
+ - 2
8
+ - 0
9
+ version: 0.2.0
11
10
  platform: ruby
12
11
  authors:
13
12
  - Petr Kovar
@@ -15,7 +14,7 @@ autorequire:
15
14
  bindir: bin
16
15
  cert_chain: []
17
16
 
18
- date: 2010-08-30 00:00:00 +02:00
17
+ date: 2011-03-08 00:00:00 +01:00
19
18
  default_executable:
20
19
  dependencies:
21
20
  - !ruby/object:Gem::Dependency
@@ -26,7 +25,6 @@ dependencies:
26
25
  requirements:
27
26
  - - <
28
27
  - !ruby/object:Gem::Version
29
- hash: 15
30
28
  segments:
31
29
  - 1
32
30
  - 0
@@ -34,7 +32,7 @@ dependencies:
34
32
  type: :runtime
35
33
  version_requirements: *id001
36
34
  description: |
37
- This gem was tested with coderay 0.9.3 and won't work with coderay from svn.
35
+ Bash highlighting for coderay. This gem was tested with coderay 0.9.3 and won't work with coderay >= 1.0.
38
36
 
39
37
  email: pejuko@gmail.com
40
38
  executables: []
@@ -49,6 +47,7 @@ files:
49
47
  - Rakefile
50
48
  - lib/coderay_bash.rb
51
49
  - lib/coderay/scanners/bash.rb
50
+ - lib/coderay/scanners/erb_bash.rb
52
51
  has_rdoc: true
53
52
  homepage: http://github.com/pejuko/coderay_bash
54
53
  licenses: []
@@ -65,7 +64,6 @@ required_ruby_version: !ruby/object:Gem::Requirement
65
64
  requirements:
66
65
  - - ">="
67
66
  - !ruby/object:Gem::Version
68
- hash: 3
69
67
  segments:
70
68
  - 0
71
69
  version: "0"
@@ -74,7 +72,6 @@ required_rubygems_version: !ruby/object:Gem::Requirement
74
72
  requirements:
75
73
  - - ">="
76
74
  - !ruby/object:Gem::Version
77
- hash: 3
78
75
  segments:
79
76
  - 0
80
77
  version: "0"