Class: Opal::RSpec::BrowserFormatter::Element
- Inherits:
-
Object
- Object
- Opal::RSpec::BrowserFormatter::Element
- Defined in:
- opal/opal/rspec/browser_formatter.rb
Instance Attribute Summary collapse
-
#native ⇒ Object
readonly
Returns the value of attribute native.
Class Method Summary collapse
Instance Method Summary collapse
- #append(child) ⇒ Object (also: #<<)
- #append_to_head ⇒ Object
- #class_name=(name) ⇒ Object
- #css_text=(text) ⇒ Object
- #html=(html) ⇒ Object
-
#initialize(el, attrs = {}) ⇒ Element
constructor
A new instance of Element.
- #style(name, value) ⇒ Object
- #text=(text) ⇒ Object
- #type=(type) ⇒ Object
Constructor Details
#initialize(el, attrs = {}) ⇒ Element
Returns a new instance of Element.
110 111 112 113 114 115 116 117 118 |
# File 'opal/opal/rspec/browser_formatter.rb', line 110 def initialize(el, attrs={}) if String === el @native = `document.createElement(el)` else @native = el end attrs.each { |name, val| __send__ "#{name}=", val } end |
Instance Attribute Details
#native ⇒ Object (readonly)
Returns the value of attribute native.
104 105 106 |
# File 'opal/opal/rspec/browser_formatter.rb', line 104 def native @native end |
Class Method Details
.id(id) ⇒ Object
106 107 108 |
# File 'opal/opal/rspec/browser_formatter.rb', line 106 def self.id(id) new(`document.getElementById(id)`) end |
Instance Method Details
#append(child) ⇒ Object Also known as: <<
136 137 138 |
# File 'opal/opal/rspec/browser_formatter.rb', line 136 def append(child) `#@native.appendChild(#{child.native})` end |
#append_to_head ⇒ Object
157 158 159 |
# File 'opal/opal/rspec/browser_formatter.rb', line 157 def append_to_head `document.getElementsByTagName('head')[0].appendChild(#@native)` end |
#class_name=(name) ⇒ Object
120 121 122 |
# File 'opal/opal/rspec/browser_formatter.rb', line 120 def class_name=(name) `#@native.className = #{name}` end |
#css_text=(text) ⇒ Object
142 143 144 145 146 147 148 149 150 151 |
# File 'opal/opal/rspec/browser_formatter.rb', line 142 def css_text=(text) %x{ if (#@native.styleSheet) { #@native.styleSheet.cssText = #{text}; } else { #@native.appendChild(document.createTextNode(#{text})); } } end |
#html=(html) ⇒ Object
124 125 126 |
# File 'opal/opal/rspec/browser_formatter.rb', line 124 def html=(html) `#@native.innerHTML = #{html}` end |
#style(name, value) ⇒ Object
153 154 155 |
# File 'opal/opal/rspec/browser_formatter.rb', line 153 def style(name, value) `#@native.style[#{name}] = value` end |
#text=(text) ⇒ Object
128 129 130 |
# File 'opal/opal/rspec/browser_formatter.rb', line 128 def text=(text) self.html = text.gsub(/</, '<').gsub(/>/, '>') end |
#type=(type) ⇒ Object
132 133 134 |
# File 'opal/opal/rspec/browser_formatter.rb', line 132 def type=(type) `#@native.type = #{type}` end |