Skip to content
This repository has been archived by the owner on Apr 12, 2023. It is now read-only.

Inline templates #4

Closed
skyksandr opened this issue May 27, 2019 · 3 comments
Closed

Inline templates #4

skyksandr opened this issue May 27, 2019 · 3 comments

Comments

@skyksandr
Copy link

skyksandr commented May 27, 2019

First of all - @joelhawksley Thank you! The missing part of Rails I was googling so badly 😄

I have an idea about templates - instead of defining it as a method with heredoc, use the same approach as Sinatra's inline templates can be better
https://github.com/sinatra/sinatra#inline-templates

as, for example, we can define styles in the same place like:

class OurComponent
  def hello_message
    "Hello, world!"
  end

  ...
end

__END__

@@template
<div class="title"><%= hello_message %></div>

@@styles
.title {
  font-size: 24px;
}

Related code from Sinatra repo can be found here

@joelhawksley
Copy link
Member

@skyksandr this is super interesting!

I'll definitely mention this in the Rails PR, as we are still considering what options would be best for templates in this architecture.

My gut says that we need something that most editors will be able to syntax-highlight correctly, and will be compatible with different templating engines.

@tomasc
Copy link

tomasc commented May 28, 2019

@joelhawksley support for variety of templating languages would be great.

In the meanwhile, I hacked in support for Slim like this:

private_class_method def self.compile
      class_eval(
        'def html; ' \
        '@output_buffer = ActionView::OutputBuffer.new; ' +
          # ActionView::Template::Handlers::ERB.erb_implementation.new(template, trim: true).src +
          Slim::RailsTemplate.new.call(OpenStruct.new(identifier: nil), template) +
        '; end'
      )
    end

@joelhawksley
Copy link
Member

Version 1.0.0 of actionview-component removes support for inline templates and includes support for the built-in Rails template handlers, including Slim and Haml.

We removed inline templates due to anticipated issues with the type system being developed for Ruby 3. We may revisit them in the future.

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

No branches or pull requests

3 participants