mireru 0.0.6 → 0.0.7

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: b65e126d1a85773d145365c952e72a055e786da6
4
- data.tar.gz: 3580c8fb933612f911b1cdf8cdb9aa79ee4c4da3
3
+ metadata.gz: c5b2947adb9a99a12d807c1f0e58d38038448eb3
4
+ data.tar.gz: 1d9776369ac1a0464740d56299d051fa13c29f73
5
5
  SHA512:
6
- metadata.gz: ec845f3882c94f8c88e9e30b9926209ada8fcb7d647692c7a68a5f35c02b20b2a40b445657be20873f99a32330c0d6a335b1c8628986e7c4748d23d61a92f423
7
- data.tar.gz: 7e43886fa097f1f5a12f4ed9bb6fbf28288b248635d65d1c5cb1f5fe6d9e0add554f0c3a06d657bcf8ac49b23edd23e8c40bc3effbc0aef5c91e976ca8dbdc60
6
+ metadata.gz: dba7074a99ee4fff2698f3da1f8fae313b92f136938fba0b1c8841437e13fb656c6ac047f011c5633685410cf48ee28cd77fe07eb72b75e5780543a7ac217dd4
7
+ data.tar.gz: a352694d1383a69a3953a5ea2826f3e3280ca0cdab381e112604cf497b21cda5a17a9df8980742becfece519cf485eedafa6a71171dbffe58bc1b734628969ab
Binary file
@@ -1,6 +1,7 @@
1
1
  require 'gtk3'
2
2
  require "mireru/logger"
3
- require "mireru/widget"
3
+ require "mireru/window"
4
+ require "mireru/container"
4
5
 
5
6
  module Mireru
6
7
  module Command
@@ -19,66 +20,36 @@ module Mireru
19
20
 
20
21
  def run(arguments)
21
22
  if arguments.empty?
22
- file_container = Dir.glob("*")
23
+ files = Dir.glob("*")
24
+ file_container = ::Mireru::Container.new(files)
23
25
  elsif /\A(-h|--help)\z/ =~ arguments[0]
24
- message = <<-EOM
25
- #{USAGE}
26
- If no argument, then search current directory.
27
- Keybind:
28
- n: next
29
- p: prev
30
- q: quit
31
- EOM
32
- @logger.info(message)
26
+ write_help_message
33
27
  exit(true)
34
28
  else
35
- file_container = arguments
29
+ files = arguments
30
+ file_container = ::Mireru::Container.new(files)
36
31
  end
37
32
 
38
- file_container.select! {|f| support_file?(f) }
39
-
40
33
  if file_container.empty?
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)
34
+ write_empty_message
47
35
  exit(false)
48
36
  end
49
37
 
50
38
  file = file_container.shift
51
- widget = ::Mireru::Widget.create(file)
52
39
 
53
- window = Gtk::Window.new
54
- window.title = File.basename(file)
40
+ window = ::Mireru::Window.new
41
+ window.add_from_file(file)
55
42
 
56
43
  window.signal_connect("key_press_event") do |w, e|
57
44
  case e.keyval
58
45
  when Gdk::Keyval::GDK_KEY_n
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)
66
- window.resize(1, 1)
46
+ file = file_container.shift(file)
47
+ window.add_from_file(file)
67
48
  when Gdk::Keyval::GDK_KEY_p
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)
49
+ file = file_container.pop(file)
50
+ window.add_from_file(file)
76
51
  when Gdk::Keyval::GDK_KEY_r
77
- window.remove(widget)
78
- widget = ::Mireru::Widget.create(file)
79
- window.add(widget)
80
- window.show_all
81
- window.resize(1, 1)
52
+ window.add_from_file(file)
82
53
  when Gdk::Keyval::GDK_KEY_q
83
54
  Gtk.main_quit
84
55
  end
@@ -88,27 +59,29 @@ Support file types: png, gif, jpeg(jpg). The others are...yet.
88
59
  Gtk.main_quit
89
60
  end
90
61
 
91
- window.add(widget)
92
- window.show_all
93
-
94
62
  Gtk.main
95
63
  end
96
64
 
97
65
  private
98
- def support_file?(file)
99
- unless file
100
- return false
101
- end
102
-
103
- unless File.file?(file)
104
- return false
105
- end
106
-
107
- unless /\.(png|jpe?g|gif|txt|rb)$/i =~ file
108
- return false
109
- end
66
+ def write_help_message
67
+ message = <<-EOM
68
+ #{USAGE}
69
+ If no argument, then search current directory.
70
+ Keybind:
71
+ n: next
72
+ p: prev
73
+ q: quit
74
+ EOM
75
+ @logger.info(message)
76
+ end
110
77
 
111
- true
78
+ def write_empty_message
79
+ message = <<-EOM
80
+ Warning: valid file not found.
81
+ #{USAGE}
82
+ Support file types: png, gif, jpeg(jpg). The others are...yet.
83
+ EOM
84
+ @logger.error(message)
112
85
  end
113
86
  end
114
87
  end
@@ -0,0 +1,34 @@
1
+ module Mireru
2
+ class Container
3
+ def initialize(files=[])
4
+ @files = files.select {|file| file?(file) }
5
+ end
6
+
7
+ def empty?
8
+ @files.empty?
9
+ end
10
+
11
+ def pop(complement_file=nil)
12
+ @files.unshift(complement_file) if complement_file
13
+ @files.pop
14
+ end
15
+
16
+ def shift(complement_file=nil)
17
+ @files.push(complement_file) if complement_file
18
+ @files.shift
19
+ end
20
+
21
+ private
22
+ def file?(file)
23
+ unless file
24
+ return false
25
+ end
26
+
27
+ unless File.file?(file)
28
+ return false
29
+ end
30
+
31
+ true
32
+ end
33
+ end
34
+ end
@@ -1,3 +1,3 @@
1
1
  module Mireru
2
- VERSION = "0.0.6"
2
+ VERSION = "0.0.7"
3
3
  end
@@ -2,22 +2,40 @@ require 'gtk3'
2
2
 
3
3
  module Mireru
4
4
  class Widget
5
- def self.create(file)
6
- case File.extname(file)
7
- when /\A\.(png|jpe?g|gif)\z/i
5
+ class << self
6
+ def create(file)
7
+ case File.extname(file)
8
+ when /\A\.(png|jpe?g|gif)\z/i
9
+ image = Gtk::Image.new
10
+ image.file = file
11
+ widget = image
12
+ else
13
+ require 'gtksourceview3'
14
+ text = File.open(file).read
15
+ return sorry unless text.valid_encoding?
16
+ buffer = GtkSource::Buffer.new
17
+ buffer.text = text
18
+ view = GtkSource::View.new(buffer)
19
+ view.show_line_numbers = true
20
+ lang = GtkSource::LanguageManager.new.get_language('ruby')
21
+ view.buffer.language = lang
22
+ view.buffer.highlight_syntax = true
23
+ view.buffer.highlight_matching_brackets = true
24
+ view.editable = false
25
+ widget = view
26
+ end
27
+ widget
28
+ end
29
+
30
+ private
31
+ def sorry
8
32
  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."
33
+ base_dir = File.join(File.dirname(__FILE__), "..", "..")
34
+ images_dir = File.join(base_dir, "images")
35
+ image_path = File.expand_path(File.join(images_dir, "sorry.png"))
36
+ image.file = image_path
37
+ image
19
38
  end
20
- widget
21
39
  end
22
40
  end
23
41
  end
@@ -0,0 +1,15 @@
1
+ require 'gtk3'
2
+ require "mireru/widget"
3
+
4
+ module Mireru
5
+ class Window < Gtk::Window
6
+ def add_from_file(file)
7
+ self.remove(@widget) if @widget
8
+ @widget = Mireru::Widget.create(file)
9
+ self.add(@widget)
10
+ self.show_all
11
+ self.title = File.basename(file)
12
+ self.resize(1, 1)
13
+ end
14
+ end
15
+ end
@@ -19,6 +19,7 @@ Gem::Specification.new do |spec|
19
19
  spec.require_paths = ["lib"]
20
20
 
21
21
  spec.add_runtime_dependency("gtk3")
22
+ spec.add_runtime_dependency("gtksourceview3")
22
23
 
23
24
  spec.add_development_dependency("test-unit")
24
25
  spec.add_development_dependency("test-unit-notify")
@@ -0,0 +1,41 @@
1
+ require "mireru/container"
2
+
3
+ class TestContainer< Test::Unit::TestCase
4
+ def setup
5
+ @container = Mireru::Container.new
6
+ end
7
+
8
+ def test_no_argument
9
+ valid = @container.__send__(:file?, nil)
10
+ assert_false(valid)
11
+ end
12
+
13
+ def test_missing_file
14
+ valid = @container.__send__(:file?, "hoge")
15
+ assert_false(valid)
16
+ end
17
+
18
+ def test_no_extention_file_type
19
+ file = File.join(File.dirname(__FILE__), "fixtures", "no-extention")
20
+ valid = @container.__send__(:file?, file)
21
+ assert_true(valid)
22
+ end
23
+
24
+ def test_png_file
25
+ file = File.join(File.dirname(__FILE__), "fixtures", "nijip.png")
26
+ valid = @container.__send__(:file?, file)
27
+ assert_true(valid)
28
+ end
29
+
30
+ def test_txt_file
31
+ file = File.join(File.dirname(__FILE__), "fixtures", "LICENSE.txt")
32
+ valid = @container.__send__(:file?, file)
33
+ assert_true(valid)
34
+ end
35
+
36
+ def test_rb_file
37
+ file = File.join(File.dirname(__FILE__), "fixtures", "nijip.rb")
38
+ valid = @container.__send__(:file?, file)
39
+ assert_true(valid)
40
+ end
41
+ end
@@ -1,45 +1,4 @@
1
1
  require "mireru/command/mireru"
2
2
 
3
- module ValidTests
4
- def test_no_argument
5
- valid = @mireru.__send__(:support_file?, nil)
6
- assert_false(valid)
7
- end
8
-
9
- def test_missing_file
10
- valid = @mireru.__send__(:support_file?, "hoge")
11
- assert_false(valid)
12
- end
13
-
14
- def test_not_support_file_type
15
- file = File.join(File.dirname(__FILE__), "fixtures", "no-extention")
16
- valid = @mireru.__send__(:support_file?, file)
17
- assert_false(valid)
18
- end
19
-
20
- def test_png_file
21
- file = File.join(File.dirname(__FILE__), "fixtures", "nijip.png")
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)
35
- assert_true(valid)
36
- end
37
- end
38
-
39
3
  class TestMireru < Test::Unit::TestCase
40
- def setup
41
- @mireru = Mireru::Command::Mireru.new
42
- end
43
-
44
- include ValidTests
45
4
  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.6
4
+ version: 0.0.7
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-06 00:00:00.000000000 Z
11
+ date: 2013-04-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: gtk3
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - '>='
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: gtksourceview3
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: test-unit
29
43
  requirement: !ruby/object:Gem::Requirement
@@ -108,17 +122,21 @@ files:
108
122
  - README.md
109
123
  - Rakefile
110
124
  - bin/mireru
125
+ - images/sorry.png
111
126
  - lib/mireru.rb
112
127
  - lib/mireru/command/mireru.rb
128
+ - lib/mireru/container.rb
113
129
  - lib/mireru/logger.rb
114
130
  - lib/mireru/version.rb
115
131
  - lib/mireru/widget.rb
132
+ - lib/mireru/window.rb
116
133
  - mireru.gemspec
117
134
  - test/fixtures/LICENSE.txt
118
135
  - test/fixtures/nijip.png
119
136
  - test/fixtures/nijip.rb
120
137
  - test/fixtures/no-extention
121
138
  - test/run-test.rb
139
+ - test/test-container.rb
122
140
  - test/test-logger.rb
123
141
  - test/test-mireru.rb
124
142
  homepage: https://github.com/myokoym/mireru
@@ -151,6 +169,7 @@ test_files:
151
169
  - test/fixtures/nijip.rb
152
170
  - test/fixtures/no-extention
153
171
  - test/run-test.rb
172
+ - test/test-container.rb
154
173
  - test/test-logger.rb
155
174
  - test/test-mireru.rb
156
175
  has_rdoc: