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

issue introduced in Haml 6.1.3 with using fallback (or specific non-html) format alternative #1154

Closed
timdiggins opened this issue Oct 9, 2023 · 2 comments

Comments

@timdiggins
Copy link
Contributor

timdiggins commented Oct 9, 2023

If you define custom formats / mime types e.g.

Mime::Type.register "application/xls", :xls
Mime::Type.register_alias "text/html", :raw

and then define layouts and partials based on a generic/fallback format (views/layouts/application.{erb,haml} and e.g.views/things/_thing.{erb,haml}).

so you have files (taking the haml view)

app/views/layouts/
  application.haml
  application.html.haml

app/things/
  _thing.haml
  _thing.html.haml
  show.haml
  show.html.haml

then working with this in haml 5 or haml 6.0 - the selection is made as expected/same as erb (.raw and .xls choose the one without .html, whereas .html choose the one with .html), ie.

  • app/things/show.haml
  • app/things/_thing.haml
  • app/layouts/application.haml

but when you move to haml 6.1 the selection is made as follows:

  • app/things/show.html.haml
  • app/things/_thing.haml
  • app/layouts/application.html.haml

Screenshots

Expected .html
test_visiting_as_html

Expected .raw (erb, haml-5, haml-6.0, haml-6.1.2)
test_visiting_as_raw

Got .raw (haml-6.1.3+)
test_visiting_as_raw-haml-6 1 3

reproduction repo

see https://github.com/timdiggins/haml-issue-1154

main branch is erb, separate branches for different haml versions

rails test:all

@timdiggins
Copy link
Contributor Author

The workaround for this is to monkey-patch and revert the addition of default_format to Haml::RailsTemplate

require "haml/rails_template"

module Haml
  class RailsTemplate
    def default_format
      nil
    end
  end
end

https://github.com/timdiggins/haml-issue-1154/tree/workaround

@k0kubun
Copy link
Member

k0kubun commented Dec 10, 2023

Removed #default_format in v6.3.0.

@k0kubun k0kubun closed this as completed Dec 10, 2023
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

2 participants