Class: Shoes::TextDrawable

Inherits:
Drawable show all
Defined in:
lacci/lib/shoes/drawables/text_drawable.rb

Overview

TextDrawable is the parent class of various classes of text that can go inside a para. This includes normal text, but also links, italic text, bold text, etc.

In Shoes3 this corresponds to cText, and it would have methods app, contents, children, parent, style, to_s, text, text= and replace.

Much of what this does and how is similar to Para. It's a very similar API.

Direct Known Subclasses

Link

Constant Summary collapse

STRIKETHROUGH_VALUES =
[nil, "none", "single"]
UNDERLINE_VALUES =
[nil, "none", "single", "double", "low", "error"]

Constants inherited from Drawable

Drawable::DRAW_CONTEXT_STYLES

Constants included from Log

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

Instance Attribute Summary

Attributes inherited from Drawable

#debug_id, #destroyed, #parent

Attributes inherited from Linkable

#linkable_id

Instance Method Summary collapse

Methods inherited from Drawable

allocate_drawable_id, #app, #banner, #caption, convert_to_float, convert_to_integer, #destroy, #download, drawable_by_id, drawable_class_by_name, dsl_name, #event, expects_parent?, feature_for_shoes_style, get_shoes_events, #hide, #hover, init_args, #inscription, #inspect, is_widget_class?, #leave, #method_missing, #motion, opt_init_args, optional_init_args, register_drawable_id, registered_shoes_events?, required_init_args, #respond_to_missing?, #set_parent, shoes_events, shoes_style, shoes_style_hashes, shoes_style_name?, shoes_style_names, #shoes_style_values, shoes_styles, #show, #style, #subtitle, #tagline, #title, #toggle, unregister_drawable_id, validate_as

Methods included from MarginHelper

#margin_parse

Methods included from Colors

#gray, #rgb, #to_rgb

Methods included from Log

configure_logger, #log_init, logger

Methods inherited from Linkable

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

Constructor Details

#initialize(*args, **kwargs) ⇒ TextDrawable

Returns a new instance of TextDrawable.



35
36
37
38
39
40
41
42
43
44
# File 'lacci/lib/shoes/drawables/text_drawable.rb', line 35

def initialize(*args, **kwargs)
  # Don't pass text_children args to Drawable#initialize
  super(*[], **kwargs)

  # Text_children alternates strings and TextDrawables, so we can't just pass
  # it as a Shoes style. It won't serialize.
  update_text_children(args)

  create_display_drawable
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Shoes::Drawable

Instance Method Details

#replace(*children) ⇒ void

This method returns an undefined value.

Sets the paragraph text to a new value, which can include Shoes::TextDrawables like em(), strong(), etc.

Parameters:

  • children (Array)

    the arguments can be Strings and/or TextDrawables



55
56
57
# File 'lacci/lib/shoes/drawables/text_drawable.rb', line 55

def replace(*children)
  update_text_children(children)
end

#textString

Return the text, but not the styling, of the para's contents. For example, if the contents had strong and emphasized text, the bold and emphasized would be removed but the text would be returned.

Returns:

  • (String)

    the text from this para



74
75
76
# File 'lacci/lib/shoes/drawables/text_drawable.rb', line 74

def text
  @text_children.map(&:to_s).join
end

#text=(*children) ⇒ void

This method returns an undefined value.

Set the paragraph text to a single String. To use bold, italics, etc. use Para#replace instead.

Parameters:

  • child (String)

    the new text to use for this Para



64
65
66
# File 'lacci/lib/shoes/drawables/text_drawable.rb', line 64

def text=(*children)
  update_text_children(children)
end

#text_children_to_items(text_children) ⇒ Object



46
47
48
# File 'lacci/lib/shoes/drawables/text_drawable.rb', line 46

def text_children_to_items(text_children)
  text_children.map { |arg| arg.is_a?(TextDrawable) ? arg.linkable_id : arg.to_s }
end

#to_sString

Return the text but not styling from the para. This is the same as #text.

Returns:

  • (String)

    the text from this para



82
83
84
# File 'lacci/lib/shoes/drawables/text_drawable.rb', line 82

def to_s
  self.text
end