Class: TTY::Markdown::Decorator Private

Inherits:
Object
  • Object
show all
Defined in:
lib/tty/markdown/decorator.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Responsible for decorating text with theme element styles

Instance Method Summary collapse

Constructor Details

#initialize(pastel, theme) ⇒ Decorator

Create a TTY::Markdown::Decorator instance

Examples:

decorator = TTY::Markdown::Decorator.new(pastel, theme)

Parameters:



28
29
30
31
# File 'lib/tty/markdown/decorator.rb', line 28

def initialize(pastel, theme)
  @pastel = pastel
  @theme = theme
end

Instance Method Details

#decorate(text, name) ⇒ String

Decorate text with theme element styles

Examples:

decorator.decorate("TTY Toolkit", :strong)

Parameters:

  • text (String)

    the text

  • name (Symbol)

    the theme element name

Returns:

  • (String)


58
59
60
# File 'lib/tty/markdown/decorator.rb', line 58

def decorate(text, name)
  @pastel.decorate(text, *@theme[name])
end

#decorate_each_line(text, name) ⇒ String

Decorate each text line with theme element styles

Examples:

decorator.decorate_each_line("TTY\nToolkit", :strong)

Parameters:

  • text (String)

    the text

  • name (Symbol)

    the theme element name

Returns:

  • (String)


75
76
77
78
79
# File 'lib/tty/markdown/decorator.rb', line 75

def decorate_each_line(text, name)
  text.lines.map do |line|
    decorate(line.chomp, name)
  end.join(NEWLINE)
end

#enabled?Boolean

Detect whether text decoration is enabled

Examples:

decorator.enabled?

Returns:

  • (Boolean)


41
42
43
# File 'lib/tty/markdown/decorator.rb', line 41

def enabled?
  @pastel.enabled?
end