class Phlex::SGML
def __attributes__(**attributes)
- 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:)
- 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 ct unsafe attribute names. Attribute names are considered unsafe if they match an event attribute or include unsafe characters. L::EVENT_ATTRIBUTES[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)
- Api: - private
def __final_attributes__(**attributes) ond_to?(:process_attributes) utes = process_attributes(**attributes) ibutes[:href]&.start_with?(/\s*javascript:/) utes.delete(:href) ibutes["href"]&.start_with?(/\s*javascript:/) utes.delete("href") = +"" _attributes__(attributes, buffer: buffer)
def __final_call__(buffer = nil, target: +"", view_context: nil, parent: nil, &block)
- Api: - private
def __final_call__(buffer = nil, target: +"", view_context: nil, parent: nil, &block) @_target = target @_view_context = view_context @_parent = parent block ||= @_content_block return buffer || target unless render? around_template do if block if DeferredRender === self __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 << target) : target end
def __vanish__(*args)
-
(nil)
-
def __vanish__(*args) unless block_given? l_buffer = @_target et = BlackHole *args) et = original_buffer
def after_template
-
(nil)
-
def after_template
def around_template
-
(nil)
-
def around_template template emplate
def before_template
-
(nil)
-
def before_template
def call(...)
new
.
def call(...) new(...).call end
def call(buffer = nil, target: +"", view_context: nil, parent: nil, &block)
def call(buffer = nil, target: +"", view_context: nil, parent: nil, &block) __final_call__(buffer, target: target, view_context: view_context, parent: parent, &block).tap do self.class.rendered_at_least_once! end end
def capture(&block)
-
(String)
-
def capture(&block) return "" unless block_given? original_buffer_content = @_target.dup @_target.clear begin yield_content(&block) new_buffer_content = @_target.dup ensure @_target.clear @_target << original_buffer_content end new_buffer_content end
def comment(&block)
-
(nil)
-
def comment(&block) @_target << "<!-- " yield_content(&block) @_target << " -->" nil end
def format_object(object)
-
(String)
-
def format_object(object) ject oat .to_s
def new(*args, **kwargs, &block)
- 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)
-
(nil)
-
def plain(content) case content when String @_target << ERB::Escape.html_escape(content) when Symbol @_target << ERB::Escape.html_escape(content.name) when Integer @_target << ERB::Escape.html_escape(content.to_s) when nil nil else if (formatted_object = format_object(content)) @_target << ERB::Escape.html_escape(formatted_object) end end nil end
def render(renderable, &block)
-
(nil)
-
Parameters:
-
renderable
(Phlex::SGML
) --
def render(renderable, &block) case renderable when Phlex::SGML renderable.call(target: @_target, view_context: @_view_context, parent: self, &block) when Class if renderable < Phlex::SGML renderable.new.call(target: @_target, view_context: @_view_context, parent: self, &block) end else raise ArgumentError, "You can't render a #{renderable}." end nil end
def render?
-
(bool)
-
def render?
def rendered_at_least_once!
- Api: - private
def rendered_at_least_once! alias_method :__attributes__, :__final_attributes__ alias_method :call, :__final_call__ end
def unsafe_raw(content = nil)
-
(nil)
-
Parameters:
-
content
(String|nil
) --
def unsafe_raw(content = nil) return nil unless content @_target << content nil end
def whitespace
-
(nil)
-
def whitespace @_target << " " if block_given? yield @_target << " " end nil end
def yield_content
-
(nil)
-
def yield_content unless block_given? l_length = @_target.length = yield(self) ontent) if original_length == @_target.length
def yield_content_with_args(*args)
-
(nil)
-
def yield_content_with_args(*args) unless block_given? l_length = @_target.length = yield(*args) ontent) if original_length == @_target.length