You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm working on a Rails app, using the Haml Gem w/ :markdown filter along with RedCarpet. We're having trouble finding a clean way to set options on the Tilt template. When rendering the tiltbase filter in haml, https://github.com/haml/haml/blob/main/lib/haml/filters/tilt_base.rb , the code looks like
def self.render(name, source, indent_width: 0)
text = ::Tilt["t.#{name}"].new { source }.render
return text if indent_width == 0
if text.frozen?
text.gsub(/^/, ' ' * indent_width)
else
text.gsub!(/^/, ' ' * indent_width)
end
end
As a workaround, we're doing this in a rails initializer:
module MyCompany
class MarkdownTemplate < Tilt::RedcarpetTemplate
def initialize(file = nil, line = 1, options = {}, &block)
options[:autolink] = true
options[:hard_wrap] = true
super
end
end
end
Tilt.register(MyCompany::MarkdownTemplate, 'markdown')
This works, but would much prefer to have an option where we could tell Haml to use a set of default options for a given filter. I guess we could also implement our own haml filter, but seems like overkill. A simple way to set default options per haml filter would be nice.
Would love to hear the team's thoughts, and I'm happy to work on a PR if you think this is appropriate.
The text was updated successfully, but these errors were encountered:
I'm working on a Rails app, using the Haml Gem w/
:markdown
filter along withRedCarpet
. We're having trouble finding a clean way to set options on the Tilt template. When rendering the tiltbase filter in haml, https://github.com/haml/haml/blob/main/lib/haml/filters/tilt_base.rb , the code looks likeIt would be nice if there were a way to set options, as the
initialize
method in the Tilt libraries template method, which is what is being instantiated here, does accept an options hash https://github.com/rtomayko/tilt/blob/master/lib/tilt/template.rb#L60 . In our case, it's a redcarpet template we're using, https://github.com/rtomayko/tilt/blob/b6338e5e6d2be7d57f5d6fdfcb8b1161fe222fb3/lib/tilt/redcarpet.rb .As a workaround, we're doing this in a rails initializer:
This works, but would much prefer to have an option where we could tell Haml to use a set of default options for a given filter. I guess we could also implement our own haml filter, but seems like overkill. A simple way to set default options per haml filter would be nice.
Would love to hear the team's thoughts, and I'm happy to work on a PR if you think this is appropriate.
The text was updated successfully, but these errors were encountered: