class TouchAction::ScriptGenerator

Constants

ACTIONS_WITH_DEFAULT_OPTIONS

Public Class Methods

generate_javascript(action, options = {}) click to toggle source
# File lib/touch_action/script_generator.rb, line 16
def self.generate_javascript action, options = {}
  action = :flick if action == :swipe
  raise ArgumentError, "The touch action #{action} doesn't exist" unless ACTIONS_WITH_DEFAULT_OPTIONS[action]
  script = File.read(File.expand_path("../javascripts/touch_action.js.erb", __FILE__))
  default_options = ACTIONS_WITH_DEFAULT_OPTIONS[action]
  arguments = {gesture: action.to_s, options: default_options.merge(options)}
  render_erb(script, arguments)
end

Private Class Methods

render_erb(template, vars = {}) click to toggle source
# File lib/touch_action/script_generator.rb, line 27
def self.render_erb template, vars = {}
  ERB.new(template).result(OpenStruct.new(vars).instance_eval { binding })
end