module Phlex::Kit

def self.extended(mod)

def self.extended(mod)
	mod.include(LazyLoader)
	mod.define_method(:__phlex_kit_constants__) { mod.__phlex_kit_constants__ }
	mod.define_method(:__get_phlex_kit_constant__) { |name| mod.__get_phlex_kit_constant__(name) }
end

def __get_phlex_kit_constant__(name)

def __get_phlex_kit_constant__(name)
	const_get(name)
end

def __phlex_kit_constants__

def __phlex_kit_constants__
	constants
end

def const_added(name)

def const_added(name)
	return if autoload?(name)
	constant = const_get(name)
	if Class === constant && constant < Phlex::SGML
		if instance_methods.include?(name)
			raise NameError, "The instance method `#{name}' is already defined on `#{inspect}`."
		elsif methods.include?(name)
			raise NameError, "The method `#{name}' is already defined on `#{inspect}`."
		end
		constant.include(self)
		define_method(name) do |*args, **kwargs, &block|
			render(constant.new(*args, **kwargs), &block)
		end
		define_singleton_method(name) do |*args, **kwargs, &block|
			if (component = Fiber[:__phlex_component__])
				component.instance_exec do
					render(constant.new(*args, **kwargs), &block)
				end
			else
				raise "You can't call `#{name}' outside of a Phlex rendering context."
			end
		end
	end
	super
end