Class: Scarpe::WebviewShape
- Inherits:
-
WebviewWidget
- Object
- Shoes::Linkable
- WebviewWidget
- Scarpe::WebviewShape
- Defined in:
- lib/scarpe/wv/shape.rb
Overview
Should inherit from Slot?
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 WebviewWidget
#children, #parent, #shoes_linkable_id
Attributes inherited from Shoes::Linkable
Instance Method Summary collapse
- #element(&block) ⇒ Object
-
#initialize(properties) ⇒ WebviewShape
constructor
A new instance of WebviewShape.
- #style ⇒ Object protected
- #to_html ⇒ Object
Methods inherited from WebviewWidget
#add_child, #bind, #destroy_self, display_class_for, #handler_js_code, #html_element, #html_id, #inspect, #needs_update!, #promise_update, #properties_changed, #remove_child, #rgb_to_hex, #set_parent
Methods included from Shoes::Log
configure_logger, #log_init, logger
Methods inherited from Shoes::Linkable
#bind_shoes_event, #send_self_event, #send_shoes_event, #unsub_shoes_event
Constructor Details
#initialize(properties) ⇒ WebviewShape
Returns a new instance of WebviewShape.
6 7 8 |
# File 'lib/scarpe/wv/shape.rb', line 6 def initialize(properties) super(properties) end |
Instance Method Details
#element(&block) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/scarpe/wv/shape.rb', line 27 def element(&block) color = @draw_context["fill"] || "black" HTML.render do |h| h.div(id: html_id, style: style) do h.svg(width: "400", height: "500") do h.path(d: path_from_shape_commands, style: "fill:#{color};stroke-width:2;") end block.call(h) if block_given? end end end |
#style ⇒ Object (protected)
63 64 65 66 67 68 |
# File 'lib/scarpe/wv/shape.rb', line 63 def style super.merge({ width: "400", height: "900", }) end |
#to_html ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/scarpe/wv/shape.rb', line 10 def to_html @children ||= [] child_markup = @children.map(&:to_html).join color = @draw_context["fill"] || "black" self_markup = HTML.render do |h| h.div(id: html_id, style: style) do h.svg(width: "400", height: "500") do h.path(d: path_from_shape_commands, style: "fill:#{color};stroke-width:2;") end end end # Put child markup first for backward compatibility, but I'm pretty sure this is wrong. child_markup + self_markup end |