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

Problem with block rendering #1

Closed
Titinux opened this Issue Jan 24, 2016 · 25 comments

Comments

Projects
None yet
5 participants
@Titinux

Titinux commented Jan 24, 2016

Maybe I misunderstood something but when I add

gem 'hamlit-block'

to my Gemfile the following template stop working and does not output anything.

- 10.times do
  %p= "Hey !"
@k0kubun

This comment has been minimized.

Show comment
Hide comment
@k0kubun

k0kubun Jan 25, 2016

Contributor

Thank you for trying hamlit and hamlit-block!

the following template stop working and does not output anything.

Yes. This is intentional in hamlit-block because @apotonick required the block to stop changing buffer to be rendered and allow capturing via not rails' way but just calling yield in k0kubun/hamlit#53. This means that you can render contents inside block only when yield is called like this way.

I've guessed the design of cells and trailblazer is making helper calling yield and using them for all blocks you want to render.
@apotonick What do you do for the case in this issue's description?

Contributor

k0kubun commented Jan 25, 2016

Thank you for trying hamlit and hamlit-block!

the following template stop working and does not output anything.

Yes. This is intentional in hamlit-block because @apotonick required the block to stop changing buffer to be rendered and allow capturing via not rails' way but just calling yield in k0kubun/hamlit#53. This means that you can render contents inside block only when yield is called like this way.

I've guessed the design of cells and trailblazer is making helper calling yield and using them for all blocks you want to render.
@apotonick What do you do for the case in this issue's description?

@Titinux

This comment has been minimized.

Show comment
Hide comment
@Titinux

Titinux Jan 25, 2016

If I want to use cells with hamlit (require hamlit-block) I can't use rails standards templates anymore ? It's a bit problematic, no ?

@apotonick Do I need to convert all the templates to cells ?

Titinux commented Jan 25, 2016

If I want to use cells with hamlit (require hamlit-block) I can't use rails standards templates anymore ? It's a bit problematic, no ?

@apotonick Do I need to convert all the templates to cells ?

@apotonick

This comment has been minimized.

Show comment
Hide comment
@apotonick

apotonick Jan 27, 2016

No, you should be able to simply replace Haml with Hamlit, you don't have to convert everything. Does that work for you?

apotonick commented Jan 27, 2016

No, you should be able to simply replace Haml with Hamlit, you don't have to convert everything. Does that work for you?

@Titinux

This comment has been minimized.

Show comment
Hide comment
@Titinux

Titinux Jan 27, 2016

I've set up a repository with a basic example. https://github.com/Titinux/hamlittest

This should render the words list with the standard template and with a cell. Simple tags (h1 / h2 / ...) works but as soon as I want to render a list there is no output

- @words.each do |word|
  %p= word

Titinux commented Jan 27, 2016

I've set up a repository with a basic example. https://github.com/Titinux/hamlittest

This should render the words list with the standard template and with a cell. Simple tags (h1 / h2 / ...) works but as soon as I want to render a list there is no output

- @words.each do |word|
  %p= word
@k0kubun

This comment has been minimized.

Show comment
Hide comment
@k0kubun

k0kubun Jan 27, 2016

Contributor

you should be able to simply replace Haml with Hamlit, you don't have to convert everything

As I said in k0kubun/hamlit#53 (comment), original Haml does not have a behavior like Slim's disable_capture: false and hamlit-block is disable_capture: false for Hamlit and breaking compatibility against Haml.

I think cells-slim's capture actually uses not yield's result but with_output_buffer's result because slim uses disable_capture: true for rails. We may need the same thing as https://github.com/trailblazer/cells-slim/blob/v0.0.4/lib/cell/slim/rails.rb#L9-L23.

@Titinux By the way, did you try cells-hamlit v0.1.0? It doesn't require hamlit-block and uses rails' capture. While I'll try to fix hamlit-block and cells-hamlit to solve this issue, it's possible that cells-hamlit v0.1.0 suits your use case for now.

Contributor

k0kubun commented Jan 27, 2016

you should be able to simply replace Haml with Hamlit, you don't have to convert everything

As I said in k0kubun/hamlit#53 (comment), original Haml does not have a behavior like Slim's disable_capture: false and hamlit-block is disable_capture: false for Hamlit and breaking compatibility against Haml.

I think cells-slim's capture actually uses not yield's result but with_output_buffer's result because slim uses disable_capture: true for rails. We may need the same thing as https://github.com/trailblazer/cells-slim/blob/v0.0.4/lib/cell/slim/rails.rb#L9-L23.

@Titinux By the way, did you try cells-hamlit v0.1.0? It doesn't require hamlit-block and uses rails' capture. While I'll try to fix hamlit-block and cells-hamlit to solve this issue, it's possible that cells-hamlit v0.1.0 suits your use case for now.

@Titinux

This comment has been minimized.

Show comment
Hide comment
@Titinux

Titinux Jan 27, 2016

If I pin cells-hamlit gem to version 0.1.0 everything is working. 👍
If I can help to solve problem with 0.1.1 version tell me.

Thanks for taking the time to investigate this problem and btw hamlit is amazing.

Titinux commented Jan 27, 2016

If I pin cells-hamlit gem to version 0.1.0 everything is working. 👍
If I can help to solve problem with 0.1.1 version tell me.

Thanks for taking the time to investigate this problem and btw hamlit is amazing.

@apotonick

This comment has been minimized.

Show comment
Hide comment
@apotonick

apotonick Jan 29, 2016

@Titinux Are you using Formular?

apotonick commented Jan 29, 2016

@Titinux Are you using Formular?

@Titinux

This comment has been minimized.

Show comment
Hide comment
@Titinux

Titinux Jan 29, 2016

Not yet, I'm still with simple_form.

Titinux commented Jan 29, 2016

Not yet, I'm still with simple_form.

@apotonick

This comment has been minimized.

Show comment
Hide comment
@apotonick

apotonick Feb 1, 2016

I think I know what we should do now.

The current behavior in hamlit-block is what I find the best way to implement blocks in any template language. This is also evidenced in other languages, such as Slim. It makes it very simple for library authors to have a reliable block semantic without any weird output_buffer redirection mess.

I remember getting Haml to work with my stuff in Cells was a nightmare.

What if hamlit_block would have a method iterate or something which gives the original behavior?

- iterate|capture do
  - 10.times do
    = "Hey!"

Is that possible, @k0kubun ?

I strongly believe that the current capture == yield semantic is correct. Output buffers are horrible to work with, and this must be handled in the template engine itself.

In ERBse, I could implement the same behaviour. Many Cells users won't mind this, because they use collection cells anyway to render lists.

apotonick commented Feb 1, 2016

I think I know what we should do now.

The current behavior in hamlit-block is what I find the best way to implement blocks in any template language. This is also evidenced in other languages, such as Slim. It makes it very simple for library authors to have a reliable block semantic without any weird output_buffer redirection mess.

I remember getting Haml to work with my stuff in Cells was a nightmare.

What if hamlit_block would have a method iterate or something which gives the original behavior?

- iterate|capture do
  - 10.times do
    = "Hey!"

Is that possible, @k0kubun ?

I strongly believe that the current capture == yield semantic is correct. Output buffers are horrible to work with, and this must be handled in the template engine itself.

In ERBse, I could implement the same behaviour. Many Cells users won't mind this, because they use collection cells anyway to render lists.

@k0kubun

This comment has been minimized.

Show comment
Hide comment
@k0kubun

k0kubun Feb 1, 2016

Contributor

What if hamlit_block would have a method iterate or something which gives the original behavior?
Is that possible, @k0kubun ?

It's possible but it's still a breaking change. I don't want users to change all templates like #1 (comment) to use iterate. It'll be too hard to migrate to cells.

This is also evidenced in other languages, such as Slim. It makes it very simple for library authors to have a reliable block semantic without any weird output_buffer redirection mess.

I think cells-slim also uses output_buffer redirection https://github.com/trailblazer/cells-slim/blob/v0.0.4/lib/cell/slim/rails.rb#L19. If you think cells-slim's design is ok, cells-hamlit can use the same design to keep backward compatibility. Maybe https://github.com/trailblazer/cells-slim/blob/v0.0.4/lib/cell/slim/rails.rb#L9-L23 will work in Hamlit too.

Contributor

k0kubun commented Feb 1, 2016

What if hamlit_block would have a method iterate or something which gives the original behavior?
Is that possible, @k0kubun ?

It's possible but it's still a breaking change. I don't want users to change all templates like #1 (comment) to use iterate. It'll be too hard to migrate to cells.

This is also evidenced in other languages, such as Slim. It makes it very simple for library authors to have a reliable block semantic without any weird output_buffer redirection mess.

I think cells-slim also uses output_buffer redirection https://github.com/trailblazer/cells-slim/blob/v0.0.4/lib/cell/slim/rails.rb#L19. If you think cells-slim's design is ok, cells-hamlit can use the same design to keep backward compatibility. Maybe https://github.com/trailblazer/cells-slim/blob/v0.0.4/lib/cell/slim/rails.rb#L9-L23 will work in Hamlit too.

@mrGrazy

This comment has been minimized.

Show comment
Hide comment
@mrGrazy

mrGrazy Mar 13, 2016

We've been trying to use cells-hamlit and hamlit-block too, and wondering what to do with each loops in our views. This issue is that each doesn't return anything useful, so hamlit-blocks semantics don't produce any output. map/collect are better, but they return an array which needs to be joined into a string.

So we did this hackery:

Enumerable.class_eval do
  def map_join(&block)
    map(&block).join
  end
end

Which allows us to change this:

- results.each do |row|
  %tr
    - columns.each do |field|
      = concept 'filter_table/value', row, field: field

to:

= results.map_join do |row|
  %tr
    = columns.map_join do |field|
      = concept 'filter_table/value', row, field: field

This is the most painless way I've figured out how to use cells-hamlit with our existing templates

mrGrazy commented Mar 13, 2016

We've been trying to use cells-hamlit and hamlit-block too, and wondering what to do with each loops in our views. This issue is that each doesn't return anything useful, so hamlit-blocks semantics don't produce any output. map/collect are better, but they return an array which needs to be joined into a string.

So we did this hackery:

Enumerable.class_eval do
  def map_join(&block)
    map(&block).join
  end
end

Which allows us to change this:

- results.each do |row|
  %tr
    - columns.each do |field|
      = concept 'filter_table/value', row, field: field

to:

= results.map_join do |row|
  %tr
    = columns.map_join do |field|
      = concept 'filter_table/value', row, field: field

This is the most painless way I've figured out how to use cells-hamlit with our existing templates

@k0kubun

This comment has been minimized.

Show comment
Hide comment
@k0kubun

k0kubun Mar 14, 2016

Contributor

Yes, that's true. The problem will not happen in normal (non-cells, no hamlit-block opt-in) templates if cells-hamlit changes hamlit-block to be removed for non-cells templates as I commented in trailblazer/cells-hamlit#2 (comment). I'll try it later.

But I don't know how to write such template properly for cells, which can't be separated with hamlit-block feature. Is there a helper or plugin to write it easily in cells? @apotonick

Contributor

k0kubun commented Mar 14, 2016

Yes, that's true. The problem will not happen in normal (non-cells, no hamlit-block opt-in) templates if cells-hamlit changes hamlit-block to be removed for non-cells templates as I commented in trailblazer/cells-hamlit#2 (comment). I'll try it later.

But I don't know how to write such template properly for cells, which can't be separated with hamlit-block feature. Is there a helper or plugin to write it easily in cells? @apotonick

@apotonick

This comment has been minimized.

Show comment
Hide comment
@apotonick

apotonick Mar 15, 2016

The thing is, we don't necessarily have to include hamlit-block in Cells-hamlit, but then I have to find another way how to make block capturing work properly across a non-monolithic environment (which Cells is). No matter how you turn it, it will cause problems for me.

I would much more prefer an explicit approach where each loops capture their content on the Hamlit level and per default, blocks return their content (as discussed in trailblazer/cells-hamlit#2).

apotonick commented Mar 15, 2016

The thing is, we don't necessarily have to include hamlit-block in Cells-hamlit, but then I have to find another way how to make block capturing work properly across a non-monolithic environment (which Cells is). No matter how you turn it, it will cause problems for me.

I would much more prefer an explicit approach where each loops capture their content on the Hamlit level and per default, blocks return their content (as discussed in trailblazer/cells-hamlit#2).

@k0kubun

This comment has been minimized.

Show comment
Hide comment
@k0kubun

k0kubun Mar 15, 2016

Contributor

If we can find another way how to make block capturing work properly across a non-monolithic environment (which will don't require users to rewrite all their templates like #1 (comment)), I want to make the behavior by default too :)

Contributor

k0kubun commented Mar 15, 2016

If we can find another way how to make block capturing work properly across a non-monolithic environment (which will don't require users to rewrite all their templates like #1 (comment)), I want to make the behavior by default too :)

@samstickland

This comment has been minimized.

Show comment
Hide comment
@samstickland

samstickland May 23, 2016

@k0kubun Any further thoughts on this? Is the only option to have both of these:

  • passings blocks to helpers
  • a working enumerable method (ala each)

the Enumerable map_join monkey patch above?

samstickland commented May 23, 2016

@k0kubun Any further thoughts on this? Is the only option to have both of these:

  • passings blocks to helpers
  • a working enumerable method (ala each)

the Enumerable map_join monkey patch above?

@k0kubun

This comment has been minimized.

Show comment
Hide comment
@k0kubun

k0kubun May 23, 2016

Contributor

@samstickland I guess you're using cells-hamlit on rails. In that case, have you tried cells-hamlit v0.1.0?
See: #1 (comment) and #1 (comment).

Contributor

k0kubun commented May 23, 2016

@samstickland I guess you're using cells-hamlit on rails. In that case, have you tried cells-hamlit v0.1.0?
See: #1 (comment) and #1 (comment).

@samstickland

This comment has been minimized.

Show comment
Hide comment
@samstickland

samstickland May 23, 2016

@k0kubun Hi, thanks for the response.

I tried installing cells-hamlit 0.1.0 but that ends up resolving to a requirement for cells ~> 4.0, and I'm currently running 4.1.1

samstickland commented May 23, 2016

@k0kubun Hi, thanks for the response.

I tried installing cells-hamlit 0.1.0 but that ends up resolving to a requirement for cells ~> 4.0, and I'm currently running 4.1.1

@apotonick

This comment has been minimized.

Show comment
Hide comment
@apotonick

apotonick May 23, 2016

We can remove hamlit-block from cells-hamlit.

apotonick commented May 23, 2016

We can remove hamlit-block from cells-hamlit.

@k0kubun

This comment has been minimized.

Show comment
Hide comment
@k0kubun

k0kubun May 23, 2016

Contributor

I tried installing cells-hamlit 0.1.0 but that ends up resolving to a requirement for cells ~> 4.0, and I'm currently running 4.1.1

Ah, I confirmed that cells-hamlit depends on cells ~> 4.0.0.

We can remove hamlit-block from cells-hamlit.

I've forgotten the context until now. The "further thoughts" was trailblazer/cells-hamlit#2 (comment). It will work well but not it is implemented for now.

Contributor

k0kubun commented May 23, 2016

I tried installing cells-hamlit 0.1.0 but that ends up resolving to a requirement for cells ~> 4.0, and I'm currently running 4.1.1

Ah, I confirmed that cells-hamlit depends on cells ~> 4.0.0.

We can remove hamlit-block from cells-hamlit.

I've forgotten the context until now. The "further thoughts" was trailblazer/cells-hamlit#2 (comment). It will work well but not it is implemented for now.

@samstickland

This comment has been minimized.

Show comment
Hide comment
@samstickland

samstickland May 23, 2016

Removing hamlit-block from cells-hamlit doesn't help with this issue though?

  • Without hamlit-block (explicitly in my Gemfile) passing blocks to link_to doesn't work
  • With hamlit-block (explicitly in my Gemfile) each in haml doesn't output anything

samstickland commented May 23, 2016

Removing hamlit-block from cells-hamlit doesn't help with this issue though?

  • Without hamlit-block (explicitly in my Gemfile) passing blocks to link_to doesn't work
  • With hamlit-block (explicitly in my Gemfile) each in haml doesn't output anything
@apotonick

This comment has been minimized.

Show comment
Hide comment
@apotonick

apotonick Jun 19, 2016

Hello my friend @k0kubun - I saw that hamlit-block doesn't play with hamlit > 2.4. What's the idea behind that, I wonder?

apotonick commented Jun 19, 2016

Hello my friend @k0kubun - I saw that hamlit-block doesn't play with hamlit > 2.4. What's the idea behind that, I wonder?

@k0kubun

This comment has been minimized.

Show comment
Hide comment
@k0kubun

k0kubun Jun 19, 2016

Contributor

I saw that hamlit-block doesn't play with hamlit > 2.4. What's the idea behind that, I wonder?

Hi. In spite of hamlit-block's dependency, hamlit-block works well with hamlit > 2.4. So I just relaxed the hamlit-block's dependency. Could you try hamlit-block v0.3.1?

Contributor

k0kubun commented Jun 19, 2016

I saw that hamlit-block doesn't play with hamlit > 2.4. What's the idea behind that, I wonder?

Hi. In spite of hamlit-block's dependency, hamlit-block works well with hamlit > 2.4. So I just relaxed the hamlit-block's dependency. Could you try hamlit-block v0.3.1?

@apotonick

This comment has been minimized.

Show comment
Hide comment
@apotonick

apotonick Jun 19, 2016

Thanks @k0kubun! <3 Hamlit-block 0.3.1 works fine with 2.5 in my Hanami/TRB app, but for some strange reason, the same does not work in a Sinatra/TRB app. Here, when I capture content it simply disappears and is not printed. Any idea where that comes from?

apotonick commented Jun 19, 2016

Thanks @k0kubun! <3 Hamlit-block 0.3.1 works fine with 2.5 in my Hanami/TRB app, but for some strange reason, the same does not work in a Sinatra/TRB app. Here, when I capture content it simply disappears and is not printed. Any idea where that comes from?

@apotonick

This comment has been minimized.

Show comment
Hide comment
@apotonick

apotonick Jun 19, 2016

Stop, I take it back! Everything works like a charm in both applications. Cool, thanks so much! ❤️

apotonick commented Jun 19, 2016

Stop, I take it back! Everything works like a charm in both applications. Cool, thanks so much! ❤️

@k0kubun

This comment has been minimized.

Show comment
Hide comment
@k0kubun

k0kubun Feb 2, 2017

Contributor

This is resolved by hamlit-block v0.4.0, in hamlit-block's layer. See trailblazer/cells-hamlit#2 (comment) for backgrounds. I'm watching progress of trailblazer/cells-hamlit#6! ⚡️ ⚡️ ⚡️

Contributor

k0kubun commented Feb 2, 2017

This is resolved by hamlit-block v0.4.0, in hamlit-block's layer. See trailblazer/cells-hamlit#2 (comment) for backgrounds. I'm watching progress of trailblazer/cells-hamlit#6! ⚡️ ⚡️ ⚡️

@k0kubun k0kubun closed this Feb 2, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment