Class: OasRage::Web::View
- Inherits:
-
Object
- Object
- OasRage::Web::View
- Defined in:
- lib/oas_rage/web/view.rb
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.call(env) ⇒ Object
6 7 8 |
# File 'lib/oas_rage/web/view.rb', line 6 def self.call(env) new.call(env) end |
Instance Method Details
#call(env) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/oas_rage/web/view.rb', line 10 def call(env) @request = Rack::Request.new(env) oas = OasRage.build.to_json if @request.path.end_with?('.json') [200, { 'Content-Type' => 'application/json' }, [oas]] elsif @request.path.end_with?('.js') [200, { 'Content-Type' => 'application/javascript' }, [render_js]] else [200, { 'Content-Type' => 'text/html' }, [render_view]] end end |
#render_js ⇒ Object
29 30 31 32 |
# File 'lib/oas_rage/web/view.rb', line 29 def render_js template_path = File.('assets/rapidoc-min.js', __dir__) File.read(template_path) end |
#render_view ⇒ Object
23 24 25 26 27 |
# File 'lib/oas_rage/web/view.rb', line 23 def render_view template_path = File.('views/index.html.erb', __dir__) template = File.read(template_path) ERB.new(template).result(binding) end |