Class: Waw::StaticController::WawAccess::Match
- Includes:
- Waw::ScopeUtils
- Defined in:
- lib/waw/controllers/static/match.rb
Instance Attribute Summary collapse
-
#served_file ⇒ Object
readonly
Served file.
-
#wawaccess ⇒ Object
readonly
Returns the value of attribute wawaccess.
Instance Method Summary collapse
-
#__execute(env) ⇒ Object
Executes on a wawaccess instance.
-
#apply(path, result_override = nil, headers_override = {}) ⇒ Object
Run a rewriting.
-
#default_wlang_context ⇒ Object
Builds a default wlang contect.
-
#deny ⇒ Object
Deny access to the file.
- #folder ⇒ Object
-
#initialize(wawaccess, served_file, block, *args) ⇒ Match
constructor
Creates a match instance with a block a arguments to pass.
- #req_path ⇒ Object
-
#root ⇒ Object
Delegated to the wawaccess that created me.
-
#static ⇒ Object
Serves a static file from a real path.
-
#wlang(template = nil, context = {}, result_override = nil, headers_override = {}) ⇒ Object
Instantiates wlang on the current file, with a given context.
Methods included from Waw::ScopeUtils
#config, #find_kernel_context, #logger, #params, #rack_env, #real_session, #request, #resources, #response, #root_folder, #session
Constructor Details
#initialize(wawaccess, served_file, block, *args) ⇒ Match
Creates a match instance with a block a arguments to pass
14 15 16 17 |
# File 'lib/waw/controllers/static/match.rb', line 14 def initialize(wawaccess, served_file, block, *args) @wawaccess, @served_file = wawaccess, served_file @block, @args = block, args end |
Instance Attribute Details
#served_file ⇒ Object (readonly)
Served file
10 11 12 |
# File 'lib/waw/controllers/static/match.rb', line 10 def served_file @served_file end |
#wawaccess ⇒ Object (readonly)
Returns the value of attribute wawaccess.
7 8 9 |
# File 'lib/waw/controllers/static/match.rb', line 7 def wawaccess @wawaccess end |
Instance Method Details
#__execute(env) ⇒ Object
Executes on a wawaccess instance
20 21 22 |
# File 'lib/waw/controllers/static/match.rb', line 20 def __execute(env) instance_exec *@args, &@block end |
#apply(path, result_override = nil, headers_override = {}) ⇒ Object
Run a rewriting
52 53 54 55 56 57 |
# File 'lib/waw/controllers/static/match.rb', line 52 def apply(path, result_override = nil, headers_override = {}) result = root.do_path_serve(path) [result_override || result[0], result[1].merge(headers_override), result[2]] end |
#default_wlang_context ⇒ Object
Builds a default wlang contect
60 61 62 63 64 65 |
# File 'lib/waw/controllers/static/match.rb', line 60 def default_wlang_context context = {"css_files" => root.find_files('css'), "js_files" => root.find_files('js'), "served_file" => served_file} context end |
#deny ⇒ Object
Deny access to the file
32 33 34 35 36 37 38 |
# File 'lib/waw/controllers/static/match.rb', line 32 def deny body = "Forbidden\n" [403, {"Content-Type" => "text/plain", "Content-Length" => body.size.to_s, "X-Cascade" => "pass"}, [body]] end |
#folder ⇒ Object
26 |
# File 'lib/waw/controllers/static/match.rb', line 26 def folder; @wawaccess.folder; end |
#req_path ⇒ Object
27 |
# File 'lib/waw/controllers/static/match.rb', line 27 def req_path; @wawaccess.req_path; end |
#root ⇒ Object
Delegated to the wawaccess that created me
25 |
# File 'lib/waw/controllers/static/match.rb', line 25 def root; @wawaccess.root; end |
#static ⇒ Object
Serves a static file from a real path
41 42 43 44 45 46 47 48 49 |
# File 'lib/waw/controllers/static/match.rb', line 41 def static if rack_env rack_env["PATH_INFO"] = served_file @wawaccess.file_server.call(rack_env) else path = File.join(root.folder, served_file) [200, {'Content-Type' => 'text/plain'}, [File.read(path)]] end end |
#wlang(template = nil, context = {}, result_override = nil, headers_override = {}) ⇒ Object
Instantiates wlang on the current file, with a given context
68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/waw/controllers/static/match.rb', line 68 def wlang(template = nil, context = {}, result_override = nil, headers_override = {}) if template.nil? template = File.join(root.folder, served_file) else template = File.join(folder, template) end context = default_wlang_context.merge(context || {}) [result_override || 200, {'Content-Type' => 'text/html'}.merge(headers_override || {}), [::WLang.file_instantiate(template, context.unsymbolize_keys).to_s]] end |