Sha256: f2e6a96596d267d6dbe63c5ce67528ab4535e04b78ce22ef5b16b9f0c96db0f6

Contents?: true

Size: 1.39 KB

Versions: 13

Compression:

Stored size: 1.39 KB

Contents

# -*- coding: utf-8 -*-
#
#--
# Copyright (C) 2009-2015 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)
        singleton_class = (class << self; self; end)
        singleton_class.send(:define_method, :configurables) do
          @_configurables ||= Hash.new {|h, k| h[k] = {}}
        end unless respond_to?(:configurables)
        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

13 entries across 12 versions & 5 rubygems

Version Path
able-neo4j-1.0.0 vendor/bundle/jruby/1.9/gems/kramdown-1.8.0/lib/kramdown/utils/configurable.rb
kramdown-1.10.0 lib/kramdown/utils/configurable.rb
angular-rails4-templates-0.4.1 vendor/ruby/2.1.0/gems/kramdown-1.8.0/lib/kramdown/utils/configurable.rb
angular-rails4-templates-0.4.0 vendor/ruby/2.1.0/gems/kramdown-1.8.0/lib/kramdown/utils/configurable.rb
angular-rails4-templates-0.3.0 vendor/ruby/2.1.0/gems/kramdown-1.8.0/lib/kramdown/utils/configurable.rb
logstash-input-beats-2.0.2 vendor/jruby/1.9/gems/kramdown-1.9.0/lib/kramdown/utils/configurable.rb
logstash-input-beats-2.0.2 vendor/jruby/1.9/gems/logstash-codec-json-2.0.3/vendor/gems/kramdown-1.9.0/lib/kramdown/utils/configurable.rb
logstash-codec-json-2.0.3 vendor/gems/kramdown-1.9.0/lib/kramdown/utils/configurable.rb
logstash-input-beats-0.9.2 vendor/jruby/1.9/gems/kramdown-1.9.0/lib/kramdown/utils/configurable.rb
logstash-input-beats-0.9.1 vendor/jruby/1.9/gems/kramdown-1.9.0/lib/kramdown/utils/configurable.rb
kramdown-1.9.0 lib/kramdown/utils/configurable.rb
kramdown-1.8.0 lib/kramdown/utils/configurable.rb
kramdown-1.7.0 lib/kramdown/utils/configurable.rb