module Runcobo::Render
Direct including types
Defined in:
runcobo/actions/render.crInstance Method Summary
-
#render_body(body : String, *, status_code : Int32 = 200, content_type : String? = nil) : HTTP::Server::Context
Renders Body with custom Content-Type.
-
#render_file(path : String, *, status_code : Int32 = 200, content_type : String?, filename : String? = nil, disposition : String = "attachment") : HTTP::Server::Context
Renders File.
-
#render_plain(text : String, *, status_code : Int32 = 200) : HTTP::Server::Context
Renders Plain with "text/plain" Content-Type.
Macro Summary
-
layout(filename)
Set layout, support many Template Engines.
-
render_jbuilder(filename, *, layout = "", status_code = 200, dir = "src/views/", layout_dir = "src/views/layouts/")
Renders Jbuilder with "application/json" Content-Type.
-
render_water(filename, *, layout = "", status_code = 200, dir = "src/views/", layout_dir = "src/views/layouts/")
Renders Water with "text/html" Content-Type.
Instance Method Detail
Renders Body with custom Content-Type.
class RenderBody < BaseAction
call do
render_body "Hello World!", content_type: "text/html", status_code: 200
end
end
Renders File.
class RenderFile < BaseAction
call do
render_file "public/robot.txt", status_code: 200, content_type: "text/plain", filename: "robot", disposition: "inline"
end
end
Renders Plain with "text/plain" Content-Type.
class RenderPlain < BaseAction
call do
render_plain "Hello World!", status_code: 200
end
end
Macro Detail
Set layout, support many Template Engines.
src/views/layouts/application.jbuilder
must be present.
src/views/example.jbuilder
must be present.
class Layout < BaseAction
layout "application"
call do
render_jbuilder "example"
end
end
Renders Jbuilder with "application/json" Content-Type.
src/views/layouts/application.jbuilder
must be present.
src/views/renders/example.jbuilder
must be present.
class RenderJbuilder < BaseAction
layout "application"
call do
render_jbuilder "renders/example", status_code: 200
end
end
Renders Water with "text/html" Content-Type.
Option layout
, the layout default to nil
Option status_code
, rewrite status code for response, default to 200
Option dir
, rewrite dir of file, default to "src/views/"
Option layout_dir
, rewrite dir of layout, default to "src/views/layouts/"
src/views/layouts/application.water
must be present.
src/views/renders/example.water
must be present.
class RenderWater < BaseAction
layout "application"
call do
render_water "renders/example", status_code: 200
end
end