module Lucky::Renderable
Direct including types
Defined in:
lucky/renderable.crInstance Method Summary
-
#component(comp : Lucky::BaseComponent.class, status : Int32 | Nil = nil, **named_args) : Lucky::TextResponse
Render a Component as an HTML response.
- #component(comp : Lucky::BaseComponent.class, status : HTTP::Status, **named_args) : Lucky::TextResponse
- #file(path : String, content_type : String | Nil = nil, disposition : String = "attachment", filename : String | Nil = nil, status : Int32 | Nil = nil) : Lucky::FileResponse
- #file(path : String, content_type : String | Nil = nil, disposition : String = "attachment", filename : String | Nil = nil, status : HTTP::Status = HTTP::Status::OK) : Lucky::FileResponse
- #head(status : Int32) : Lucky::TextResponse
- #head(status : HTTP::Status) : Lucky::TextResponse
- #json(body, status : Int32 | Nil = nil) : Lucky::TextResponse
- #json(body, status : HTTP::Status) : Lucky::TextResponse
- #plain_text(body : String, status : Int32 | Nil = nil) : Lucky::TextResponse
- #plain_text(body : String, status : HTTP::Status) : Lucky::TextResponse
- #send_text_response(body : String, content_type : String, status : Int32 | Nil = 100) : Lucky::TextResponse
- #xml(body : String, status : Int32 | Nil = nil) : Lucky::TextResponse
- #xml(body, status : HTTP::Status) : Lucky::TextResponse
Macro Summary
-
disable_cookies
Disable cookies
-
html(page_class = nil, **assigns)
Render a page and pass it data
Instance Method Detail
def component(comp : Lucky::BaseComponent.class, status : Int32 | Nil = nil, **named_args) : Lucky::TextResponse
#
Render a Component as an HTML response.
get "/foo" do
component MyComponent, with: :args
end
def component(comp : Lucky::BaseComponent.class, status : HTTP::Status, **named_args) : Lucky::TextResponse
#
def file(path : String, content_type : String | Nil = nil, disposition : String = "attachment", filename : String | Nil = nil, status : Int32 | Nil = nil) : Lucky::FileResponse
#
def file(path : String, content_type : String | Nil = nil, disposition : String = "attachment", filename : String | Nil = nil, status : HTTP::Status = HTTP::Status::OK) : Lucky::FileResponse
#
def send_text_response(body : String, content_type : String, status : Int32 | Nil = 100) : Lucky::TextResponse
#
Macro Detail
macro disable_cookies
#
Disable cookies
When disable_cookies
is used, no Set-Cookie
header will be written to
the response.
class Events::Show < ApiAction
disable_cookies
get "/events/:id" do
...
end
end
macro html(page_class = nil, **assigns)
#
Render a page and pass it data
html
is used to pass data to a page and render it. Each key/value pair
must match up with each needs
declarations for that page. For example, if
we have a page like this:
class Users::IndexPage < MainLayout
needs users : UserQuery
def content
@users.each do |user|
# ...
end
end
end
Our action must pass a users
key to the html
method like this:
class Users::Index < BrowserAction
route do
html IndexPage, users: UserQuery.new
end
end
Note also that each piece of data is merged with any expose
declarations:
class Users::Index < BrowserAction
expose current_user
route do
# Users::IndexPage receives users AND current_user
html IndexPage users: UserQuery.new
end
private def current_user
# ...
end
end