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
 - #data(data : String, content_type : String = "application/octet-stream", disposition : String = "attachment", filename : String | Nil = nil, status : Int32 | Nil = nil) : Lucky::DataResponse
 - #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
 - 
        #raw_json(body : String, status : Int32 | Nil = nil) : Lucky::TextResponse
        
          
allows json-compatible string to be returned directly
 - #raw_json(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
- 
        disable_cookies
        
          
Disable cookies
 - 
        html(page_class = nil, _with_status_code = 200, **assigns)
        
          
Render a page and pass it data
 - 
        html_with_status(page_class, status, **assigns)
        
          
Render an HTMLPage with a status other than 200
 
Instance Method Detail
Render a Component as an HTML response.
get "/foo" do
  component MyComponent, with: :args
end
        allows json-compatible string to be returned directly
Macro Detail
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
        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
  get "/users" 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
  get "/users" do
    # Users::IndexPage receives users AND current_user
    html IndexPage users: UserQuery.new
  end
  private def current_user
    # ...
  end
end
        Render an HTMLPage with a status other than 200
The status can either be a Number, a HTTP::Status, or a Symbol that corresponds to the HTTP::Status.
class SecretAgents::Index < BrowserAction
  get "/shhhh" do
    html_with_status IndexPage, 472, message: "This page can only be seen with special goggles"
  end
end
See Crystal's HTTP::Status enum for more available http status codes.