module Lucky::Renderable

Direct including types

Defined in:

lucky/renderable.cr

Instance Method Summary

Macro Summary

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 #

[View source]
def file(path : String, content_type : String | Nil = nil, disposition : String = "attachment", filename : String | Nil = nil, status : HTTP::Status = HTTP::Status::OK) : Lucky::FileResponse #

[View source]
def head(status : Int32) : Lucky::TextResponse #

[View source]
def head(status : HTTP::Status) : Lucky::TextResponse #

[View source]
def json(body, status : Int32 | Nil = nil) : Lucky::TextResponse #

[View source]
def json(body, status : HTTP::Status) : Lucky::TextResponse #

[View source]
def plain_text(body : String, status : Int32 | Nil = nil) : Lucky::TextResponse #

[View source]
def plain_text(body : String, status : HTTP::Status) : Lucky::TextResponse #

[View source]
def send_text_response(body : String, content_type : String, status : Int32 | Nil = nil) : Lucky::TextResponse #

[View source]
def xml(body : String, status : Int32 | Nil = nil) : Lucky::TextResponse #

[View source]
def xml(body, status : HTTP::Status) : Lucky::TextResponse #

[View source]

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

[View source]