utopia-gallery 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +21 -0
- data/.rspec +5 -0
- data/Gemfile +14 -0
- data/README.md +95 -0
- data/Rakefile +1 -0
- data/lib/utopia/gallery.rb +24 -0
- data/lib/utopia/gallery/cache.rb +77 -0
- data/lib/utopia/gallery/container.rb +68 -0
- data/lib/utopia/gallery/media.rb +57 -0
- data/lib/utopia/gallery/process.rb +72 -0
- data/lib/utopia/gallery/tags.rb +84 -0
- data/lib/utopia/gallery/version.rb +5 -0
- data/spec/spec_helper.rb +29 -0
- data/spec/utopia/gallery/cache_spec.rb +25 -0
- data/spec/utopia/gallery/container_spec.rb +9 -0
- data/spec/utopia/gallery/site/pages/_photo.xnode +6 -0
- data/spec/utopia/gallery/site/pages/gallery.xnode +1 -0
- data/spec/utopia/gallery/site/pages/index.xnode +1 -0
- data/spec/utopia/gallery/site/pages/sample_images/IMG_3340.jpg +0 -0
- data/spec/utopia/gallery/site/pages/sample_images/IMG_3341.jpg +0 -0
- data/spec/utopia/gallery/site/pages/sample_images/IMG_3344.jpg +0 -0
- data/spec/utopia/gallery/site/pages/sample_images/IMG_3351.jpg +0 -0
- data/spec/utopia/gallery/site_spec.rb +70 -0
- data/spec/utopia/gallery/site_spec.ru +13 -0
- data/utopia-gallery.gemspec +25 -0
- metadata +151 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 69f0a0aec906b446239d6e3048f8eda7e3f65361
|
4
|
+
data.tar.gz: ae8c0c3da88f1aa55ef289665025d70b307f1221
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: c1402cbdf7fdce1316ef63cbce5cf2ac610260e8d32a2130dd029d6050593b5ab44301afd087f0b488ad4813bf206754a1e52d7323d9d97ce67416e288ed50fc
|
7
|
+
data.tar.gz: f081553113a7f74d1cffd008229c0d319712e2985f3d88c82521260019486c1e0a6d6eec59b7b5d638ce949653748c8a99520a71073a16104605bd2614a9beec
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,95 @@
|
|
1
|
+
# Utopia::Gallery
|
2
|
+
|
3
|
+
This extension for [Utopia](https://github.com/ioquatix/utopia) provides tags for generating photo galleries. Works well in conjunction with [jQuery.LiteBox](https://github.com/ioquatix/jquery-litebox).
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your website's Gemfile:
|
8
|
+
|
9
|
+
gem 'utopia-gallery'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
## Usage
|
16
|
+
|
17
|
+
Require the tag in your `config/environment.rb`:
|
18
|
+
|
19
|
+
require 'utopia/gallery'
|
20
|
+
|
21
|
+
In your `config.ru` add the `gallery` namespace:
|
22
|
+
|
23
|
+
use Utopia::Content,
|
24
|
+
namespaces: {
|
25
|
+
'gallery' => Utopia::Gallery::Tags.new
|
26
|
+
}
|
27
|
+
|
28
|
+
In your `xnode`:
|
29
|
+
|
30
|
+
```html
|
31
|
+
<gallery:container path="_photos"/>
|
32
|
+
```
|
33
|
+
|
34
|
+
### Customizing Generated Markup
|
35
|
+
|
36
|
+
The best way to customize the output is to specify a tag to use:
|
37
|
+
|
38
|
+
```html
|
39
|
+
<gallery:container path="_photos" tag="content:photo"/>
|
40
|
+
```
|
41
|
+
|
42
|
+
Add `_photo.xnode` such as:
|
43
|
+
|
44
|
+
```html
|
45
|
+
<figure class="photo">
|
46
|
+
<a href="#{attributes[:src].large}" title="#{attributes[:alt]}">
|
47
|
+
<img src="#{attributes[:src].small}" alt="#{attributes[:alt]}"/>
|
48
|
+
</a>
|
49
|
+
<figcaption>#{attributes[:alt]}</figcaption>
|
50
|
+
</figure>
|
51
|
+
```
|
52
|
+
|
53
|
+
### Adding Captions
|
54
|
+
|
55
|
+
You can add captions and other metadata by adding a `gallery.yaml` file:
|
56
|
+
|
57
|
+
```yaml
|
58
|
+
bear.jpg:
|
59
|
+
caption: "Brown bear is angry!"
|
60
|
+
order: 1
|
61
|
+
```
|
62
|
+
|
63
|
+
This file needs to be placed in the same directory as the images, and metadata can be accessed via the `alt` attribute, e.g. `attributes[:alt]['caption']`.
|
64
|
+
|
65
|
+
## Contributing
|
66
|
+
|
67
|
+
1. Fork it
|
68
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
69
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
70
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
71
|
+
5. Create new Pull Request
|
72
|
+
|
73
|
+
## License
|
74
|
+
|
75
|
+
Released under the MIT license.
|
76
|
+
|
77
|
+
Copyright, 2012, by [Samuel G. D. Williams](http://www.codeotaku.com/samuel-williams).
|
78
|
+
|
79
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
80
|
+
of this software and associated documentation files (the "Software"), to deal
|
81
|
+
in the Software without restriction, including without limitation the rights
|
82
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
83
|
+
copies of the Software, and to permit persons to whom the Software is
|
84
|
+
furnished to do so, subject to the following conditions:
|
85
|
+
|
86
|
+
The above copyright notice and this permission notice shall be included in
|
87
|
+
all copies or substantial portions of the Software.
|
88
|
+
|
89
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
90
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
91
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
92
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
93
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
94
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
95
|
+
THE SOFTWARE.
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# Copyright, 2012, by Samuel G. D. Williams. <http://www.codeotaku.com>
|
2
|
+
#
|
3
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
# of this software and associated documentation files (the "Software"), to deal
|
5
|
+
# in the Software without restriction, including without limitation the rights
|
6
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
+
# copies of the Software, and to permit persons to whom the Software is
|
8
|
+
# furnished to do so, subject to the following conditions:
|
9
|
+
#
|
10
|
+
# The above copyright notice and this permission notice shall be included in
|
11
|
+
# all copies or substantial portions of the Software.
|
12
|
+
#
|
13
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
|
+
# THE SOFTWARE.
|
20
|
+
|
21
|
+
require_relative 'gallery/container'
|
22
|
+
require_relative 'gallery/process'
|
23
|
+
require_relative 'gallery/cache'
|
24
|
+
require_relative 'gallery/tags'
|
@@ -0,0 +1,77 @@
|
|
1
|
+
# Copyright, 2012, by Samuel G. D. Williams. <http://www.codeotaku.com>
|
2
|
+
#
|
3
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
# of this software and associated documentation files (the "Software"), to deal
|
5
|
+
# in the Software without restriction, including without limitation the rights
|
6
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
+
# copies of the Software, and to permit persons to whom the Software is
|
8
|
+
# furnished to do so, subject to the following conditions:
|
9
|
+
#
|
10
|
+
# The above copyright notice and this permission notice shall be included in
|
11
|
+
# all copies or substantial portions of the Software.
|
12
|
+
#
|
13
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
|
+
# THE SOFTWARE.
|
20
|
+
|
21
|
+
module Utopia
|
22
|
+
module Gallery
|
23
|
+
class Cache
|
24
|
+
# @param root [String] The root path for media files.
|
25
|
+
def initialize(media_root, cache_root, cache_path, media, processes)
|
26
|
+
# TODO: It's a lot of things to keep track of... perhaps a configuration class?
|
27
|
+
@media_root = media_root
|
28
|
+
@cache_root = cache_root
|
29
|
+
@cache_path = cache_path
|
30
|
+
@media = media
|
31
|
+
|
32
|
+
@processes = processes
|
33
|
+
end
|
34
|
+
|
35
|
+
attr :media_root
|
36
|
+
attr :cache_root
|
37
|
+
attr :processes
|
38
|
+
attr :media
|
39
|
+
|
40
|
+
def to_s
|
41
|
+
@media.path
|
42
|
+
end
|
43
|
+
|
44
|
+
def output_path_for(process)
|
45
|
+
File.join(@cache_root, process.relative_path(@media))
|
46
|
+
end
|
47
|
+
|
48
|
+
def source_path_for(process)
|
49
|
+
File.join(@cache_path, process.relative_path(@media))
|
50
|
+
end
|
51
|
+
|
52
|
+
# Process the media, update files in the cache.
|
53
|
+
def update
|
54
|
+
locals = {}
|
55
|
+
|
56
|
+
@processes.values.each do |process|
|
57
|
+
process.call(self, locals)
|
58
|
+
end
|
59
|
+
|
60
|
+
return self
|
61
|
+
end
|
62
|
+
|
63
|
+
# This allows dynamic path lookup based on process name, e.g. `cache.small`.
|
64
|
+
def method_missing(name, *args)
|
65
|
+
if process = @processes[name]
|
66
|
+
return source_path_for(process)
|
67
|
+
else
|
68
|
+
super
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
def respond_to?(name)
|
73
|
+
@processes.include?(name) || super
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
# Copyright, 2012, by Samuel G. D. Williams. <http://www.codeotaku.com>
|
2
|
+
#
|
3
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
# of this software and associated documentation files (the "Software"), to deal
|
5
|
+
# in the Software without restriction, including without limitation the rights
|
6
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
+
# copies of the Software, and to permit persons to whom the Software is
|
8
|
+
# furnished to do so, subject to the following conditions:
|
9
|
+
#
|
10
|
+
# The above copyright notice and this permission notice shall be included in
|
11
|
+
# all copies or substantial portions of the Software.
|
12
|
+
#
|
13
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
|
+
# THE SOFTWARE.
|
20
|
+
|
21
|
+
require_relative 'media'
|
22
|
+
|
23
|
+
module Utopia
|
24
|
+
module Gallery
|
25
|
+
class Container
|
26
|
+
include Enumerable
|
27
|
+
|
28
|
+
def initialize(root, path, filter: /(jpe?g|png)$/i)
|
29
|
+
@root = root
|
30
|
+
@path = path
|
31
|
+
@filter = filter
|
32
|
+
end
|
33
|
+
|
34
|
+
def each
|
35
|
+
return to_enum unless block_given?
|
36
|
+
|
37
|
+
gallery_metadata = load_metadata
|
38
|
+
|
39
|
+
entries.each do |name|
|
40
|
+
path = File.join(@path, name)
|
41
|
+
media_metadata = gallery_metadata.delete(name)
|
42
|
+
|
43
|
+
yield Media.new(path, media_metadata || {})
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
private
|
48
|
+
|
49
|
+
def full_path
|
50
|
+
File.join(@root, @path)
|
51
|
+
end
|
52
|
+
|
53
|
+
def entries
|
54
|
+
Dir.entries(full_path).select{|name| name =~ @filter}
|
55
|
+
end
|
56
|
+
|
57
|
+
def load_metadata
|
58
|
+
metadata_path = File.join(full_path, 'gallery.yaml')
|
59
|
+
|
60
|
+
if File.exist? metadata_path
|
61
|
+
return YAML::load(File.read(metadata_path))
|
62
|
+
else
|
63
|
+
return {}
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
# Copyright, 2017, by Samuel G. D. Williams. <http://www.codeotaku.com>
|
2
|
+
#
|
3
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
# of this software and associated documentation files (the "Software"), to deal
|
5
|
+
# in the Software without restriction, including without limitation the rights
|
6
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
+
# copies of the Software, and to permit persons to whom the Software is
|
8
|
+
# furnished to do so, subject to the following conditions:
|
9
|
+
#
|
10
|
+
# The above copyright notice and this permission notice shall be included in
|
11
|
+
# all copies or substantial portions of the Software.
|
12
|
+
#
|
13
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
|
+
# THE SOFTWARE.
|
20
|
+
|
21
|
+
module Utopia
|
22
|
+
module Gallery
|
23
|
+
# Represents a single unit of media, e.g. a video or image.
|
24
|
+
class Media
|
25
|
+
# @param path [String] The full path to the media asset.
|
26
|
+
def initialize(path, metadata)
|
27
|
+
@path = path
|
28
|
+
@metadata = metadata
|
29
|
+
end
|
30
|
+
|
31
|
+
attr :path
|
32
|
+
attr :metadata
|
33
|
+
|
34
|
+
def [] key
|
35
|
+
@metadata[key.to_s]
|
36
|
+
end
|
37
|
+
|
38
|
+
def caption
|
39
|
+
@metadata['caption']
|
40
|
+
end
|
41
|
+
|
42
|
+
def to_s
|
43
|
+
caption || File.basename(@path, ".*")
|
44
|
+
end
|
45
|
+
|
46
|
+
ORDER_KEY = 'order'.freeze
|
47
|
+
|
48
|
+
def <=> other
|
49
|
+
if a = self[ORDER_KEY] and b = other[ORDER_KEY]
|
50
|
+
a <=> b
|
51
|
+
else
|
52
|
+
self.path.last <=> other.path.last
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,72 @@
|
|
1
|
+
# Copyright, 2012, by Samuel G. D. Williams. <http://www.codeotaku.com>
|
2
|
+
#
|
3
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
# of this software and associated documentation files (the "Software"), to deal
|
5
|
+
# in the Software without restriction, including without limitation the rights
|
6
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
+
# copies of the Software, and to permit persons to whom the Software is
|
8
|
+
# furnished to do so, subject to the following conditions:
|
9
|
+
#
|
10
|
+
# The above copyright notice and this permission notice shall be included in
|
11
|
+
# all copies or substantial portions of the Software.
|
12
|
+
#
|
13
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
|
+
# THE SOFTWARE.
|
20
|
+
|
21
|
+
require 'vips/thumbnail'
|
22
|
+
require 'fileutils'
|
23
|
+
|
24
|
+
module Utopia
|
25
|
+
module Gallery
|
26
|
+
class Process
|
27
|
+
def initialize(name)
|
28
|
+
@name = name.to_sym
|
29
|
+
end
|
30
|
+
|
31
|
+
attr :name
|
32
|
+
|
33
|
+
def relative_path(media)
|
34
|
+
source_path = media.path
|
35
|
+
|
36
|
+
File.join(File.dirname(source_path), @name.to_s, File.basename(source_path))
|
37
|
+
end
|
38
|
+
|
39
|
+
def fresh?(input_path, output_path)
|
40
|
+
return File.exist?(output_path) && File.mtime(input_path) < File.mtime(output_path)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
class ResizeImage < Process
|
45
|
+
def initialize(name, size = [800, 800], method = :resize_to_fit, **options)
|
46
|
+
super(name)
|
47
|
+
|
48
|
+
@size = size
|
49
|
+
@method = method
|
50
|
+
@options = options
|
51
|
+
end
|
52
|
+
|
53
|
+
def call(cache, locals)
|
54
|
+
output_path = cache.output_path_for(self)
|
55
|
+
media = cache.media
|
56
|
+
media_path = File.join(cache.media_root, media.path)
|
57
|
+
|
58
|
+
return if fresh?(media_path, output_path)
|
59
|
+
|
60
|
+
resizer = locals[:resizer] ||= Vips::Thumbnail::Resizer.new(media_path)
|
61
|
+
|
62
|
+
FileUtils.mkdir_p(File.dirname(output_path))
|
63
|
+
|
64
|
+
if output_image = resizer.send(@method, @size)
|
65
|
+
output_image.write_to_file output_path, **@options
|
66
|
+
else
|
67
|
+
FileUtils.ln(media_path, output_path)
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
@@ -0,0 +1,84 @@
|
|
1
|
+
# Copyright, 2012, by Samuel G. D. Williams. <http://www.codeotaku.com>
|
2
|
+
#
|
3
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
# of this software and associated documentation files (the "Software"), to deal
|
5
|
+
# in the Software without restriction, including without limitation the rights
|
6
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
+
# copies of the Software, and to permit persons to whom the Software is
|
8
|
+
# furnished to do so, subject to the following conditions:
|
9
|
+
#
|
10
|
+
# The above copyright notice and this permission notice shall be included in
|
11
|
+
# all copies or substantial portions of the Software.
|
12
|
+
#
|
13
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
|
+
# THE SOFTWARE.
|
20
|
+
|
21
|
+
require 'utopia/content/namespace'
|
22
|
+
|
23
|
+
require_relative 'container'
|
24
|
+
require_relative 'process'
|
25
|
+
require_relative 'cache'
|
26
|
+
|
27
|
+
module Utopia
|
28
|
+
module Gallery
|
29
|
+
class Tags
|
30
|
+
DEFAULT_PROCESSES = [
|
31
|
+
ResizeImage.new(:small, [400, 400], :resize_to_fill),
|
32
|
+
ResizeImage.new(:medium, [800, 800], :resize_to_fill),
|
33
|
+
ResizeImage.new(:large, [1600, 1600], :resize_to_fit),
|
34
|
+
]
|
35
|
+
|
36
|
+
# @param media_root [String] Directory where media is stored.
|
37
|
+
# @param cache_root [String] Directory where media is cached.
|
38
|
+
# @param cache_root [String] The prefix path for the cached assets, served as static content.
|
39
|
+
def initialize(media_root: Utopia.default_root, cache_root: Utopia.default_root('public/_gallery'), cache_path: '/_gallery', processes: DEFAULT_PROCESSES)
|
40
|
+
@media_root = media_root
|
41
|
+
@cache_root = cache_root
|
42
|
+
@cache_path = cache_path
|
43
|
+
@processes = {}
|
44
|
+
|
45
|
+
processes.each do |process|
|
46
|
+
name = process.name
|
47
|
+
|
48
|
+
raise ArgumentError.new("Duplicate process #{name}") if @processes.include?(name)
|
49
|
+
|
50
|
+
@processes[name] = process
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def container(document, state)
|
55
|
+
node = document.parent.node
|
56
|
+
path = node.uri_path.dirname + Utopia::Path[state[:path]]
|
57
|
+
|
58
|
+
options = {}
|
59
|
+
if filetypes = state[:filetypes]
|
60
|
+
options[:filter] = Regexp.new("(#{filetypes})$", Regexp::IGNORECASE)
|
61
|
+
elsif filter = state[:filter]
|
62
|
+
options[:filter] = Regexp.new(filter, Regexp::IGNORECASE)
|
63
|
+
end
|
64
|
+
|
65
|
+
# Where should we get this from?
|
66
|
+
container = Container.new(@media_root, path, **options)
|
67
|
+
|
68
|
+
media_tag_name = state[:tag] || 'img'
|
69
|
+
|
70
|
+
document.tag('div', class: 'gallery') do
|
71
|
+
container.each do |media|
|
72
|
+
cache = Cache.new(@media_root, @cache_root, @cache_path, media, @processes).update
|
73
|
+
document.tag(media_tag_name, src: cache, alt: media)
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
def call(name, node)
|
79
|
+
# TODO: Validate security implications/leaky abstraction.
|
80
|
+
self.method(name)
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
|
2
|
+
if ENV['COVERAGE']
|
3
|
+
begin
|
4
|
+
require 'simplecov'
|
5
|
+
|
6
|
+
SimpleCov.start do
|
7
|
+
add_filter "/spec/"
|
8
|
+
end
|
9
|
+
|
10
|
+
if ENV['TRAVIS']
|
11
|
+
require 'coveralls'
|
12
|
+
Coveralls.wear!
|
13
|
+
end
|
14
|
+
rescue LoadError
|
15
|
+
warn "Could not load simplecov: #{$!}"
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
require "bundler/setup"
|
20
|
+
require "utopia/gallery"
|
21
|
+
|
22
|
+
RSpec.configure do |config|
|
23
|
+
# Enable flags like --only-failures and --next-failure
|
24
|
+
config.example_status_persistence_file_path = ".rspec_status"
|
25
|
+
|
26
|
+
config.expect_with :rspec do |c|
|
27
|
+
c.syntax = :expect
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
|
2
|
+
RSpec.describe Utopia::Gallery::Cache do
|
3
|
+
let(:pages_root) {File.join(__dir__, 'site/pages')}
|
4
|
+
let(:cache_root) {File.join(__dir__, 'site/public/_gallery')}
|
5
|
+
|
6
|
+
before(:each) do
|
7
|
+
FileUtils.rm_rf cache_root
|
8
|
+
end
|
9
|
+
|
10
|
+
# Cache wants processes as a hash by name.
|
11
|
+
let(:processes) do
|
12
|
+
{
|
13
|
+
small: Utopia::Gallery::ResizeImage.new(:small, [400, 400], :resize_to_fill),
|
14
|
+
large: Utopia::Gallery::ResizeImage.new(:large, [800, 800], :resize_to_fit),
|
15
|
+
}
|
16
|
+
end
|
17
|
+
|
18
|
+
let(:container) {Utopia::Gallery::Container.new(pages_root, 'sample_images')}
|
19
|
+
|
20
|
+
subject{container.collect{|media| described_class.new(pages_root, cache_root, '/_gallery', media, processes)}}
|
21
|
+
|
22
|
+
it "should generate thumbnails" do
|
23
|
+
subject.each(&:update)
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
<gallery:container tag="content:photo" path="sample_images" />
|
@@ -0,0 +1 @@
|
|
1
|
+
<gallery:container path="sample_images"/>
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
@@ -0,0 +1,70 @@
|
|
1
|
+
# Copyright, 2012, by Samuel G. D. Williams. <http://www.codeotaku.com>
|
2
|
+
#
|
3
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
# of this software and associated documentation files (the "Software"), to deal
|
5
|
+
# in the Software without restriction, including without limitation the rights
|
6
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
+
# copies of the Software, and to permit persons to whom the Software is
|
8
|
+
# furnished to do so, subject to the following conditions:
|
9
|
+
#
|
10
|
+
# The above copyright notice and this permission notice shall be included in
|
11
|
+
# all copies or substantial portions of the Software.
|
12
|
+
#
|
13
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
|
+
# THE SOFTWARE.
|
20
|
+
|
21
|
+
require 'rack/test'
|
22
|
+
require 'utopia/content'
|
23
|
+
|
24
|
+
describe Utopia::Gallery do
|
25
|
+
include Rack::Test::Methods
|
26
|
+
|
27
|
+
let(:app) {Rack::Builder.parse_file(File.expand_path('site_spec.ru', __dir__)).first}
|
28
|
+
|
29
|
+
let(:cache_root) {File.join(__dir__, 'site/public/_gallery')}
|
30
|
+
|
31
|
+
before(:each) do
|
32
|
+
FileUtils.rm_rf cache_root
|
33
|
+
end
|
34
|
+
|
35
|
+
it "should generate gallery of sample images" do
|
36
|
+
get "/index"
|
37
|
+
|
38
|
+
expect(last_response.body).to be == '<div class="gallery"><img src="/sample_images/IMG_3340.jpg" alt="IMG_3340"/><img src="/sample_images/IMG_3341.jpg" alt="IMG_3341"/><img src="/sample_images/IMG_3344.jpg" alt="IMG_3344"/><img src="/sample_images/IMG_3351.jpg" alt="IMG_3351"/></div>'
|
39
|
+
end
|
40
|
+
|
41
|
+
it "should generate a gallery using the specified tag" do
|
42
|
+
get "/gallery"
|
43
|
+
|
44
|
+
expect(last_response.body).to be == '<div class="gallery"><span class="photo">
|
45
|
+
<a rel="photos" class="thumbnail" href="/_gallery/sample_images/large/IMG_3340.jpg" title="IMG_3340">
|
46
|
+
<img src="/_gallery/sample_images/small/IMG_3340.jpg" alt="IMG_3340"/>
|
47
|
+
</a>
|
48
|
+
<div class="caption">IMG_3340</div>
|
49
|
+
</span>
|
50
|
+
<span class="photo">
|
51
|
+
<a rel="photos" class="thumbnail" href="/_gallery/sample_images/large/IMG_3341.jpg" title="IMG_3341">
|
52
|
+
<img src="/_gallery/sample_images/small/IMG_3341.jpg" alt="IMG_3341"/>
|
53
|
+
</a>
|
54
|
+
<div class="caption">IMG_3341</div>
|
55
|
+
</span>
|
56
|
+
<span class="photo">
|
57
|
+
<a rel="photos" class="thumbnail" href="/_gallery/sample_images/large/IMG_3344.jpg" title="IMG_3344">
|
58
|
+
<img src="/_gallery/sample_images/small/IMG_3344.jpg" alt="IMG_3344"/>
|
59
|
+
</a>
|
60
|
+
<div class="caption">IMG_3344</div>
|
61
|
+
</span>
|
62
|
+
<span class="photo">
|
63
|
+
<a rel="photos" class="thumbnail" href="/_gallery/sample_images/large/IMG_3351.jpg" title="IMG_3351">
|
64
|
+
<img src="/_gallery/sample_images/small/IMG_3351.jpg" alt="IMG_3351"/>
|
65
|
+
</a>
|
66
|
+
<div class="caption">IMG_3351</div>
|
67
|
+
</span>
|
68
|
+
</div>'
|
69
|
+
end
|
70
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
|
2
|
+
require 'utopia/content'
|
3
|
+
|
4
|
+
pages_root = File.expand_path('site/pages', __dir__)
|
5
|
+
gallery_root = File.expand_path('site/public/_gallery', __dir__)
|
6
|
+
|
7
|
+
use Utopia::Content,
|
8
|
+
root: pages_root,
|
9
|
+
namespaces: {
|
10
|
+
'gallery' => Utopia::Gallery::Tags.new(media_root: pages_root, cache_root: gallery_root, cache_path: '/_gallery')
|
11
|
+
}
|
12
|
+
|
13
|
+
run lambda{|env| [200, {}, []]}
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
require_relative 'lib/utopia/gallery/version'
|
3
|
+
|
4
|
+
Gem::Specification.new do |spec|
|
5
|
+
spec.name = "utopia-gallery"
|
6
|
+
spec.version = Utopia::Gallery::VERSION
|
7
|
+
spec.authors = ["Samuel Williams"]
|
8
|
+
spec.email = ["samuel.williams@oriontransfer.co.nz"]
|
9
|
+
|
10
|
+
spec.summary = %q{A gallery tag for use with the Utopia web framework.}
|
11
|
+
spec.homepage = "https://github.com/ioquatix/utopia-gallery"
|
12
|
+
spec.license = "MIT"
|
13
|
+
|
14
|
+
spec.files = `git ls-files`.split($/)
|
15
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
16
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
17
|
+
spec.require_paths = ["lib"]
|
18
|
+
|
19
|
+
spec.add_dependency "utopia", "~> 2.0"
|
20
|
+
spec.add_dependency "vips-thumbnail"
|
21
|
+
|
22
|
+
spec.add_development_dependency "bundler", "~> 1.14"
|
23
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
24
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
25
|
+
end
|
metadata
ADDED
@@ -0,0 +1,151 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: utopia-gallery
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 2.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Samuel Williams
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-03-23 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: utopia
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '2.0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '2.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: vips-thumbnail
|
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'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.14'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.14'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '10.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '10.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rspec
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '3.0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '3.0'
|
83
|
+
description:
|
84
|
+
email:
|
85
|
+
- samuel.williams@oriontransfer.co.nz
|
86
|
+
executables: []
|
87
|
+
extensions: []
|
88
|
+
extra_rdoc_files: []
|
89
|
+
files:
|
90
|
+
- ".gitignore"
|
91
|
+
- ".rspec"
|
92
|
+
- Gemfile
|
93
|
+
- README.md
|
94
|
+
- Rakefile
|
95
|
+
- lib/utopia/gallery.rb
|
96
|
+
- lib/utopia/gallery/cache.rb
|
97
|
+
- lib/utopia/gallery/container.rb
|
98
|
+
- lib/utopia/gallery/media.rb
|
99
|
+
- lib/utopia/gallery/process.rb
|
100
|
+
- lib/utopia/gallery/tags.rb
|
101
|
+
- lib/utopia/gallery/version.rb
|
102
|
+
- spec/spec_helper.rb
|
103
|
+
- spec/utopia/gallery/cache_spec.rb
|
104
|
+
- spec/utopia/gallery/container_spec.rb
|
105
|
+
- spec/utopia/gallery/site/pages/_photo.xnode
|
106
|
+
- spec/utopia/gallery/site/pages/gallery.xnode
|
107
|
+
- spec/utopia/gallery/site/pages/index.xnode
|
108
|
+
- spec/utopia/gallery/site/pages/sample_images/IMG_3340.jpg
|
109
|
+
- spec/utopia/gallery/site/pages/sample_images/IMG_3341.jpg
|
110
|
+
- spec/utopia/gallery/site/pages/sample_images/IMG_3344.jpg
|
111
|
+
- spec/utopia/gallery/site/pages/sample_images/IMG_3351.jpg
|
112
|
+
- spec/utopia/gallery/site_spec.rb
|
113
|
+
- spec/utopia/gallery/site_spec.ru
|
114
|
+
- utopia-gallery.gemspec
|
115
|
+
homepage: https://github.com/ioquatix/utopia-gallery
|
116
|
+
licenses:
|
117
|
+
- MIT
|
118
|
+
metadata: {}
|
119
|
+
post_install_message:
|
120
|
+
rdoc_options: []
|
121
|
+
require_paths:
|
122
|
+
- lib
|
123
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
124
|
+
requirements:
|
125
|
+
- - ">="
|
126
|
+
- !ruby/object:Gem::Version
|
127
|
+
version: '0'
|
128
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
129
|
+
requirements:
|
130
|
+
- - ">="
|
131
|
+
- !ruby/object:Gem::Version
|
132
|
+
version: '0'
|
133
|
+
requirements: []
|
134
|
+
rubyforge_project:
|
135
|
+
rubygems_version: 2.6.10
|
136
|
+
signing_key:
|
137
|
+
specification_version: 4
|
138
|
+
summary: A gallery tag for use with the Utopia web framework.
|
139
|
+
test_files:
|
140
|
+
- spec/spec_helper.rb
|
141
|
+
- spec/utopia/gallery/cache_spec.rb
|
142
|
+
- spec/utopia/gallery/container_spec.rb
|
143
|
+
- spec/utopia/gallery/site/pages/_photo.xnode
|
144
|
+
- spec/utopia/gallery/site/pages/gallery.xnode
|
145
|
+
- spec/utopia/gallery/site/pages/index.xnode
|
146
|
+
- spec/utopia/gallery/site/pages/sample_images/IMG_3340.jpg
|
147
|
+
- spec/utopia/gallery/site/pages/sample_images/IMG_3341.jpg
|
148
|
+
- spec/utopia/gallery/site/pages/sample_images/IMG_3344.jpg
|
149
|
+
- spec/utopia/gallery/site/pages/sample_images/IMG_3351.jpg
|
150
|
+
- spec/utopia/gallery/site_spec.rb
|
151
|
+
- spec/utopia/gallery/site_spec.ru
|