iterm2-viewer 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Guardfile +37 -0
- data/bin/iterm2-viewer +18 -134
- data/iterm2-viewer.gemspec +19 -18
- data/lib/iterm2/viewer.rb +3 -2
- data/lib/iterm2/viewer/version.rb +1 -1
- metadata +11 -38
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4c939586a9e3fcfe8bb750d994245c67c77ef1b3
|
4
|
+
data.tar.gz: d3acb5b1f9ae229d1ac4699965a2e204e5c01ad2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0ac2ed4d9b107d109a00c8cad44ed0049ec68074211d69337201532b9a314fc8673105bcfd0287c0b413d0a4242e22b70e8bdfc3386e9cc6371351711d7a928a
|
7
|
+
data.tar.gz: eceed5eab5b7a1c9cb5db0ab26d0fe7c925f89ee5d8771e8b6466b759bc29a6203ef90fa228ff4262b4b2ab9642938f80d18a9b875e3444e3475911e580fc531
|
data/Guardfile
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
# A sample Guardfile
|
2
|
+
# More info at https://github.com/guard/guard#readme
|
3
|
+
|
4
|
+
guard :bundler do
|
5
|
+
watch('Gemfile')
|
6
|
+
watch(/^.+\.gemspec/)
|
7
|
+
end
|
8
|
+
|
9
|
+
guard :inch do
|
10
|
+
watch(/.+\.rb/)
|
11
|
+
end
|
12
|
+
|
13
|
+
guard :reek do
|
14
|
+
watch(%r{.+\.rb$})
|
15
|
+
end
|
16
|
+
|
17
|
+
guard :rubocop, cli: ['--format', 'simple'] do
|
18
|
+
watch(%r{.+\.rb$})
|
19
|
+
watch(%r{(?:.+/)?\.rubocop\.yml$}) { |m| File.dirname(m[0]) }
|
20
|
+
end
|
21
|
+
|
22
|
+
guard :yard do
|
23
|
+
watch(%r{bin/.+\.rb})
|
24
|
+
watch(%r{lib/.+\.rb})
|
25
|
+
end
|
26
|
+
|
27
|
+
guard :minitest do
|
28
|
+
# with Minitest::Unit
|
29
|
+
watch(%r{^test/(.*)\/?test_(.*)\.rb$})
|
30
|
+
watch(%r{^lib/(.*/)?([^/]+)\.rb$}) { |m| "test/#{m[1]}test_#{m[2]}.rb" }
|
31
|
+
watch(%r{^test/test_helper\.rb$}) { 'test' }
|
32
|
+
|
33
|
+
# with Minitest::Spec
|
34
|
+
# watch(%r{^spec/(.*)_spec\.rb$})
|
35
|
+
# watch(%r{^lib/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
|
36
|
+
# watch(%r{^spec/spec_helper\.rb$}) { 'spec' }
|
37
|
+
end
|
data/bin/iterm2-viewer
CHANGED
@@ -1,143 +1,27 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
# encoding: utf-8
|
3
3
|
|
4
|
-
|
5
|
-
lib
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
#
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
end
|
21
|
-
|
22
|
-
# public method for overriding default configuration
|
23
|
-
# @return [Hash] of parameters
|
24
|
-
def self.configure
|
25
|
-
self.configuration ||= Configuration.new
|
26
|
-
yield(configuration)
|
27
|
-
end
|
28
|
-
|
29
|
-
# Configuration class
|
30
|
-
class Configuration
|
31
|
-
attr_accessor :viewport
|
32
|
-
|
33
|
-
# Defaults configuration
|
34
|
-
def initialize
|
35
|
-
@viewport =
|
36
|
-
{
|
37
|
-
width: 'auto',
|
38
|
-
height: 'auto',
|
39
|
-
keep_aspect_ratio: true
|
40
|
-
}
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
# initialization method which pass the arguments from the shell
|
45
|
-
def self.show(arguments)
|
46
|
-
Base.new arguments if arguments.any?
|
47
|
-
end
|
48
|
-
|
49
|
-
# Validate and render objects passed in arguments
|
50
|
-
class Base
|
51
|
-
# Insaniate and render media objects
|
52
|
-
def initialize(routes)
|
53
|
-
routes.each { |object| render Media.new object if exist? object }
|
54
|
-
end
|
55
|
-
|
56
|
-
# Determine is file exist or not
|
57
|
-
# @return [Boolean] availability of object
|
58
|
-
def exist?(object)
|
59
|
-
File.file? object
|
60
|
-
end
|
61
|
-
|
62
|
-
# Create new instance of renderable object
|
63
|
-
class Media < String
|
64
|
-
# @return [Symbol] renderable validator which determine that file is supportable or not
|
65
|
-
# @return [Symbol] data return base64 string of file
|
66
|
-
attr_reader :renderable, :data
|
67
|
-
|
68
|
-
# Create new media object
|
69
|
-
def initialize(data)
|
70
|
-
super(data)
|
71
|
-
@mime ||= MIME::Types.of(self).first
|
72
|
-
@data ||= construct
|
73
|
-
end
|
74
|
-
|
75
|
-
# Construct base64 blob from binary
|
76
|
-
# @return [String] base64 data of binary file
|
77
|
-
# if file is renderable
|
78
|
-
# @return [Boolean] false
|
79
|
-
# if object can not be render
|
80
|
-
def construct
|
81
|
-
if self.renderable?
|
82
|
-
source = open self
|
83
|
-
Base64.encode64(source.read)
|
84
|
-
else
|
85
|
-
nil
|
86
|
-
end
|
87
|
-
end
|
88
|
-
|
89
|
-
# Detect current kind such as (application, image, docuemtn) and so on of selected file
|
90
|
-
# @return [String] current kind of file
|
91
|
-
def kind
|
92
|
-
@mime.media_type
|
93
|
-
end
|
94
|
-
|
95
|
-
# Detect current type such as (.png, .pdf, .txt) and so on of selected file
|
96
|
-
# @return [String] current type of file
|
97
|
-
def type
|
98
|
-
@mime.sub_type
|
99
|
-
end
|
100
|
-
|
101
|
-
# Determine whether that type is renderable
|
102
|
-
# @note Renderable Types and MIME's listed below in Type module
|
103
|
-
# @return [Boolean] current condition
|
104
|
-
def type_renderable?
|
105
|
-
Type.const_get kind.capitalize
|
106
|
-
rescue NameError
|
107
|
-
false
|
108
|
-
end
|
109
|
-
|
110
|
-
# Determine whether that type is renderable
|
111
|
-
# @note Renderable Types and MIME's listed below in Type module
|
112
|
-
# @return [Boolean]
|
113
|
-
def kind_renderable?
|
114
|
-
type_renderable? ? (Type.const_get(kind.capitalize)::MIME.include? type) : false
|
115
|
-
end
|
116
|
-
alias_method :renderable?, :kind_renderable?
|
117
|
-
|
118
|
-
# Store renderable types and kinds
|
119
|
-
module Type
|
120
|
-
module Image
|
121
|
-
MIME = %w(jpeg jpg png tiff gif)
|
4
|
+
lib = File.expand_path(File.dirname(__FILE__) + '/../lib')
|
5
|
+
$LOAD_PATH.unshift(lib) if File.directory?(lib) && !$LOAD_PATH.include?(lib)
|
6
|
+
|
7
|
+
require 'iterm2/viewer'
|
8
|
+
|
9
|
+
module Iterm2
|
10
|
+
module Viewer
|
11
|
+
# Command line interface
|
12
|
+
# @param [String, #arguments] routes to files
|
13
|
+
class << self
|
14
|
+
def show(arguments)
|
15
|
+
# initialize whenever application called from iTerm2
|
16
|
+
if ENV['TERM_PROGRAM'] == 'iTerm.app'
|
17
|
+
arguments.each do |route|
|
18
|
+
Render.new Media.new route if File.file? route
|
19
|
+
end
|
122
20
|
end
|
123
|
-
|
124
|
-
end
|
125
|
-
|
126
|
-
# Render object in command line
|
127
|
-
# @todo add options support
|
128
|
-
# @param object [Viewer::Base::Media]
|
129
|
-
def render(object)
|
130
|
-
# @see http://iterm2.com/images.html
|
131
|
-
# @note based on https://raw.githubusercontent.com/gnachman/iTerm2/master/tests/imgcat
|
132
|
-
puts "\033]1337;File=;inline=1:#{object.data}\a\n" if object.renderable?
|
21
|
+
end
|
133
22
|
end
|
134
23
|
end
|
135
24
|
end
|
136
25
|
|
137
|
-
# Override defaults
|
138
|
-
Viewer.configure do |config|
|
139
|
-
config.viewport[:width] = 10
|
140
|
-
end
|
141
|
-
|
142
26
|
# Run application with shell parameters
|
143
|
-
Viewer.show ARGV
|
27
|
+
Iterm2::Viewer.show ARGV
|
data/iterm2-viewer.gemspec
CHANGED
@@ -1,49 +1,50 @@
|
|
1
|
-
#
|
1
|
+
# encoding: utf-8
|
2
2
|
lib = File.expand_path('../lib', __FILE__)
|
3
3
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
4
|
require 'iterm2/viewer/version'
|
5
5
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
|
-
spec.name =
|
7
|
+
spec.name = 'iterm2-viewer'
|
8
8
|
spec.version = Iterm2::Viewer::VERSION
|
9
|
-
spec.authors = [
|
10
|
-
spec.email = [
|
9
|
+
spec.authors = ['Andrey']
|
10
|
+
spec.email = ['andrey@antipov.me']
|
11
11
|
spec.summary = %q{Display media files in iTerm2.}
|
12
12
|
spec.description = %q{Display media files in terminal. iTerm2 is required}
|
13
|
-
spec.homepage =
|
14
|
-
spec.license =
|
13
|
+
spec.homepage = 'https://github.com/AndreyAntipov/iterm2-viewer'
|
14
|
+
spec.license = 'MIT'
|
15
15
|
|
16
16
|
spec.files = `git ls-files -z`.split("\x0")
|
17
17
|
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
18
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
-
spec.require_paths = [
|
19
|
+
spec.require_paths = ['lib']
|
20
20
|
|
21
|
-
spec.add_development_dependency
|
22
|
-
spec.add_development_dependency
|
21
|
+
spec.add_development_dependency 'bundler', '~> 1.7'
|
22
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
23
23
|
|
24
24
|
# runtime dependency
|
25
25
|
spec.add_runtime_dependency 'mime-types'
|
26
26
|
|
27
27
|
# docs
|
28
28
|
spec.add_development_dependency 'yard'
|
29
|
-
spec.add_development_dependency 'inch'
|
30
29
|
|
31
|
-
#
|
30
|
+
# code coverage
|
32
31
|
spec.add_development_dependency 'simplecov'
|
33
|
-
spec.add_development_dependency '
|
32
|
+
spec.add_development_dependency 'inch'
|
33
|
+
|
34
|
+
# code metrics
|
34
35
|
spec.add_development_dependency 'rubocop'
|
35
36
|
spec.add_development_dependency 'reek'
|
36
|
-
|
37
|
-
|
38
|
-
spec.add_development_dependency '
|
37
|
+
|
38
|
+
# tests
|
39
|
+
spec.add_development_dependency 'minitest'
|
40
|
+
spec.add_development_dependency 'minitest-reporters'
|
39
41
|
|
40
42
|
# automation
|
41
43
|
spec.add_development_dependency 'guard'
|
42
44
|
spec.add_development_dependency 'guard-inch'
|
43
|
-
spec.add_development_dependency 'guard-rubocop'
|
44
45
|
spec.add_development_dependency 'guard-yard'
|
45
46
|
spec.add_development_dependency 'guard-reek'
|
46
|
-
spec.add_development_dependency 'guard-
|
47
|
+
spec.add_development_dependency 'guard-rubocop'
|
48
|
+
spec.add_development_dependency 'guard-minitest'
|
47
49
|
spec.add_development_dependency 'guard-bundler'
|
48
|
-
|
49
50
|
end
|
data/lib/iterm2/viewer.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: iterm2-viewer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
|
-
-
|
7
|
+
- Andrey
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-11-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -66,20 +66,6 @@ dependencies:
|
|
66
66
|
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
|
-
- !ruby/object:Gem::Dependency
|
70
|
-
name: inch
|
71
|
-
requirement: !ruby/object:Gem::Requirement
|
72
|
-
requirements:
|
73
|
-
- - ">="
|
74
|
-
- !ruby/object:Gem::Version
|
75
|
-
version: '0'
|
76
|
-
type: :development
|
77
|
-
prerelease: false
|
78
|
-
version_requirements: !ruby/object:Gem::Requirement
|
79
|
-
requirements:
|
80
|
-
- - ">="
|
81
|
-
- !ruby/object:Gem::Version
|
82
|
-
version: '0'
|
83
69
|
- !ruby/object:Gem::Dependency
|
84
70
|
name: simplecov
|
85
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -95,7 +81,7 @@ dependencies:
|
|
95
81
|
- !ruby/object:Gem::Version
|
96
82
|
version: '0'
|
97
83
|
- !ruby/object:Gem::Dependency
|
98
|
-
name:
|
84
|
+
name: inch
|
99
85
|
requirement: !ruby/object:Gem::Requirement
|
100
86
|
requirements:
|
101
87
|
- - ">="
|
@@ -137,21 +123,7 @@ dependencies:
|
|
137
123
|
- !ruby/object:Gem::Version
|
138
124
|
version: '0'
|
139
125
|
- !ruby/object:Gem::Dependency
|
140
|
-
name:
|
141
|
-
requirement: !ruby/object:Gem::Requirement
|
142
|
-
requirements:
|
143
|
-
- - ">="
|
144
|
-
- !ruby/object:Gem::Version
|
145
|
-
version: '0'
|
146
|
-
type: :development
|
147
|
-
prerelease: false
|
148
|
-
version_requirements: !ruby/object:Gem::Requirement
|
149
|
-
requirements:
|
150
|
-
- - ">="
|
151
|
-
- !ruby/object:Gem::Version
|
152
|
-
version: '0'
|
153
|
-
- !ruby/object:Gem::Dependency
|
154
|
-
name: rspec-expectations
|
126
|
+
name: minitest
|
155
127
|
requirement: !ruby/object:Gem::Requirement
|
156
128
|
requirements:
|
157
129
|
- - ">="
|
@@ -165,7 +137,7 @@ dependencies:
|
|
165
137
|
- !ruby/object:Gem::Version
|
166
138
|
version: '0'
|
167
139
|
- !ruby/object:Gem::Dependency
|
168
|
-
name:
|
140
|
+
name: minitest-reporters
|
169
141
|
requirement: !ruby/object:Gem::Requirement
|
170
142
|
requirements:
|
171
143
|
- - ">="
|
@@ -207,7 +179,7 @@ dependencies:
|
|
207
179
|
- !ruby/object:Gem::Version
|
208
180
|
version: '0'
|
209
181
|
- !ruby/object:Gem::Dependency
|
210
|
-
name: guard-
|
182
|
+
name: guard-yard
|
211
183
|
requirement: !ruby/object:Gem::Requirement
|
212
184
|
requirements:
|
213
185
|
- - ">="
|
@@ -221,7 +193,7 @@ dependencies:
|
|
221
193
|
- !ruby/object:Gem::Version
|
222
194
|
version: '0'
|
223
195
|
- !ruby/object:Gem::Dependency
|
224
|
-
name: guard-
|
196
|
+
name: guard-reek
|
225
197
|
requirement: !ruby/object:Gem::Requirement
|
226
198
|
requirements:
|
227
199
|
- - ">="
|
@@ -235,7 +207,7 @@ dependencies:
|
|
235
207
|
- !ruby/object:Gem::Version
|
236
208
|
version: '0'
|
237
209
|
- !ruby/object:Gem::Dependency
|
238
|
-
name: guard-
|
210
|
+
name: guard-rubocop
|
239
211
|
requirement: !ruby/object:Gem::Requirement
|
240
212
|
requirements:
|
241
213
|
- - ">="
|
@@ -249,7 +221,7 @@ dependencies:
|
|
249
221
|
- !ruby/object:Gem::Version
|
250
222
|
version: '0'
|
251
223
|
- !ruby/object:Gem::Dependency
|
252
|
-
name: guard-
|
224
|
+
name: guard-minitest
|
253
225
|
requirement: !ruby/object:Gem::Requirement
|
254
226
|
requirements:
|
255
227
|
- - ">="
|
@@ -286,6 +258,7 @@ extra_rdoc_files: []
|
|
286
258
|
files:
|
287
259
|
- ".gitignore"
|
288
260
|
- Gemfile
|
261
|
+
- Guardfile
|
289
262
|
- LICENSE.txt
|
290
263
|
- README.md
|
291
264
|
- Rakefile
|