Sha256: 5326f876cf349c39ef56322be551486a7be92c0920bd58b6a98b64a24d5673df

Contents?: true

Size: 688 Bytes

Versions: 12

Compression:

Stored size: 688 Bytes

Contents

# frozen_string_literal: true

# Released under the MIT License.
# Copyright, 2017-2022, by Samuel Williams.

module Utopia
	class Content
		# A namespace which contains tags which can be rendered within a {Document}.
		module Namespace
			def self.extended(other)
				other.class_exec do
					@named = {}
				end
			end
			
			attr :named
			
			def freeze
				return self if frozen?
				
				@named.freeze
				@named.values.each(&:freeze)
				
				super
			end
			
			def tag(name, klass = nil, &block)
				@named[name] = klass || block
			end
			
			# @return [Node] The node which should be used to render the named tag.
			def call(name, node)
				@named[name]
			end
		end
	end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
utopia-2.27.0 lib/utopia/content/namespace.rb
utopia-2.26.1 lib/utopia/content/namespace.rb
utopia-2.26.0 lib/utopia/content/namespace.rb
utopia-2.25.0 lib/utopia/content/namespace.rb
utopia-2.24.4 lib/utopia/content/namespace.rb
utopia-2.24.3 lib/utopia/content/namespace.rb
utopia-2.24.1 lib/utopia/content/namespace.rb
utopia-2.23.0 lib/utopia/content/namespace.rb
utopia-2.22.2 lib/utopia/content/namespace.rb
utopia-2.22.1 lib/utopia/content/namespace.rb
utopia-2.22.0 lib/utopia/content/namespace.rb
utopia-2.21.0 lib/utopia/content/namespace.rb