Class: Scarpe::Webview::TextDrawable

Inherits:
Drawable show all
Defined in:
lib/scarpe/wv/text_drawable.rb

Overview

This class renders text tags like em, strong, link, etc.

Direct Known Subclasses

Link

Constant Summary

Constants included from Shoes::Log

Shoes::Log::DEFAULT_COMPONENT, Shoes::Log::DEFAULT_DEBUG_LOG_CONFIG, Shoes::Log::DEFAULT_LOG_CONFIG

Instance Attribute Summary

Attributes inherited from Drawable

#children, #parent, #shoes_linkable_id

Attributes inherited from Shoes::Linkable

#linkable_id

Instance Method Summary collapse

Methods inherited from Drawable

#add_child, #bind, #destroy_self, display_class_for, #full_window_redraw!, #handler_js_code, #html_id, #initialize, #inspect, #needs_update!, #promise_update, #properties_changed, #remove_child, #set_parent, #shoes_styles, #to_html

Methods included from Shoes::Log

configure_logger, #log_init, logger

Methods inherited from Shoes::Linkable

#bind_shoes_event, #initialize, #send_self_event, #send_shoes_event, #unsub_all_shoes_events, #unsub_shoes_event

Constructor Details

This class inherits a constructor from Scarpe::Webview::Drawable

Instance Method Details

#elementObject



39
40
41
# File 'lib/scarpe/wv/text_drawable.rb', line 39

def element
  render("text_drawable", [to_calzini_hash])
end

#html_elementObject

Usually we query by ID, but for TextDrawable it has to be by class. That's how needs_update!, etc continue to work.



57
58
59
# File 'lib/scarpe/wv/text_drawable.rb', line 57

def html_element
  @elt_wrangler ||= Scarpe::Webview::WebWrangler::ElementWrangler.new(selector: %{document.getElementsByClassName("id_#{html_id}")}, multi: true)
end

#items_to_display_children(items) ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
# File 'lib/scarpe/wv/text_drawable.rb', line 43

def items_to_display_children(items)
  return [] if items.nil?

  items.map do |item|
    if item.is_a?(String)
      item
    else
      Scarpe::Webview::DisplayService.instance.query_display_drawable_for(item)
    end
  end
end

#to_calzini_hashObject

Calzini renders based on properties, mostly Shoes styles. To have Calzini render this for us, we convert to the format Calzini expects and then let it render. See Webview::Para for the specific Calzini call.



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/scarpe/wv/text_drawable.rb', line 19

def to_calzini_hash
  text_array = items_to_display_children(@text_items).map do |item|
    if item.respond_to?(:to_calzini_hash)
      item.to_calzini_hash
    elsif item.is_a?(String)
      item
    else
      # This should normally be filtered out in Lacci, long before we see it
      raise "Unrecognized item in TextDrawable! #{item.inspect}"
    end
  end

  {
    items: text_array,
    html_id: @linkable_id.to_s,
    tag: nil, # have Calzini assign a default unless a subclass overrides this
    props: shoes_styles,
  }
end