hylite 1.0.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: '029f1390d68bcdad670b11ba3c3bd1c7688745dd'
4
- data.tar.gz: 5e1a2079b48cc1fbe2b501c36f155611647402a1
3
+ metadata.gz: d62665fa2a24a184b51d5ab4bf55882c323885f9
4
+ data.tar.gz: 3dcd0bdeb8cbc8a5cd1fb0f947e8fb4104e5e96e
5
5
  SHA512:
6
- metadata.gz: 525bf92d906fc94f8eb4891162c1cf7d21aaea4d75b9ec8b04e73309674131d43d98c1f1382c505579e7fd8aa42acdb4f1b4d99d18b48955311e96172a6159c0
7
- data.tar.gz: 21175e7b41dff749412da917726f9045a3651a308188b2f3cfe44a82e4197bd4811ad8d439f21a5bf689d406a407f5f0e2fb8cf6b62bf7c1861f4d9f524b38a6
6
+ metadata.gz: cfe3816c2a24afc19906855b85cc10b91cfea1340e45ad6555c6c3ecf673d72d28fb330bda9f0633eaac1635cb88a0b135cea25eb78f450bb728b8f9b3c7cdcb
7
+ data.tar.gz: 63d935be6b66b5c4a142756a9ea23db326229df3b69602db1b0b2661307e02bda17e64407ce3973391d7ab893dedb53fb943b5bc3913e30cb731b74d029aa18b
@@ -4,33 +4,10 @@ require 'hylite/hyliters'
4
4
  class Hylite
5
5
  module ChooseHyliter
6
6
  extend self
7
-
8
7
  def call(code, lang)
9
- case
10
- when rouge_available? then Rouge.new(code, lang)
11
- when pygments_available? then Pygments.new(code, lang)
12
- when coderay_available? then CodeRay.new(code, lang)
13
- end
14
- end
15
-
16
- def rouge_available?
17
- require 'rouge'
18
- true
19
- rescue LoadError
20
- false
21
- end
22
-
23
- def pygments_available?
24
- ENV['PATH'].split(File::PATH_SEPARATOR).any? do |dir|
25
- File.exist? File.join(dir, 'pygmentize')
26
- end
27
- end
28
-
29
- def coderay_available?
30
- require 'rouge'
31
- true
32
- rescue LoadError
33
- false
8
+ Rouge.new?( code, lang) ||
9
+ Pygments.new?(code, lang) ||
10
+ CodeRay.new?( code, lang)
34
11
  end
35
12
  end
36
13
  end
data/lib/hylite/cli.rb CHANGED
@@ -7,10 +7,6 @@ class Hylite
7
7
  self.argv = argv
8
8
  end
9
9
 
10
- def errors
11
- config.errors
12
- end
13
-
14
10
  def result
15
11
  ensure_evaluated
16
12
  @result
@@ -2,19 +2,38 @@ require 'open3'
2
2
 
3
3
  class Hylite
4
4
  class Hyliter
5
+ def self.new?(code, lang)
6
+ return nil unless available?
7
+ new code, lang
8
+ end
9
+
10
+ def self.available?
11
+ raise NotImplementedError, 'Subclass should define'
12
+ end
13
+
5
14
  attr_reader :code, :lang
15
+
6
16
  def initialize(code, lang)
7
17
  @code, @lang = code, lang
8
18
  end
19
+
9
20
  def type
10
21
  raise NotImplementedError, 'Subclass should define'
11
22
  end
12
23
  end
13
24
 
14
25
  class Rouge < Hyliter
26
+ def self.available?
27
+ require 'rouge'
28
+ true
29
+ rescue LoadError
30
+ false
31
+ end
32
+
15
33
  def type
16
34
  :rouge
17
35
  end
36
+
18
37
  def call
19
38
  # From Fish, you can see all styles with:
20
39
  # for style in (rougify help style | tail -1 | tr -d ' ' | tr , \n); echo \n===== $style =====; rougify highlight -t $style -l ruby bin/hylite ; end
@@ -27,9 +46,16 @@ class Hylite
27
46
  end
28
47
 
29
48
  class Pygments < Hyliter
49
+ def self.available?
50
+ ENV['PATH'].split(File::PATH_SEPARATOR).any? do |dir|
51
+ File.exist? File.join(dir, 'pygmentize')
52
+ end
53
+ end
54
+
30
55
  def type
31
56
  :pygments
32
57
  end
58
+
33
59
  def call
34
60
  # From Fish, you can see all styles with:
35
61
  # for style in (pygmentize -L styles | sed -n '/\*/s/[*: ]//gp'); echo \n===== $style =====; pygmentize -f terminal256 -O style=$style -l ruby < lib/hylite.rb ; end
@@ -46,9 +72,17 @@ class Hylite
46
72
  end
47
73
 
48
74
  class CodeRay < Hyliter
75
+ def self.available?
76
+ require 'coderay'
77
+ true
78
+ rescue LoadError
79
+ false
80
+ end
81
+
49
82
  def type
50
83
  :coderay
51
84
  end
85
+
52
86
  def call
53
87
  ::CodeRay.encode(code, lang, :terminal)
54
88
  end
@@ -1,3 +1,3 @@
1
1
  class Hylite
2
- VERSION = '1.0.0'
2
+ VERSION = '1.1.0'
3
3
  end
data/spec/binary_spec.rb CHANGED
@@ -98,8 +98,8 @@ RSpec.describe 'binaries' do
98
98
  expect(stdout).to_not be_empty
99
99
  end
100
100
 
101
- specify 'highlight_syntax: warns you to use hylite, but still works' do
102
- stdout, stderr, status = Open3.capture3 'highlight_syntax', stdin_data: '1+1'
101
+ specify 'hilight_syntax: warns you to use hylite, but still works' do
102
+ stdout, stderr, status = Open3.capture3 'hilight_syntax', stdin_data: '1+1'
103
103
  expect(stderr).to match /hylite/
104
104
  expect(status).to be_success
105
105
  expect(stdout).to_not be_empty
@@ -2,47 +2,32 @@ require 'hylite/choose_hyliter'
2
2
  require 'rouge'
3
3
 
4
4
  RSpec.describe 'ChooseHyliter' do
5
- # ugh, might be better to inject require than this nonsense >.<
5
+ def assert_hilights!(name, unavailable:[])
6
+ Array(unavailable).each do |klass|
7
+ allow(klass).to receive(:new?).and_return(nil)
8
+ end
6
9
 
7
- it 'uses rouge if available' do
8
10
  hyliter = Hylite::ChooseHyliter.call("#a { color: #FFF; }" , "css")
9
- expect(hyliter.type).to eq :rouge
11
+ expect(hyliter.type).to eq name
10
12
 
11
13
  hylited = hyliter.call
12
14
  expect(hyliter.call).to include 'FFF'
13
15
  expect(hyliter.call).to include "\e[" # an escape sequence in there somewhere
14
16
  end
15
17
 
18
+ it 'uses rouge if available' do
19
+ assert_hilights! :rouge
20
+ end
16
21
 
17
22
  it 'does not use rouge if it does not support the requested language'
18
23
 
19
-
20
24
  it 'uses pygments if rouge, isn\'t available' do
21
- allow(Hylite::ChooseHyliter).to receive(:require).with('rouge').and_raise(LoadError)
22
-
23
- hyliter = Hylite::ChooseHyliter.call("#a { color: #FFF; }" , "css")
24
- expect(hyliter.type).to eq :pygments
25
-
26
- hylited = hyliter.call
27
- expect(hyliter.call).to include 'FFF'
28
- expect(hyliter.call).to include "\e[" # an escape sequence in there somewhere
25
+ assert_hilights! :pygments, unavailable: [Hylite::Rouge]
29
26
  end
30
27
 
31
-
32
28
  it 'uses coderay if rouge and pygmentize aren\'t available' do
33
- require 'coderay'
34
- allow(File).to receive(:exist?).and_return(false)
35
- allow(Hylite::ChooseHyliter).to receive(:require).with('rouge').and_raise(LoadError)
36
- allow(Hylite::ChooseHyliter).to receive(:require).with('coderay').and_return(true)
37
-
38
- hyliter = Hylite::ChooseHyliter.call("#a { color: #FFF; }" , "css")
39
- expect(hyliter.type).to eq :coderay
40
-
41
- hylited = hyliter.call
42
- expect(hyliter.call).to include 'FFF'
43
- expect(hyliter.call).to include "\e[" # an escape sequence in there somewhere
29
+ assert_hilights! :coderay, unavailable: [Hylite::Rouge, Hylite::Pygments]
44
30
  end
45
31
 
46
-
47
32
  it 'tells you how to install these other libs if none of them are available'
48
33
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hylite
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Josh Cheek
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-12-23 00:00:00.000000000 Z
11
+ date: 2016-12-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec