hermitage 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (80) hide show
  1. data/.gitignore +20 -0
  2. data/.rspec +2 -0
  3. data/.rvmrc +1 -0
  4. data/.travis.yml +4 -0
  5. data/Gemfile +4 -0
  6. data/LICENSE.txt +22 -0
  7. data/README.md +175 -0
  8. data/Rakefile +7 -0
  9. data/app/assets/javascripts/hermitage.js.coffee +263 -0
  10. data/config.ru +7 -0
  11. data/hermitage.gemspec +33 -0
  12. data/lib/generators/hermitage/install_generator.rb +17 -0
  13. data/lib/generators/hermitage/templates/hermitage.rb +29 -0
  14. data/lib/hermitage/defaults.rb +31 -0
  15. data/lib/hermitage/engine.rb +6 -0
  16. data/lib/hermitage/railtie.rb +9 -0
  17. data/lib/hermitage/version.rb +3 -0
  18. data/lib/hermitage/view_helpers.rb +42 -0
  19. data/lib/hermitage.rb +13 -0
  20. data/spec/dummy/README.rdoc +28 -0
  21. data/spec/dummy/Rakefile +6 -0
  22. data/spec/dummy/app/assets/images/.keep +0 -0
  23. data/spec/dummy/app/assets/images/0-full.png +0 -0
  24. data/spec/dummy/app/assets/images/0-thumbnail.png +0 -0
  25. data/spec/dummy/app/assets/images/1-full.png +0 -0
  26. data/spec/dummy/app/assets/images/1-thumbnail.png +0 -0
  27. data/spec/dummy/app/assets/images/2-full.png +0 -0
  28. data/spec/dummy/app/assets/images/2-thumbnail.png +0 -0
  29. data/spec/dummy/app/assets/javascripts/application.js +15 -0
  30. data/spec/dummy/app/assets/stylesheets/application.css +13 -0
  31. data/spec/dummy/app/controllers/application_controller.rb +5 -0
  32. data/spec/dummy/app/controllers/concerns/.keep +0 -0
  33. data/spec/dummy/app/controllers/images_controller.rb +8 -0
  34. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  35. data/spec/dummy/app/mailers/.keep +0 -0
  36. data/spec/dummy/app/models/.keep +0 -0
  37. data/spec/dummy/app/models/concerns/.keep +0 -0
  38. data/spec/dummy/app/models/dummy.rb +32 -0
  39. data/spec/dummy/app/views/images/index.html.erb +1 -0
  40. data/spec/dummy/app/views/layouts/application.html.erb +14 -0
  41. data/spec/dummy/bin/bundle +3 -0
  42. data/spec/dummy/bin/rails +4 -0
  43. data/spec/dummy/bin/rake +4 -0
  44. data/spec/dummy/config/application.rb +31 -0
  45. data/spec/dummy/config/boot.rb +5 -0
  46. data/spec/dummy/config/database.yml +25 -0
  47. data/spec/dummy/config/environment.rb +5 -0
  48. data/spec/dummy/config/environments/development.rb +29 -0
  49. data/spec/dummy/config/environments/production.rb +80 -0
  50. data/spec/dummy/config/environments/test.rb +36 -0
  51. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  52. data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  53. data/spec/dummy/config/initializers/inflections.rb +16 -0
  54. data/spec/dummy/config/initializers/mime_types.rb +5 -0
  55. data/spec/dummy/config/initializers/secret_token.rb +12 -0
  56. data/spec/dummy/config/initializers/session_store.rb +3 -0
  57. data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
  58. data/spec/dummy/config/locales/en.yml +23 -0
  59. data/spec/dummy/config/routes.rb +3 -0
  60. data/spec/dummy/config.ru +4 -0
  61. data/spec/dummy/db/schema.rb +16 -0
  62. data/spec/dummy/lib/assets/.keep +0 -0
  63. data/spec/dummy/log/.keep +0 -0
  64. data/spec/dummy/log/development.log +0 -0
  65. data/spec/dummy/public/404.html +58 -0
  66. data/spec/dummy/public/422.html +58 -0
  67. data/spec/dummy/public/500.html +57 -0
  68. data/spec/dummy/public/favicon.ico +0 -0
  69. data/spec/features/engine_spec.rb +8 -0
  70. data/spec/features/navigation_spec.rb +90 -0
  71. data/spec/features/render_gallery_spec.rb +19 -0
  72. data/spec/features/scale_spec.rb +78 -0
  73. data/spec/features/viewer_spec.rb +40 -0
  74. data/spec/generators/install_spec.rb +19 -0
  75. data/spec/lib/hermitage/defaults_spec.rb +18 -0
  76. data/spec/lib/hermitage/railtie_spec.rb +7 -0
  77. data/spec/lib/hermitage/view_helpers_spec.rb +71 -0
  78. data/spec/lib/hermitage_spec.rb +11 -0
  79. data/spec/spec_helper.rb +26 -0
  80. metadata +362 -0
data/.gitignore ADDED
@@ -0,0 +1,20 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ .DS_Store
19
+ spec/dummy/db/*.sqlite3
20
+ spec/dummy/log/*.log
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format progress
data/.rvmrc ADDED
@@ -0,0 +1 @@
1
+ rvm use 1.9.3@hermitage --create
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.0.0
4
+ - 1.9.3
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in hermitage.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Alexander Borovykh
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.
data/README.md ADDED
@@ -0,0 +1,175 @@
1
+ # Hermitage
2
+
3
+ Ruby library for generation of image galleries (thumbnails and full size images viewer).
4
+
5
+ ## Requirements
6
+
7
+ Hermitage requires Ruby on Rails version >= 3.1 with support of jQuery and CoffeeScript (jquery-rails and coffee-rails gems, respectively).
8
+
9
+ ## Installation
10
+
11
+ Add this line to your application's Gemfile:
12
+
13
+ gem 'hermitage'
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install hermitage
22
+
23
+ Also you have to run installation script to create config file and add require statement to your application.js file.
24
+
25
+ rails generate hermitage:install
26
+
27
+ ## Quick Start
28
+
29
+ Add this line to your view:
30
+
31
+ render_gallery_for @images # or any other array of objects with image attachments
32
+
33
+ It is enough in theory.
34
+
35
+ ## Usage
36
+
37
+ The example from Quick Start section works well when you are using Paperclip gem for file attachment and your model looks like this:
38
+
39
+ class Image < ActiveRecord::Base
40
+ attr_accessible :file
41
+ has_attached_file :file, styles: { thumbnail: "100x100>" }
42
+ end
43
+
44
+ Then
45
+
46
+ render_gallery_for @images
47
+
48
+ will render markup for the gallery.
49
+
50
+ In other cases some configuration is necessary.
51
+
52
+ ### Options
53
+
54
+ You can pass options hash to `render_gallery_for` method if you want to customize Hermitage behavior.
55
+
56
+ #### Specify Image Path
57
+
58
+ E.g. your `Photo` model has methods `image_full` and `image_thumb` that return path to full image and its thumbnail, respectively.
59
+ Then you can write in your view file:
60
+
61
+ render_gallery_for @photos, attribute_full_size: 'image_full', attribute_thumbnail: 'image_thumb'
62
+
63
+ Then Hermitage will use the specified methods to get paths to your images and thumbnails.
64
+
65
+ If the only method returns both paths according to passed parameters you can specify it like this:
66
+
67
+ render_gallery_for @posts, attribute_full_size: 'attachment(:full)', attribute_thumbnail: 'attachment(:thumbnail)'
68
+
69
+ #### Markup
70
+
71
+ Hermitage renders markup that will look nice with Twitter Bootstrap by default:
72
+
73
+ <ul class="thumbnails">
74
+ <li class="span4">
75
+ <a href="/path/to/full/image" class="thumbnail" rel="hermitage">
76
+ <img src="/path/to/thumbnail" />
77
+ </a>
78
+ </li>
79
+ </ul>
80
+
81
+ You can configure any element of this markup by overwriting `list_tag`, `item_tag`, `list_class`, `item_class`, `link_class` and `image_class` properties.
82
+
83
+ For example this line of code:
84
+
85
+ render_gallery_for @images, list_tag: :div, item_tag: :p, item_class: 'image'
86
+
87
+ will render the following markup:
88
+
89
+ <div class="thumbnails">
90
+ <p class="image">
91
+ <a href="/path/to/full/image" class="thumbnail" rel="hermitage">
92
+ <img src="/path/to/thumbnail" />
93
+ </a>
94
+ </p>
95
+ </div>
96
+
97
+ ### Configuration
98
+
99
+ It is more handy to use configs to customize Hermitage behavior.
100
+
101
+ When you call `render_gallery_for` method Hermitage looks for config with name formed by the plural form of class name of the first element in passed array.
102
+ In the example above Hermitage tries to find :images config because first argument of `render_gallery_for` method was array of Image instances.
103
+ If there is no proper config :default config is used.
104
+
105
+ Hermitage configs are described in config/initializers/hermitage.rb file.
106
+
107
+ #### Overwrite Defaults
108
+
109
+ You can overwrite :default config. These changes will be applied to all the galleries in your application.
110
+
111
+ Uncoment the following lines in config/initializers/hermitage.rb file and make some changes here:
112
+
113
+ Hermitage.configs[:default].merge!({
114
+ attribute_full_size: 'image.url(:medium)',
115
+ attribute_thumbnail: 'image.url(:small)'
116
+ })
117
+
118
+ Now Hermitage will use `image.url` method with :medium or :small argument to get images for the gallery.
119
+
120
+ #### Custom Configs
121
+
122
+ When there are several galleries that need different markup it is better to use custom configs.
123
+
124
+ For example there are 2 models in your application:
125
+
126
+ class Picture < ActiveRecord::Base
127
+ def image_path(style = :large)
128
+ # magically returns correct image url for :large and :small styles
129
+ end
130
+ end
131
+
132
+ and
133
+
134
+ class Post < ActiveRecord::Base
135
+ attr_accessible :attachment
136
+ has_attached_file :attachment, styles: { tiny: "200x200>" }
137
+ end
138
+
139
+ Suppose that pictures should be rendered with Twitter Bootstrap style, but posts should be wrapped by simple blocks.
140
+ Then your config/initializers/hermitage.rb could looks like this:
141
+
142
+ # Some rules for :default config if needed...
143
+
144
+ Hermitage.configs[:pictures] = {
145
+ attribute_full_size: 'image_path',
146
+ attribute_thumbnail: 'image_path(:small)'
147
+ }
148
+
149
+ Hermitage.configs[:pictures] = {
150
+ attribute_full_size: 'attachment',
151
+ attribute_thumbnail: 'attachment(:tiny)',
152
+ list_tag: :div,
153
+ item_tag: div,
154
+ list_class: 'posts',
155
+ item_class: 'post'
156
+ }
157
+
158
+ Now when you write `render_gallery_for @pictures` or `render_gallery_for @posts` Hermitage will automatically choose the proper config.
159
+
160
+ #### Configs Priority
161
+
162
+ You have noticed that it is not neccessary to specify every parameter in config or options block.
163
+ So, Hermitage looks for parameters with the following priority:
164
+
165
+ * It uses all parameters from default config;
166
+ * Then it overwrites some of them by custom config's parameters if they were specified;
167
+ * Finally it overwrites both of them by the values from options hash passed to `render_gallery_for` method (if there are such values, of course).
168
+
169
+ ## Contributing
170
+
171
+ 1. Fork it
172
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
173
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
174
+ 4. Push to the branch (`git push origin my-new-feature`)
175
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,7 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new
5
+
6
+ task :default => :spec
7
+ task :test => :spec
@@ -0,0 +1,263 @@
1
+ root = exports ? this
2
+
3
+ #
4
+ # Data
5
+ #
6
+
7
+ # Array of images of current gallery
8
+ root.images = []
9
+
10
+ # Distance between navigation buttons and image
11
+ root.navigation_button_margin = 10
12
+
13
+ # Color of navigation button's border and symbols
14
+ root.navigation_button_color = "#777"
15
+
16
+ # Minimum distance between window borders and image
17
+ root.window_padding_x = 50
18
+ root.window_padding_y = 50
19
+
20
+ # Minimum size of scaled image
21
+ root.minimum_scaled_width = 100
22
+ root.minimum_scaled_height = 100
23
+
24
+ # Initializes the gallery on this page
25
+ root.init_hermitage = ->
26
+ # Create simple gallery layer if it doesn't exist
27
+ if ($("#hermitage").length == 0)
28
+ hermitage = $("<div>", {id: "hermitage"})
29
+ $("body").append(hermitage)
30
+ hermitage.css("z-index", 10)
31
+ hermitage.hide()
32
+
33
+ # Clear old images array
34
+ images.length = 0
35
+
36
+ # Create new images array
37
+ $.each $('a[rel="hermitage"]'), ->
38
+ images.push($(this).attr('href'))
39
+
40
+ # Set on click handlers to all elements that
41
+ # have 'hermitage' rel attribute
42
+ $('a[rel="hermitage"]').click (event) ->
43
+ open_gallery(this)
44
+ event.preventDefault()
45
+
46
+ #
47
+ # Helpers
48
+ #
49
+
50
+ # Place element at the center of screen
51
+ jQuery.fn.center = () ->
52
+ this.css("position", "fixed")
53
+ this.css("top", Math.max(0, (($(window).height() - $(this).outerHeight()) / 2) + $(window).scrollTop()) + "px")
54
+ this.css("left", Math.max(0, (($(window).width() - $(this).outerWidth()) / 2) + $(window).scrollLeft()) + "px")
55
+ this
56
+
57
+
58
+ #
59
+ # Simple gallery logic
60
+ #
61
+
62
+ # Creates overlay layer, shows it and sets its click handler
63
+ create_overlay = () ->
64
+ overlay = $("<div>", {id: "overlay"})
65
+ $("#hermitage").append(overlay)
66
+
67
+ overlay.css("position", "fixed")
68
+ overlay.css("top", "0")
69
+ overlay.css("left", "0")
70
+ overlay.css("background", "#000")
71
+ overlay.css("display", "block")
72
+ overlay.css("opacity", "0.75")
73
+ overlay.css("filter", "alpha(opacity=75)")
74
+ overlay.css("width", "100%")
75
+ overlay.css("height", "100%")
76
+
77
+ overlay.hide()
78
+ overlay.fadeIn()
79
+
80
+ overlay.click (event) ->
81
+ close_gallery()
82
+
83
+ overlay
84
+
85
+
86
+ # Creates base navigation button and returns it
87
+ create_navigation_button = () ->
88
+ button = $("<div>")
89
+ $("#hermitage").append(button)
90
+
91
+ button.css("position", "fixed")
92
+ button.css("width", "50px")
93
+ button.css("display", "block")
94
+ button.css("cursor", "pointer")
95
+
96
+ button.css("border-width", "1px")
97
+ button.css("border-style", "solid")
98
+ button.css("border-color", navigation_button_color)
99
+ button.css("display", "block")
100
+ button.css("border-radius", "7px")
101
+ button.css("-webkit-border-radius", "7px")
102
+ button.css("-moz-border-radius", "7px")
103
+
104
+ button.css("color", navigation_button_color)
105
+ button.css("text-align", "center")
106
+ button.css("vertical-align", "middle")
107
+ button.css("font", "30px Tahoma,Arial,Helvetica,sans-serif")
108
+
109
+ button.hide()
110
+
111
+ button
112
+
113
+ # Creates right navigation button and returns it
114
+ create_right_navigation_button = () ->
115
+ button = create_navigation_button()
116
+ button.attr("id", "navigation-right")
117
+ button.css("border-top-left-radius", "0")
118
+ button.css("-webkit-border-top-left-radius", "0")
119
+ button.css("-moz-border-top-left-radius", "0")
120
+ button.css("border-bottom-left-radius", "0")
121
+ button.css("-webkit-border-bottom-left-radius", "0")
122
+ button.css("-moz-border-bottom-left-radius", "0")
123
+ button.append(">")
124
+
125
+ button.click (event) ->
126
+ show_next_image()
127
+
128
+ button
129
+
130
+ # Create left navigation button and returns it
131
+ create_left_navigation_button = () ->
132
+ button = create_navigation_button()
133
+ button.attr("id", "navigation-left")
134
+ button.css("border-top-right-radius", "0")
135
+ button.css("-webkit-border-top-right-radius", "0")
136
+ button.css("-moz-border-top-right-radius", "0")
137
+ button.css("border-bottom-right-radius", "0")
138
+ button.css("-webkit-border-bottom-right-radius", "0")
139
+ button.css("-moz-border-bottom-right-radius", "0")
140
+ button.append("<")
141
+
142
+ button.click (event) ->
143
+ show_previous_image()
144
+
145
+ button
146
+
147
+
148
+ # Shows full size image of the chosen one
149
+ open_gallery = (image) ->
150
+ $("#hermitage").empty()
151
+ $("#hermitage").show()
152
+ create_overlay()
153
+ create_right_navigation_button()
154
+ create_left_navigation_button()
155
+
156
+ show_image(images.indexOf($(image).attr("href")))
157
+
158
+
159
+ # Shows image with specified index from images array
160
+ show_image = (index) ->
161
+ # Create full size image at the center of screen
162
+ img = $("<img />")
163
+ img.attr("src", images[index])
164
+ img.attr("class", "current")
165
+ img.css("cursor", "pointer")
166
+ img.hide()
167
+
168
+ $("#hermitage").append(img)
169
+
170
+ img.click (event) ->
171
+ if (event.pageX >= $(window).width() / 2)
172
+ show_next_image()
173
+ else
174
+ show_previous_image()
175
+
176
+ # When image will be loaded set correct size,
177
+ # center element and show it
178
+ $("<img />").attr("src", images[index]).load ->
179
+ max_width = $(window).width() - (window_padding_x + $("#navigation-left").outerWidth() + navigation_button_margin) * 2
180
+ max_height = $(window).height() - window_padding_y * 2
181
+
182
+ scale = 1.0
183
+
184
+ if (max_width <= minimum_scaled_width || max_height <= minimum_scaled_height)
185
+ if (max_width < max_height)
186
+ max_width = minimum_scaled_width
187
+ max_height = max_width * (this.height / this.width)
188
+ else
189
+ max_height = minimum_scaled_height
190
+ max_width = max_height * (this.width / this.height)
191
+
192
+ if (this.width > max_width || this.height > max_height)
193
+ scale = Math.min(max_width / this.width, max_height / this.height)
194
+
195
+ img.width(this.width * scale)
196
+ img.height(this.height * scale)
197
+
198
+ img.center()
199
+ img.fadeIn()
200
+ adjust_navigation_buttons()
201
+
202
+ # Shows next image
203
+ show_next_image = ->
204
+ current = $("img.current")
205
+ if (current.length == 1)
206
+ index = images.indexOf(current.attr("src"))
207
+ hide_current_image()
208
+ if (index < images.length - 1)
209
+ show_image(index + 1)
210
+ else
211
+ show_image(0)
212
+
213
+ # Shows previous image
214
+ show_previous_image = ->
215
+ current = $("img.current")
216
+ if (current.length == 1)
217
+ index = images.indexOf(current.attr("src"))
218
+ hide_current_image()
219
+ if (index > 0)
220
+ show_image(index - 1)
221
+ else
222
+ show_image(images.length - 1)
223
+
224
+ # Hides current image
225
+ hide_current_image = ->
226
+ current = $("img.current")
227
+ if (current.length == 1)
228
+ current.attr("class", "")
229
+ current.fadeOut 400, ->
230
+ current.remove()
231
+
232
+ # Starts fade out animation and clears simple gallery at the end of animation
233
+ close_gallery = () ->
234
+ $("#hermitage :not(#overlay)").fadeOut()
235
+ $("#overlay").fadeOut 400, ->
236
+ $("#hermitage").hide()
237
+ $("#hermitage").empty()
238
+
239
+
240
+ # Moves navigation buttons to proper positions
241
+ adjust_navigation_buttons = () ->
242
+ left = $("#navigation-left")
243
+ right = $("#navigation-right")
244
+
245
+ current = $(".current")
246
+
247
+ left_new_height = current.outerHeight() + "px"
248
+ left_new_left = (current.position().left - left.outerWidth() - navigation_button_margin) + "px"
249
+ left_new_top = current.position().top + "px"
250
+
251
+ right_new_height = current.outerHeight() + "px"
252
+ right_new_left = (current.position().left + current.outerWidth() + navigation_button_margin) + "px"
253
+ right_new_top = current.position().top + "px"
254
+
255
+ left.animate({ height: left_new_height, 'line-height': left_new_height, left: left_new_left, top: left_new_top}, 400)
256
+ right.animate({ height: right_new_height, 'line-height': right_new_height, left: right_new_left, top: right_new_top}, 400)
257
+
258
+ left.fadeIn() if (left.css("display") == "none")
259
+ right.fadeIn() if (right.css("display") == "none")
260
+
261
+ # Initialize gallery on page load
262
+ $(document).ready(init_hermitage)
263
+ $(document).on('page:load', init_hermitage)
data/config.ru ADDED
@@ -0,0 +1,7 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+
4
+ Bundler.require :default, :development
5
+
6
+ Combustion.initialize!
7
+ run Combustion::Application
data/hermitage.gemspec ADDED
@@ -0,0 +1,33 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'hermitage/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'hermitage'
8
+ spec.version = Hermitage::VERSION
9
+ spec.authors = ['Alexander Borovykh']
10
+ spec.email = ['immaculate.pine@gmail.com']
11
+ spec.description = %q{Ruby library for generation of image galleries.}
12
+ spec.summary = %q{Ruby library for generation of image galleries (thumbnails and full size images viewer).}
13
+ spec.homepage = 'https://github.com/ImmaculatePine/hermitage'
14
+ spec.license = 'MIT'
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ['lib']
20
+
21
+ spec.add_dependency 'rails', '>= 3.2'
22
+ spec.add_dependency 'jquery-rails'
23
+ spec.add_dependency 'coffee-rails'
24
+
25
+ spec.add_development_dependency 'bundler', '~> 1.3'
26
+ spec.add_development_dependency 'rake'
27
+ spec.add_development_dependency 'rspec-rails'
28
+ spec.add_development_dependency 'capybara'
29
+ spec.add_development_dependency 'sqlite3'
30
+ spec.add_development_dependency 'therubyracer'
31
+ spec.add_development_dependency 'poltergeist'
32
+ spec.add_development_dependency 'genspec'
33
+ end
@@ -0,0 +1,17 @@
1
+ module Hermitage
2
+ module Generators
3
+ class InstallGenerator < ::Rails::Generators::Base
4
+ desc 'Creates Hermitage configuration file at config/initializers and adds require statement to application.js file.'
5
+ source_root File.expand_path('../templates', __FILE__)
6
+
7
+ def copy_initializer
8
+ template 'hermitage.rb', 'config/initializers/hermitage.rb'
9
+ end
10
+
11
+ def insert_require_into_application_js
12
+ inject_into_file 'app/assets/javascripts/application.js', "\n//= require hermitage", after: %r{^//= require +['"]?jquery['"]?$}
13
+ end
14
+
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,29 @@
1
+ # Configuration file for hermitage gem
2
+
3
+ # Default config is used as base options hash for every gallery.
4
+ # You can configure any of its options and they will be applied for every rendering.
5
+ #
6
+ # Hermitage.configs[:default].merge!({
7
+ # attribute_full_size: 'file.url',
8
+ # attribute_thumbnail: 'file.url(:thumbnail)',
9
+ # list_tag: :ul,
10
+ # item_tag: :li,
11
+ # list_class: 'thumbnails',
12
+ # item_class: 'span4',
13
+ # link_class: 'thumbnail',
14
+ # image_class: nil
15
+ # })
16
+
17
+ # Also you can create your own configs that will be merged with default config to overwrite default options.
18
+ #
19
+ # E.g. when you write
20
+ #
21
+ # render_gallery_for @images
22
+ #
23
+ # :images config will be used.
24
+ #
25
+ # All available options are listed in default config above.
26
+ #
27
+ # Hermitage.configs[:images] = {
28
+
29
+ # }
@@ -0,0 +1,31 @@
1
+ module Hermitage
2
+ module Defaults
3
+ # Model's attribute (or method) that returns the path to the full size image
4
+ ATTRIBUTE_FULL_SIZE = 'file.url'
5
+
6
+ # Model's attribute (or method) that returns the path to the image's thumbnail
7
+ ATTRIBUTE_THUMBNAIL = 'file.url(:thumbnail)'
8
+
9
+ # Wrapper for the whole gallery
10
+ LIST_TAG = :ul
11
+
12
+ # Wrapepr for each gallery item
13
+ ITEM_TAG = :li
14
+
15
+ # CSS classes for elements of markup
16
+ # (defaults are for pretty look with Twitter Bootstrap)
17
+ LIST_CLASS = 'thumbnails'
18
+ ITEM_CLASS = 'span4'
19
+ LINK_CLASS = 'thumbnail'
20
+ IMAGE_CLASS = nil
21
+
22
+ # Returns hash of default options
23
+ def self.to_hash
24
+ hash = {}
25
+ Hermitage::Defaults.constants.each do |c|
26
+ hash[c.downcase.to_sym] = Hermitage::Defaults.const_get(c)
27
+ end
28
+ hash
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,6 @@
1
+ module Hermitage
2
+ module Rails
3
+ class Engine < ::Rails::Engine
4
+ end
5
+ end
6
+ end
@@ -0,0 +1,9 @@
1
+ require 'hermitage/view_helpers'
2
+
3
+ module Hermitage
4
+ class Railtie < Rails::Railtie
5
+ initializer 'hermitage.view_helpers' do |app|
6
+ ActionView::Base.send :include, ViewHelpers
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,3 @@
1
+ module Hermitage
2
+ VERSION = '0.0.1'
3
+ end