hermitage 0.0.2.1 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -38,10 +38,11 @@ module Hermitage
38
38
  lists.each do |list|
39
39
  # Array of items in current list
40
40
  items = list.collect do |item|
41
- full_image_path = eval("item.#{options[:attribute_full_size]}")
42
- thumbnail_image_path = eval("item.#{options[:attribute_thumbnail]}")
43
- image = image_tag(thumbnail_image_path, class: options[:image_class])
44
- link_to(image, full_image_path, rel: 'hermitage', class: options[:link_class])
41
+ original_path = eval("item.#{options[:original]}")
42
+ thumbnail_path = eval("item.#{options[:thumbnail]}")
43
+ title = options[:title] ? eval("item.#{options[:title]}") : nil
44
+ image = image_tag(thumbnail_path, class: options[:image_class])
45
+ link_to(image, original_path, rel: 'hermitage', class: options[:link_class], title: title)
45
46
  end
46
47
 
47
48
  # Convert these items into content tag string
@@ -20,8 +20,13 @@ end
20
20
  class DummyImage
21
21
  attr_accessor :file
22
22
  def initialize(name)
23
+ @name = name
23
24
  @file = DummyFile.new(name)
24
25
  end
26
+
27
+ def description
28
+ "description of #{@name}"
29
+ end
25
30
  end
26
31
 
27
32
  class DummyPhoto < DummyBase
@@ -0,0 +1,28 @@
1
+ require 'spec_helper'
2
+ require 'features_helper'
3
+
4
+ describe 'bottom_panel', type: :feature, js: true do
5
+ before(:each) do
6
+ Hermitage.configs[:default].merge!({ title: 'description' })
7
+ visit images_path
8
+ page.first('a[rel="hermitage"]').click
9
+ page.should have_css('img.current')
10
+ end
11
+
12
+ # I don't want any influence of this config to another tests
13
+ after(:each) { Hermitage.configs[:default] = Hermitage::Defaults.to_hash() }
14
+
15
+ it 'has bottom panel' do
16
+ page.should have_css('#hermitage .bottom-panel')
17
+ end
18
+
19
+ it 'has description of image' do
20
+ page.should have_css('#hermitage .bottom-panel .text')
21
+ jquery_text('#hermitage .bottom-panel .text').should == 'description of 0'
22
+ end
23
+
24
+ it 'affects upon image size and position' do
25
+ top('.current').should == 221 # if window height is 768px
26
+ end
27
+
28
+ end
@@ -41,35 +41,63 @@ describe 'navigation', type: :feature, js: true do
41
41
  end
42
42
  end
43
43
 
44
+ context 'with loop' do
45
+ before(:each) do
46
+ visit images_path
47
+ page.first('a[href="/assets/1-full.png"]').click
48
+ page.should have_css('img.current') # Wait for loading before testing
49
+ end
44
50
 
45
- before(:each) do
46
- visit images_path
47
- page.first('a[href="/assets/1-full.png"]').click
48
- page.should have_css('img.current') # Wait for loading before testing
49
- end
51
+ describe 'by clicking on image' do
52
+ describe 'at the right side' do
53
+ let(:click_action) { Proc.new { click_at_right('img.current') } }
54
+ it_behaves_like 'navigation to next'
55
+ end
50
56
 
51
- describe 'by clicking on image' do
52
- describe 'at the right side' do
53
- let(:click_action) { Proc.new { click_at_right('img.current') } }
54
- it_behaves_like 'navigation to next'
57
+ describe 'at the left side' do
58
+ let(:click_action) { Proc.new { click_at_left('img.current') } }
59
+ it_behaves_like 'navigation to previous'
60
+ end
55
61
  end
56
62
 
57
- describe 'at the left side' do
58
- let(:click_action) { Proc.new { click_at_left('img.current') } }
59
- it_behaves_like 'navigation to previous'
63
+ describe 'by clicking on navigation button' do
64
+ describe 'right' do
65
+ let(:click_action) { Proc.new { page.find('#navigation-right').click() } }
66
+ it_behaves_like 'navigation to next'
67
+ end
68
+
69
+ describe 'left' do
70
+ let(:click_action) { Proc.new { page.find('#navigation-left').click() } }
71
+ it_behaves_like 'navigation to previous'
72
+ end
60
73
  end
61
74
  end
62
75
 
63
- describe 'by clicking on navigation button' do
64
- describe 'right' do
65
- let(:click_action) { Proc.new { page.find('#navigation-right').click() } }
66
- it_behaves_like 'navigation to next'
76
+ context 'without loop' do
77
+ before(:each) do
78
+ visit images_path
79
+ evaluate_script('hermitage.looped = false')
80
+ page.first("a[href='/assets/#{image}-full.png']").click
81
+ page.should have_css('img.current')
82
+ end
83
+
84
+ describe 'first image' do
85
+ let(:image) { "0" }
86
+ it { page.should_not have_css('#navigation-left') }
87
+ it { page.should have_css('#navigation-right') }
88
+ end
89
+
90
+ describe 'middle image' do
91
+ let(:image) { "1" }
92
+ it { page.should have_css('#navigation-left') }
93
+ it { page.should have_css('#navigation-right') }
67
94
  end
68
95
 
69
- describe 'left' do
70
- let(:click_action) { Proc.new { page.find('#navigation-left').click() } }
71
- it_behaves_like 'navigation to previous'
96
+ describe 'last image' do
97
+ let(:image) { "2" }
98
+ it { page.should have_css('#navigation-left') }
99
+ it { page.should_not have_css('#navigation-right') }
72
100
  end
73
101
  end
74
-
102
+
75
103
  end
@@ -0,0 +1,51 @@
1
+ require 'spec_helper'
2
+ require 'features_helper'
3
+
4
+ describe 'resize', type: :feature, js: true do
5
+ before(:each) do
6
+ visit images_path
7
+ page.first('a[rel="hermitage"]').click
8
+ page.should have_css('img.current')
9
+ end
10
+
11
+ shared_examples 'resize' do
12
+ before(:each) do
13
+ page.driver.resize(window_width, window_height)
14
+ sleep(1) # Wait for animation complete
15
+ end
16
+
17
+ it 'adjusts image' do
18
+ width('.current').should == expected_width
19
+ height('.current').should == expected_height
20
+ top('.current').should == expected_top
21
+ left('.current').should == expected_left
22
+ end
23
+
24
+ it 'adjusts navigation buttons' do
25
+ css('#navigation-left', 'line-height').should == expected_line_height
26
+ css('#navigation-right', 'line-height').should == expected_line_height
27
+ end
28
+ end
29
+
30
+ describe 'make window smaller' do
31
+ let(:window_width) { 300 }
32
+ let(:window_height) { 300 }
33
+ let(:expected_width) { 200 }
34
+ let(:expected_height) { 200 }
35
+ let(:expected_top) { 50 }
36
+ let(:expected_left) { 50 }
37
+ let(:expected_line_height) { '300px' }
38
+ it_behaves_like 'resize'
39
+
40
+ describe 'then make window larger' do
41
+ let(:window_width) { 500 }
42
+ let(:window_height) { 500 }
43
+ let(:expected_width) { 256 }
44
+ let(:expected_height) { 256 }
45
+ let(:expected_top) { 122 }
46
+ let(:expected_left) { 122 }
47
+ let(:expected_line_height) { '500px' }
48
+ it_behaves_like 'resize'
49
+ end
50
+ end
51
+ end
@@ -11,18 +11,18 @@ describe 'scale', type: :feature, js: true do
11
11
  end
12
12
 
13
13
  context 'exceed the bounds of window by width' do
14
- let(:window_width) { 400 }
14
+ let(:window_width) { 300 }
15
15
  let(:window_height) { 1000 }
16
16
 
17
17
  it 'scales the image' do
18
- width('.current').should == 176
19
- height('.current').should == 176
18
+ width('.current').should == 200
19
+ height('.current').should == 200
20
20
  end
21
21
  end
22
22
 
23
23
  context 'exceed the bounds of window by height' do
24
24
  let(:window_width) { 1000 }
25
- let(:window_height) { 300 }
25
+ let(:window_height) { 200 }
26
26
 
27
27
  it 'scales the image' do
28
28
  width('.current').should == 200
@@ -31,12 +31,12 @@ describe 'scale', type: :feature, js: true do
31
31
  end
32
32
 
33
33
  context 'exceed the bounds of window by both dimensions' do
34
- let(:window_width) { 400 }
34
+ let(:window_width) { 250 }
35
35
  let(:window_height) { 300 }
36
36
 
37
37
  it 'scales the image to the minimum scale coefficient' do
38
- width('.current').should == 176
39
- height('.current').should == 176
38
+ width('.current').should == 150
39
+ height('.current').should == 150
40
40
  end
41
41
  end
42
42
 
@@ -50,20 +50,20 @@ describe 'scale', type: :feature, js: true do
50
50
  end
51
51
 
52
52
  context 'by width' do
53
- let(:window_width) { 200 }
53
+ let(:window_width) { 150 }
54
54
  let(:window_height) { 1000 }
55
55
  it_behaves_like 'minimum allowed size'
56
56
  end
57
57
 
58
58
  context 'by height' do
59
59
  let(:window_width) { 1000 }
60
- let(:window_height) { 200 }
60
+ let(:window_height) { 90 }
61
61
  it_behaves_like 'minimum allowed size'
62
62
  end
63
63
 
64
64
  context 'by both dimensions' do
65
- let(:window_width) { 200 }
66
- let(:window_height) { 200 }
65
+ let(:window_width) { 150 }
66
+ let(:window_height) { 90 }
67
67
  it_behaves_like 'minimum allowed size'
68
68
  end
69
69
  end
@@ -14,80 +14,51 @@ describe 'viewer_customization', type: :feature, js: true do
14
14
  # There will be sleep(1) in tests where we should wait until fade in animation is ended
15
15
  end
16
16
 
17
- context 'zIndex' do
18
- let(:js) { 'hermitage.zIndex = 5'}
19
- it { css('#hermitage', 'z-index').should == '5' }
20
- end
21
-
22
17
  context 'darkening.opacity' do
23
18
  let(:js) { 'hermitage.darkening.opacity = 0.5'}
24
19
  before(:each) { sleep(1) }
25
20
  it { css('#overlay', 'opacity').should == '0.5' }
26
21
  end
27
22
 
28
- context 'darkening.color' do
29
- let(:js) { 'hermitage.darkening.color = "#FAFAFA"' }
23
+ context 'darkening.styles' do
24
+ let(:js) { 'hermitage.darkening.styles = { backgroundColor: "#FAFAFA" }' }
30
25
  it { css('#overlay', 'background-color').should == 'rgb(250, 250, 250)' }
31
26
  end
32
27
 
33
- context 'navigationButton.enabled' do
34
- let(:js) { 'hermitage.navigationButton.enabled = false' }
28
+ context 'navigationButtons.enabled' do
29
+ let(:js) { 'hermitage.navigationButtons.enabled = false' }
35
30
  it { should_not have_css('#navigation-left') }
36
31
  it { should_not have_css('#navigation-right') }
37
32
  end
38
33
 
39
- context 'navigationButton.color' do
40
- let(:js) { 'hermitage.navigationButton.color = "#000"'}
41
-
42
- shared_examples 'navigation button' do
43
- it 'sets border color' do
44
- css(selector, 'border-top-color').should == 'rgb(0, 0, 0)'
45
- css(selector, 'border-right-color').should == 'rgb(0, 0, 0)'
46
- css(selector, 'border-bottom-color').should == 'rgb(0, 0, 0)'
47
- css(selector, 'border-left-color').should == 'rgb(0, 0, 0)'
48
- end
49
- end
50
-
51
- context 'left' do
52
- let(:selector) { '#navigation-left' }
53
- it_behaves_like 'navigation button'
54
- end
55
-
56
- context 'right' do
57
- let(:selector) { '#navigation-right' }
58
- it_behaves_like 'navigation button'
59
- end
34
+ context 'navigationButtons.styles' do
35
+ let(:js) { 'hermitage.navigationButtons.styles = { backgroundColor: "#000", width: "100px" }'}
36
+ it { css('#navigation-left', 'background-color').should == 'rgb(0, 0, 0)' }
37
+ it { css('#navigation-left', 'width').should == '100px' }
38
+ it { css('#navigation-right', 'background-color').should == 'rgb(0, 0, 0)' }
39
+ it { css('#navigation-right', 'width').should == '100px' }
60
40
  end
61
41
 
62
- context 'navigationButton.width' do
63
- let(:js) { 'hermitage.navigationButton.width = 100' }
64
- it { css('#navigation-left', 'width').should == '100px' }
42
+ context 'navigationButtons.next.styles' do
43
+ let(:js) { 'hermitage.navigationButtons.next.styles = { width: "100px" }'}
44
+ it { css('#navigation-left', 'width').should == '50px' }
65
45
  it { css('#navigation-right', 'width').should == '100px' }
66
46
  end
67
47
 
68
- context 'navigationButton.borderRadius' do
69
- let(:js) { 'hermitage.navigationButton.borderRadius = 5' }
48
+ context 'navigationButtons.previous.styles' do
49
+ let(:js) { 'hermitage.navigationButtons.previous.styles = { width: "100px" }'}
50
+ it { css('#navigation-left', 'width').should == '100px' }
51
+ it { css('#navigation-right', 'width').should == '50px' }
52
+ end
70
53
 
71
- it 'sets border radiuses for left button' do
72
- css('#navigation-left', 'border-top-left-radius').should == '5px'
73
- css('#navigation-left', 'border-bottom-left-radius').should == '5px'
74
- css('#navigation-left', 'border-top-right-radius').should == '0px'
75
- css('#navigation-left', 'border-bottom-right-radius').should == '0px'
76
- end
77
-
78
- it 'sets border radiuses for right button' do
79
- css('#navigation-right', 'border-top-left-radius').should == '0px'
80
- css('#navigation-right', 'border-bottom-left-radius').should == '0px'
81
- css('#navigation-right', 'border-top-right-radius').should == '5px'
82
- css('#navigation-right', 'border-bottom-right-radius').should == '5px'
83
- end
54
+ context 'navigationButtons.next.text' do
55
+ let(:js) { 'hermitage.navigationButtons.next.text = ">"'}
56
+ it { jquery_text('#navigation-right').should == '>' }
84
57
  end
85
-
86
- context 'navigationButton.margin' do
87
- let(:js) { 'hermitage.navigationButton.margin = 30' }
88
- before(:each) { sleep(1) }
89
- it { css('#navigation-left', 'left').should == "#{left('.current') - 30 - width('#navigation-left')}px" }
90
- it { css('#navigation-right', 'left').should == "#{left('.current') + width('.current') + 30}px" }
58
+
59
+ context 'navigationButtons.previous.text' do
60
+ let(:js) { 'hermitage.navigationButtons.previous.text = "<"'}
61
+ it { jquery_text('#navigation-left').should == '<' }
91
62
  end
92
63
 
93
64
  context 'closeButton.enabled' do
@@ -97,37 +68,32 @@ describe 'viewer_customization', type: :feature, js: true do
97
68
 
98
69
  context 'closeButton.text' do
99
70
  let(:js) { 'hermitage.closeButton.text = "Close"' }
100
- it { text('#close-button').should == 'Close' }
71
+ it { jquery_text('#close-button').should == 'Close' }
101
72
  end
102
73
 
103
- context 'closeButton.color' do
104
- let(:js) { 'hermitage.closeButton.color = "#777"' }
74
+ context 'closeButton.styles' do
75
+ let(:js) { 'hermitage.closeButton.styles = { color: "#777" }' }
105
76
  it { css('#close-button', 'color').should == 'rgb(119, 119, 119)' }
106
77
  end
107
78
 
108
- context 'closeButton.fontSize' do
109
- let(:js) { 'hermitage.closeButton.fontSize = 10' }
110
- it { css('#close-button', 'font-size').should == '10px' }
111
- end
112
-
113
- context 'windowPadding.x' do
114
- let(:js) { 'hermitage.windowPadding.x = 100'}
115
- let(:before_click) { Proc.new{ page.driver.resize(500, 1000) } }
116
-
117
- it 'scales the image' do
118
- width('.current').should == 176
119
- height('.current').should == 176
79
+ context 'image.styles' do
80
+ let(:js) { 'hermitage.image.styles = { border: "5px solid #000" }' }
81
+ it 'sets all borders width to 5px' do
82
+ css('.current', 'border-top-width').should == '5px'
83
+ css('.current', 'border-right-width').should == '5px'
84
+ css('.current', 'border-bottom-width').should == '5px'
85
+ css('.current', 'border-left-width').should == '5px'
120
86
  end
121
87
  end
122
88
 
123
- context 'windowPadding.y' do
124
- let(:js) { 'hermitage.windowPadding.y = 100'}
125
- let(:before_click) { Proc.new{ page.driver.resize(1000, 400) } }
89
+ context 'bottomPanel.styles' do
90
+ let(:js) { 'hermitage.bottomPanel.styles = { backgroundColor: "#777" }' }
91
+ it { css('#hermitage .bottom-panel', 'background-color').should == 'rgb(119, 119, 119)' }
92
+ end
126
93
 
127
- it 'scales the image' do
128
- width('.current').should == 200
129
- height('.current').should == 200
130
- end
94
+ context 'bottomPanel.text.styles' do
95
+ let(:js) { 'hermitage.bottomPanel.text.styles = { textAlign: "left" }' }
96
+ it { css('#hermitage .bottom-panel .text', 'text-align').should == 'left' }
131
97
  end
132
98
 
133
99
  shared_examples 'image scaled to the minimum allowed size' do
@@ -139,13 +105,13 @@ describe 'viewer_customization', type: :feature, js: true do
139
105
 
140
106
  context 'minimumSize.width' do
141
107
  let(:js) { 'hermitage.minimumSize.width = 200'}
142
- let(:before_click) { Proc.new{ page.driver.resize(300, 1000) } }
108
+ let(:before_click) { Proc.new{ page.driver.resize(250, 1000) } }
143
109
  it_behaves_like 'image scaled to the minimum allowed size'
144
110
  end
145
111
 
146
112
  context 'minimumSize.width' do
147
113
  let(:js) { 'hermitage.minimumSize.height = 200'}
148
- let(:before_click) { Proc.new{ page.driver.resize(1000, 250) } }
114
+ let(:before_click) { Proc.new{ page.driver.resize(1000, 150) } }
149
115
  it_behaves_like 'image scaled to the minimum allowed size'
150
116
  end
151
117
 
@@ -15,7 +15,7 @@ describe 'viewer', type: :feature, js: true do
15
15
  page.should have_css('div#hermitage div#overlay')
16
16
  end
17
17
 
18
- it 'has full size image' do
18
+ it 'has original image' do
19
19
  page.should have_css("div#hermitage img[src='/assets/0-full.png']")
20
20
  end
21
21
 
@@ -37,6 +37,6 @@ def click_at_right(selector)
37
37
  click_at(selector, 0.75, 0.5)
38
38
  end
39
39
 
40
- def text(selector)
40
+ def jquery_text(selector)
41
41
  evaluate_script("$('#{selector}').text()")
42
42
  end
@@ -4,8 +4,9 @@ describe Hermitage::Defaults do
4
4
  describe '#to_hash' do
5
5
  it "returns hash with symbolized constants' names as keys" do
6
6
  Hermitage::Defaults.to_hash().should == {
7
- attribute_full_size: 'file.url',
8
- attribute_thumbnail: 'file.url(:thumbnail)',
7
+ original: 'file.url',
8
+ thumbnail: 'file.url(:thumbnail)',
9
+ title: nil,
9
10
  list_tag: :ul,
10
11
  item_tag: :li,
11
12
  list_class: 'thumbnails',
@@ -19,12 +19,18 @@ describe Hermitage::ViewHelpers, type: :helper do
19
19
 
20
20
  context 'with options' do
21
21
 
22
- context 'attribute_full_size and attribute_thumbnail' do
23
- subject { template.render_gallery_for images, attribute_full_size: 'photo', attribute_thumbnail: 'photo(:thumbnail)' }
22
+ context 'original and thumbnail' do
23
+ subject { template.render_gallery_for images, original: 'photo', thumbnail: 'photo(:thumbnail)' }
24
24
  let(:images) { Array.new(2) { |i| DummyPhoto.new(i.to_s) } }
25
25
  it { should == expected }
26
26
  end
27
27
 
28
+ context 'title' do
29
+ subject { template.render_gallery_for images, title: 'description' }
30
+ let(:expected) { '<ul class="thumbnails"><li class="span4"><a class="thumbnail" href="/assets/0-full.png" rel="hermitage" title="description of 0"><img alt="0 thumbnail" src="/assets/0-thumbnail.png" /></a></li><li class="span4"><a class="thumbnail" href="/assets/1-full.png" rel="hermitage" title="description of 1"><img alt="1 thumbnail" src="/assets/1-thumbnail.png" /></a></li></ul>' }
31
+ it { should == expected }
32
+ end
33
+
28
34
  context 'list_tag and item_tag' do
29
35
  subject { template.render_gallery_for images, list_tag: :div, item_tag: :div }
30
36
  let(:expected) { '<div class="thumbnails"><div class="span4"><a class="thumbnail" href="/assets/0-full.png" rel="hermitage"><img alt="0 thumbnail" src="/assets/0-thumbnail.png" /></a></div><div class="span4"><a class="thumbnail" href="/assets/1-full.png" rel="hermitage"><img alt="1 thumbnail" src="/assets/1-thumbnail.png" /></a></div></div>' }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hermitage
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2.1
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-09-05 00:00:00.000000000 Z
12
+ date: 2013-09-08 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
@@ -187,7 +187,7 @@ dependencies:
187
187
  - - ! '>='
188
188
  - !ruby/object:Gem::Version
189
189
  version: '0'
190
- description: Ruby library for generation of image galleries.
190
+ description: Ruby library for image galleries generation.
191
191
  email:
192
192
  - immaculate.pine@gmail.com
193
193
  executables: []
@@ -263,9 +263,11 @@ files:
263
263
  - spec/dummy/public/422.html
264
264
  - spec/dummy/public/500.html
265
265
  - spec/dummy/public/favicon.ico
266
+ - spec/features/bottom_panel_spec.rb
266
267
  - spec/features/engine_spec.rb
267
268
  - spec/features/navigation_spec.rb
268
269
  - spec/features/render_gallery_spec.rb
270
+ - spec/features/resize_spec.rb
269
271
  - spec/features/scale_spec.rb
270
272
  - spec/features/viewer_customization_spec.rb
271
273
  - spec/features/viewer_spec.rb
@@ -300,8 +302,8 @@ rubyforge_project:
300
302
  rubygems_version: 1.8.25
301
303
  signing_key:
302
304
  specification_version: 3
303
- summary: Ruby library for generation of image galleries (thumbnails and full size
304
- images viewer).
305
+ summary: Ruby library for image galleries generation (thumbnails and original images
306
+ viewer).
305
307
  test_files:
306
308
  - spec/dummy/README.rdoc
307
309
  - spec/dummy/Rakefile
@@ -352,9 +354,11 @@ test_files:
352
354
  - spec/dummy/public/422.html
353
355
  - spec/dummy/public/500.html
354
356
  - spec/dummy/public/favicon.ico
357
+ - spec/features/bottom_panel_spec.rb
355
358
  - spec/features/engine_spec.rb
356
359
  - spec/features/navigation_spec.rb
357
360
  - spec/features/render_gallery_spec.rb
361
+ - spec/features/resize_spec.rb
358
362
  - spec/features/scale_spec.rb
359
363
  - spec/features/viewer_customization_spec.rb
360
364
  - spec/features/viewer_spec.rb