Module: Taggable::FacetedPage::InstanceMethods

Defined in:
lib/taggable/faceted_page.rb

Instance Method Summary collapse

Instance Method Details

#cache?Boolean

Faceted pages map nicely onto urls and are cacheable. There can be redundancy if tags are specified in varying order, but the site controller tries to normalize everything.

Returns:

  • (Boolean)


29
30
31
# File 'lib/taggable/faceted_page.rb', line 29

def cache?
  true
end

#find_by_path(path, live = true, clean = false) ⇒ Object Also known as: find_by_url

We override the normal Page#find_by_path mechanism and treat nonexistent child paths are understood as tag sets. Note that the extended site_controller will add to this set any tags that have been supplied in query string parameters. This may trigger a redirect to bring the request path into line with the consolidated tag set.



38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/taggable/faceted_page.rb', line 38

def find_by_path(path, live = true, clean = false)
  path = clean_path(path) if clean
  return false unless path =~ /^#{Regexp.quote(self.path)}(.*)/
  tags = $1.split('/')
  if slug_child = children.find_by_slug(tags[0])
    found = slug_child.find_by_url(path, live, clean)
    return found if found
  end
  remove_tags, add_tags = tags.partition{|t| t.first == '-'}
  add_request_tags(add_tags)
  remove_request_tags(remove_tags)
  self
end

#path_with_tags(tags = requested_tags) ⇒ Object

The normal ‘path` method is extended to append the (sorted and deduped) tags attached to the page request



61
62
63
# File 'lib/taggable/faceted_page.rb', line 61

def path_with_tags(tags = requested_tags)
  clean_path( path_without_tags + '/' + tags.uniq.compact.sort.map(&:clean_title).to_param )
end

#requested_tagsObject

The set of tags attached to the page request.



55
56
57
# File 'lib/taggable/faceted_page.rb', line 55

def requested_tags
  @requested_tags ||= []
end