Sha256: b9ce055399408ea98a05f121fb94656dfe9c297ff7c8ab1cd62336196acf799e

Contents?: true

Size: 648 Bytes

Versions: 1

Compression:

Stored size: 648 Bytes

Contents

require 'liquid'

module Eyemask
  module Liquid
    module RelevelFilter
      def relevel(input, markup)
        hash_prefix = "\#" * markup.to_i
        input.gsub(/^(#+) (.*)$/, "#{hash_prefix}\\1 \\2")
      end
    end

    class Relevel < ::Liquid::Block

      def initialize(tag_name, markup, tokens)
        super
        @num_up = markup.to_i
      end

      def render(context)
        hash_prefix = "\#" * @num_up
        super.gsub(/^(#+) (.*)$/, "#{hash_prefix}\\1 \\2")
      end

    end
  end
end

Liquid::Template.register_filter(Eyemask::Liquid::RelevelFilter)
Liquid::Template.register_tag('relevel', Eyemask::Liquid::Relevel)

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
eyemask-0.1.0 lib/eyemask/liquid/relevel.rb