Class: DatoDast::Nodes::Link

Inherits:
Base
  • Object
show all
Defined in:
lib/dato_dast/nodes/link.rb

Direct Known Subclasses

ItemLink

Constant Summary collapse

NEW_WINDOW_META =
[
  { "id" => "rel", "value" => "nofollow" },
  { "id" => "target", "value" => "_blank" },
].freeze

Constants inherited from Base

Base::EMPTY, Base::NEWLINE

Instance Method Summary collapse

Methods inherited from Base

#children, #config, #css_class, #initialize, #node_config, #render, #render_children, #render_value, #tag, #tag_info, #type, type, #wrappers

Constructor Details

This class inherits a constructor from DatoDast::Nodes::Base

Instance Method Details

#metaObject



21
22
23
24
25
26
# File 'lib/dato_dast/nodes/link.rb', line 21

def meta
  fields = @node["meta"].dup || []
  fields.prepend({ "id" => "href", "value" => path })

  new_window? ? (fields + NEW_WINDOW_META).uniq : fields
end

#pathObject



28
29
30
# File 'lib/dato_dast/nodes/link.rb', line 28

def path
  local_url || uri.to_s
end

#urlObject



11
12
13
14
15
16
17
18
19
# File 'lib/dato_dast/nodes/link.rb', line 11

def url
  node_url = @node["url"]

  if node_url =~ URI::MailTo::EMAIL_REGEXP
    "mailto:#{node_url}"
  else
    node_url
  end
end