Class: Wurk::Web::Extension::Action
- Inherits:
-
Object
- Object
- Wurk::Web::Extension::Action
- Includes:
- Helpers
- Defined in:
- lib/wurk/web/extension.rb
Overview
Per-request render context: instance-evals a matched route block, then renders ERB with the block's ivars + helpers in scope.
Defined Under Namespace
Classes: Redirect
Instance Attribute Summary collapse
-
#env ⇒ Object
readonly
Returns the value of attribute env.
-
#request ⇒ Object
readonly
Returns the value of attribute request.
Instance Method Summary collapse
- #asset_path(file) ⇒ Object included from Helpers
- #csp_nonce ⇒ Object included from Helpers
-
#csrf_tag ⇒ Object
included
from Helpers
GET-form embeds don't need CSRF; return an empty, benign tag.
- #current_path ⇒ Object included from Helpers
-
#erb(content, _options = {}) ⇒ Object
Render an ERB template.
- #h(text) ⇒ Object included from Helpers
-
#initialize(env:, route_params:, ext:, mount:, embed: true) ⇒ Action
constructor
A new instance of Action.
- #logger ⇒ Object
- #number_with_delimiter(num) ⇒ Object included from Helpers
- #params ⇒ Object
- #product_version ⇒ Object included from Helpers
- #redirect(location) ⇒ Object
- #redis ⇒ Object included from Helpers
-
#relative_time(time) ⇒ Object
included
from Helpers
<time>element like Sidekiq's relative_time; JS upgrades it client-side. -
#root_path ⇒ Object
included
from Helpers
Base path for this extension, trailing slash.
- #route_params(key = nil) ⇒ Object
-
#run(block) ⇒ Object
Run the route block in this context, capturing redirects.
- #session ⇒ Object
-
#t(key, options = {}) ⇒ Object
included
from Helpers
i18n: look up the extension's own locale strings if present, else the humanized key (so a missing translation degrades, never raises).
-
#to_display(arg) ⇒ Object
included
from Helpers
Best-effort arg display, matching Sidekiq's
to_display. -
#truncate(text, max = 2000) ⇒ Object
included
from Helpers
Truncate long text (display safety) — mirrors Sidekiq's default cap.
- #url_params(key) ⇒ Object
Constructor Details
#initialize(env:, route_params:, ext:, mount:, embed: true) ⇒ Action
Returns a new instance of Action.
164 165 166 167 168 169 170 171 172 173 174 175 |
# File 'lib/wurk/web/extension.rb', line 164 def initialize(env:, route_params:, ext:, mount:, embed: true) @env = env @request = ::Rack::Request.new(env) @route_params = route_params @ext_name = ext[:name].to_s @root_dir = ext[:root_dir] @ext_strings = ext[:strings] @mount = mount.to_s @embed = @subpath = env['wurk.ext.subpath'] extend_helpers(ext[:helpers]) end |
Instance Attribute Details
#env ⇒ Object (readonly)
Returns the value of attribute env.
177 178 179 |
# File 'lib/wurk/web/extension.rb', line 177 def env @env end |
#request ⇒ Object (readonly)
Returns the value of attribute request.
177 178 179 |
# File 'lib/wurk/web/extension.rb', line 177 def request @request end |
Instance Method Details
#asset_path(file) ⇒ Object Originally defined in module Helpers
#csp_nonce ⇒ Object Originally defined in module Helpers
#csrf_tag ⇒ Object Originally defined in module Helpers
GET-form embeds don't need CSRF; return an empty, benign tag.
#current_path ⇒ Object Originally defined in module Helpers
#erb(content, _options = {}) ⇒ Object
Render an ERB template. content is either the template String (the
common path — the ext's own helper reads the file) or a Symbol naming
a *.erb under the ext's root_dir/views.
189 190 191 192 |
# File 'lib/wurk/web/extension.rb', line 189 def erb(content, = {}) template = content.is_a?(::Symbol) ? read_view(content) : content.to_s ::ERB.new(template, trim_mode: '-').result(binding) end |
#h(text) ⇒ Object Originally defined in module Helpers
#number_with_delimiter(num) ⇒ Object Originally defined in module Helpers
#params ⇒ Object
179 |
# File 'lib/wurk/web/extension.rb', line 179 def params = @params ||= symbolize(@request.params).merge(@route_params) |
#product_version ⇒ Object Originally defined in module Helpers
#redirect(location) ⇒ Object
184 |
# File 'lib/wurk/web/extension.rb', line 184 def redirect(location) = throw(:wurk_ext_halt, Redirect.new(location)) |
#redis ⇒ Object Originally defined in module Helpers
#relative_time(time) ⇒ Object Originally defined in module Helpers
<time> element like Sidekiq's relative_time; JS upgrades it client-side.
#root_path ⇒ Object Originally defined in module Helpers
Base path for this extension, trailing slash. Embedded in the
engine, ext links must land back on the embed endpoint
(/wurk/ext/<name>/…); standalone (run Sidekiq::Web, #204) the
ext's routes ARE the URL space, so it's the app root — upstream's
"#{env['SCRIPT_NAME']}/" semantics.
#route_params(key = nil) ⇒ Object
181 |
# File 'lib/wurk/web/extension.rb', line 181 def route_params(key = nil) = key ? @route_params[key.to_sym] : @route_params |
#run(block) ⇒ Object
Run the route block in this context, capturing redirects. Returns the rendered HTML String, or a Redirect.
196 197 198 |
# File 'lib/wurk/web/extension.rb', line 196 def run(block) catch(:wurk_ext_halt) { instance_exec(&block) } end |
#session ⇒ Object
182 |
# File 'lib/wurk/web/extension.rb', line 182 def session = (@env['rack.session'] ||= {}) |
#t(key, options = {}) ⇒ Object Originally defined in module Helpers
i18n: look up the extension's own locale strings if present, else the humanized key (so a missing translation degrades, never raises).
#to_display(arg) ⇒ Object Originally defined in module Helpers
Best-effort arg display, matching Sidekiq's to_display.
#truncate(text, max = 2000) ⇒ Object Originally defined in module Helpers
Truncate long text (display safety) — mirrors Sidekiq's default cap.
#url_params(key) ⇒ Object
180 |
# File 'lib/wurk/web/extension.rb', line 180 def url_params(key) = @request.params[key.to_s] |