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 its destination obj is active.
-
#destination_object ⇒ Object
deprecated
Deprecated.
use #obj instead
-
#destination_object_id ⇒ Object
deprecated
Deprecated.
use #obj.id instead
-
#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”.
-
#fragment=(value) ⇒ Object
Set the link’s anchor as in “index.html#anchor”.
-
#initialize(link_data) ⇒ Link
constructor
Create a new link obj.
-
#internal? ⇒ Boolean
Returns true this Link links to a CMS Object.
-
#obj ⇒ Object
Returns the Obj this link is referencing.
-
#obj=(value) ⇒ Object
Set the Obj this link is referencing.
-
#query ⇒ Object
Returns the link’s query string as in “index.html?query_string”.
-
#query=(value) ⇒ Object
Set the link’s query string as in “index.html?query_string”.
-
#target ⇒ Object
Returns the browser window or browser frame to be used as a target for this link.
-
#target=(value) ⇒ Object
Set the browser window or browser frame to be used as a target for this link.
-
#title ⇒ Object
The link’s title.
-
#title=(value) ⇒ Object
Set the link’s title.
-
#url ⇒ Object
The link’s external url.
-
#url=(value) ⇒ Object
Set the link’s external url.
Constructor Details
#initialize(link_data) ⇒ Link
Create a new link obj
18 19 20 |
# File 'lib/rails_connector/link.rb', line 18 def initialize(link_data) @link_data = link_data.with_indifferent_access end |
Instance Method Details
#active? ⇒ Boolean
An internal Link is active if its destination obj is active. An external Link is always active. @ deprecated this method will be removed without substitution
169 170 171 172 |
# File 'lib/rails_connector/link.rb', line 169 def active? Deprecation.warn_method('Link#active?') external? || (obj && obj.active?) end |
#destination_object ⇒ Object
186 187 188 189 |
# File 'lib/rails_connector/link.rb', line 186 def destination_object Deprecation.warn_method('Link#destination_object', :obj) obj end |
#destination_object_id ⇒ Object
use #obj.id instead
Returns the id of the Links’ destination obj.
137 138 139 140 |
# File 'lib/rails_connector/link.rb', line 137 def destination_object_id Deprecation.warn_method('Link#destination_object_id', 'obj.id') obj.id 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.
146 147 148 149 150 151 |
# File 'lib/rails_connector/link.rb', line 146 def display_title dt = title dt = obj.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.
161 162 163 |
# File 'lib/rails_connector/link.rb', line 161 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.
125 126 127 128 129 130 131 132 |
# File 'lib/rails_connector/link.rb', line 125 def file_extension if internal? obj ? obj.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).
83 84 85 |
# File 'lib/rails_connector/link.rb', line 83 def fragment @link_data[:fragment] end |
#fragment=(value) ⇒ Object
Set the link’s anchor as in “index.html#anchor”. See RFC3986 for details (www.ietf.org/rfc/rfc3986.txt).
91 92 93 |
# File 'lib/rails_connector/link.rb', line 91 def fragment=(value) @link_data[:fragment] = value end |
#internal? ⇒ Boolean
Returns true this Link links to a CMS Object.
155 156 157 |
# File 'lib/rails_connector/link.rb', line 155 def internal? url.nil? end |
#obj ⇒ Object
Returns the Obj this link is referencing. May be nil if the link is external.
40 41 42 |
# File 'lib/rails_connector/link.rb', line 40 def obj @link_data[:obj] end |
#obj=(value) ⇒ Object
Set the Obj this link is referencing. May be nil if the link is external.
48 49 50 |
# File 'lib/rails_connector/link.rb', line 48 def obj=(value) @link_data[:obj] = value 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).
68 69 70 |
# File 'lib/rails_connector/link.rb', line 68 def query @link_data[:query] end |
#query=(value) ⇒ Object
Set the link’s query string as in “index.html?query_string”. See RFC3986 for details (www.ietf.org/rfc/rfc3986.txt).
76 77 78 |
# File 'lib/rails_connector/link.rb', line 76 def query=(value) @link_data[:query] = value 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.
98 99 100 |
# File 'lib/rails_connector/link.rb', line 98 def target @link_data[:target] end |
#target=(value) ⇒ Object
Set 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.
106 107 108 |
# File 'lib/rails_connector/link.rb', line 106 def target=(value) @link_data[:target] = value end |
#title ⇒ Object
The link’s title.
54 55 56 |
# File 'lib/rails_connector/link.rb', line 54 def title @link_data[:title] end |
#title=(value) ⇒ Object
Set the link’s title.
61 62 63 |
# File 'lib/rails_connector/link.rb', line 61 def title=(value) @link_data[:title] = value 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.
26 27 28 |
# File 'lib/rails_connector/link.rb', line 26 def url @link_data[:url] end |
#url=(value) ⇒ Object
Set the link’s external url. This will lead to an external link.
33 34 35 |
# File 'lib/rails_connector/link.rb', line 33 def url=(value) @link_data[:url] = value end |