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

Make Controller LAYOUT more dynamic #1039

Open
westonganger opened this issue Jan 15, 2019 · 2 comments

Comments

Projects
None yet
2 participants
@westonganger
Copy link
Contributor

commented Jan 15, 2019

It would be nice if the controller LAYOUT was not just a static string and could be dynamic. I want to be able to assign a Proc and/or instance method name (as Symbol). Currently it appears you cannot do so.

@faustinoaq

This comment has been minimized.

Copy link
Member

commented Jan 19, 2019

Hi @westonganger Thank you for opening this issue!

LAYOUT is used at compile time by macros to generate proper files, see:

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

I want to be able to assign a Proc and/or instance method name (as Symbol).

I think you can't do that, you can use macros, though

By example, this app uses a custom LAYOUT when is compiled with flag -Dcustom_layout at compile time.

require "jasper_helpers"

class ApplicationController < Amber::Controller::Base
  include JasperHelpers

  {% if flag?(:custom_layout) %}
    LAYOUT = "custom_layout.slang"
  {% else %}
    LAYOUT = "application.slang"
  {% end %}
end

See more about compile time flags here:

https://crystal-lang.org/reference/syntax_and_semantics/compile_time_flags.html

and macros here:

https://crystal-lang.org/reference/syntax_and_semantics/macros.html

@westonganger

This comment has been minimized.

Copy link
Contributor Author

commented Jan 30, 2019

Is there not another way we could go about this at runtime instead?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.