Module: Taggable::FacetedPage::InstanceMethods

Defined in:
lib/taggable/faceted_page.rb

Instance Method Summary collapse

Instance Method Details

#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.



29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/taggable/faceted_page.rb', line 29

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



52
53
54
# File 'lib/taggable/faceted_page.rb', line 52

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.



46
47
48
# File 'lib/taggable/faceted_page.rb', line 46

def requested_tags
  @requested_tags ||= []
end