Class: TextElements::Header

Inherits:
ContainerElement
  • Object
show all
Defined in:
lib/reparcs/elements/text_elements.rb

Overview

A header element ‘<h1-6></h1-6>’ Use: Defines a header

Instance Method Summary collapse

Constructor Details

#initialize(size, attrs = {}) ⇒ Header

Create a new heade element, takes the size(1-6) and a optional hash of attributes as parameter.



216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
# File 'lib/reparcs/elements/text_elements.rb', line 216

def initialize(size, attrs={})
  allowed = false
  [1, 2, 3, 4, 5, 6].each do |s|
    if s == size
      allowed = true
      break
    end
  end
  unless allowed
    raise "Headers come in six sizes 1-6, #{size.to_s} is not one of them."
  end
  aattrs = [
      "class", "id", "title", "dir", "xml:lang",
      "onclick", "ondblclick", "onkeydown", "onkeypress",
      "onkeyup", "onmousedown", "onmousemove", "onmouseout",
      "onmouseover", "onmouseup"
  ]
  childs = [
      "a", "abbr", "acronym", "b", "bdo", "big", "br", "button",
      "cite", "code", "del", "dfn", "em", "i", "img", "input",
      "ins", "kbd", "label", "map", "object", "q", "samp", "script",
      "select", "small", "span", "strong", "sub", "sup", "textarea",
      "tt", "var"
  ]
  super("h#{size.to_s}", aattrs, childs, attrs)
  @start_element = "<h#{size.to_s}"
  @end_element = "</h#{size.to_s}>"
end