act 0.0.4 → 0.0.5

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 626ce8cd7e573620e8fe2b43549afb1cc4f65b58
4
- data.tar.gz: 78164113d48edf33d4437457e78c3bcb76ebe577
3
+ metadata.gz: b08ce5a70e4451a521ed09fb58f04628cdb0422b
4
+ data.tar.gz: 84a6c6195590c0bde72933cbba111fce91644822
5
5
  SHA512:
6
- metadata.gz: 767f83cbaab9409a310b798ba02eb8c3b0d11ca9bea3edcf702a4a9d75486b7c5def2f37a22358304d8efd9880c2e442c6f33b58380376ec92d520cc9eddee7d
7
- data.tar.gz: 72c0c6840315a642727fd6b220a15c575b7bed615bc336158a81bc59df5a9c9daa3bc377516a1cbe3395fbe50ead9aec6675e26f24826bcd45a5b2ea792054cc
6
+ metadata.gz: 47c0d81edde860d3fc822d1218210a412c6af8ae786beaa197891e6ff6721b584e08e68a904d11e99b15ad6d3034d193080baa10ed182810dea12a22c9fcbcc0
7
+ data.tar.gz: 8f43c7b2ac9fd87964b36f6862ef1d68bda02380193802837be39084b505db37c3c2332c94de42ec5a664ea315fe31c10347b38a15bf82a882fcaba5988473c4
@@ -8,7 +8,7 @@ Gem::Specification.new do |spec|
8
8
  spec.version = Act::VERSION
9
9
  spec.authors = ["Fabio Pelosin"]
10
10
  spec.email = ["fabiopelosin@gmail.com"]
11
- spec.summary = %q{Act the command line tool to act on files.}
11
+ spec.summary = %q{Act, the command line tool to act on files.}
12
12
  spec.homepage = "https://github.com/irrationalfab/act"
13
13
  spec.license = "MIT"
14
14
 
@@ -19,6 +19,7 @@ Gem::Specification.new do |spec|
19
19
 
20
20
  spec.add_runtime_dependency "claide", "~> 0.5"
21
21
  spec.add_runtime_dependency "colored", "~> 1.2"
22
+ spec.add_runtime_dependency "rouge", '~> 1.7'
22
23
  spec.add_runtime_dependency "activesupport"
23
24
 
24
25
  spec.add_development_dependency "bundler", "~> 1.5"
@@ -15,7 +15,7 @@ module Act
15
15
 
16
16
  def self.arguments
17
17
  [
18
- ['PATH', :optional],
18
+ CLAide::Argument.new('PATH', false),
19
19
  ]
20
20
  end
21
21
 
@@ -23,7 +23,8 @@ module Act
23
23
  [
24
24
  ['--open', 'Open the file in $EDITOR instead of printing it'],
25
25
  ['--prettify', 'Prettify output'],
26
- ['--line-numbers', 'Show output without line numbers'],
26
+ ['--always-color', 'Always color the output'],
27
+ ['--line-numbers', 'Show output with line numbers'],
27
28
  ['--lexer=NAME', 'Use the given lexer'],
28
29
  ].concat(super)
29
30
  end
@@ -41,6 +42,7 @@ module Act
41
42
  @prettify = argv.flag?('prettify', false)
42
43
  @number_lines = argv.flag?('line-numbers', false)
43
44
  @lexer = argv.option('lexer', false)
45
+ @always_color = argv.flag?('always-color')
44
46
  @file_string = argv.shift_argument
45
47
  super
46
48
  end
@@ -130,12 +132,12 @@ module Act
130
132
  def cat_string(string, file = nil)
131
133
  if string
132
134
  path = file.path if file
133
- @lexer ||= Helper.lexer(path)
135
+ @lexer ||= Helper.lexer(path, string)
134
136
  string = Helper.strip_indentation(string)
135
137
  string = Helper.prettify(string, @lexer) if @prettify
136
- string = Helper.syntax_highlith(string, @lexer) if self.ansi_output?
138
+ string = Helper.syntax_highlight(string, @lexer) if ansi_output? || @always_color
137
139
  string = Helper.add_line_numbers(string, file.from_line, file.highlight_line) if @number_lines && file
138
- UI.puts "\n#{string}"
140
+ UI.puts UI.tty? ? "\n#{string}" : string
139
141
  else
140
142
  UI.warn '[!] Nothing to show'
141
143
  end
@@ -1,6 +1,7 @@
1
1
  require 'colored'
2
2
  require 'active_support/core_ext/string/strip'
3
3
  require 'open3'
4
+ require 'rouge'
4
5
 
5
6
  module Act
6
7
  module Helper
@@ -63,18 +64,11 @@ module Act
63
64
  numbered_lines.join
64
65
  end
65
66
 
66
- def self.lexer(file_name)
67
- case file_name
68
- when 'Gemfile', 'Rakefile', 'Podfile'
69
- 'rb'
70
- when 'Podfile.lock', 'Gemfile.lock'
71
- 'yaml'
67
+ def self.lexer(file_name, string = nil)
68
+ if string
69
+ Rouge::Lexer.guess(:filename => file_name, :source => string).tag
72
70
  else
73
- if file_name
74
- `pygmentize -N #{file_name}`.chomp
75
- else
76
- 'text'
77
- end
71
+ Rouge::Lexer.guess_by_filename(file_name).tag
78
72
  end
79
73
  end
80
74
 
@@ -92,21 +86,9 @@ module Act
92
86
 
93
87
  # @return [String]
94
88
  #
95
- def self.syntax_highlith(string, lexer)
96
- raise ArgumentError unless string
97
- raise ArgumentError unless lexer
98
- return string if `which pygmentize`.strip.empty?
99
- result = nil
100
- Open3.popen3("pygmentize -l #{lexer} -O encoding=utf8") do |stdin, stdout, stderr, wait_thr|
101
- stdin.write(string)
102
- stdin.close_write
103
- result = stdout.read
104
- unless wait_thr.value.success?
105
- warn '[!] Syntax highlighting via the pygmentize tool failed'
106
- result = string
107
- end
108
- end
109
- result
89
+ def self.syntax_highlight(string, lexer)
90
+ formatter = Rouge::Formatters::Terminal256.new(:theme => 'monokai')
91
+ Rouge.highlight(string, lexer, formatter)
110
92
  end
111
93
 
112
94
  end
@@ -9,6 +9,10 @@ module Act
9
9
  def self.warn(message)
10
10
  STDERR.puts message
11
11
  end
12
+
13
+ def self.tty?
14
+ STDOUT.tty?
15
+ end
12
16
  end
13
17
 
14
18
  UI = UserInterface
@@ -1,3 +1,3 @@
1
1
  module Act
2
- VERSION = '0.0.4'
2
+ VERSION = '0.0.5'
3
3
  end
@@ -52,16 +52,23 @@ module Act
52
52
  #-------------------------------------------------------------------------#
53
53
 
54
54
  describe 'lexer' do
55
- it 'infers the lexer according to the extension using pygmentize' do
55
+ it 'infers the lexer according to the extension' do
56
56
  file_name = 'test.rb'
57
57
  result = @subject.lexer(file_name)
58
- result.should == 'rb'
58
+ result.should == 'ruby'
59
+ end
60
+
61
+ it 'infers the lexer according to the text' do
62
+ file_name = 'rm'
63
+ text = "#!/usr/bin/ruby\n\nrequire 'set'\nputs 'hello'\n3.tap { p 3 }"
64
+ result = @subject.lexer(file_name, text)
65
+ result.should == 'ruby'
59
66
  end
60
67
 
61
68
  it 'infers the lexer according to the file name' do
62
69
  file_name = 'Gemfile'
63
70
  result = @subject.lexer(file_name)
64
- result.should == 'rb'
71
+ result.should == 'ruby'
65
72
  end
66
73
  end
67
74
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: act
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Fabio Pelosin
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-07-26 00:00:00.000000000 Z
11
+ date: 2014-12-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: claide
@@ -38,6 +38,20 @@ dependencies:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '1.2'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rouge
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.7'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.7'
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: activesupport
43
57
  requirement: !ruby/object:Gem::Requirement
@@ -127,10 +141,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
127
141
  version: '0'
128
142
  requirements: []
129
143
  rubyforge_project:
130
- rubygems_version: 2.2.2
144
+ rubygems_version: 2.4.1
131
145
  signing_key:
132
146
  specification_version: 4
133
- summary: Act the command line tool to act on files.
147
+ summary: Act, the command line tool to act on files.
134
148
  test_files:
135
149
  - spec/argument_parser_spec.rb
136
150
  - spec/command_spec.rb