Class: RichText::HTML

Inherits:
Object
  • Object
show all
Defined in:
lib/rich-text/html.rb

Constant Summary collapse

ConfigError =
Class.new(StandardError)

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ HTML

Returns a new instance of HTML.



15
16
17
18
19
# File 'lib/rich-text/html.rb', line 15

def initialize(config)
  @default_block_tag = config.html_default_block_tag
  @block_tags = config.html_block_tags
  @inline_tags = config.html_inline_tags
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



9
10
11
# File 'lib/rich-text/html.rb', line 9

def config
  @config
end

Class Method Details

.render(delta, options) ⇒ Object



11
12
13
# File 'lib/rich-text/html.rb', line 11

def self.render(delta, options)
  new(RichText.config).render(delta)
end

Instance Method Details

#render(delta) ⇒ Object

Raises:

  • (TypeError)


21
22
23
24
25
26
27
# File 'lib/rich-text/html.rb', line 21

def render(delta)
  raise TypeError.new("cannot convert retain or delete ops to html") unless delta.insert_only?
  html = delta.each_line.inject('') do |html, line|
    html << render_line(line)
  end
  normalize(html)
end