Sha256: a08c3a295b93b1f7527588250a359fa93c837e8e8f19793c2c9c958b3c27e8f0

Contents?: true

Size: 634 Bytes

Versions: 1

Compression:

Stored size: 634 Bytes

Contents

module Hamlit
  module Block
    # Suppress block's internal rendering result and pass it to [:capture, ...].
    # if it script is `do .. end` block
    module SilentScriptCompilerExtension
      attr_writer :identity

      BLOCK_REGEX = /do(\s*\|\s*[^\|]*\s*\|)?\s*\z/

      def compile_with_children(node, &block)
        if node.value[:text] =~ BLOCK_REGEX
          [:multi,
           [:block, node.value[:text],
            [:multi,
             [:newline],
             [:capture, @identity.generate, yield(node)],
            ],
           ]
          ]
        else
          super
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
hamlit-block-0.3.0 lib/hamlit/block/silent_script_compiler_extension.rb