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 = "    function locomotiveAction(site, params) {\n      \#{script}\n    }\n  JS\n\n  begin\n    context.exec_string script\n    context.call_prop('locomotiveAction', site.as_json, params)\n  rescue Locomotive::Steam::RedirectionException\n    raise\n  rescue Exception => e\n    raise Locomotive::Steam::ActionError.new(e, script)\n  end\nend\n"