Class: RailsConnector::Link
- Inherits:
-
Object
- Object
- RailsConnector::Link
- Extended by:
- ActiveModel::Naming
- Defined in:
- lib/rails_connector/link.rb
Overview
This class provides an interfaces for handling CMS Links. To format a link for rendering in an html page, use the cms_path or cms_url methods.
Instance Method Summary collapse
-
#active? ⇒ Boolean
An internal Link is active if it’s destination object is active.
-
#destination_object ⇒ Object
Returns the destination object (
Obj) of this Link. -
#destination_object_id ⇒ Object
Returns the id of the Links’ destination_object.
-
#display_title ⇒ Object
Returns the title of this Link if it is set.
-
#external? ⇒ Boolean
Returns true if this Link links to an external URL.
-
#file_extension ⇒ Object
Returns the file extension (e.g. zip, pdf) of this link’s (internal or external) target.
-
#fragment ⇒ Object
Returns the link’s anchor as in “index.html#anchor”.
-
#internal? ⇒ Boolean
Returns true this Link links to a CMS Object.
-
#query ⇒ Object
Returns the link’s query string as in “index.html?query_string”.
-
#search ⇒ Object
Depricated: use Link#query instead.
-
#target ⇒ Object
Returns the browser window or browser frame to be used as a target for this link.
-
#title ⇒ Object
The link’s title.
-
#url ⇒ Object
The link’s external url.
Instance Method Details
#active? ⇒ Boolean
An internal Link is active if it’s destination object is active. An external Link is always active.
109 110 111 |
# File 'lib/rails_connector/link.rb', line 109 def active? external? || (destination_object && destination_object.active?) end |
#destination_object ⇒ Object
Returns the destination object (Obj) of this Link. May be nil if the link is external or internal without an existing destination object.
124 125 126 127 128 |
# File 'lib/rails_connector/link.rb', line 124 def destination_object @destination_object ||= Obj.find(destination) if resolved_internal? rescue RailsConnector::ResourceNotFound nil end |
#destination_object_id ⇒ Object
Returns the id of the Links’ destination_object.
79 80 81 |
# File 'lib/rails_connector/link.rb', line 79 def destination_object_id destination end |
#display_title ⇒ Object
Returns the title of this Link if it is set. Otherwise it returns the display_title of the destination object for internal Links or the URL for external Links.
87 88 89 90 91 92 |
# File 'lib/rails_connector/link.rb', line 87 def display_title dt = title dt = destination_object.display_title if dt.blank? && !external? dt = url if dt.blank? dt end |
#external? ⇒ Boolean
Returns true if this Link links to an external URL.
102 103 104 |
# File 'lib/rails_connector/link.rb', line 102 def external? !internal? end |
#file_extension ⇒ Object
Returns the file extension (e.g. zip, pdf) of this link’s (internal or external) target. Returns an empty string if the file extension is can not be determined.
68 69 70 71 72 73 74 75 |
# File 'lib/rails_connector/link.rb', line 68 def file_extension if internal? destination_object ? destination_object.file_extension : "" else path = URI.parse(url).path rescue nil path.blank? ? "" : File.extname(path)[1..-1] || "" end end |
#fragment ⇒ Object
Returns the link’s anchor as in “index.html#anchor”. See RFC3986 for details (www.ietf.org/rfc/rfc3986.txt).
46 47 48 |
# File 'lib/rails_connector/link.rb', line 46 def fragment @link_data[:fragment] end |
#internal? ⇒ Boolean
Returns true this Link links to a CMS Object.
96 97 98 |
# File 'lib/rails_connector/link.rb', line 96 def internal? url.nil? end |
#query ⇒ Object
Returns the link’s query string as in “index.html?query_string”. See RFC3986 for details (www.ietf.org/rfc/rfc3986.txt).
31 32 33 |
# File 'lib/rails_connector/link.rb', line 31 def query @link_data[:query] end |
#search ⇒ Object
Depricated: use Link#query instead. Returns the link’s query string as in “index.html?query_string”. See RFC3986 for details (www.ietf.org/rfc/rfc3986.txt).
39 40 41 |
# File 'lib/rails_connector/link.rb', line 39 def search query end |
#target ⇒ Object
Returns the browser window or browser frame to be used as a target for this link. Example: Links that should be opened in a new window will return “_blank” as their target.
53 54 55 |
# File 'lib/rails_connector/link.rb', line 53 def target @link_data[:target] end |
#title ⇒ Object
The link’s title.
24 25 26 |
# File 'lib/rails_connector/link.rb', line 24 def title @link_data[:title] end |
#url ⇒ Object
The link’s external url. Only available for external links. Warning: Do not output the url directly unless you know what you are doing. Normally you want to use the cms_path or cms_url methods to format a link.
18 19 20 |
# File 'lib/rails_connector/link.rb', line 18 def url @link_data[:url] end |