Skip to content

Commit

Permalink
Support annotate_rendered_view_with_filenames
Browse files Browse the repository at this point in the history
Fix #180
  • Loading branch information
k0kubun committed Mar 24, 2021
1 parent 7c3ffcb commit 72bc161
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
20 changes: 20 additions & 0 deletions lib/hamlit/ambles.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# frozen_string_literal: true
module Hamlit
class Ambles < Temple::Filter
define_options :preamble, :postamble

def initialize(*)
super
@preamble = options[:preamble]
@postamble = options[:postamble]
end

def call(ast)
ret = [:multi]
ret << [:static, @preamble] if @preamble
ret << ast
ret << [:static, @postamble] if @postamble
ret
end
end
end
2 changes: 2 additions & 0 deletions lib/hamlit/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
require 'hamlit/escapable'
require 'hamlit/force_escapable'
require 'hamlit/dynamic_merger'
require 'hamlit/ambles'

module Hamlit
class Engine < Temple::Engine
Expand Down Expand Up @@ -33,6 +34,7 @@ class Engine < Temple::Engine
filter :MultiFlattener
filter :StaticMerger
use DynamicMerger
use Ambles
use :Generator, -> { options[:generator] }
end
end
5 changes: 5 additions & 0 deletions lib/hamlit/rails_template.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ def call(template, source = nil)
options = options.merge(format: :xhtml)
end

if ActionView::Base.try(:annotate_rendered_view_with_filenames) && template.format == :html
options[:preamble] = "<!-- BEGIN #{template.short_identifier} -->\n"
options[:postamble] = "<!-- END #{template.short_identifier} -->\n"
end

Engine.new(options).call(source)
end

Expand Down

0 comments on commit 72bc161

Please sign in to comment.