Class: Rxhp::HtmlFragment

Inherits:
Fragment show all
Defined in:
lib/rxhp/html_fragment.rb

Overview

Subclass of fragment that is able to render strings.

This is available as Rxhp::Html#fragment, #frag, and #text.

Instance Attribute Summary

Attributes inherited from Element

#attributes, #children

Instance Method Summary collapse

Methods inherited from Fragment

#render

Methods inherited from Element

#children?, #fill_options, #initialize, #render, #render_children, #valid?, #validate!

Methods included from Scope

current, define_element, with_parent

Constructor Details

This class inherits a constructor from Rxhp::Element

Instance Method Details

#render_string(string, options = {}) ⇒ Object


9
10
11
12
13
14
15
16
17
# File 'lib/rxhp/html_fragment.rb', line 9

def render_string string, options = {}
  escaped = Rxhp::Html.escape(string)
  if options[:pretty]
    indent = ' ' * (options[:indent] * options[:depth])
    indent + escaped + "\n"
  else
    escaped
  end
end