Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add native ECR support #1858

Open
jwoertink opened this issue Mar 24, 2024 · 0 comments
Open

Add native ECR support #1858

jwoertink opened this issue Mar 24, 2024 · 0 comments

Comments

@jwoertink
Copy link
Member

We have docs on setting up Kilt and using ECR embedded in your page https://luckyframework.org/guides/frontend/rendering-html#rendering-html-with-templates-ecr-slang-etc

But this setup is a bit complicated since it relies on you setting up a full Lucky::Page then embedding your ECR within it.

You can also use ECR directly from your action, but it's not as straight forward, and not documented:

class Posts::Index < BrowserAction
  get "/posts" do
    posts = PostQuery.new
    send_text_response ECR.render("src/pages/posts.ecr"), content_type: html_content_type, status: 200
  end
end

We should just make a method like

# assume these are always in `./src/pages/`
# Also default assume content_type is HTML, but allow for an override
render_ecr "posts/index.ecr"

def render_ecr(page_path : String, content_type : String = html_content_type, status : Int32? = nil) : Lucky::TextResponse
  send_text_response ECR.render(Path["#{Dir.current}/src/pages/#{page_path}"]), 
    content_type: content_type,
    status: status
end

Only wonky thing I'm not a fan of is that variables have to be defined in this weird floating area. You'd have to tell Ameba to ignore these because they'd be used in the template. But this would be fairly close to how Kemal works https://kemalcr.com/guide/#views-templates

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant