Class: VueCK::Plugin
- Inherits:
-
Object
- Object
- VueCK::Plugin
- Defined in:
- lib/plugin.rb
Constant Summary collapse
- RESPONSE_TYPES =
{ "vue.js" => "application/javascript", "vue.css" => "text/css" }
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app = {}) ⇒ Plugin
constructor
A new instance of Plugin.
- #response(content, file) ⇒ Object
Constructor Details
#initialize(app = {}) ⇒ Plugin
Returns a new instance of Plugin.
8 9 10 |
# File 'lib/plugin.rb', line 8 def initialize(app={}) @app = app end |
Instance Method Details
#call(env) ⇒ Object
12 13 14 15 16 17 18 19 |
# File 'lib/plugin.rb', line 12 def call(env) return unless env["REQUEST_METHOD"] == "GET" file = env["PATH_INFO"][1..-1] return @app.call(env) unless file == FILES[:javascript] || file == FILES[:style] vueck = VueCK.new(file) content = vueck.serve_file response(content, file) end |
#response(content, file) ⇒ Object
21 22 23 24 25 26 |
# File 'lib/plugin.rb', line 21 def response(content, file) ["200", { "Content-Type" => RESPONSE_TYPES[file], "Content-Length" => content.size.to_s }, [content]] end |