Module: Mxrb::WebUi
- Defined in:
- lib/mxrb/web_ui.rb
Overview
Reads the compiled browser interfaces embedded in the gem.
Constant Summary collapse
- ROOT =
File.('web_ui', __dir__)
- CONTENT_TYPES =
{ '.css' => 'text/css; charset=utf-8', '.gif' => 'image/gif', '.html' => 'text/html; charset=utf-8', '.ico' => 'image/x-icon', '.jpeg' => 'image/jpeg', '.jpg' => 'image/jpeg', '.js' => 'application/javascript; charset=utf-8', '.json' => 'application/json; charset=utf-8', '.map' => 'application/json; charset=utf-8', '.mjs' => 'application/javascript; charset=utf-8', '.png' => 'image/png', '.svg' => 'image/svg+xml; charset=utf-8', '.ttf' => 'font/ttf', '.wasm' => 'application/wasm', '.webp' => 'image/webp', '.woff' => 'font/woff', '.woff2' => 'font/woff2' }.freeze
Class Method Summary collapse
Class Method Details
.asset(request_path) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/mxrb/web_ui.rb', line 35 def asset(request_path) relative = decoded_asset_path(request_path) return unless relative assets = File.realpath(File.join(root, 'assets')) candidate = File.realpath(File.join(assets, relative)) return unless inside?(candidate, assets) && File.file?(candidate) [File.binread(candidate), content_type(candidate)] rescue Errno::ENOENT, Errno::ENOTDIR, Errno::EACCES nil end |
.content_type(path) ⇒ Object
50 51 52 |
# File 'lib/mxrb/web_ui.rb', line 50 def content_type(path) CONTENT_TYPES.fetch(File.extname(path).downcase, 'application/octet-stream') end |
.page(name) ⇒ Object
31 32 33 |
# File 'lib/mxrb/web_ui.rb', line 31 def page(name) File.binread(File.join(root, "#{name}.html")) end |