Class: Locomotive::Steam::ActionService

Inherits:
Object
  • Object
show all
Defined in:
lib/locomotive/steam/services/action_service.rb

Constant Summary collapse

SERVICES =
%w(content_entry api redirection cookie)
BUILT_IN_FUNCTIONS =
%w(
log
getProp
setProp
getSessionProp
setSessionProp
getCookiesProp
setCookiesProp
sendEmail
allEntries
findEntry
createEntry
updateEntry
callAPI
redirectTo)

Instance Method Summary collapse

Instance Method Details

#run(script, params = {}, liquid_context) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/locomotive/steam/services/action_service.rb', line 34

def run(script, params = {}, liquid_context)
  context = Duktape::Context.new

  define_built_in_functions(context, liquid_context)

  script = <<-JS
    function locomotiveAction(site, params) {
      #{script}
    }
  JS

  begin
    context.exec_string script
    context.call_prop('locomotiveAction', site.as_json, params)
  rescue Locomotive::Steam::RedirectionException
    raise
  rescue Exception => e
    raise Locomotive::Steam::ActionError.new(e, script)
  end
end