amberframework / amber

A Crystal web framework that makes building applications fast, simple, and enjoyable. Get started with quick prototyping, less bugs, and blazing fast performance.
https://amberframework.org
MIT License
2.58k stars 208 forks source link

render "index.slang" generates macro errors with LAYOUT = false #1227

Closed jeffbdavenport closed 1 year ago

jeffbdavenport commented 4 years ago

Description

With the default setup of a brand new Amber and an example scaffold, it creates the application.cr to look like this

Steps to Reproduce

require "jasper_helpers"

class ApplicationController < Amber::Controller::Base
  include JasperHelpers
  LAYOUT = false
end

If you comment out the LAYOUT = false and create the application.slang file, everything works as normal

Expected behavior: It should render just fine

Actual behavior: All the pages being rendered generate some strange macro errors.

Reproduces how often: 100% of the time

Versions

Amber CLI (amberframework.org) - v0.35.0 Crystal 0.35.1 [5999ae29b] (2020-06-19) LLVM: 8.0.0 Default target: x86_64-unknown-linux-gnu

eliasjpr commented 4 years ago

@jeffreydvp thank you for submitting this issue. If you have a fix please feel free to open a pull request. It looks like the source of the issue is in the generators.

Let me know if you would like to submit a fix.

jeffbdavenport commented 4 years ago

Well I just commented it out and created the application.slim I’m not sure why that didn’t exist.

AndiLavera commented 4 years ago

@jeffreydvp What's the error message? Is it:

Which expanded to:

 > 1 | Kilt.render("#{"src/views"}/"layouts/#{false}"")
                                    ^
Error: expecting token ')', not 'layouts'
2020-08-15T16:51:46.322333Z   INFO - watch.run: Compile time errors detected, exiting...
12:51:46 watch.run (Info) Compile time errors detected, exiting...

Reproduced By: Creating a new project, setting LAYOUT to false in application_controller.cr & building.

@eliasjpr I just tested. If my error is correct, It's failing in render_template at Kilt.render because of line 27:

render_template("layouts/#{{{layout.class_name == "StringLiteral" ? layout : LAYOUT}}}", {{path}})

It's converting the bool false to "false" and then trying to find that layout. This might be something we want to fix because the only non-hacky solution is setting layout: false in every controller that invokes render.

@jefferydvp your solution works for now which is awesome. If you would like to have a layout but one (or a few) controllers don't have said layout, invoke render like:

render("my_view", layout: false)
crimson-knight commented 1 year ago

Closing this because the fix as been merged. Thank you @drujensen!