iterm2-viewer 0.0.6 → 0.0.7

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: 832d19f977fb9f52c754339921906db1b41975e0
4
- data.tar.gz: a5ea41ede95ac467e297d87df41f702d0d2f381a
3
+ metadata.gz: 0e417f4367b8b80c7902713896212183aa1e99c9
4
+ data.tar.gz: 91b35f01b824c186f706177764fd88d4b9dfde6a
5
5
  SHA512:
6
- metadata.gz: 82a9726452593757dc86e15ab3cd3b2b1569fa7ff9d1ceff89eae82ba90c75e4766a3095a7f7bbd265a0e5bd143a7212f47cc649acad5f18081b43cc123f7686
7
- data.tar.gz: 36852f9fc8071c2cc71b85da6d7adefcba7bbc3ce074a2b8c26f601f6cb7930381ee3825688578185acf049eeb336515f2363b0dbbac0d83f7bb6069bb1e05ba
6
+ metadata.gz: f7dc4efb0b686d4a762cea57338bb603545095f5c54d8aa80767b872938347008451a4fe0a86c4afa75209b102a818a5c50555611cbe1e879221c6db37203fb2
7
+ data.tar.gz: d602b0322a57604665cea12f58f36151b80c5f361e549d51e01a8ff6ed73f95db07be2f2c28715d9662d1a05b17d77e2058d00baf7536f5c89a227e146739906
@@ -3,7 +3,6 @@ rvm:
3
3
  - 2.1.1
4
4
  - 2.0.0
5
5
  - 1.9.3
6
- - 1.8.7
7
6
  addons:
8
7
  code_climate:
9
8
  repo_token: ab8664da98d6bfb6a14e4bd439bb87efe95b19785f42ba496077b3fd5ef3ecc3
data/Guardfile CHANGED
@@ -1,6 +1,5 @@
1
1
  # A sample Guardfile
2
2
  # More info at https://github.com/guard/guard#readme
3
-
4
3
  guard :bundler do
5
4
  watch('Gemfile')
6
5
  watch(/^.+\.gemspec/)
data/Rakefile CHANGED
@@ -2,7 +2,8 @@ require 'rake/testtask'
2
2
 
3
3
  Rake::TestTask.new do |t|
4
4
  t.libs << 'test'
5
- t.pattern = 'test/**/test_*.rb'
5
+ t.pattern = 'test/lib/**/test_*.rb'
6
+ t.verbose = true
6
7
  end
7
8
 
8
9
  desc 'Guard'
@@ -1,30 +1,53 @@
1
1
  #!/usr/bin/env ruby
2
2
  # encoding: utf-8
3
3
 
4
+ # Setup patches
4
5
  lib = File.expand_path(File.dirname(__FILE__) + '/../lib')
5
6
  $LOAD_PATH.unshift(lib) if File.directory?(lib) && !$LOAD_PATH.include?(lib)
6
7
 
7
8
  require 'iterm2/viewer'
8
9
 
9
10
  module Iterm2
10
- # Display media files in command line
11
+ # CLI interface for view images in terminal
11
12
  module Viewer
12
- # Command line interface
13
+ # Common methods
13
14
  # @param [String, #arguments] routes to files
15
+ # @todo write tests
14
16
  class << self
15
17
  def show(arguments)
16
- # initialize whenever application called from iTerm2
17
- return unless ENV['TERM_PROGRAM'] == 'iTerm.app'
18
+ # initialize whenever application called from iTerm2 with arguments
19
+ return unless ENV['TERM_PROGRAM'] == 'iTerm.app' || arguments.nil?
18
20
 
19
- # show current version
20
- puts VERSION if arguments[0].to_s == '--version' || arguments[0].to_s == '-v'
21
+ # catch options
22
+ if arguments[0] =~ /^(-\w|--\w{2,}?)$/
23
+ # @todo refactoring
24
+ # @todo add notification — command not found
25
+ version if arguments[0].to_s == '--version' || arguments[0].to_s == '-v'
26
+ # switch to renders
27
+ else
28
+ # clean entire screen
29
+ # todo: optimize (fit to enitre screen)
30
+ print "\e[2J\e[f"
21
31
 
22
- # initialize routes
23
- arguments.each { |route| Render.new(Media.new route) if File.file? route }
32
+ # reveal media files
33
+ arguments.each do |route|
34
+ begin
35
+ Render.new(Media.new route).reveal
36
+ # skip incorrect routes
37
+ rescue ArgumentError
38
+ next
39
+ end
40
+ end
41
+ end
24
42
  end
43
+
44
+ def version
45
+ abort VERSION
46
+ end
47
+
25
48
  end
26
49
  end
27
50
  end
28
51
 
29
- # Run application with shell parameters
52
+ # Run application with shell arguments
30
53
  Iterm2::Viewer.show ARGV
@@ -14,7 +14,7 @@ Gem::Specification.new do |spec|
14
14
  spec.homepage = 'https://github.com/AndreyAntipov/iterm2-viewer'
15
15
  spec.license = 'MIT'
16
16
 
17
- spec.files = `git ls-files -z`.split("\x0")
17
+ spec.files = `git ls-files`.split($/)
18
18
  spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
19
19
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
20
20
  spec.require_paths = ['lib']
@@ -1,26 +1,29 @@
1
1
  module Iterm2
2
2
  module Viewer
3
3
  # Create a new media object
4
- class Media
4
+ class Media < String
5
5
  # Dependency
6
6
  require 'mime/types'
7
7
  require 'base64'
8
8
 
9
9
  # Validate and construct media object
10
10
  #
11
- # @param object [String] file path which are need to open
11
+ # @param object [String] need to prepare to render
12
12
  def initialize(object)
13
+
14
+ # Raise error if file doesn't exist
15
+ fail ArgumentError, 'file doesn\'t exist' unless File.file? object
16
+
17
+ # Get file MIME
13
18
  @mime ||= MIME::Types.of(object).first
14
19
 
15
- # Raise error an error if file type isn't supported
16
- fail TypeError unless renderable?
20
+ # Raise error if file type isn't supported
21
+ fail TypeError, 'file type isn\'t supported' unless renderable?
17
22
 
18
- @data ||= renderable? ? construct(object) : nil
23
+ # construct object and inject blob into parent class
24
+ super(construct object)
19
25
  end
20
26
 
21
- # @return [Symbol] data return base64 string of file
22
- attr_reader :data
23
-
24
27
  # Construct base64 blob from binary
25
28
  #
26
29
  # @param object [String] file path which are need to open
@@ -38,7 +41,7 @@ module Iterm2
38
41
  end
39
42
 
40
43
  # Helper method.
41
- # Detect current type such as (.png, .pdf, .txt) and so on of se
44
+ # Detect current type such as (.png, .pdf, .txt)
42
45
  #
43
46
  # @return [String] current type of file
44
47
  def type
@@ -5,9 +5,14 @@ module Iterm2
5
5
  class Render
6
6
  def initialize(object)
7
7
  fail ArgumentError, 'incorrect media file' unless object.is_a? Iterm2::Viewer::Media
8
+ @data ||= object
9
+ end
10
+
11
+ # Display media file
12
+ def reveal
8
13
  # @see http://iterm2.com/images.html
9
14
  # @note https://raw.githubusercontent.com/gnachman/iTerm2/master/tests/imgcat
10
- puts "\033]1337;File=;inline=1:#{object.data}\a\n"
15
+ puts "\033]1337;File=;inline=1:#{@data}\a\n"
11
16
  end
12
17
  end
13
18
  end
@@ -2,6 +2,6 @@ module Iterm2
2
2
  # Display media files in command line
3
3
  module Viewer
4
4
  # Current version of application
5
- VERSION = '0.0.6'
5
+ VERSION = '0.0.7'
6
6
  end
7
7
  end
@@ -1,12 +1,20 @@
1
1
  require 'test_helper'
2
2
 
3
- # Testing media object
4
- class Media < Minitest::Test
5
- def object_will_not_created_with_unsupported_type
6
- skip 'this test will pass later'
7
- end
3
+ describe Iterm2::Viewer::Media do
4
+ it 'media will not be created without route argument' do
5
+ assert_raises ArgumentError do
6
+ Iterm2::Viewer::Media.new
7
+ end
8
+ end
8
9
 
9
- def object_will_be_rendered_with_supported_type
10
- skip 'this test will pass later'
11
- end
10
+ it 'media will not be created with incorrect route argument' do
11
+ assert_raises ArgumentError do
12
+ Iterm2::Viewer::Media.new 'String'
13
+ end
14
+ end
15
+
16
+ it 'media will be created if route and mime argument is correct' do
17
+ file = File.absolute_path(__dir__ + '/../../../media/supported.png')
18
+ Iterm2::Viewer::Media.new(file).wont_be_empty
19
+ end
12
20
  end
@@ -1,18 +1,23 @@
1
1
  require 'test_helper'
2
2
 
3
- # Testing render class
4
- class Render < Minitest::Test
5
- def test_that_object_will_not_render_until_argument_isnt_set
6
- assert_raises ArgumentError do
7
- Render.new
3
+
4
+ describe Iterm2::Viewer::Render do
5
+ it 'renderer will not be created without media object as argument' do
6
+ assert_raises ArgumentError do
7
+ Iterm2::Viewer::Render.new
8
+ end
9
+ end
10
+
11
+ it 'renderer will not be initialized with incorrect object argument' do
12
+ assert_raises ArgumentError do
13
+ Iterm2::Viewer::Render.new 'String'
14
+ end
8
15
  end
9
- end
10
16
 
11
- def test_that_object_will_not_rendered_with_wrong_type_of_object
12
- skip 'this test will pass later'
13
- end
17
+ it 'render will be initialized if object type will be correct' do
18
+ file = File.absolute_path(__dir__ + '/../../../media/supported.png')
19
+ media = Iterm2::Viewer::Media.new(file)
14
20
 
15
- def test_that_object_will_render_with_correct_type_of_object
16
- skip 'this test will pass later'
17
- end
21
+ Iterm2::Viewer::Render.new(media).wont_be_nil
22
+ end
18
23
  end
File without changes
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.6
4
+ version: 0.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrey Antipov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-11-21 00:00:00.000000000 Z
11
+ date: 2014-11-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -277,8 +277,8 @@ files:
277
277
  - test/lib/iterm2/viewer/test_media.rb
278
278
  - test/lib/iterm2/viewer/test_render.rb
279
279
  - test/lib/iterm2/viewer/test_version.rb
280
- - test/media/supported
281
- - test/media/unsupported
280
+ - test/media/supported.png
281
+ - test/media/unsupported.txt
282
282
  - test/test_helper.rb
283
283
  homepage: https://github.com/AndreyAntipov/iterm2-viewer
284
284
  licenses:
@@ -308,7 +308,7 @@ test_files:
308
308
  - test/lib/iterm2/viewer/test_media.rb
309
309
  - test/lib/iterm2/viewer/test_render.rb
310
310
  - test/lib/iterm2/viewer/test_version.rb
311
- - test/media/supported
312
- - test/media/unsupported
311
+ - test/media/supported.png
312
+ - test/media/unsupported.txt
313
313
  - test/test_helper.rb
314
314
  has_rdoc: