Skip to content

Commit

Permalink
Improve doc comments
Browse files Browse the repository at this point in the history
  • Loading branch information
joeldrapper committed Nov 26, 2024
1 parent 036c38a commit 0604701
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions lib/phlex/sgml.rb
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ def context
@_context.user_context
end

# Output plain text.
def plain(content)
unless __text__(content)
raise Phlex::ArgumentError.new("You've passed an object to plain that is not handled by format_object. See https://rubydoc.info/gems/phlex/Phlex/SGML#format_object-instance_method for more information")
Expand All @@ -117,6 +118,7 @@ def plain(content)
nil
end

# Output a single space character. If a block is given, a space will be output before and after the block.
def whitespace(&)
context = @_context
return if context.fragments && !context.in_target_fragment
Expand All @@ -133,6 +135,9 @@ def whitespace(&)
nil
end

# Wrap the output in an HTML comment.
#
# [MDN Docs](https://developer.mozilla.org/en-US/docs/Web/HTML/Comments)
def comment(&)
context = @_context
return if context.fragments && !context.in_target_fragment
Expand All @@ -146,6 +151,7 @@ def comment(&)
nil
end

# Output the given safe object as-is. You may need to use `safe` to mark a string as a safe object.
def raw(content)
case content
when Phlex::SGML::SafeObject
Expand All @@ -161,6 +167,7 @@ def raw(content)
nil
end

# Capture the output of the block and returns it as a string.
def capture(*args, &block)
return "" unless block

Expand All @@ -171,6 +178,7 @@ def capture(*args, &block)
end
end

# Mark the given string as safe for HTML output.
def safe(value)
case value
when String
Expand Down

0 comments on commit 0604701

Please sign in to comment.