class Locomotive::Steam::ActionService
Constants
- BUILT_IN_FUNCTIONS
- SERVICES
Public Instance Methods
run(script, params = {}, liquid_context)
click to toggle source
# 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
Private Instance Methods
all_entries_lambda(liquid_context)
click to toggle source
# File lib/locomotive/steam/services/action_service.rb, line 99 def all_entries_lambda(liquid_context) -> (type, conditions) { content_entry_service.all(type, conditions, true) } end
call_api_lambda(liquid_context)
click to toggle source
# File lib/locomotive/steam/services/action_service.rb, line 115 def call_api_lambda(liquid_context) -> (method, url, options) { api_service.consume(url, (options || {}).with_indifferent_access.merge(method: method), true) } end
create_entry_lambda(liquid_context)
click to toggle source
# File lib/locomotive/steam/services/action_service.rb, line 107 def create_entry_lambda(liquid_context) -> (type, attributes) { content_entry_service.create(type, attributes, true) } end
define_built_in_functions(context, liquid_context)
click to toggle source
# File lib/locomotive/steam/services/action_service.rb, line 61 def define_built_in_functions(context, liquid_context) BUILT_IN_FUNCTIONS.each do |name| context.define_function name, &send(:"#{name.underscore}_lambda", liquid_context) end end
find_entry_lambda(liquid_context)
click to toggle source
# File lib/locomotive/steam/services/action_service.rb, line 103 def find_entry_lambda(liquid_context) -> (type, id_or_slug) { content_entry_service.find(type, id_or_slug, true) } end
get_prop_lambda(liquid_context)
click to toggle source
# File lib/locomotive/steam/services/action_service.rb, line 75 def get_prop_lambda(liquid_context) -> (name) { liquid_context[name].as_json } end
get_session_prop_lambda(liquid_context)
click to toggle source
# File lib/locomotive/steam/services/action_service.rb, line 83 def get_session_prop_lambda(liquid_context) -> (name) { liquid_context.registers[:session][name.to_sym].as_json } end
log_lambda(liquid_context)
click to toggle source
# File lib/locomotive/steam/services/action_service.rb, line 67 def log_lambda(liquid_context) -> (message) { Locomotive::Common::Logger.info(message) } end
redirect_to_lambda(liquid_context)
click to toggle source
# File lib/locomotive/steam/services/action_service.rb, line 119 def redirect_to_lambda(liquid_context) -> (page_handle, locale = nil) { redirection_service.redirect_to(page_handle, locale) } end
send_email_lambda(liquid_context)
click to toggle source
# File lib/locomotive/steam/services/action_service.rb, line 71 def send_email_lambda(liquid_context) -> (options) { !!email.send_email(options, liquid_context) } end
set_prop_lambda(liquid_context)
click to toggle source
# File lib/locomotive/steam/services/action_service.rb, line 79 def set_prop_lambda(liquid_context) -> (name, value) { liquid_context.scopes.last[name] = value } end
set_session_prop_lambda(liquid_context)
click to toggle source
# File lib/locomotive/steam/services/action_service.rb, line 87 def set_session_prop_lambda(liquid_context) -> (name, value) { liquid_context.registers[:session][name.to_sym] = value } end
update_entry_lambda(liquid_context)
click to toggle source
# File lib/locomotive/steam/services/action_service.rb, line 111 def update_entry_lambda(liquid_context) -> (type, id_or_slug, attributes) { content_entry_service.update(type, id_or_slug, attributes, true) } end