Module: Library::LibraryTags

Includes:
LibraryHelper, Radiant::Taggable
Included in:
LibraryPage
Defined in:
lib/library/library_tags.rb

Defined Under Namespace

Classes: TagError

Instance Method Summary collapse

Methods included from LibraryHelper

#clean_html, #strip_html, #truncate_words

Instance Method Details

#_default_library_find_optionsObject

a bit of extra logic so that in the absence of any requested tags we default to all, not none



278
279
280
281
282
283
# File 'lib/library/library_tags.rb', line 278

def _default_library_find_options
  {
    :by => 'created_at',
    :order => 'desc'
  }
end

#_get_assets(tag) ⇒ Object



293
294
295
296
297
298
299
# File 'lib/library/library_tags.rb', line 293

def _get_assets(tag)
  options = asset_find_options(tag)
  requested = _get_requested_tags(tag)
  assets = Asset.scoped(options)
  assets = assets.tagged_with(requested) if requested.any?
  assets
end

#_get_pages(tag) ⇒ Object



285
286
287
288
289
290
291
# File 'lib/library/library_tags.rb', line 285

def _get_pages(tag)
  options = children_find_options(tag)
  requested = _get_requested_tags(tag)
  pages = Page.scoped(options)
  pages = pages.tagged_with(requested) if requested.any?
  pages
end

#asset_find_options(tag) ⇒ Object

duplicate of children_find_options except: no virtual or status options defaults to chronological descending



305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
# File 'lib/library/library_tags.rb', line 305

def asset_find_options(tag)
  attr = tag.attr.symbolize_keys

  options = {}

  [:limit, :offset].each do |symbol|
    if number = attr[symbol]
      if number =~ /^\d{1,4}$/
        options[symbol] = number.to_i
      else
        raise TagError.new("`#{symbol}' attribute of `each' tag must be a positive number between 1 and 4 digits")
      end
    end
  end

  by = (attr[:by] || 'created_at').strip
  order = (attr[:order] || 'desc').strip
  order_string = ''
  if self.attributes.keys.include?(by)
    order_string << by
  else
    raise TagError.new("`by' attribute of `each' tag must be set to a valid field name")
  end
  if order =~ /^(asc|desc)$/i
    order_string << " #{$1.upcase}"
  else
    raise TagError.new(%{`order' attribute of `each' tag must be set to either "asc" or "desc"})
  end
  options[:order] = order_string
  options
end