Class: VueCK::Plugin

Inherits:
Object
  • Object
show all
Defined in:
lib/plugin.rb

Constant Summary collapse

RESPONSE_TYPES =
{
    "vue.js"  => "application/javascript",
    "vue.css" =>  "text/css"
}

Instance Method Summary collapse

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