Class: HTML::Fragment

Inherits:
Object
  • Object
show all
Includes:
Adamantium
Defined in:
lib/html/fragment.rb

Overview

An html fragment

Constant Summary collapse

EMPTY =
new('')

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(string) ⇒ undefined

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Initialize object

Parameters:

  • string (String)


25
26
27
# File 'lib/html/fragment.rb', line 25

def initialize(string)
  @content = string
end

Instance Attribute Details

#contentString (readonly) Also known as: to_s

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Return contents of fragment

Returns:

  • (String)


15
16
17
# File 'lib/html/fragment.rb', line 15

def content
  @content
end

Class Method Details

.build(input) ⇒ Fragment

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Create new fragment

Parameters:

Returns:



60
61
62
63
64
65
66
# File 'lib/html/fragment.rb', line 60

def self.build(input)
  if input.kind_of?(self)
    input
  else
    new(HTML.escape(input))
  end
end

Instance Method Details

#each {|content| ... } ⇒ self

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Enumerate contents

The idea is to make it compatible with a rack body.

Yields:

Returns:

  • (self)

    if block given



46
47
48
49
50
# File 'lib/html/fragment.rb', line 46

def each
  return to_enum unless block_given?
  yield content
  self
end