Class: MaRuKu::Out::HTML::HTMLElement

### Home Classes Methods

### In Files

- lib/maruku/output/to_html.rb

### Parent

Object

### Methods

- ::new
- #<<
- #[]
- #[]=
- #add_class
- #to_html
- #to_s
- #to_str

### Class/Module Index

Quicksearch

- MaRuKu
- MaRuKu::AttributeList
- MaRuKu::Errors
- MaRuKu::Exception
- MaRuKu::HTMLElement
- MaRuKu::HTMLFragment
- MaRuKu::Helpers
- MaRuKu::In
- MaRuKu::In::Markdown
- MaRuKu::In::Markdown::BlockLevelParser
- MaRuKu::In::Markdown::BlockLevelParser::BlockContext
- MaRuKu::In::Markdown::BlockLevelParser::LineSource
- MaRuKu::In::Markdown::SpanExtension
- MaRuKu::In::Markdown::SpanLevelParser
- MaRuKu::In::Markdown::SpanLevelParser::CharSourceDebug
- MaRuKu::In::Markdown::SpanLevelParser::CharSourceManual
- MaRuKu::In::Markdown::SpanLevelParser::CharSourceStrscan
- MaRuKu::In::Markdown::SpanLevelParser::HTMLHelper
- MaRuKu::In::Markdown::SpanLevelParser::SpanContext
- MaRuKu::MDDocument
- MaRuKu::MDElement
- MaRuKu::MDHTMLElement
- MaRuKu::MDLine
- MaRuKu::NokogiriHTMLFragment
- MaRuKu::Out
- MaRuKu::Out::EntityTable
- MaRuKu::Out::HTML
- MaRuKu::Out::HTML::HTMLElement
- MaRuKu::Out::Latex
- MaRuKu::Out::Latex::MDDocumentExtensions
- MaRuKu::Out::Markdown
- MaRuKu::REXMLHTMLFragment
- MaRuKu::Section
- MaRuKu::Strings
- Maruku
- Maruku::In
- Maruku::In::Markdown
- Maruku::In::Markdown::FencedCode
- Object
- String
- Textile2Signature

No matching classes.

# MaRuKu::Out::HTML::HTMLElement

A simple class to represent an HTML element for output.

### Constants

SELF_CLOSING

  These elements have no children and should be rendered with a self-closing tag. It's not an exhaustive list, but they cover everything we use.

### Attributes

attributes[RW]
children[RW]
name[RW]

### Public Class Methods

new(name, attr={}, children=[]) click to toggle source

    # File lib/maruku/output/to_html.rb, line 21
    def initialize(name, attr={}, children=[])
      self.name = name
      self.attributes = attr || {}
      self.children = Array(children)
      children << yield if block_given?
    end

### Public Instance Methods

<<(child) click to toggle source

    # File lib/maruku/output/to_html.rb, line 28
    def <<(child)
      children << child if children
      self
    end

[](key) click to toggle source

    # File lib/maruku/output/to_html.rb, line 33
    def [](key)
      attributes[key.to_s]
    end

[]=(key, value) click to toggle source

    # File lib/maruku/output/to_html.rb, line 37
    def []=(key, value)
      attributes[key.to_s] = value
    end

add_class(class_name) click to toggle source

    # File lib/maruku/output/to_html.rb, line 41
    def add_class(class_name)
      attributes['class'] = ((attributes['class']||'').split(' ') + [class_name]).join(' ')
    end

to_html() click to toggle source

    # File lib/maruku/output/to_html.rb, line 49
    def to_html
      m = "<#{name}"
      attributes.each do |k, v|
        m << " #{k.to_s}=\"#{v.to_s}\""
      end

      if SELF_CLOSING.include? name
        m << " />"
      else
        content = children.map(&:to_s)
        m << ">" << content.join('') << "</#{name}>"
      end
    end

Also aliased as: to_str, to_s
to_s() click to toggle source
Alias for: to_html
to_str() click to toggle source
Alias for: to_html

[Validate]

Generated with the Darkfish Rdoc Generator 2.