hermitage 0.0.4.1 → 0.0.5.2

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.md CHANGED
@@ -1,3 +1,10 @@
1
+ ### 0.0.5 ###
2
+
3
+ * Loading animation added
4
+ * Original, thumbnail and title options can be lambdas
5
+ * Bug with looped gallery with the only one image fixed
6
+ * Wrong behavior with Turbolinks when user clicks back in browser fixed
7
+
1
8
  ### 0.0.4.1 ###
2
9
 
3
10
  * RailsRenderCore is not a child of ActionView::Base anymore
data/README.md CHANGED
@@ -5,6 +5,8 @@
5
5
 
6
6
  Ruby library for generation of image galleries (thumbnails and original images viewer).
7
7
 
8
+ There is a [demo](http://immaculatepine.github.io/hermitage/demo/default.html) with customization examples at project's [homepage](http://immaculatepine.github.io/hermitage/).
9
+
8
10
  ## Requirements
9
11
 
10
12
  Hermitage requires Ruby on Rails version >= 3.1 with support of jQuery and CoffeeScript (jquery-rails and coffee-rails gems, respectively).
@@ -69,6 +71,10 @@ If the only method returns both paths according to passed parameters you can spe
69
71
 
70
72
  render_gallery_for @posts, original: 'attachment(:full)', thumbnail: 'attachment(:thumbnail)'
71
73
 
74
+ Also you can specify those values by lambdas:
75
+
76
+ render_gallery_for @posts, original: -> post { post.attachment(:full) }, thumbnail: -> post { post.attachment(:thumbnail) }
77
+
72
78
  #### Markup
73
79
 
74
80
  Hermitage renders markup that will look nice with Twitter Bootstrap by default:
@@ -140,8 +146,8 @@ You can overwrite :default config. These changes will be applied to all the gall
140
146
  Uncoment the following lines in config/initializers/hermitage.rb file and make some changes here:
141
147
 
142
148
  Hermitage.configure :default do
143
- original 'image.url(:medium)'
144
- thumbnail 'image.url(:small)'
149
+ original -> item { item.image.url(:medium) }
150
+ thumbnail -> item { image.url(:small) }
145
151
  end
146
152
 
147
153
  Now Hermitage will use `image.url` method with :medium or :small argument to get images for the gallery.
@@ -170,11 +176,13 @@ Then your config/initializers/hermitage.rb could looks like this:
170
176
 
171
177
  # Some rules for :default config if needed...
172
178
 
179
+ # Setup by lambdas...
173
180
  Hermitage.configure :pictures do
174
- original 'image_path'
175
- thumbnail 'image_path(:small)'
181
+ original -> item { item.image_path }
182
+ thumbnail -> item { item.image_path(:small) }
176
183
  end
177
184
 
185
+ # ...or by strings
178
186
  Hermitage.configure :posts do
179
187
  original 'attachment'
180
188
  thumbnail 'attachment(:tiny)'
@@ -223,6 +231,9 @@ You can customize the following parameters:
223
231
  * `image.styles` - any custom CSS for current image
224
232
  * `bottomPanel.styles` - any custom CSS for bottom panel
225
233
  * `bottomPanel.text.styles` - any custom CSS for text block of bottom panel
234
+ * `loader.image` - custom image for loader
235
+ * `loader.timeout` - timeout before loader animation should appear
236
+ * `loader.styles` - custom styles for loader
226
237
  * `minimumSize.width` - minimum width of scaled image, px
227
238
  * `minimumSize.height` - minimum height of scaled image, px
228
239
  * `animationDuration` - duration of UI animations, ms
@@ -115,6 +115,15 @@ root.hermitage =
115
115
  color: '#FAFAFA'
116
116
  styles: {}
117
117
 
118
+ loaderTimer: undefined
119
+ loader:
120
+ default:
121
+ attributes: { class: 'loader' }
122
+ styles: {}
123
+ styles: {}
124
+ image: '<%= asset_path 'hermitage-loader.gif' %>'
125
+ timeout: 100
126
+
118
127
  # Minimum size of scaled image, px
119
128
  minimumSize:
120
129
  width: 100
@@ -285,6 +294,26 @@ createBotomPanel = ->
285
294
  createElement($('<div>'), hermitage.bottomPanel.text)
286
295
  .appendTo(bottomPanel)
287
296
 
297
+ createLoader = ->
298
+ loadImage hermitage.loader.image, ->
299
+ createElement($('<img>'), hermitage.loader)
300
+ .attr('src', hermitage.loader.image)
301
+ .appendTo($('#hermitage'))
302
+ .hide()
303
+ .center()
304
+
305
+ clearLoaderTimer = -> clearTimeout(hermitage.loaderTimer) if hermitage.loaderTimer
306
+
307
+ showLoader = ->
308
+ clearLoaderTimer()
309
+ hermitage.loaderTimer = setTimeout \
310
+ -> $('#hermitage .loader').show(),
311
+ hermitage.loader.timeout
312
+
313
+ hideLoader = ->
314
+ clearLoaderTimer()
315
+ $('#hermitage .loader').hide()
316
+
288
317
  # Shows original image of the chosen one
289
318
  openGallery = (image) ->
290
319
  $('#hermitage')
@@ -296,11 +325,14 @@ openGallery = (image) ->
296
325
  createLeftNavigationButton()
297
326
  createCloseButton()
298
327
  createBotomPanel()
328
+ createLoader()
299
329
 
300
330
  showImage(indexOfImage(image))
301
331
 
302
332
  # Shows image with specified index from images array
303
333
  showImage = (index, direction = undefined) ->
334
+ showLoader()
335
+
304
336
  img = createElement($('<img />'), hermitage.image)
305
337
  .attr('src', sourceFor(index))
306
338
  .hide()
@@ -366,7 +398,6 @@ closeGallery = ->
366
398
  $('#hermitage').hide()
367
399
  .empty()
368
400
 
369
-
370
401
  # Moves image to correct position and sets correct size.
371
402
  # Then it calls adjusting methods for navigation and close buttons.
372
403
  # Attributes:
@@ -377,7 +408,6 @@ closeGallery = ->
377
408
  # * 'right' - move from the right bound of screen
378
409
  # * 'left' - move from the left bound of screen
379
410
  adjustImage = (withAnimation = false, image = undefined, direction = undefined) ->
380
-
381
411
  if image is undefined
382
412
  image = $('#hermitage img.current')
383
413
  return unless image.length is 1
@@ -426,9 +456,12 @@ adjustImage = (withAnimation = false, image = undefined, direction = undefined)
426
456
  else
427
457
  image.fadeIn(hermitage.animationDuration)
428
458
 
459
+ hideLoader()
460
+
429
461
  adjustNavigationButtons(withAnimation, image)
430
462
  adjustCloseButton(withAnimation, image)
431
463
  adjustBottomPanel(withAnimation)
464
+ $('#hermitage .loader').center()
432
465
 
433
466
  # Moves navigation buttons to proper positions
434
467
  adjustNavigationButtons = (withAnimation, current) ->
@@ -479,12 +512,16 @@ adjustBottomPanel = (withAnimation) ->
479
512
  panel.fadeIn(hermitage.animationDuration)
480
513
 
481
514
  canShowNextAfter = (index) ->
515
+ return false if hermitage.images.length < 2
516
+
482
517
  if index < hermitage.images.length - 1
483
518
  true
484
519
  else
485
520
  hermitage.looped
486
521
 
487
522
  canShowPreviousBefore = (index) ->
523
+ return false if hermitage.images.length < 2
524
+
488
525
  if index > 0
489
526
  true
490
527
  else
@@ -522,4 +559,4 @@ previousIndexBefore = (index) ->
522
559
 
523
560
  # Initialize gallery on page load
524
561
  $(document).ready(hermitage.init)
525
- $(document).on('page:load', hermitage.init)
562
+ $(document).on('page:change', hermitage.init)
data/hermitage.gemspec CHANGED
@@ -10,7 +10,7 @@ Gem::Specification.new do |spec|
10
10
  spec.email = ['immaculate.pine@gmail.com']
11
11
  spec.description = %q{Ruby library for image galleries generation.}
12
12
  spec.summary = %q{Ruby library for image galleries generation (thumbnails and original images viewer).}
13
- spec.homepage = 'https://github.com/ImmaculatePine/hermitage'
13
+ spec.homepage = 'http://immaculatepine.github.io/hermitage/'
14
14
  spec.license = 'MIT'
15
15
 
16
16
  spec.files = `git ls-files`.split($/)
@@ -4,8 +4,8 @@
4
4
  # You can configure any of its options and they will be applied for every rendering.
5
5
  #
6
6
  # Hermitage.configure :default do
7
- # original 'file.url'
8
- # thumbnail 'file.url(:thumbnail)'
7
+ # original -> item { item.file.url }
8
+ # thumbnail -> item { item.file.url(:thumbnail) }
9
9
  # title nil
10
10
  # list_tag :ul
11
11
  # item_tag :li
@@ -37,11 +37,21 @@ module Hermitage
37
37
  end
38
38
  end
39
39
 
40
+ # Returns value of item's attribute
41
+ def value_for(item, option)
42
+ attribute = @options[option]
43
+ if attribute.is_a? Proc
44
+ attribute.call(item)
45
+ else
46
+ eval("item.#{attribute}")
47
+ end
48
+ end
49
+
40
50
  # Renders link to the specific image in a gallery
41
51
  def render_link_for(item)
42
- original_path = eval("item.#{@options[:original]}")
43
- thumbnail_path = eval("item.#{@options[:thumbnail]}")
44
- title = @options[:title] ? eval("item.#{@options[:title]}") : nil
52
+ original_path = value_for(item, :original)
53
+ thumbnail_path = value_for(item, :thumbnail)
54
+ title = @options[:title] ? value_for(item, :title) : nil
45
55
  image = @template.image_tag(thumbnail_path, class: @options[:image_class])
46
56
  @template.link_to(image, original_path, rel: 'hermitage', class: @options[:link_class], title: title)
47
57
  end
@@ -1,3 +1,3 @@
1
1
  module Hermitage
2
- VERSION = '0.0.4.1'
2
+ VERSION = '0.0.5.2'
3
3
  end
@@ -20,15 +20,31 @@ describe Hermitage::ViewHelpers, type: :helper do
20
20
  context 'with options' do
21
21
 
22
22
  context 'original and thumbnail' do
23
- subject { template.render_gallery_for images, original: 'photo', thumbnail: 'photo(:thumbnail)' }
24
23
  let(:images) { Array.new(2) { |i| DummyPhoto.new(i.to_s) } }
25
- it { should == expected }
24
+
25
+ context 'by string' do
26
+ subject { template.render_gallery_for images, original: 'photo', thumbnail: 'photo(:thumbnail)' }
27
+ it { should == expected }
28
+ end
29
+
30
+ context 'by proc' do
31
+ subject { template.render_gallery_for images, original: -> item { item.photo }, thumbnail: -> item { item.photo(:thumbnail) } }
32
+ it { should == expected }
33
+ end
26
34
  end
27
35
 
28
36
  context 'title' do
29
- subject { template.render_gallery_for images, title: 'description' }
30
37
  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 }
38
+
39
+ context 'by string' do
40
+ subject { template.render_gallery_for images, title: 'description' }
41
+ it { should == expected }
42
+ end
43
+
44
+ context 'by proc' do
45
+ subject { template.render_gallery_for images, title: -> item { item.description } }
46
+ it { should == expected }
47
+ end
32
48
  end
33
49
 
34
50
  context 'list_tag and item_tag' do
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.4.1
4
+ version: 0.0.5.2
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-11 00:00:00.000000000 Z
12
+ date: 2013-09-13 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
@@ -203,7 +203,8 @@ files:
203
203
  - LICENSE.txt
204
204
  - README.md
205
205
  - Rakefile
206
- - app/assets/javascripts/hermitage.js.coffee
206
+ - app/assets/images/hermitage-loader.gif
207
+ - app/assets/javascripts/hermitage.js.coffee.erb
207
208
  - config.ru
208
209
  - hermitage.gemspec
209
210
  - lib/generators/hermitage/install_generator.rb
@@ -282,7 +283,7 @@ files:
282
283
  - spec/lib/hermitage/view_helpers_spec.rb
283
284
  - spec/lib/hermitage_spec.rb
284
285
  - spec/spec_helper.rb
285
- homepage: https://github.com/ImmaculatePine/hermitage
286
+ homepage: http://immaculatepine.github.io/hermitage/
286
287
  licenses:
287
288
  - MIT
288
289
  post_install_message: