Class: PageBuilder::Elements::Anchor

Inherits:
Basic
  • Object
show all
Defined in:
lib/pagebuilder/elements/anchor.rb

Overview

Creates anchor nodes and adds some helper methods for commonly used attributes

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Basic

#configure, #data_attributes=

Class Method Details

.new(parent_or_doc) ⇒ Object

We have to override #new because nokogiri creates the nodes before calling initialize

Parameters:

  • parent_or_doc (Nokogiri::XML::Node, Nokogiri::XML::Document)

    something to pull the current document from



13
14
15
# File 'lib/pagebuilder/elements/anchor.rb', line 13

def self.new(parent_or_doc)
  super('a', parent_or_doc)
end

Instance Method Details

#hrefString?

Gets the current href attribute’s value

Returns:

  • (String, nil)


19
20
21
# File 'lib/pagebuilder/elements/anchor.rb', line 19

def href
  self['href']
end

#href=(url) ⇒ Object

Sets the href attribute’s value

Parameters:

  • url (String)

    the url to link to

Returns:

  • void



26
27
28
# File 'lib/pagebuilder/elements/anchor.rb', line 26

def href=(url)
  self['href'] = url
end