rembrandt 0.0.2 → 0.0.3
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.
- checksums.yaml +4 -4
- data/lib/rembrandt/engines/pygmentize.rb +10 -1
- data/lib/rembrandt/engines/web_service.rb +5 -0
- data/lib/rembrandt/highlighter.rb +3 -3
- data/lib/rembrandt/version.rb +1 -1
- data/rembrandt.gemspec +1 -0
- data/test/rembrandt/engines/pygmentize_test.rb +5 -0
- data/test/rembrandt/engines/web_service_test.rb +6 -0
- data/test/rembrandt/highlighter_test.rb +16 -1
- data/test/support/vcr_cassettes/web_engine_is_accessible.yml +34 -0
- data/test/test_helper.rb +1 -0
- metadata +18 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a112457eb1b4df68b42a90a4776fc11c5eee535a
|
4
|
+
data.tar.gz: 106843ea850f71e800213a19cc52158df22b483b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1ef0e17c8794f1d61522813f4e838ad9d1c43fe4a6eb43e8b04cbd647e423d4ffd904c350f334ca066333655b9ba240392f7287ccd4c66b673f632a5e95a4b85
|
7
|
+
data.tar.gz: d90d7325af4d8a74478f69fba12e6c73c2c513a7cac4889fbdcd1cf973c8093e9dcbb8f555d074c1a0561576fd34c6174979f5e85298d03817fcde693437d599
|
@@ -5,10 +5,19 @@ module Rembrandt
|
|
5
5
|
tmp_file = File.open(".colorize_temp", "w")
|
6
6
|
tmp_file.write(input)
|
7
7
|
tmp_file.close
|
8
|
-
output = `pygmentize -f html -l #{language} .colorize_temp`
|
8
|
+
output = `pygmentize -f html -l #{language} -O encoding=utf8 .colorize_temp`
|
9
9
|
`rm .colorize_temp`
|
10
10
|
output
|
11
11
|
end
|
12
|
+
|
13
|
+
def self.available?
|
14
|
+
present_on_system?
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.present_on_system?
|
18
|
+
!`which pygmentize`.empty?
|
19
|
+
end
|
20
|
+
|
12
21
|
end
|
13
22
|
end
|
14
23
|
end
|
@@ -5,15 +5,15 @@ module Rembrandt
|
|
5
5
|
attr_reader :engine
|
6
6
|
|
7
7
|
def initialize(input_engine = nil)
|
8
|
-
@engine = (input_engine ||
|
8
|
+
@engine = (input_engine || autoselect_engine).new
|
9
9
|
end
|
10
10
|
|
11
11
|
def default_language
|
12
12
|
"ruby"
|
13
13
|
end
|
14
14
|
|
15
|
-
def
|
16
|
-
Engines::Pygmentize
|
15
|
+
def autoselect_engine
|
16
|
+
[Engines::Pygmentize, Engines::WebService].detect(&:available?)
|
17
17
|
end
|
18
18
|
|
19
19
|
def highlight(input, language = default_language)
|
data/lib/rembrandt/version.rb
CHANGED
data/rembrandt.gemspec
CHANGED
@@ -15,4 +15,9 @@ class EnginesPygmentizeTest < CodeHighlightTest
|
|
15
15
|
def test_it_highlights
|
16
16
|
assert_highlight 'ruby_sample_1.rb', 'ruby'
|
17
17
|
end
|
18
|
+
|
19
|
+
def test_it_is_available_when_present_on_the_local_system
|
20
|
+
Rembrandt::Engines::Pygmentize.stubs(:present_on_system?).returns(true)
|
21
|
+
assert Rembrandt::Engines::Pygmentize.available?
|
22
|
+
end
|
18
23
|
end
|
@@ -17,4 +17,10 @@ class EnginesPygmentizeTest < CodeHighlightTest
|
|
17
17
|
assert_highlight 'ruby_sample_1.rb', 'ruby'
|
18
18
|
end
|
19
19
|
end
|
20
|
+
|
21
|
+
def test_it_is_available_when_the_website_responds
|
22
|
+
VCR.use_cassette('web_engine_is_accessible') do
|
23
|
+
assert Rembrandt::Engines::WebService.available?
|
24
|
+
end
|
25
|
+
end
|
20
26
|
end
|
@@ -1,5 +1,5 @@
|
|
1
1
|
require './test/test_helper'
|
2
|
-
require './lib/rembrandt
|
2
|
+
require './lib/rembrandt'
|
3
3
|
|
4
4
|
class HighlighterTest < CodeHighlightTest
|
5
5
|
def test_it_exists
|
@@ -38,4 +38,19 @@ class HighlighterTest < CodeHighlightTest
|
|
38
38
|
stubbed_highlighter = Rembrandt::Highlighter.new(StubEngine)
|
39
39
|
assert_equal "stub highlight", stubbed_highlighter.highlight("hello", "ruby")
|
40
40
|
end
|
41
|
+
|
42
|
+
def test_it_defaults_to_pygmentize_if_available
|
43
|
+
expected_engine = Rembrandt::Engines::Pygmentize
|
44
|
+
expected_engine.stubs(:available?).returns(true)
|
45
|
+
lighter = Rembrandt::Highlighter.new
|
46
|
+
assert_equal expected_engine, lighter.engine.class
|
47
|
+
end
|
48
|
+
|
49
|
+
def test_it_uses_the_web_engine_if_pygmentize_is_not_available
|
50
|
+
Rembrandt::Engines::Pygmentize.stubs(:available?).returns(false)
|
51
|
+
Rembrandt::Engines::WebService.stubs(:available?).returns(true)
|
52
|
+
expected_engine = Rembrandt::Engines::WebService
|
53
|
+
lighter = Rembrandt::Highlighter.new
|
54
|
+
assert_equal expected_engine, lighter.engine.class
|
55
|
+
end
|
41
56
|
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: head
|
5
|
+
uri: http://pygmentize.herokuapp.com/
|
6
|
+
body:
|
7
|
+
encoding: US-ASCII
|
8
|
+
string: ''
|
9
|
+
headers:
|
10
|
+
Accept:
|
11
|
+
- '*/*'
|
12
|
+
User-Agent:
|
13
|
+
- Ruby
|
14
|
+
response:
|
15
|
+
status:
|
16
|
+
code: 200
|
17
|
+
message: OK
|
18
|
+
headers:
|
19
|
+
Content-Length:
|
20
|
+
- '1885'
|
21
|
+
Content-Type:
|
22
|
+
- text/html; charset=utf-8
|
23
|
+
Date:
|
24
|
+
- Mon, 23 Dec 2013 01:24:09 GMT
|
25
|
+
Server:
|
26
|
+
- Werkzeug/0.8.1 Python/2.7.1
|
27
|
+
Connection:
|
28
|
+
- keep-alive
|
29
|
+
body:
|
30
|
+
encoding: UTF-8
|
31
|
+
string: ''
|
32
|
+
http_version:
|
33
|
+
recorded_at: Mon, 23 Dec 2013 01:24:09 GMT
|
34
|
+
recorded_with: VCR 2.8.0
|
data/test/test_helper.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rembrandt
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jeff Casimir
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-12-
|
11
|
+
date: 2013-12-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -94,6 +94,20 @@ dependencies:
|
|
94
94
|
- - '>='
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: mocha
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - '>='
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - '>='
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
97
111
|
description: A library for generating and storing syntax-highlighted code
|
98
112
|
email:
|
99
113
|
- jeff@casimircreative.com
|
@@ -123,6 +137,7 @@ files:
|
|
123
137
|
- test/support/ruby_sample_1.rb
|
124
138
|
- test/support/ruby_sample_1.rb.html
|
125
139
|
- test/support/vcr_cassettes/web_engine_highlights_ruby_sample_1.yml
|
140
|
+
- test/support/vcr_cassettes/web_engine_is_accessible.yml
|
126
141
|
- test/test_helper.rb
|
127
142
|
homepage: http://github.com/jcasimir/rembrandt
|
128
143
|
licenses:
|
@@ -158,4 +173,5 @@ test_files:
|
|
158
173
|
- test/support/ruby_sample_1.rb
|
159
174
|
- test/support/ruby_sample_1.rb.html
|
160
175
|
- test/support/vcr_cassettes/web_engine_highlights_ruby_sample_1.yml
|
176
|
+
- test/support/vcr_cassettes/web_engine_is_accessible.yml
|
161
177
|
- test/test_helper.rb
|