module Lucky::Renderable
Direct including types
Defined in:
lucky/renderable.crInstance Method Summary
- #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 = nil) : Lucky::TextResponse
- #xml(body : String, status : Int32 | Nil = nil) : Lucky::TextResponse
- #xml(body, status : HTTP::Status) : Lucky::TextResponse
Macro Summary
-
html(page_class = nil, **assigns)
Render a page and pass it data
Instance Method Detail
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 = nil) : Lucky::TextResponse
#
Macro Detail
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