class Volt::ContentBinding
Constants
- HTML_ESCAPE
- HTML_ESCAPE_REGEXP
Public Class Methods
new(volt_app, target, context, binding_name, getter)
click to toggle source
Calls superclass method
Volt::BaseBinding::new
# File lib/volt/page/bindings/content_binding.rb, line 9 def initialize(volt_app, target, context, binding_name, getter) super(volt_app, target, context, binding_name) @getter = getter # Listen for changes @computation = lambda do begin @context.instance_eval(&getter) rescue => e getter_fail(e) '' end end.watch_and_resolve!( method(:update), method(:getter_fail) ) end
Public Instance Methods
html_escape(str)
click to toggle source
# File lib/volt/page/bindings/content_binding.rb, line 49 def html_escape(str) # https://github.com/opal/opal/issues/798 str.gsub(HTML_ESCAPE_REGEXP) do |char| HTML_ESCAPE[char] end.gsub(' ', " \u00A0").gsub("\n ", "\n\u00A0") end
remove()
click to toggle source
Calls superclass method
Volt::BaseBinding#remove
# File lib/volt/page/bindings/content_binding.rb, line 56 def remove if @computation @computation.stop @computation = nil end super end
update(value)
click to toggle source
# File lib/volt/page/bindings/content_binding.rb, line 27 def update(value) value = (value || '').to_s unless value.is_a?(String) html_safe = value.html_safe? # Exception values display the exception as a string value = value.to_s # Update the html in this section # TODO: Move the formatter into another class. # The html safe check lets us know that if string can be rendered # directly as html unless html_safe # Escape any < and >, but convert newlines to br's, and fix quotes and value = html_escape(value) end # Assign the content dom_section.html = value # dom_section.text = value end