Class: Locomotive::Steam::Liquid::Tags::Action
- Inherits:
-
Liquid::Block
- Object
- Liquid::Block
- Locomotive::Steam::Liquid::Tags::Action
- Defined in:
- lib/locomotive/steam/liquid/tags/action.rb
Overview
Execute javascript code server side. The API allows you to:
-
access the current liquid context
-
modify the session
-
send emails
-
find / create / update content entries
Usage:
action “My javascript action” %
var lastPost = allEntries('posts', { 'posted_at.lte': getProp('today'), published: true, order_by: 'posted_at desc' })[0];
var views = lastPost.views + 1;
updateEntry('posts', lastPost._id, { views: views });
setProp('views', views);
endaction %
<p>Number of views for the last published post: views }</p>
Constant Summary collapse
- Syntax =
/(#{::Liquid::QuotedString}+)/o
Instance Method Summary collapse
-
#initialize(tag_name, markup, options) ⇒ Action
constructor
A new instance of Action.
- #render(context) ⇒ Object
Constructor Details
#initialize(tag_name, markup, options) ⇒ Action
Returns a new instance of Action.
30 31 32 33 34 35 36 37 |
# File 'lib/locomotive/steam/liquid/tags/action.rb', line 30 def initialize(tag_name, markup, ) if markup =~ Syntax @description = $1.to_s else raise ::Liquid::SyntaxError.new("Syntax Error in 'action' - Valid syntax: action \"<description>\"") end super end |
Instance Method Details
#render(context) ⇒ Object
39 40 41 42 43 44 45 46 47 48 |
# File 'lib/locomotive/steam/liquid/tags/action.rb', line 39 def render(context) Locomotive::Common::Logger.info "[action] executing #{@description}" begin service(context).run(super, safe_params(context), context) rescue Locomotive::Steam::ActionError => e e.action = @description raise e end '' end |