iterm2-viewer 0.0.4 → 0.0.5

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: 4c939586a9e3fcfe8bb750d994245c67c77ef1b3
4
- data.tar.gz: d3acb5b1f9ae229d1ac4699965a2e204e5c01ad2
3
+ metadata.gz: e669b5969e6184f423ac372b5fc2dec5d8a29f40
4
+ data.tar.gz: ce0019766d06fc9b4f263ed531033e252268df0c
5
5
  SHA512:
6
- metadata.gz: 0ac2ed4d9b107d109a00c8cad44ed0049ec68074211d69337201532b9a314fc8673105bcfd0287c0b413d0a4242e22b70e8bdfc3386e9cc6371351711d7a928a
7
- data.tar.gz: eceed5eab5b7a1c9cb5db0ab26d0fe7c925f89ee5d8771e8b6466b759bc29a6203ef90fa228ff4262b4b2ab9642938f80d18a9b875e3444e3475911e580fc531
6
+ metadata.gz: 3645f7d37581fd296342db543c593b2d31e6787b3894951db07097657167ef454a11f37ae3449bb514b1cdecd649a6ebc493410dd8d1c1f49f4be45e7d49556b
7
+ data.tar.gz: 56e3b46fd2d1455445f6d0179e2679f4b6dd89f5db3abe42b56751143d3130f628c3b01b250c9bf47476d591482922983b32da6b44921d952174b36d582d31d6
@@ -0,0 +1,11 @@
1
+ language: ruby
2
+ gemfile:
3
+ - gemfiles/Gemfile
4
+ addons:
5
+ code_climate:
6
+ repo_token: ab8664da98d6bfb6a14e4bd439bb87efe95b19785f42ba496077b3fd5ef3ecc3
7
+ rvm:
8
+ - 2.1.1
9
+ - 2.0.0
10
+ - 1.9.3
11
+ #cache: bundler
data/Gemfile CHANGED
@@ -1,4 +1,9 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
+ group :test do
4
+ gem 'rake'
5
+ gem "codeclimate-test-reporter", require: nil
6
+ end
7
+
3
8
  # Specify your gem's dependencies in iterm2-viewer.gemspec
4
9
  gemspec
data/README.md CHANGED
@@ -1,11 +1,19 @@
1
1
  [![Code Climate](https://codeclimate.com/github/AndreyAntipov/iterm2-viewer/badges/gpa.svg)](https://codeclimate.com/github/AndreyAntipov/iterm2-viewer)
2
2
  [![Dependency Status](https://gemnasium.com/AndreyAntipov/iterm2-viewer.svg)](https://gemnasium.com/AndreyAntipov/iterm2-viewer)
3
3
  [![Gem Version](https://badge.fury.io/rb/iterm2-viewer.svg)](http://badge.fury.io/rb/iterm2-viewer)
4
+ [![Build Status](https://travis-ci.org/AndreyAntipov/iterm2-viewer.svg?branch=master)](https://travis-ci.org/AndreyAntipov/iterm2-viewer)
5
+ [![Test Coverage](https://codeclimate.com/github/AndreyAntipov/iterm2-viewer/badges/coverage.svg)](https://codeclimate.com/github/AndreyAntipov/iterm2-viewer)
4
6
 
5
7
  # iterm2-viewer
6
8
 
7
9
  Display media files in terminal. iTerm2-nightly is required
8
10
 
11
+ ## Supported types
12
+ - png
13
+ - jpeg
14
+ - tiff
15
+ - gif
16
+
9
17
  ## Installation
10
18
 
11
19
  Add this line to your application's Gemfile:
@@ -25,11 +33,11 @@ Or install it yourself as:
25
33
  ## Usage
26
34
 
27
35
  ```ruby
28
- iterm2-viewer YOUR_IMAGE_FILE_PATH
36
+ iterm2-viewer IMAGE_FILE_PATH
29
37
  ```
30
- or
38
+ display multiple images
31
39
  ```ruby
32
- iterm2-viewer YOUR_IMAGE_FILE_1_PATH YOUR_IMAGE_FILE_2_PATH
40
+ iterm2-viewer IMAGE_FILE_1_PATH IMAGE_FILE_2_PATH
33
41
  ```
34
42
  ---
35
43
 
@@ -47,7 +55,7 @@ Permission is hereby granted, free of charge, to any person obtaining a copy of
47
55
 
48
56
  ## Contributing
49
57
 
50
- 1. Fork it ( https://github.com/[my-github-username]/iterm2-viewer/fork )
58
+ 1. Fork it ( https://github.com/AndreyAntipov/iterm2-viewer/fork )
51
59
  2. Create your feature branch (`git checkout -b my-new-feature`)
52
60
  3. Commit your changes (`git commit -am 'Add some feature'`)
53
61
  4. Push to the branch (`git push origin my-new-feature`)
data/Rakefile CHANGED
@@ -1,2 +1,9 @@
1
- require "bundler/gem_tasks"
1
+ require 'rake/testtask'
2
2
 
3
+ Rake::TestTask.new do |t|
4
+ t.libs << 'test'
5
+ # t.warning = true
6
+ #t.verbose = true
7
+ t.pattern = "test/**/test_*.rb"
8
+ end
9
+ task :default => [:test]
@@ -12,10 +12,13 @@ module Iterm2
12
12
  # @param [String, #arguments] routes to files
13
13
  class << self
14
14
  def show(arguments)
15
+ # show current version
16
+ puts VERSION if arguments[0].to_s == "--version" || arguments[0].to_s == "-v"
17
+
15
18
  # initialize whenever application called from iTerm2
16
19
  if ENV['TERM_PROGRAM'] == 'iTerm.app'
17
20
  arguments.each do |route|
18
- Render.new Media.new route if File.file? route
21
+ Render.new(Media.new route) if File.file? route
19
22
  end
20
23
  end
21
24
  end
@@ -0,0 +1,57 @@
1
+ module Iterm2
2
+ module Viewer
3
+ # Create a new media object
4
+ class Media
5
+ # Dependency
6
+ require 'mime/types'
7
+ require 'base64'
8
+
9
+ def initialize(object)
10
+ @mime ||= MIME::Types.of(object).first
11
+
12
+ # Raise error an error if file type isn't supported
13
+ raise TypeError unless renderable?
14
+
15
+ @data ||= renderable? ? construct(object) : nil
16
+ end
17
+
18
+ # @return [Symbol] data return base64 string of file
19
+ attr_reader :data
20
+
21
+ # Construct base64 blob from binary
22
+ # @param [String] file which are need to open
23
+ # @return [String] base64 data of binary file
24
+ def construct(object)
25
+ Base64.encode64(open(object).read)
26
+ end
27
+
28
+ # Helper method.
29
+ # Detect current kind such as (application, image, document) and so on of selected file
30
+ # @return [String] current kind of file
31
+ def kind
32
+ @mime.media_type.to_sym
33
+ end
34
+
35
+ # Helper method.
36
+ # Detect current type such as (.png, .pdf, .txt) and so on of se
37
+ # @return [String] current type of file
38
+ def type
39
+ @mime.sub_type
40
+ end
41
+
42
+ # Determine whether type is renderable
43
+ # @note Renderable Types and MIME's listed below in supported_types method
44
+ # @return [Boolean]
45
+ def renderable?
46
+ supported_types.key?(kind) && supported_types[kind].include?(type)
47
+ end
48
+
49
+ # Renderable types and kinds
50
+ def supported_types
51
+ {
52
+ image: %w(jpeg jpg png tiff gif)
53
+ }
54
+ end
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,14 @@
1
+ module Iterm2
2
+ module Viewer
3
+ # Render new object in terminal
4
+ # @param object [Iterm2::Viewer::Entity]
5
+ class Render
6
+ def initialize(object)
7
+ raise ArgumentError, "incorrect media file" unless object.is_a? Iterm2::Viewer::Media
8
+ # @see http://iterm2.com/images.html
9
+ # @note based on https://raw.githubusercontent.com/gnachman/iTerm2/master/tests/imgcat
10
+ puts "\033]1337;File=;inline=1:#{object.data}\a\n"
11
+ end
12
+ end
13
+ end
14
+ end
@@ -1,5 +1,5 @@
1
1
  module Iterm2
2
2
  module Viewer
3
- VERSION = '0.0.4'
3
+ VERSION = '0.0.5'
4
4
  end
5
5
  end
@@ -0,0 +1,5 @@
1
+ {
2
+ "result": {
3
+ "covered_percent": 100.0
4
+ }
5
+ }
@@ -0,0 +1,7 @@
1
+ {
2
+ "MiniTest": {
3
+ "coverage": {
4
+ },
5
+ "timestamp": 1416492861
6
+ }
7
+ }
File without changes
@@ -0,0 +1,13 @@
1
+ require 'test_helper'
2
+
3
+ class Media < Minitest::Test
4
+
5
+ def object_will_not_created_with_unsupported_type
6
+ skip "this test will pass later"
7
+ end
8
+
9
+ def object_will_be_rendered_with_supported_type
10
+ skip "this test will pass later"
11
+ end
12
+
13
+ end
@@ -0,0 +1,21 @@
1
+ require 'test_helper'
2
+
3
+ class Render < Minitest::Test
4
+
5
+ def test_that_object_will_not_render_until_argument_isnt_set
6
+ assert_raises ArgumentError do
7
+ Render.new
8
+ end
9
+ end
10
+
11
+ def test_that_object_will_not_rendered_with_wrong_type_of_object
12
+ assert_raises ArgumentError do
13
+ Render.new "wrong type of object"
14
+ end
15
+ end
16
+
17
+ def test_that_object_will_render_with_correct_type_of_object
18
+ skip "this test will pass later"
19
+ end
20
+
21
+ end
@@ -0,0 +1,7 @@
1
+ require 'test_helper'
2
+
3
+ describe Iterm2::Viewer do
4
+ it "must be defined" do
5
+ Iterm2::Viewer::VERSION.wont_be_nil
6
+ end
7
+ end
@@ -0,0 +1,8 @@
1
+ require 'minitest/autorun'
2
+ require 'minitest/unit'
3
+ require 'minitest/pride'
4
+ require File.expand_path('../../lib/iterm2/viewer.rb', __FILE__)
5
+
6
+ require 'codeclimate-test-reporter'
7
+
8
+ CodeClimate::TestReporter.start
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.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrey
@@ -257,6 +257,7 @@ extensions: []
257
257
  extra_rdoc_files: []
258
258
  files:
259
259
  - ".gitignore"
260
+ - ".travis.yml"
260
261
  - Gemfile
261
262
  - Guardfile
262
263
  - LICENSE.txt
@@ -265,7 +266,16 @@ files:
265
266
  - bin/iterm2-viewer
266
267
  - iterm2-viewer.gemspec
267
268
  - lib/iterm2/viewer.rb
269
+ - lib/iterm2/viewer/media.rb
270
+ - lib/iterm2/viewer/render.rb
268
271
  - lib/iterm2/viewer/version.rb
272
+ - test/coverage/.last_run.json
273
+ - test/coverage/.resultset.json
274
+ - test/coverage/.resultset.json.lock
275
+ - test/lib/iterm2/viewer/test_media.rb
276
+ - test/lib/iterm2/viewer/test_render.rb
277
+ - test/lib/iterm2/viewer/test_version.rb
278
+ - test/test_helper.rb
269
279
  homepage: https://github.com/AndreyAntipov/iterm2-viewer
270
280
  licenses:
271
281
  - MIT
@@ -290,5 +300,12 @@ rubygems_version: 2.2.2
290
300
  signing_key:
291
301
  specification_version: 4
292
302
  summary: Display media files in iTerm2.
293
- test_files: []
303
+ test_files:
304
+ - test/coverage/.last_run.json
305
+ - test/coverage/.resultset.json
306
+ - test/coverage/.resultset.json.lock
307
+ - test/lib/iterm2/viewer/test_media.rb
308
+ - test/lib/iterm2/viewer/test_render.rb
309
+ - test/lib/iterm2/viewer/test_version.rb
310
+ - test/test_helper.rb
294
311
  has_rdoc: