Class: LibraryPage

Inherits:
Page
  • Object
show all
Includes:
Library::LibraryTags, WillPaginate::ViewHelpers
Defined in:
app/models/library_page.rb

Defined Under Namespace

Classes: RedirectRequired

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Library::LibraryTags

#_default_library_find_options, #_get_assets, #_get_pages, #asset_find_options

Methods included from LibraryHelper

#clean_html, #strip_html, #truncate_words

Instance Attribute Details

#requested_tagsObject

Returns the value of attribute requested_tags.



11
12
13
# File 'app/models/library_page.rb', line 11

def requested_tags
  @requested_tags
end

#strict_matchObject

Returns the value of attribute strict_match.



11
12
13
# File 'app/models/library_page.rb', line 11

def strict_match
  @strict_match
end

Instance Method Details

#add_request_tags(tags = []) ⇒ Object



32
33
34
35
36
37
# File 'app/models/library_page.rb', line 32

def add_request_tags(tags=[])
  if tags.any?
    tags.collect! { |tag| Tag.find_by_title(Rack::Utils::unescape(tag)) }
    self.requested_tags = (self.requested_tags + tags.select{|t| !t.nil?}).uniq
  end
end

#cache?Boolean

Returns:

  • (Boolean)


13
14
15
# File 'app/models/library_page.rb', line 13

def cache?
  true
end

#find_by_url(url, live = true, clean = false) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'app/models/library_page.rb', line 17

def find_by_url(url, live = true, clean = false)
  url = clean_url(url) if clean
  my_url = self.url
  return false unless url =~ /^#{Regexp.quote(my_url)}(.*)/
  tags = $1.split('/')
  if slug_child = children.find_by_slug(tags[0])
    found = slug_child.find_by_url(url, 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

#remove_request_tags(tags = []) ⇒ Object



39
40
41
42
43
44
45
46
47
# File 'app/models/library_page.rb', line 39

def remove_request_tags(tags=[])
  if tags.any?
    tags.collect! { |tag|
      tag.slice!(0) if tag.first == '-' 
      Tag.find_by_title(Rack::Utils::unescape(tag)) 
    }
    self.requested_tags = (self.requested_tags - tags.select{|t| !t.nil?}).uniq
  end
end

#url_with_tags(tags = requested_tags) ⇒ Object

this isn’t very pleasing but it’s the best way to let the controller know of our real address once tags have been added and removed.



56
57
58
# File 'app/models/library_page.rb', line 56

def url_with_tags(tags = requested_tags)
  clean_url( url_without_tags + '/' + tags.uniq.map(&:clean_title).to_param )
end