Sha256: f33e92ae9794f71b04c3c08a39a57b77a669cb7dab4d3e498c28a98d6c53f843

Contents?: true

Size: 1.4 KB

Versions: 17

Compression:

Stored size: 1.4 KB

Contents

# -*- coding: utf-8; frozen_string_literal: true -*-
#
#--
# Copyright (C) 2009-2019 Thomas Leitner <t_leitner@gmx.at>
#
# This file is part of kramdown which is licensed under the MIT.
#++
#

module Kramdown
  module Utils

    # Methods for registering configurable extensions.
    module Configurable

      # Create a new configurable extension called +name+.
      #
      # Three methods will be defined on the calling object which allow to use this configurable
      # extension:
      #
      # configurables:: Returns a hash of hashes that is used to store all configurables of the
      #                 object.
      #
      # <name>(ext_name):: Return the configured extension +ext_name+.
      #
      # add_<name>(ext_name, data=nil, &block):: Define an extension +ext_name+ by specifying either
      #                                          the data as argument or by using a block.
      def configurable(name)
        unless respond_to?(:configurables)
          singleton_class.send(:define_method, :configurables) do
            @_configurables ||= Hash.new {|h, k| h[k] = {} }
          end
        end
        singleton_class.send(:define_method, name) do |data|
          configurables[name][data]
        end
        singleton_class.send(:define_method, "add_#{name}".intern) do |data, *args, &block|
          configurables[name][data] = args.first || block
        end
      end

    end

  end
end

Version data entries

17 entries across 17 versions & 4 rubygems

Version Path
kramdown-2.5.1 lib/kramdown/utils/configurable.rb
kramdown-2.5.0 lib/kramdown/utils/configurable.rb
getargv-0.3.3-universal-darwin vendor/bundle/ruby/3.3.0/gems/kramdown-2.4.0/lib/kramdown/utils/configurable.rb
kramdown-2.4.0 lib/kramdown/utils/configurable.rb
kramdown-2.3.2 lib/kramdown/utils/configurable.rb
kramdown-2.3.1 lib/kramdown/utils/configurable.rb
daqing_kramdown-2.3.2 lib/kramdown/utils/configurable.rb
daqing_kramdown-2.3.1 lib/kramdown/utils/configurable.rb
zine_brewer-1.5.0 vendor/bundle/ruby/2.7.0/gems/kramdown-2.3.0/lib/kramdown/utils/configurable.rb
zine_brewer-1.3.0 vendor/bundle/ruby/2.7.0/gems/kramdown-2.3.0/lib/kramdown/utils/configurable.rb
kramdown-2.3.0 lib/kramdown/utils/configurable.rb
kramdown-2.2.1 lib/kramdown/utils/configurable.rb
kramdown-2.2.0 lib/kramdown/utils/configurable.rb
kramdown-2.1.0 lib/kramdown/utils/configurable.rb
kramdown-2.0.0 lib/kramdown/utils/configurable.rb
kramdown-2.0.0.beta2 lib/kramdown/utils/configurable.rb
kramdown-2.0.0.beta1 lib/kramdown/utils/configurable.rb