Module: Card::Set::All::Links::Format
- Extended by:
- Card::Set::AbstractFormat
- Defined in:
- platypus/tmp/set/gem-defaults/mod004-format/all/links.rb
Overview
The #link_to methods support smart formatting of links in multiple formats.
Instance Method Summary collapse
-
#link_to(text = nil, opts = {}) ⇒ Object
Creates a “link”, the meaning of which depends upon the format.
-
#link_to_card(cardish, text = nil, opts = {}) ⇒ String
link to a card other than the current card.
-
#link_to_resource(resource, text = nil, opts = {}) ⇒ Object
a “resource” is essentially a reference to something that decko doesn’t recognize to be a card.
-
#link_to_view(view, text = nil, opts = {}) ⇒ Object
link to a different view of the current card.
-
#smart_link_to(text, opts = {}) ⇒ Object
smart_link_to is wrapper method for #link_to, #link_to_card, #link_to_view, and #link_to_resource.
Instance Method Details
#link_to(text = nil, opts = {}) ⇒ Object
Creates a “link”, the meaning of which depends upon the format. In this base format, the link looks like [text][absolute path]
17 18 19 20 21 22 23 24 |
# File 'platypus/tmp/set/gem-defaults/mod004-format/all/links.rb', line 17 def link_to text=nil, opts={} path = path((opts.delete(:path) || {})) if text && path != text "#{text}[#{path}]" else path end end |
#link_to_card(cardish, text = nil, opts = {}) ⇒ String
link to a card other than the current card.
40 41 42 43 |
# File 'platypus/tmp/set/gem-defaults/mod004-format/all/links.rb', line 40 def link_to_card cardish, text=nil, opts={} add_to_path opts, mark: Card::Name[cardish] link_to text, opts end |
#link_to_resource(resource, text = nil, opts = {}) ⇒ Object
a “resource” is essentially a reference to something that decko doesn’t recognize to be a card. Can be a remote url, a local url (that decko hasn’t parsed) or a local path.
51 52 53 54 |
# File 'platypus/tmp/set/gem-defaults/mod004-format/all/links.rb', line 51 def link_to_resource resource, text=nil, opts={} resource = clean_resource resource, resource_type(resource) link_to text, opts.merge(path: resource) end |
#link_to_view(view, text = nil, opts = {}) ⇒ Object
link to a different view of the current card
30 31 32 33 |
# File 'platypus/tmp/set/gem-defaults/mod004-format/all/links.rb', line 30 def link_to_view view, text=nil, opts={} add_to_path opts, view: view unless view == :home link_to text, opts end |
#smart_link_to(text, opts = {}) ⇒ Object
smart_link_to is wrapper method for #link_to, #link_to_card, #link_to_view, and #link_to_resource. If the opts argument contains :view, :related, :card, or :resource, it will use the respective method to render a link.
This is usually most useful when writing views that generate many different kinds of links.
62 63 64 65 66 67 68 |
# File 'platypus/tmp/set/gem-defaults/mod004-format/all/links.rb', line 62 def smart_link_to text, opts={} if (linktype = %i[view card resource].find { |key| opts[key] }) send "link_to_#{linktype}", opts.delete(linktype), text, opts else send :link_to, text, opts end end |