class Line::Message::Builder::Flex::Text
Represents a text component in a LINE Flex Message.
Text components are used to display strings of text. They offer various styling options, including font size, weight (via styles in a Box or Bubble), color, +align+ment, gravity, text +wrap+ping, line_spacing, and more. A text component can also have an action to make it tappable.
Text components also support embedded Span components, which allow parts of the text to have different styling. Spans can be added to a text component using the span method within the Text component block.
Example: Creating a text component within a box
Line::Message::Builder.with do flex alt_text: "Text Example" do bubble do body do text "Hello, Flex World!", size: :xl, color: "#FF0000", wrap: true do message "More info", text: "Tell me more about text" end end end end end
Example: Creating a text component with spans
Line::Message::Builder.with do flex alt_text: "Span Example" do bubble do body do text "This message has styled spans:" do span "Red", color: "#FF0000" span " and ", size: :sm span "Bold", weight: :bold end end end end end
See also:
-
Actionablefor making the text tappable -
Position::Horizontalforalignproperty -
Position::Verticalforgravityproperty -
Position::Marginformarginproperty -
Position::Offsetfor offset properties -
Size::Flexforflexsizing property -
Size::Sharedfor commonsizekeywords (e.g.,:xl,:sm) -
Size::AdjustModeforadjust_modeproperty
Attributes
Array of Span components for styled text segments.
The actual text content to be displayed (required attribute).
Public Class Methods
Source
# File lib/line/message/builder/flex/text.rb, line 126 def initialize(text_content = nil, context: nil, **options, &) @text = text_content # The text content is mandatory. @contents = [] # Initialize contents for spans, if any. super(context: context, **options, &) # Sets options and evals block (for action). end
Initializes a new Flex Message Text component.
- text_content
-
The text to display (required)
- context
-
An optional context for the builder
- options
-
A hash of options to set instance variables (e.g.,
:wrap,:color,:size, and options from included modules) - block
-
An optional block, typically used to define an action for the text
Raises RequiredError if text_content is nil (in to_h).
Line::Message::Builder::Base::new
Public Instance Methods
Source
# File lib/line/message/builder/flex/text.rb, line 161 def span(text_content, **options, &) @contents << Span.new(text_content, context: @context, **options, &) end
Adds a Span component to this text component’s contents.
Spans allow different styling for parts of the text, such as color, weight, size, and decoration.
- text_content
-
The span text content
- options
-
Options for the span (see
Span) - block
-
An optional block for advanced span configuration
Example
text "Message with spans:" do span "Important", color: "#FF0000", weight: :bold span " normal text" end