utopia-gallery 2.0.3 → 2.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 03fb77bfb663311263c588d8b8f8fe3aaaab4aa0
4
- data.tar.gz: 502e44584091b100cd4dcda5b11f49001da757b5
3
+ metadata.gz: 2d3002edbbeffeaf8c5f2e98f47ec631d8f9fe7d
4
+ data.tar.gz: fb90b5bdfa8ee4d95223cf418f534179641f8198
5
5
  SHA512:
6
- metadata.gz: c991284fd407efa94e5f9013446e6a557837c0612e47656a8647ae39e57e47d42bdf993cd2679f5c7a8e39f399fcae9c0c010df6d440cd4ac2773e195ef00443
7
- data.tar.gz: 4f33aa3535e26ad29a208154095766354b36c307927cc86537b4d3eb1b25c20a1776c6c36c0f4079b7566f7a2cf3fc7b351302b1bd131832c670907fdfa86a6b
6
+ metadata.gz: 663e13e7e9359179e0efe47227ee747b7dffa569fa5fad0b01fdaafdd151bc194717c2711ee09d597cb4987d3636082838e6a1f01525b0405f59b610e2c4c744
7
+ data.tar.gz: 619821213836725b794e66b847ace542a1eb11cdf9846d4cb28837f4c372a6afdec5da6b06941a05e8997f629bdd700d716384cdfb97520e6362ca382bf253f3
@@ -18,6 +18,8 @@
18
18
  # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
19
  # THE SOFTWARE.
20
20
 
21
+ require 'trenni/uri'
22
+
21
23
  module Utopia
22
24
  module Gallery
23
25
  class Cache
@@ -37,10 +39,6 @@ module Utopia
37
39
  attr :processes
38
40
  attr :media
39
41
 
40
- def to_s
41
- @media.path
42
- end
43
-
44
42
  def input_path
45
43
  File.join(@media_root, @media.path)
46
44
  end
@@ -76,10 +74,19 @@ module Utopia
76
74
  return self
77
75
  end
78
76
 
77
+ # Original path.
78
+ def to_s
79
+ original.to_s
80
+ end
81
+
82
+ def original
83
+ Trenni::URI(@media.path)
84
+ end
85
+
79
86
  # This allows dynamic path lookup based on process name, e.g. `cache.small`.
80
87
  def method_missing(name, *args)
81
88
  if process = @processes[name]
82
- return source_path_for(process)
89
+ return Trenni::URI(source_path_for(process))
83
90
  else
84
91
  super
85
92
  end
@@ -32,6 +32,7 @@ module Utopia
32
32
 
33
33
  attr :name
34
34
 
35
+ # The relative path for the output generated by this process, given a specific input media:
35
36
  def relative_path(media)
36
37
  source_path = media.path
37
38
 
@@ -73,6 +74,28 @@ module Utopia
73
74
  attr :method
74
75
  attr :options
75
76
 
77
+ def relative_path(media)
78
+ path = super
79
+
80
+ if path.end_with?(".pdf")
81
+ path += ".png"
82
+ end
83
+
84
+ return path
85
+ end
86
+
87
+ def generate_output(resizer, output_path)
88
+ if output_image = resizer.send(@method, @size)
89
+ output_image.write_to_file output_path, **@options
90
+ else
91
+ Process.link(resizer.input_path, output_path)
92
+ end
93
+ end
94
+
95
+ def resizer_for(media_path)
96
+ Vips::Thumbnail::Resizer.new(media_path)
97
+ end
98
+
76
99
  def call(cache, locals)
77
100
  output_path = cache.output_path_for(self)
78
101
  media = cache.media
@@ -80,16 +103,36 @@ module Utopia
80
103
 
81
104
  return if Process.fresh?(media_path, output_path)
82
105
 
83
- resizer = locals[:resizer] ||= Vips::Thumbnail::Resizer.new(media_path)
106
+ resizer = locals[:resizer] ||= resizer_for(media_path)
84
107
 
85
108
  FileUtils.mkdir_p(File.dirname(output_path))
86
109
 
110
+ generate_output(resizer, output_path)
111
+ end
112
+ end
113
+
114
+ class ResizeVector < ResizeImage
115
+ def initialize(*args, extension: ".png", scale: 1, **options)
116
+ super(*args, **options)
117
+ @extension = extension
118
+ @scale = scale
119
+ end
120
+
121
+ def relative_path(media)
122
+ super + @extension
123
+ end
124
+
125
+ def generate_output(resizer, output_path)
87
126
  if output_image = resizer.send(@method, @size)
88
127
  output_image.write_to_file output_path, **@options
89
128
  else
90
- Process.link(media_path, output_path)
129
+ resizer.input_image.write_to_file output_path, **@options
91
130
  end
92
131
  end
132
+
133
+ def resizer_for(media_path)
134
+ Vips::Thumbnail::Resizer.new(media_path, scale: @scale)
135
+ end
93
136
  end
94
137
  end
95
138
  end
@@ -68,7 +68,7 @@ module Utopia
68
68
  media_tag_name = state[:tag] || 'img'
69
69
 
70
70
  document.tag('div', class: 'gallery') do
71
- container.each do |media|
71
+ container.sort.each do |media|
72
72
  cache = Cache.new(@media_root, @cache_root, @cache_path, media, @processes).update
73
73
  document.tag(media_tag_name, src: cache, alt: media)
74
74
  end
@@ -1,5 +1,5 @@
1
1
  module Utopia
2
2
  module Gallery
3
- VERSION = "2.0.3"
3
+ VERSION = "2.1.0"
4
4
  end
5
5
  end
@@ -0,0 +1,8 @@
1
+ IMG_3340.jpg:
2
+ order: 0
3
+ IMG_3341.jpg:
4
+ order: 1
5
+ IMG 3344.jpg:
6
+ order: 2
7
+ IMG_3351.jpg:
8
+ order: 3
@@ -35,7 +35,7 @@ describe Utopia::Gallery do
35
35
  it "should generate gallery of sample images" do
36
36
  get "/index"
37
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>'
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
39
  end
40
40
 
41
41
  it "should generate a gallery using the specified tag" do
@@ -54,10 +54,10 @@ describe Utopia::Gallery do
54
54
  <div class="caption">IMG_3341</div>
55
55
  </span>
56
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"/>
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
59
  </a>
60
- <div class="caption">IMG_3344</div>
60
+ <div class="caption">IMG 3344</div>
61
61
  </span>
62
62
  <span class="photo">
63
63
  <a rel="photos" class="thumbnail" href="/_gallery/sample_images/large/IMG_3351.jpg" title="IMG_3351">
@@ -17,7 +17,8 @@ Gem::Specification.new do |spec|
17
17
  spec.require_paths = ["lib"]
18
18
 
19
19
  spec.add_dependency "utopia", "~> 2.0"
20
- spec.add_dependency "vips-thumbnail"
20
+ spec.add_dependency "trenni", "~> 3.1"
21
+ spec.add_dependency "vips-thumbnail", "~> 1.1"
21
22
 
22
23
  spec.add_development_dependency "bundler", "~> 1.4"
23
24
  spec.add_development_dependency "rake", "~> 10.5"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: utopia-gallery
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.3
4
+ version: 2.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel Williams
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-03-26 00:00:00.000000000 Z
11
+ date: 2017-03-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: utopia
@@ -24,20 +24,34 @@ dependencies:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '2.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: trenni
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '3.1'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '3.1'
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: vips-thumbnail
29
43
  requirement: !ruby/object:Gem::Requirement
30
44
  requirements:
31
- - - ">="
45
+ - - "~>"
32
46
  - !ruby/object:Gem::Version
33
- version: '0'
47
+ version: '1.1'
34
48
  type: :runtime
35
49
  prerelease: false
36
50
  version_requirements: !ruby/object:Gem::Requirement
37
51
  requirements:
38
- - - ">="
52
+ - - "~>"
39
53
  - !ruby/object:Gem::Version
40
- version: '0'
54
+ version: '1.1'
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: bundler
43
57
  requirement: !ruby/object:Gem::Requirement
@@ -107,10 +121,11 @@ files:
107
121
  - spec/utopia/gallery/site/pages/_photo.xnode
108
122
  - spec/utopia/gallery/site/pages/gallery.xnode
109
123
  - spec/utopia/gallery/site/pages/index.xnode
124
+ - spec/utopia/gallery/site/pages/sample_images/IMG 3344.jpg
110
125
  - spec/utopia/gallery/site/pages/sample_images/IMG_3340.jpg
111
126
  - spec/utopia/gallery/site/pages/sample_images/IMG_3341.jpg
112
- - spec/utopia/gallery/site/pages/sample_images/IMG_3344.jpg
113
127
  - spec/utopia/gallery/site/pages/sample_images/IMG_3351.jpg
128
+ - spec/utopia/gallery/site/pages/sample_images/gallery.yaml
114
129
  - spec/utopia/gallery/site_spec.rb
115
130
  - spec/utopia/gallery/site_spec.ru
116
131
  - utopia-gallery.gemspec
@@ -145,9 +160,10 @@ test_files:
145
160
  - spec/utopia/gallery/site/pages/_photo.xnode
146
161
  - spec/utopia/gallery/site/pages/gallery.xnode
147
162
  - spec/utopia/gallery/site/pages/index.xnode
163
+ - spec/utopia/gallery/site/pages/sample_images/IMG 3344.jpg
148
164
  - spec/utopia/gallery/site/pages/sample_images/IMG_3340.jpg
149
165
  - spec/utopia/gallery/site/pages/sample_images/IMG_3341.jpg
150
- - spec/utopia/gallery/site/pages/sample_images/IMG_3344.jpg
151
166
  - spec/utopia/gallery/site/pages/sample_images/IMG_3351.jpg
167
+ - spec/utopia/gallery/site/pages/sample_images/gallery.yaml
152
168
  - spec/utopia/gallery/site_spec.rb
153
169
  - spec/utopia/gallery/site_spec.ru