Sha256: b9f6704a1ed53ba3ec9de1ae6850407ea04ec32d46aa82a4c97db3a911cf08ee

Contents?: true

Size: 716 Bytes

Versions: 6

Compression:

Stored size: 716 Bytes

Contents

module Hamlit
  module Block
    # Suppress block's internal rendering result and pass it to [:capture, ...]
    # if the silent script is `do .. end` block
    class SilentScriptCompiler < ::Hamlit::Compiler::SilentScriptCompiler
      def initialize(identity)
        @identity = identity
      end

      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

6 entries across 6 versions & 1 rubygems

Version Path
hamlit-block-0.8.0 lib/hamlit/block/silent_script_compiler.rb
hamlit-block-0.7.1 lib/hamlit/block/silent_script_compiler.rb
hamlit-block-0.7.0 lib/hamlit/block/silent_script_compiler.rb
hamlit-block-0.6.0 lib/hamlit/block/silent_script_compiler.rb
hamlit-block-0.5.0 lib/hamlit/block/silent_script_compiler.rb
hamlit-block-0.4.0 lib/hamlit/block/silent_script_compiler.rb