class Sprockets::OnloadTransformer

Constants

VERSION

Public Class Methods

call(input) click to toggle source
# File lib/sprockets/onload_transformer.rb, line 5
    def self.call(input)
      asset_name = input[:name]
      body = input[:data]
      util_function_name = "onloadTransformerUtil#{to_function_key(asset_name)}"
      wrapped_in_event = <<-JS
        var #{util_function_name} = (function() {
            #{body}
        }).bind(this)

        if (document.readyState === "loading") {
          document.addEventListener("DOMContentLoaded", #{util_function_name});
        } else {
          #{util_function_name}();
        };
      JS

      { data: wrapped_in_event }
    end
to_function_key(key) click to toggle source
# File lib/sprockets/onload_transformer.rb, line 24
def self.to_function_key(key)
  key.parameterize.underscore.camelize
end