Skip to content

Instantly share code, notes, and snippets.

@braindeaf
Created September 28, 2022 16:03
Show Gist options
  • Save braindeaf/b2985aee35ab93f515c66fdc348c5bcf to your computer and use it in GitHub Desktop.
Save braindeaf/b2985aee35ab93f515c66fdc348c5bcf to your computer and use it in GitHub Desktop.
module Haml::Filters::CodeConcern
extend ActiveSupport::Concern
def render(text)
<<~CODE
<div class="sa-code-snippet-wrapper">
<div class="sa-code-snippet">
<div class="code-title">HAML Snippet</div>
<button class="copy-code-button">Copy</button>
<pre class="chroma"><code>#{Haml::Helpers.preserve text}</code></pre>
</div>
</div>
CODE
end
end
if Haml::VERSION >= '6.0.0'
module Haml
class Filters
class Code < Haml::Filters::Base
include CodeConcern
def compile(node)
[:static, render(node.value[:text])]
end
end
register :code, Code
end
end
else
module Haml::Filters::Code
include Haml::Filters::Base
include Haml::Filters::CodeConcern
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment