mireru 0.2.1 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,38 +0,0 @@
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 size
12
- @files.size
13
- end
14
-
15
- def pop(complement_file=nil)
16
- @files.unshift(complement_file) if complement_file
17
- @files.pop
18
- end
19
-
20
- def shift(complement_file=nil)
21
- @files.push(complement_file) if complement_file
22
- @files.shift
23
- end
24
-
25
- private
26
- def file?(file)
27
- unless file
28
- return false
29
- end
30
-
31
- unless File.file?(file)
32
- return false
33
- end
34
-
35
- true
36
- end
37
- end
38
- end
@@ -1,43 +0,0 @@
1
- module Mireru
2
- module Widget
3
- class Thumbnail
4
- class << self
5
- def create(files, width, height)
6
- nums_in_a_row = Math.sqrt(files.size)
7
- rows = Gtk::Box.new(:vertical)
8
- files.each_slice(nums_in_a_row) do |a_row_files|
9
- row = Gtk::Box.new(:horizontal)
10
- a_row_files.each do |file|
11
- cell_width = width / nums_in_a_row
12
- cell_height = height / nums_in_a_row
13
- if Widget.image?(file)
14
- image = image_from_file(file, cell_width, cell_height)
15
- row.add(image)
16
- else
17
- label = label_from_file(file, cell_width, cell_height)
18
- row.add(label)
19
- end
20
- end
21
- rows.add(row)
22
- end
23
- rows
24
- end
25
-
26
- private
27
- def image_from_file(file, width=100, height=100)
28
- image = Gtk::Image.new
29
- pixbuf = Gdk::Pixbuf.new(file, width, height)
30
- image.pixbuf = pixbuf
31
- image
32
- end
33
-
34
- def label_from_file(file, width=100, height=100)
35
- label = Gtk::Label.new(File.basename(file))
36
- label.set_size_request(width, height)
37
- label.wrap = true
38
- label
39
- end
40
- end
41
- end
42
- end
43
- end
@@ -1,52 +0,0 @@
1
- require "mireru/container"
2
-
3
- class ContainerTest < Test::Unit::TestCase
4
- include MireruTestUtils
5
-
6
- def setup
7
- @container = Mireru::Container.new
8
- end
9
-
10
- def test_size
11
- assert_equal(0, @container.size)
12
- files = @container.instance_variable_get(:@files)
13
- files << __FILE__
14
- assert_equal(1, @container.size)
15
- files << __FILE__
16
- assert_equal(2, @container.size)
17
- end
18
-
19
- def test_no_argument
20
- valid = @container.__send__(:file?, nil)
21
- assert_false(valid)
22
- end
23
-
24
- def test_missing_file
25
- valid = @container.__send__(:file?, "hoge")
26
- assert_false(valid)
27
- end
28
-
29
- def test_no_extention_file_type
30
- file = File.join(fixtures_dir, "no-extention")
31
- valid = @container.__send__(:file?, file)
32
- assert_true(valid)
33
- end
34
-
35
- def test_png_file
36
- file = File.join(fixtures_dir, "nijip.png")
37
- valid = @container.__send__(:file?, file)
38
- assert_true(valid)
39
- end
40
-
41
- def test_txt_file
42
- file = File.join(fixtures_dir, "LICENSE.txt")
43
- valid = @container.__send__(:file?, file)
44
- assert_true(valid)
45
- end
46
-
47
- def test_rb_file
48
- file = File.join(fixtures_dir, "nijip.rb")
49
- valid = @container.__send__(:file?, file)
50
- assert_true(valid)
51
- end
52
- end
@@ -1,18 +0,0 @@
1
- require "mireru/widget/thumbnail"
2
-
3
- class ThumbnailTest < Test::Unit::TestCase
4
- include MireruTestUtils
5
-
6
- def test_image_from_file
7
- widget = Mireru::Widget::Thumbnail.__send__(:image_from_file,
8
- File.join(fixtures_dir,
9
- "nijip.png"))
10
- assert_equal(Gtk::Image, widget.class)
11
- end
12
-
13
- def test_label_from_fil
14
- widget = Mireru::Widget::Thumbnail.__send__(:label_from_file,
15
- __FILE__)
16
- assert_equal(Gtk::Label, widget.class)
17
- end
18
- end