bulldog 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +5 -0
- data/lib/bulldog/attachment/maybe.rb +10 -2
- data/lib/bulldog/version.rb +1 -1
- data/spec/unit/attachment/maybe_spec.rb +108 -58
- metadata +3 -3
data/CHANGELOG
CHANGED
@@ -152,7 +152,11 @@ module Bulldog
|
|
152
152
|
def interpolate_path(style_name, params={})
|
153
153
|
template = reflection.path_template
|
154
154
|
style = reflection.styles[style_name]
|
155
|
-
|
155
|
+
if template.is_a?(Symbol)
|
156
|
+
record.send(template, name, style)
|
157
|
+
else
|
158
|
+
Interpolation.interpolate(template, record, name, style, params)
|
159
|
+
end
|
156
160
|
end
|
157
161
|
|
158
162
|
#
|
@@ -166,7 +170,11 @@ module Bulldog
|
|
166
170
|
def interpolate_url(style_name, params={})
|
167
171
|
template = reflection.url_template
|
168
172
|
style = reflection.styles[style_name]
|
169
|
-
|
173
|
+
if template.is_a?(Symbol)
|
174
|
+
record.send(template, name, style)
|
175
|
+
else
|
176
|
+
Interpolation.interpolate(template, record, name, style, params)
|
177
|
+
end
|
170
178
|
end
|
171
179
|
|
172
180
|
protected # ---------------------------------------------------
|
data/lib/bulldog/version.rb
CHANGED
@@ -22,107 +22,157 @@ describe Attachment::Maybe do
|
|
22
22
|
end
|
23
23
|
|
24
24
|
describe "#interpolate_path" do
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
25
|
+
describe "when the path template is a Symbol" do
|
26
|
+
before do
|
27
|
+
Thing.class_eval do
|
28
|
+
has_attachment :photo do
|
29
|
+
path :test_path
|
30
|
+
end
|
31
|
+
|
32
|
+
define_method :test_path do |@name, @style|
|
33
|
+
"#{name}-#{style.name}"
|
34
|
+
end
|
35
|
+
|
36
|
+
attr_reader :name, :style
|
37
|
+
end
|
38
|
+
@thing = Thing.new
|
29
39
|
end
|
30
|
-
@thing.photo.interpolate_path(:original).should == "#{temporary_directory}/photo.original.jpg"
|
31
|
-
end
|
32
40
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
41
|
+
it "should call the specified method with the attachment name and style" do
|
42
|
+
@thing.photo.interpolate_path(:original).should == "photo-original"
|
43
|
+
@thing.name == :photo
|
44
|
+
@thing.style.name == :original
|
37
45
|
end
|
38
|
-
@thing.photo.interpolate_path(:original, :style => 'STYLE').should == "#{temporary_directory}/photo.STYLE.jpg"
|
39
46
|
end
|
40
47
|
|
41
|
-
|
42
|
-
|
43
|
-
configure_attachment do
|
44
|
-
style :processed, :format => 'png'
|
45
|
-
path "#{spec.temporary_directory}/:attachment.:style.:extension"
|
46
|
-
end
|
47
|
-
@thing.photo.interpolate_path(:processed, :format => 'png').should == "#{temporary_directory}/photo.processed.png"
|
48
|
-
end
|
49
|
-
|
50
|
-
describe "for the original style" do
|
51
|
-
it "should support the :basename interpolation key if the basename is given" do
|
48
|
+
describe "when the path template is a String" do
|
49
|
+
it "should return the path that the given style name would be stored at" do
|
52
50
|
spec = self
|
53
51
|
configure_attachment do
|
54
|
-
path "#{spec.temporary_directory}/:attachment.:style
|
52
|
+
path "#{spec.temporary_directory}/:attachment.:style.jpg"
|
55
53
|
end
|
56
|
-
@thing.photo.interpolate_path(:original
|
54
|
+
@thing.photo.interpolate_path(:original).should == "#{temporary_directory}/photo.original.jpg"
|
57
55
|
end
|
58
56
|
|
59
|
-
it "should
|
57
|
+
it "should use the given interpolation parameters" do
|
60
58
|
spec = self
|
61
59
|
configure_attachment do
|
62
|
-
path "#{spec.temporary_directory}/:attachment.:style
|
60
|
+
path "#{spec.temporary_directory}/:attachment.:style.jpg"
|
63
61
|
end
|
64
|
-
@thing.photo.interpolate_path(:original, :
|
62
|
+
@thing.photo.interpolate_path(:original, :style => 'STYLE').should == "#{temporary_directory}/photo.STYLE.jpg"
|
65
63
|
end
|
66
64
|
|
67
|
-
it "should
|
65
|
+
it "should use the style's format attribute for the extension by default" do
|
68
66
|
spec = self
|
69
67
|
configure_attachment do
|
68
|
+
style :processed, :format => 'png'
|
70
69
|
path "#{spec.temporary_directory}/:attachment.:style.:extension"
|
71
70
|
end
|
72
|
-
@thing.photo.interpolate_path(:
|
71
|
+
@thing.photo.interpolate_path(:processed, :format => 'png').should == "#{temporary_directory}/photo.processed.png"
|
73
72
|
end
|
74
|
-
end
|
75
|
-
end
|
76
73
|
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
74
|
+
describe "for the original style" do
|
75
|
+
it "should support the :basename interpolation key if the basename is given" do
|
76
|
+
spec = self
|
77
|
+
configure_attachment do
|
78
|
+
path "#{spec.temporary_directory}/:attachment.:style/:basename"
|
79
|
+
end
|
80
|
+
@thing.photo.interpolate_path(:original, :basename => 'file.xyz').should == "#{temporary_directory}/photo.original/file.xyz"
|
81
|
+
end
|
82
|
+
|
83
|
+
it "should support the :extension interpolation key if the basename is given" do
|
84
|
+
spec = self
|
85
|
+
configure_attachment do
|
86
|
+
path "#{spec.temporary_directory}/:attachment.:style.:extension"
|
87
|
+
end
|
88
|
+
@thing.photo.interpolate_path(:original, :basename => 'file.xyz').should == "#{temporary_directory}/photo.original.xyz"
|
89
|
+
end
|
90
|
+
|
91
|
+
it "should support the :extension interpolation key if the extension is given" do
|
92
|
+
spec = self
|
93
|
+
configure_attachment do
|
94
|
+
path "#{spec.temporary_directory}/:attachment.:style.:extension"
|
95
|
+
end
|
96
|
+
@thing.photo.interpolate_path(:original, :extension => 'xyz').should == "#{temporary_directory}/photo.original.xyz"
|
97
|
+
end
|
82
98
|
end
|
83
|
-
@thing.photo.interpolate_url(:original).should == "/photo.original.jpg"
|
84
99
|
end
|
100
|
+
end
|
85
101
|
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
102
|
+
describe "#interpolate_url" do
|
103
|
+
describe "when the url template is a Symbol" do
|
104
|
+
before do
|
105
|
+
Thing.class_eval do
|
106
|
+
has_attachment :photo do
|
107
|
+
url :test_url
|
108
|
+
end
|
109
|
+
|
110
|
+
define_method :test_url do |@name, @style|
|
111
|
+
"#{name}-#{style.name}"
|
112
|
+
end
|
113
|
+
|
114
|
+
attr_reader :name, :style
|
115
|
+
end
|
116
|
+
@thing = Thing.new
|
90
117
|
end
|
91
|
-
@thing.photo.interpolate_url(:original, :style => 'STYLE').should == "/photo.STYLE.jpg"
|
92
|
-
end
|
93
118
|
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
style
|
98
|
-
url "/:attachment.:style.:extension"
|
119
|
+
it "should call the specified method with the attachment name and style" do
|
120
|
+
@thing.photo.interpolate_url(:original).should == "photo-original"
|
121
|
+
@thing.name == :photo
|
122
|
+
@thing.style.name == :original
|
99
123
|
end
|
100
|
-
@thing.photo.interpolate_url(:processed).should == "/photo.processed.png"
|
101
124
|
end
|
102
125
|
|
103
|
-
describe "
|
104
|
-
it "should
|
126
|
+
describe "when the url template is a String" do
|
127
|
+
it "should return the url that the given style name would be found at" do
|
105
128
|
spec = self
|
106
129
|
configure_attachment do
|
107
|
-
url "/:attachment.:style
|
130
|
+
url "/:attachment.:style.jpg"
|
108
131
|
end
|
109
|
-
@thing.photo.interpolate_url(:original
|
132
|
+
@thing.photo.interpolate_url(:original).should == "/photo.original.jpg"
|
110
133
|
end
|
111
134
|
|
112
|
-
it "should
|
135
|
+
it "should use the given interpolation parameters" do
|
113
136
|
spec = self
|
114
137
|
configure_attachment do
|
115
|
-
url "/:attachment.:style
|
138
|
+
url "/:attachment.:style.jpg"
|
116
139
|
end
|
117
|
-
@thing.photo.interpolate_url(:original, :
|
140
|
+
@thing.photo.interpolate_url(:original, :style => 'STYLE').should == "/photo.STYLE.jpg"
|
118
141
|
end
|
119
142
|
|
120
|
-
it "should
|
143
|
+
it "should use the style's format attribute for the extension by default" do
|
121
144
|
spec = self
|
122
145
|
configure_attachment do
|
146
|
+
style :processed, :format => 'png'
|
123
147
|
url "/:attachment.:style.:extension"
|
124
148
|
end
|
125
|
-
@thing.photo.interpolate_url(:
|
149
|
+
@thing.photo.interpolate_url(:processed).should == "/photo.processed.png"
|
150
|
+
end
|
151
|
+
|
152
|
+
describe "for the original style" do
|
153
|
+
it "should support the :basename interpolation key if the basename is given" do
|
154
|
+
spec = self
|
155
|
+
configure_attachment do
|
156
|
+
url "/:attachment.:style/:basename"
|
157
|
+
end
|
158
|
+
@thing.photo.interpolate_url(:original, :basename => 'file.xyz').should == "/photo.original/file.xyz"
|
159
|
+
end
|
160
|
+
|
161
|
+
it "should support the :extension interpolation key if the basename is given" do
|
162
|
+
spec = self
|
163
|
+
configure_attachment do
|
164
|
+
url "/:attachment.:style.:extension"
|
165
|
+
end
|
166
|
+
@thing.photo.interpolate_url(:original, :basename => 'file.xyz').should == "/photo.original.xyz"
|
167
|
+
end
|
168
|
+
|
169
|
+
it "should support the :extension interpolation key if the extension is given" do
|
170
|
+
spec = self
|
171
|
+
configure_attachment do
|
172
|
+
url "/:attachment.:style.:extension"
|
173
|
+
end
|
174
|
+
@thing.photo.interpolate_url(:original, :extension => 'xyz').should == "/photo.original.xyz"
|
175
|
+
end
|
126
176
|
end
|
127
177
|
end
|
128
178
|
end
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 2
|
8
|
-
-
|
9
|
-
version: 0.2.
|
8
|
+
- 1
|
9
|
+
version: 0.2.1
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- George Ogata
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-07-
|
17
|
+
date: 2010-07-15 00:00:00 -04:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|