Class: Gumdrop::ContentList
- Inherits:
-
Hash
- Object
- Hash
- Gumdrop::ContentList
show all
- Defined in:
- lib/gumdrop/content.rb
Instance Method Summary
collapse
Methods inherited from Hash
#ends_with?, #starts_with?, #to_hash_object, #to_symbolized_hash
Constructor Details
Returns a new instance of ContentList.
196
197
198
199
|
# File 'lib/gumdrop/content.rb', line 196
def initialize
@cache = {}
super
end
|
Instance Method Details
#add(content, uri = nil) ⇒ Object
206
207
208
209
210
|
# File 'lib/gumdrop/content.rb', line 206
def add(content, uri=nil)
uri= content.uri if uri.nil?
self[uri]= content
content
end
|
#all(pattern = nil) ⇒ Object
Returns Array of content objects
218
219
220
|
# File 'lib/gumdrop/content.rb', line 218
def all(pattern=nil)
pattern.nil? ? values : find(pattern)
end
|
#clear ⇒ Object
234
235
236
237
|
# File 'lib/gumdrop/content.rb', line 234
def clear
@cache.clear()
super
end
|
#create(path, generator = nil, &block) ⇒ Object
201
202
203
204
|
# File 'lib/gumdrop/content.rb', line 201
def create(path, generator=nil, &block)
content= Content.new path, generator, &block
add content end
|
#find(pattern) ⇒ Object
Scans the filenames (keys) and uses fnmatch to find maches
223
224
225
226
227
228
229
230
231
232
|
# File 'lib/gumdrop/content.rb', line 223
def find(pattern)
patterns= [pattern].flatten
contents=[]
self.each_pair do |path, content|
patterns.each do |pattern|
contents << content if Content.path_match? path, pattern
end
end
contents
end
|
#first(pattern) ⇒ Object
243
244
245
246
247
248
249
|
# File 'lib/gumdrop/content.rb', line 243
def first(pattern)
if @cache.has_key? pattern
@cache[pattern]
else
@cache[pattern]= find(pattern).first
end
end
|
#get(key) ⇒ Object
239
240
241
|
# File 'lib/gumdrop/content.rb', line 239
def get(key)
self[key]
end
|
#remove(content) ⇒ Object
212
213
214
215
|
# File 'lib/gumdrop/content.rb', line 212
def remove(content)
uri = content.is_a? String ? content : content.uri
self.delete uri
end
|