mireru 0.0.5 → 0.0.6

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: ee216063487b526fe0bed9bc27ce8b46c5bdb89b
4
- data.tar.gz: 27cbe68ba5678985d175ad8aa2329473a1f68919
3
+ metadata.gz: b65e126d1a85773d145365c952e72a055e786da6
4
+ data.tar.gz: 3580c8fb933612f911b1cdf8cdb9aa79ee4c4da3
5
5
  SHA512:
6
- metadata.gz: 8df06e44085f7137453e05c02b54defd93f1f9b3a16bc3295fbf4de581b98c001bfb6366f59225fa493c13a56875c24fcefb8191dbc0df58bce9dd2cf3b4e78e
7
- data.tar.gz: 93259e7fe5584cc5d66841cfecde0b360b5cecd47bcee15af275b5f263cda1688261ceaacc6ace4625bc9d58500bad100bd99df58501ba547ad8d0c99676f3bc
6
+ metadata.gz: ec845f3882c94f8c88e9e30b9926209ada8fcb7d647692c7a68a5f35c02b20b2a40b445657be20873f99a32330c0d6a335b1c8628986e7c4748d23d61a92f423
7
+ data.tar.gz: 7e43886fa097f1f5a12f4ed9bb6fbf28288b248635d65d1c5cb1f5fe6d9e0add554f0c3a06d657bcf8ac49b23edd23e8c40bc3effbc0aef5c91e976ca8dbdc60
@@ -1,4 +1,6 @@
1
1
  require 'gtk3'
2
+ require "mireru/logger"
3
+ require "mireru/widget"
2
4
 
3
5
  module Mireru
4
6
  module Command
@@ -12,20 +14,22 @@ module Mireru
12
14
  end
13
15
 
14
16
  def initialize
17
+ @logger = ::Mireru::Logger.new
15
18
  end
16
19
 
17
20
  def run(arguments)
18
21
  if arguments.empty?
19
22
  file_container = Dir.glob("*")
20
23
  elsif /\A(-h|--help)\z/ =~ arguments[0]
21
- puts(USAGE)
22
- puts <<-EOS
24
+ message = <<-EOM
25
+ #{USAGE}
23
26
  If no argument, then search current directory.
24
27
  Keybind:
25
28
  n: next
26
29
  p: prev
27
30
  q: quit
28
- EOS
31
+ EOM
32
+ @logger.info(message)
29
33
  exit(true)
30
34
  else
31
35
  file_container = arguments
@@ -34,29 +38,46 @@ Keybind:
34
38
  file_container.select! {|f| support_file?(f) }
35
39
 
36
40
  if file_container.empty?
37
- puts("Warning: valid file not found.")
38
- puts(USAGE)
39
- puts("Support file types: png, gif, jpeg(jpg). The others are...yet.")
41
+ message = <<-EOM
42
+ Warning: valid file not found.
43
+ #{USAGE}
44
+ Support file types: png, gif, jpeg(jpg). The others are...yet.
45
+ EOM
46
+ @logger.error(message)
40
47
  exit(false)
41
48
  end
42
49
 
43
- image = Gtk::Image.new
44
- image.file = file_container.shift
50
+ file = file_container.shift
51
+ widget = ::Mireru::Widget.create(file)
45
52
 
46
53
  window = Gtk::Window.new
47
- window.title = File.basename(image.file)
54
+ window.title = File.basename(file)
48
55
 
49
56
  window.signal_connect("key_press_event") do |w, e|
50
57
  case e.keyval
51
58
  when Gdk::Keyval::GDK_KEY_n
52
- file_container.push(image.file)
53
- image.file = file_container.shift
54
- window.title = File.basename(image.file)
59
+ window.remove(widget)
60
+ file_container.push(file)
61
+ file = file_container.shift
62
+ widget = ::Mireru::Widget.create(file)
63
+ window.add(widget)
64
+ window.show_all
65
+ window.title = File.basename(file)
55
66
  window.resize(1, 1)
56
67
  when Gdk::Keyval::GDK_KEY_p
57
- file_container.unshift(image.file)
58
- image.file = file_container.pop
59
- window.title = File.basename(image.file)
68
+ window.remove(widget)
69
+ file_container.unshift(file)
70
+ file = file_container.pop
71
+ widget = ::Mireru::Widget.create(file)
72
+ window.add(widget)
73
+ window.show_all
74
+ window.title = File.basename(file)
75
+ window.resize(1, 1)
76
+ when Gdk::Keyval::GDK_KEY_r
77
+ window.remove(widget)
78
+ widget = ::Mireru::Widget.create(file)
79
+ window.add(widget)
80
+ window.show_all
60
81
  window.resize(1, 1)
61
82
  when Gdk::Keyval::GDK_KEY_q
62
83
  Gtk.main_quit
@@ -67,37 +88,13 @@ Keybind:
67
88
  Gtk.main_quit
68
89
  end
69
90
 
70
- window.add(image)
91
+ window.add(widget)
71
92
  window.show_all
72
93
 
73
94
  Gtk.main
74
95
  end
75
96
 
76
97
  private
77
- def valid?(arguments)
78
- file = arguments[0]
79
-
80
- unless file
81
- puts("Error: no argument.")
82
- puts(USAGE)
83
- return false
84
- end
85
-
86
- unless File.file?(file)
87
- puts("Error: missing file.")
88
- puts(USAGE)
89
- return false
90
- end
91
-
92
- unless /\.(png|jpe?g|gif)$/i =~ file
93
- puts("Error: this file type is not support as yet.")
94
- puts(USAGE)
95
- return false
96
- end
97
-
98
- true
99
- end
100
-
101
98
  def support_file?(file)
102
99
  unless file
103
100
  return false
@@ -107,7 +104,7 @@ Keybind:
107
104
  return false
108
105
  end
109
106
 
110
- unless /\.(png|jpe?g|gif)$/i =~ file
107
+ unless /\.(png|jpe?g|gif|txt|rb)$/i =~ file
111
108
  return false
112
109
  end
113
110
 
@@ -0,0 +1,14 @@
1
+ module Mireru
2
+ class Logger
3
+ def initialize
4
+ end
5
+
6
+ def info(message)
7
+ puts(message)
8
+ end
9
+
10
+ def error(message)
11
+ $stderr.puts(message)
12
+ end
13
+ end
14
+ end
@@ -1,3 +1,3 @@
1
1
  module Mireru
2
- VERSION = "0.0.5"
2
+ VERSION = "0.0.6"
3
3
  end
@@ -0,0 +1,23 @@
1
+ require 'gtk3'
2
+
3
+ module Mireru
4
+ class Widget
5
+ def self.create(file)
6
+ case File.extname(file)
7
+ when /\A\.(png|jpe?g|gif)\z/i
8
+ image = Gtk::Image.new
9
+ image.file = file
10
+ widget = image
11
+ when /\A\.(txt|rb)\z/i
12
+ buffer = Gtk::TextBuffer.new
13
+ buffer.text = File.open(file).read
14
+ text = Gtk::TextView.new(buffer)
15
+ text.editable = false
16
+ widget = text
17
+ else
18
+ raise "coding error: uncheck file type."
19
+ end
20
+ widget
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Masafumi Yokoyama
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,35 @@
1
+ require 'cairo'
2
+
3
+ w = 400
4
+ h = 400
5
+
6
+ Cairo::ImageSurface.new(w, h) do |surface|
7
+ context = Cairo::Context.new(surface)
8
+
9
+ # 放射グラデーション
10
+ pattern = Cairo::RadialPattern.new(w/3, h/3, 330, w/3, h/3, 0)
11
+ start = 1.0
12
+ [:white,
13
+ :red,
14
+ :orange,
15
+ :yellow,
16
+ :green,
17
+ :aqua,
18
+ :blue,
19
+ :purple,
20
+ :black].each do |c|
21
+ pattern.add_color_stop(start -= 0.1, c)
22
+ end
23
+ context.set_source(pattern)
24
+
25
+ # 背景
26
+ #context.paint(0.1)
27
+
28
+ # 文字
29
+ context.select_font_face('Ubuntu')
30
+ context.move_to(60, 350)
31
+ context.font_size = 250
32
+ context.show_text("my")
33
+
34
+ surface.write_to_png("nijip.png")
35
+ end
File without changes
@@ -0,0 +1,39 @@
1
+ require "mireru/logger"
2
+ require "stringio"
3
+
4
+ class TestLogger < Test::Unit::TestCase
5
+ def setup
6
+ @logger = Mireru::Logger.new
7
+ end
8
+
9
+ def test_info
10
+ s = ""
11
+ io = StringIO.new(s)
12
+ $stdout = io
13
+ message = <<-EOM
14
+ #{Mireru::Command::Mireru::USAGE}
15
+ If no argument, then search current directory.
16
+ Keybind:
17
+ n: next
18
+ p: prev
19
+ q: quit
20
+ EOM
21
+ @logger.info(message)
22
+ $stdout = STDOUT
23
+ assert_equal(message, s)
24
+ end
25
+
26
+ def test_error
27
+ s = ""
28
+ io = StringIO.new(s)
29
+ $stderr = io
30
+ message = <<-EOM
31
+ Warning: valid file not found.
32
+ #{Mireru::Command::Mireru::USAGE}
33
+ Support file types: png, gif, jpeg(jpg). The others are...yet.
34
+ EOM
35
+ @logger.error(message)
36
+ $stderr = STDERR
37
+ assert_equal(message, s)
38
+ end
39
+ end
data/test/test-mireru.rb CHANGED
@@ -1,49 +1,37 @@
1
1
  require "mireru/command/mireru"
2
- require "stringio"
3
2
 
4
3
  module ValidTests
5
4
  def test_no_argument
6
- s = ""
7
- io = StringIO.new(s)
8
- $stdout = io
9
- valid = @mireru.__send__(:valid?, [])
10
- $stdout = STDOUT
5
+ valid = @mireru.__send__(:support_file?, nil)
11
6
  assert_false(valid)
12
- assert_equal(<<-EOT, s)
13
- Error: no argument.
14
- #{Mireru::Command::Mireru::USAGE}
15
- EOT
16
7
  end
17
8
 
18
9
  def test_missing_file
19
- s = ""
20
- io = StringIO.new(s)
21
- $stdout = io
22
- valid = @mireru.__send__(:valid?, ["hoge"])
23
- $stdout = STDOUT
10
+ valid = @mireru.__send__(:support_file?, "hoge")
24
11
  assert_false(valid)
25
- assert_equal(<<-EOT, s)
26
- Error: missing file.
27
- #{Mireru::Command::Mireru::USAGE}
28
- EOT
29
12
  end
30
13
 
31
14
  def test_not_support_file_type
32
- s = ""
33
- io = StringIO.new(s)
34
- $stdout = io
35
- valid = @mireru.__send__(:valid?, [__FILE__])
36
- $stdout = STDOUT
15
+ file = File.join(File.dirname(__FILE__), "fixtures", "no-extention")
16
+ valid = @mireru.__send__(:support_file?, file)
37
17
  assert_false(valid)
38
- assert_equal(<<-EOT, s)
39
- Error: this file type is not support as yet.
40
- #{Mireru::Command::Mireru::USAGE}
41
- EOT
42
18
  end
43
19
 
44
20
  def test_png_file
45
21
  file = File.join(File.dirname(__FILE__), "fixtures", "nijip.png")
46
- valid = @mireru.__send__(:valid?, [file])
22
+ valid = @mireru.__send__(:support_file?, file)
23
+ assert_true(valid)
24
+ end
25
+
26
+ def test_txt_file
27
+ file = File.join(File.dirname(__FILE__), "fixtures", "LICENSE.txt")
28
+ valid = @mireru.__send__(:support_file?, file)
29
+ assert_true(valid)
30
+ end
31
+
32
+ def test_rb_file
33
+ file = File.join(File.dirname(__FILE__), "fixtures", "nijip.rb")
34
+ valid = @mireru.__send__(:support_file?, file)
47
35
  assert_true(valid)
48
36
  end
49
37
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mireru
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Masafumi Yokoyama
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-04-05 00:00:00.000000000 Z
11
+ date: 2013-04-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: gtk3
@@ -110,10 +110,16 @@ files:
110
110
  - bin/mireru
111
111
  - lib/mireru.rb
112
112
  - lib/mireru/command/mireru.rb
113
+ - lib/mireru/logger.rb
113
114
  - lib/mireru/version.rb
115
+ - lib/mireru/widget.rb
114
116
  - mireru.gemspec
117
+ - test/fixtures/LICENSE.txt
115
118
  - test/fixtures/nijip.png
119
+ - test/fixtures/nijip.rb
120
+ - test/fixtures/no-extention
116
121
  - test/run-test.rb
122
+ - test/test-logger.rb
117
123
  - test/test-mireru.rb
118
124
  homepage: https://github.com/myokoym/mireru
119
125
  licenses:
@@ -140,7 +146,11 @@ signing_key:
140
146
  specification_version: 4
141
147
  summary: Flexible File Viewer
142
148
  test_files:
149
+ - test/fixtures/LICENSE.txt
143
150
  - test/fixtures/nijip.png
151
+ - test/fixtures/nijip.rb
152
+ - test/fixtures/no-extention
144
153
  - test/run-test.rb
154
+ - test/test-logger.rb
145
155
  - test/test-mireru.rb
146
156
  has_rdoc: