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
Deprecated: 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.
117 118 119 |
# File 'lib/rails_connector/link.rb', line 117 def active? external? || (destination_object && destination_object.active?) end |
#destination_object ⇒ Object
Returns the destination object (Obj
) of this Link.
131 132 133 |
# File 'lib/rails_connector/link.rb', line 131 def destination_object @destination_object ||= Obj.find(destination) if resolved_internal? end |
#destination_object_id ⇒ Object
Returns the id of the Links’ destination_object.
87 88 89 |
# File 'lib/rails_connector/link.rb', line 87 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.
95 96 97 98 99 100 |
# File 'lib/rails_connector/link.rb', line 95 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.
110 111 112 |
# File 'lib/rails_connector/link.rb', line 110 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.
76 77 78 79 80 81 82 83 |
# File 'lib/rails_connector/link.rb', line 76 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.
104 105 106 |
# File 'lib/rails_connector/link.rb', line 104 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[:search] end |
#search ⇒ Object
Deprecated: 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 |