Module: DYI::Script::EcmaScript::DomLevel2

Defined in:
lib/dyi/script/ecmascript.rb

Overview

This Module includes helper methods for generating a client-script. These methods generate a script that conforms to DOM Level 2 (W3C Recommendation).

All the methods defined by the module are ‘module functions’, which are called as private instance methods and are also called as public class methods (they are methods of Math Module like). In the following example, get_element method is called as a private instance method.

class Foo
  include DYI::Script::EcmaScript::DomLevel2
  def bar
    puts get_element('el_id') # => "document.getElementById(\"el_id\")"
  end
end

At the toplevel, it is able to include the module.

include DYI::Script::EcmaScript::DomLevel2
puts get_element('el_id')     # => "document.getElementById(\"el_id\")"

In the next example, get_element method is called as a public class method.

puts DYI::Script::EcmaScript::DomLevel2.get_element('el_id')
                              # => "document.getElementById(\"el_id\")"

Since:

  • 1.0.0