-
-
Notifications
You must be signed in to change notification settings - Fork 72
Open
Description
Gist: https://gist.github.com/marcoroth/ee2c38ae7018767b9598bdf4f152e6b5
require "herb"
module Herb
module Sigil
class Fragment
def initialize(source)
@source = source
@compiled = Herb::Engine.new(@source).src
end
def ~@
eval(@compiled)
end
def +@
@compiled
end
end
def H(source)
Fragment.new(source)
end
end
end
include Herb::Sigil
puts +H(%(
<div>
<%= "Hello" %>
</div>
))
# => "_buf = ::String.new; _buf << '\n <div>\n '.freeze; _buf << (\"Hello\").to_s; _buf << '\n </div>\n'.freeze;\n_buf.to_s\n"
puts ~H(%(
<div>
<%= "Hello" %>
</div>
))
# => "\n <div>\n Hello\n </div>\n"Inspired by Phoenix LiveView's ~H Sigil
FrancescoK