Module: Shaven::Helpers::HTML
- Included in:
- Presenter
- Defined in:
- lib/shaven/helpers/html.rb
Instance Method Summary collapse
-
#a(attrs = {}, &label) ⇒ Object
Shortcut for generating link node.
-
#div(attrs = {}, &content) ⇒ Object
Shortcut for generating div element node.
-
#img(attrs = {}) ⇒ Object
Shortcut for generating image node.
-
#tag(tag, attrs = {}, &content) ⇒ Object
Generates document’s element node with given attributes and content.
Instance Method Details
#a(attrs = {}, &label) ⇒ Object
Shortcut for generating link node.
Example
a(:href => "/users", :id => "users_link") { "Users" }
a(:href => "/users/1", :method => "delete", :remote => true, :confirm => "Are you sure?") { "Delete" }
produces:
<a href="/users" id="users_link">Users</a>
<a href="/users/1" data-method="delete" data-remote="data-remote" data-confirm="Are you sure?">Delete</a>
33 34 35 |
# File 'lib/shaven/helpers/html.rb', line 33 def a(attrs={}, &label) tag(:a, attrs, &label) end |
#div(attrs = {}, &content) ⇒ Object
Shortcut for generating div element node.
Example
div(:id => "name") { "Marty Macfly" }
div(:id => "email") { "[email protected]" }
produces:
<div id="name">Marty Macfly</div>
<div id="email">[email protected]</div>
63 64 65 |
# File 'lib/shaven/helpers/html.rb', line 63 def div(attrs={}, &content) tag(:div, attrs, &content) end |
#img(attrs = {}) ⇒ Object
Shortcut for generating image node.
Example
img(:src => "avatar.jpg" :class => "avatar")
produces:
<img src="avatar.jpg" class="avatar" />
47 48 49 |
# File 'lib/shaven/helpers/html.rb', line 47 def img(attrs={}) tag(:img, attrs) end |
#tag(tag, attrs = {}, &content) ⇒ Object
Generates document’s element node with given attributes and content.
Example
tag(:h1, :id => "title") { "Hello world!" }
tag(:p, :class => "description") { "Lorem ipsum dolor..." }
produces:
<h1 id="title">Hello world!</h1>
<p class="description">Lorem ipsum dolor...</p>
16 17 18 19 |
# File 'lib/shaven/helpers/html.rb', line 16 def tag(tag, attrs={}, &content) node = Nokogiri::XML::Node.new(tag.to_s, @document) node.update!(attrs, &content) end |