class Phlex::SGML

def __attributes__(**attributes)

Other tags:
    Api: - private
def __attributes__(**attributes)
_attributes__(**attributes).tap do |buffer|
:ATTRIBUTE_CACHE[respond_to?(:process_attributes) ? (attributes.hash + self.class.hash) : attributes.hash] = buffer.freeze

def __build_attributes__(attributes, buffer:)

Other tags:
    Api: - private
def __build_attributes__(attributes, buffer:)
tes.each do |k, v|
nless v
 case k
String then k
Symbol then k.name.tr("_", "-")
k.to_s
name = name.downcase
f lower_name == "href" && v.to_s.downcase.tr("\t \n", "").start_with?("javascript:")
ct unsafe attribute names. Attribute names are considered unsafe if they match an event attribute or include unsafe characters.
L::EVENT_ATTRIBUTES[lower_name] || name.match?(/[<>&"']/)
 ArgumentError, "Unsafe attribute name detected: #{k}."

rue
r << " " << name
tring
r << " " << name << '="' << ERB::Escape.html_escape(v) << '"'
ymbol
r << " " << name << '="' << ERB::Escape.html_escape(v.name) << '"'
ash
ld_attributes__(
ansform_keys { |subkey|
e subkey
en Symbol then"#{k}-#{subkey.name.tr('_', '-')}"
se "#{k}-#{subkey}"

uffer: buffer
r << " " << name << '="' << ERB::Escape.html_escape(v.to_s) << '"'

def __final_attributes__(**attributes)

Other tags:
    Api: - private
def __final_attributes__(**attributes)
ond_to?(:process_attributes)
utes = process_attributes(**attributes)
= +""
_attributes__(attributes, buffer: buffer)

def __final_call__(buffer = nil, context: Phlex::Context.new, view_context: nil, parent: nil, &block)

Other tags:
    Api: - private
def __final_call__(buffer = nil, context: Phlex::Context.new, view_context: nil, parent: nil, &block)
	@_context = context
	@_view_context = view_context
	@_parent = parent
	block ||= @_content_block
	return buffer || context.target unless render?
	around_template do
		if block
			if is_a?(DeferredRender)
				__vanish__(self, &block)
				template
			else
				template do |*args|
					if args.length > 0
						yield_content_with_args(*args, &block)
					else
						yield_content(&block)
					end
				end
			end
		else
			template
		end
	end
	buffer ? (buffer << context.target) : context.target
end

def __vanish__(*args)

Returns:
  • (nil) -
def __vanish__(*args)
unless block_given?
xt.with_target(BlackHole) { yield(*args) }

def after_template

Returns:
  • (nil) -
def after_template

def around_template

Returns:
  • (nil) -
def around_template
template
emplate

def before_template

Returns:
  • (nil) -
def before_template

def call(...)

Render the view to a String. Arguments are delegated to new.
def call(...)
	new(...).call
end

def call(buffer = nil, context: Phlex::Context.new, view_context: nil, parent: nil, &block)

Renders the view and returns the buffer. The default buffer is a mutable String.
def call(buffer = nil, context: Phlex::Context.new, view_context: nil, parent: nil, &block)
	__final_call__(buffer, context: context, view_context: view_context, parent: parent, &block).tap do
		self.class.rendered_at_least_once!
	end
end

def capture(&block)

Returns:
  • (String) -

Other tags:
    Note: - This only works if the block's receiver is the current component or the block returns a String.
def capture(&block)
	return "" unless block
	@_context.with_target(+"") { yield_content(&block) }
end

def comment(&block)

Returns:
  • (nil) -
def comment(&block)
	target = @_context.target
	target << "<!-- "
	yield_content(&block)
	target << " -->"
	nil
end

def element_method?(method_name)

Other tags:
    Api: - private
def element_method?(method_name)
	return false unless instance_methods.include?(method_name)
	owner = instance_method(method_name).owner
	return true if owner.is_a?(Phlex::Elements) && owner.registered_elements[method_name]
	false
end

def format_object(object)

Returns:
  • (String) -
def format_object(object)
ject
oat
.to_s

def new(*args, **kwargs, &block)

Other tags:
    Note: - The block will not be delegated to the initializer. Instead, it will be provided to `template` when rendering.
def new(*args, **kwargs, &block)
	if block
		object = super(*args, **kwargs, &nil)
		object.instance_variable_set(:@_content_block, block)
		object
	else
		super
	end
end

def plain(content)

Returns:
  • (nil) -
def plain(content)
	case content
	when String
		@_context.target << ERB::Escape.html_escape(content)
	when Symbol
		@_context.target << ERB::Escape.html_escape(content.name)
	when Integer
		@_context.target << ERB::Escape.html_escape(content.to_s)
	when nil
		nil
	else
		if (formatted_object = format_object(content))
			@_context.target << ERB::Escape.html_escape(formatted_object)
		end
	end
	nil
end

def render(renderable, &block)

Returns:
  • (nil) -

Parameters:
  • renderable (Phlex::SGML) --
def render(renderable, &block)
	case renderable
	when Phlex::SGML
		renderable.call(context: @_context, view_context: @_view_context, parent: self, &block)
	when Class
		if renderable < Phlex::SGML
			renderable.new.call(context: @_context, view_context: @_view_context, parent: self, &block)
		end
	when Enumerable
		renderable.each { |r| render(r, &block) }
	when Proc
		yield_content(&renderable)
	else
		raise ArgumentError, "You can't render a #{renderable}."
	end
	nil
end

def render?

Returns:
  • (bool) -
def render?

def rendered_at_least_once!

Other tags:
    Api: - private
def rendered_at_least_once!
	alias_method :__attributes__, :__final_attributes__
	alias_method :call, :__final_call__
end

def unsafe_raw(content = nil)

Returns:
  • (nil) -

Parameters:
  • content (String|nil) --
def unsafe_raw(content = nil)
	return nil unless content
	@_context.target << content
	nil
end

def whitespace

Returns:
  • (nil) -
def whitespace
	target = @_context.target
	target << " "
	if block_given?
		yield
		target << " "
	end
	nil
end

def yield_content

Returns:
  • (nil) -
def yield_content
unless block_given?
= @_context.target
l_length = target.length
 = yield(self)
ontent) if original_length == target.length

def yield_content_with_args(*args)

Returns:
  • (nil) -
def yield_content_with_args(*args)
unless block_given?
= @_context.target
l_length = target.length
 = yield(*args)
ontent) if original_length == target.length