iterm2-viewer 0.0.2 → 0.0.3

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: 6d63bfeab1ba076032eca30e3f2a884292e7fbc6
4
- data.tar.gz: 4642bcdfc73f99e8fbdfd853535f51b8c6ae247a
3
+ metadata.gz: 00ade4c0971642bec72b2e0982f40f31b0b802e1
4
+ data.tar.gz: 045f7d2ca65386bc955388bc529dadb84a75671e
5
5
  SHA512:
6
- metadata.gz: 303ec9563abcbedb0c7a0efe484600646e9aea5e1395c4beb648f9c57b3a18790a8b68e509cb882f81c2b53e4d1246312488eedb6ba1ad498402763c610c585f
7
- data.tar.gz: 7379c8a12eef52c0a37d33b93a7e0e2d1b1a4aeef2896d082805903e7b84201abedd00951d6875a243249e4339af9928c9d6d50062a38d0a569c322dcff13f30
6
+ metadata.gz: 21cd093e1df2539c3fd2ac86e31d3e224b5824da552a2e512bf5a3c68a6c94d5a0d165e75d966f68379a419ed01a719efbb45f187cb1c1e5b88ae4850276d0be
7
+ data.tar.gz: e1c3e35bb45b7db5bf440051d46d6bdf49540ff6fa10c7370834fa32940af4b5786d7b91583c008ee9e6b234710c78e901f33b68c796323c3b49a7f5d93f3270
data/README.md CHANGED
@@ -1,6 +1,10 @@
1
- # Iterm2::Viewer
1
+ [![Code Climate](https://codeclimate.com/github/AndreyAntipov/iterm2-viewer/badges/gpa.svg)](https://codeclimate.com/github/AndreyAntipov/iterm2-viewer)
2
+ [![Dependency Status](https://gemnasium.com/AndreyAntipov/iterm2-viewer.svg)](https://gemnasium.com/AndreyAntipov/iterm2-viewer)
3
+ [![Gem Version](https://badge.fury.io/rb/iterm2-viewer.svg)](http://badge.fury.io/rb/iterm2-viewer)
2
4
 
3
- TODO: Write a gem description
5
+ # iterm2-viewer
6
+
7
+ Display media files in terminal. iTerm2-nightly is required
4
8
 
5
9
  ## Installation
6
10
 
@@ -20,7 +24,26 @@ Or install it yourself as:
20
24
 
21
25
  ## Usage
22
26
 
23
- TODO: Write usage instructions here
27
+ ```ruby
28
+ iterm2-viewer YOUR_IMAGE_FILE_PATH
29
+ ```
30
+ or
31
+ ```ruby
32
+ iterm2-viewer YOUR_IMAGE_FILE_1_PATH YOUR_IMAGE_FILE_2_PATH
33
+ ```
34
+ ---
35
+
36
+ ![How it look like 1](https://raw.githubusercontent.com/AndreyAntipov/iterm2-viewer/media/screenshot_1.png "How it look like 1")
37
+
38
+ ![How it look like 2](https://raw.githubusercontent.com/AndreyAntipov/iterm2-viewer/media/screenshot_2.png "How it look like 2")
39
+
40
+ ---
41
+
42
+ ## License
43
+
44
+ The MIT License (MIT)
45
+
46
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions in [LICENSE.txt](https://github.com/AndreyAntipov/iterm2-viewer/blob/master/LICENSE.txt)
24
47
 
25
48
  ## Contributing
26
49
 
data/bin/iterm2-viewer CHANGED
@@ -1,65 +1,84 @@
1
1
  #!/usr/bin/env ruby
2
- # encoding: UTF-8
2
+ # encoding: utf-8
3
3
 
4
+ # Resolve dependencies
5
+ lib = File.expand_path('../lib', __FILE__)
6
+ $LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..', 'lib')
7
+
8
+ # Dependencies
4
9
  require 'base64'
5
10
  require 'mime/types'
6
11
 
12
+ # Core module of application
7
13
  module Viewer
8
14
 
15
+ # Metaclass
9
16
  class << self
17
+ # @return [Symbol] instance of configuration hash
18
+ # @return [Symbol] show interface for initialization withs arguments
10
19
  attr_accessor :configuration, :show
11
20
  end
12
21
 
22
+ # public method for overriding default configuration
23
+ # @return [Hash] of parameters
13
24
  def self.configure
14
25
  self.configuration ||= Configuration.new
15
26
  yield(configuration)
16
27
  end
17
28
 
29
+ # Configuration class
18
30
  class Configuration
19
31
  attr_accessor :viewport
20
32
 
21
- #defaults
33
+ # Defaults configuration
22
34
  def initialize
23
35
  @viewport =
24
36
  {
25
- width: "auto",
26
- height: "auto",
37
+ width: 'auto',
38
+ height: 'auto',
27
39
  keep_aspect_ratio: true
28
40
  }
29
41
  end
30
42
  end
31
43
 
32
- # interface class
44
+ # initialization method which pass the arguments from the shell
33
45
  def self.show(arguments)
34
46
  Base.new arguments if arguments.any?
35
47
  end
36
48
 
49
+ # Validate and render objects passed in arguments
37
50
  class Base
38
-
51
+ # Insaniate and render media objects
39
52
  def initialize(routes)
40
- # display objects
41
- routes.each do |object|
42
- if exist? object
43
- display Media.new object
44
- end
45
- end
53
+ routes.each { |object| render Media.new object if exist? object }
46
54
  end
47
55
 
56
+ # Determine is file exist or not
57
+ # @return [Boolean] availability of object
48
58
  def exist?(object)
49
- File.file? object
59
+ File.file? object
50
60
  end
51
61
 
62
+ # Create new instance of renderable object
52
63
  class Media < String
53
-
64
+ # @return [Symbol] renderable validator which determine that file is supportable or not
65
+ # @return [Symbol] data return base64 string of file
54
66
  attr_reader :renderable, :data
55
67
 
68
+ # Create new media object
56
69
  def initialize(data)
57
70
  super(data)
71
+ @mime ||= MIME::Types.of(self).first
58
72
  @data ||= construct
59
73
  end
60
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
61
80
  def construct
62
- if renderable?
81
+ if self.renderable?
63
82
  source = open self
64
83
  Base64.encode64(source.read)
65
84
  else
@@ -67,45 +86,58 @@ module Viewer
67
86
  end
68
87
  end
69
88
 
89
+ # Detect current kind such as (application, image, docuemtn) and so on of selected file
90
+ # @return [String] current kind of file
70
91
  def kind
71
- MIME::Types.of(self).first.media_type
92
+ @mime.media_type
72
93
  end
73
94
 
95
+ # Detect current type such as (.png, .pdf, .txt) and so on of selected file
96
+ # @return [String] current type of file
74
97
  def type
75
- MIME::Types.of(self).first.sub_type
98
+ @mime.sub_type
76
99
  end
77
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
78
104
  def type_renderable?
79
- Type.const_get kind.capitalize
105
+ Type.const_get kind.capitalize
80
106
  rescue NameError
81
107
  false
82
108
  end
83
109
 
110
+ # Determine whether that type is renderable
111
+ # @note Renderable Types and MIME's listed below in Type module
112
+ # @return [Boolean]
84
113
  def kind_renderable?
85
114
  type_renderable? ? (Type.const_get(kind.capitalize)::MIME.include? type) : false
86
115
  end
87
116
  alias_method :renderable?, :kind_renderable?
88
117
 
118
+ # Store renderable types and kinds
89
119
  module Type
90
120
  module Image
91
- MIME = ['jpeg','jpg','png','tiff','gif']
121
+ MIME = %w(jpeg jpg png tiff gif)
92
122
  end
93
123
  end
94
124
  end
95
125
 
96
- # TODO: Add options support
97
- def display(object)
98
- # http://iterm2.com/images.html
99
- # based on https://raw.githubusercontent.com/gnachman/iTerm2/master/tests/imgcat
100
- puts "\033]1337;File=;inline=1:#{object.data}\a\n" if object.renderable?
101
- end
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?
102
133
  end
134
+ end
103
135
  end
104
136
 
105
- # override defaults
137
+ # Override defaults
106
138
  Viewer.configure do |config|
107
139
  config.viewport[:width] = 10
108
140
  end
109
141
 
110
- # run application with shell parameters
142
+ # Run application with shell parameters
111
143
  Viewer.show ARGV
@@ -20,4 +20,30 @@ Gem::Specification.new do |spec|
20
20
 
21
21
  spec.add_development_dependency "bundler", "~> 1.7"
22
22
  spec.add_development_dependency "rake", "~> 10.0"
23
+
24
+ # runtime dependency
25
+ spec.add_runtime_dependency 'mime-types'
26
+
27
+ # docs
28
+ spec.add_development_dependency 'yard'
29
+ spec.add_development_dependency 'inch'
30
+
31
+ # tests
32
+ spec.add_development_dependency 'simplecov'
33
+ spec.add_development_dependency 'factory_girl'
34
+ spec.add_development_dependency 'rubocop'
35
+ spec.add_development_dependency 'reek'
36
+ spec.add_development_dependency 'rspec'
37
+ spec.add_development_dependency 'rspec-expectations'
38
+ spec.add_development_dependency 'fuubar'
39
+
40
+ # automation
41
+ spec.add_development_dependency 'guard'
42
+ spec.add_development_dependency 'guard-inch'
43
+ spec.add_development_dependency 'guard-rubocop'
44
+ spec.add_development_dependency 'guard-yard'
45
+ spec.add_development_dependency 'guard-reek'
46
+ spec.add_development_dependency 'guard-rspec'
47
+ spec.add_development_dependency 'guard-bundler'
48
+
23
49
  end
@@ -1,5 +1,5 @@
1
1
  module Iterm2
2
2
  module Viewer
3
- VERSION = "0.0.2"
3
+ VERSION = "0.0.3"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: iterm2-viewer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - " Andrey"
@@ -38,6 +38,244 @@ dependencies:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: mime-types
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: yard
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
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
+ - !ruby/object:Gem::Dependency
84
+ name: simplecov
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: factory_girl
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'
111
+ - !ruby/object:Gem::Dependency
112
+ name: rubocop
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: reek
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: rspec
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
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - ">="
158
+ - !ruby/object:Gem::Version
159
+ version: '0'
160
+ type: :development
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - ">="
165
+ - !ruby/object:Gem::Version
166
+ version: '0'
167
+ - !ruby/object:Gem::Dependency
168
+ name: fuubar
169
+ requirement: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - ">="
172
+ - !ruby/object:Gem::Version
173
+ version: '0'
174
+ type: :development
175
+ prerelease: false
176
+ version_requirements: !ruby/object:Gem::Requirement
177
+ requirements:
178
+ - - ">="
179
+ - !ruby/object:Gem::Version
180
+ version: '0'
181
+ - !ruby/object:Gem::Dependency
182
+ name: guard
183
+ requirement: !ruby/object:Gem::Requirement
184
+ requirements:
185
+ - - ">="
186
+ - !ruby/object:Gem::Version
187
+ version: '0'
188
+ type: :development
189
+ prerelease: false
190
+ version_requirements: !ruby/object:Gem::Requirement
191
+ requirements:
192
+ - - ">="
193
+ - !ruby/object:Gem::Version
194
+ version: '0'
195
+ - !ruby/object:Gem::Dependency
196
+ name: guard-inch
197
+ requirement: !ruby/object:Gem::Requirement
198
+ requirements:
199
+ - - ">="
200
+ - !ruby/object:Gem::Version
201
+ version: '0'
202
+ type: :development
203
+ prerelease: false
204
+ version_requirements: !ruby/object:Gem::Requirement
205
+ requirements:
206
+ - - ">="
207
+ - !ruby/object:Gem::Version
208
+ version: '0'
209
+ - !ruby/object:Gem::Dependency
210
+ name: guard-rubocop
211
+ requirement: !ruby/object:Gem::Requirement
212
+ requirements:
213
+ - - ">="
214
+ - !ruby/object:Gem::Version
215
+ version: '0'
216
+ type: :development
217
+ prerelease: false
218
+ version_requirements: !ruby/object:Gem::Requirement
219
+ requirements:
220
+ - - ">="
221
+ - !ruby/object:Gem::Version
222
+ version: '0'
223
+ - !ruby/object:Gem::Dependency
224
+ name: guard-yard
225
+ requirement: !ruby/object:Gem::Requirement
226
+ requirements:
227
+ - - ">="
228
+ - !ruby/object:Gem::Version
229
+ version: '0'
230
+ type: :development
231
+ prerelease: false
232
+ version_requirements: !ruby/object:Gem::Requirement
233
+ requirements:
234
+ - - ">="
235
+ - !ruby/object:Gem::Version
236
+ version: '0'
237
+ - !ruby/object:Gem::Dependency
238
+ name: guard-reek
239
+ requirement: !ruby/object:Gem::Requirement
240
+ requirements:
241
+ - - ">="
242
+ - !ruby/object:Gem::Version
243
+ version: '0'
244
+ type: :development
245
+ prerelease: false
246
+ version_requirements: !ruby/object:Gem::Requirement
247
+ requirements:
248
+ - - ">="
249
+ - !ruby/object:Gem::Version
250
+ version: '0'
251
+ - !ruby/object:Gem::Dependency
252
+ name: guard-rspec
253
+ requirement: !ruby/object:Gem::Requirement
254
+ requirements:
255
+ - - ">="
256
+ - !ruby/object:Gem::Version
257
+ version: '0'
258
+ type: :development
259
+ prerelease: false
260
+ version_requirements: !ruby/object:Gem::Requirement
261
+ requirements:
262
+ - - ">="
263
+ - !ruby/object:Gem::Version
264
+ version: '0'
265
+ - !ruby/object:Gem::Dependency
266
+ name: guard-bundler
267
+ requirement: !ruby/object:Gem::Requirement
268
+ requirements:
269
+ - - ">="
270
+ - !ruby/object:Gem::Version
271
+ version: '0'
272
+ type: :development
273
+ prerelease: false
274
+ version_requirements: !ruby/object:Gem::Requirement
275
+ requirements:
276
+ - - ">="
277
+ - !ruby/object:Gem::Version
278
+ version: '0'
41
279
  description: Display media files in terminal. iTerm2 is required
42
280
  email:
43
281
  - andrey@antipov.me