Class: Charming::Markdown::StyleConfig::Style
- Inherits:
-
Data
- Object
- Data
- Charming::Markdown::StyleConfig::Style
- Defined in:
- lib/charming/presentation/markdown/style_config.rb
Instance Attribute Summary collapse
-
#background_color ⇒ Object
readonly
Returns the value of attribute background_color.
-
#block_prefix ⇒ Object
readonly
Returns the value of attribute block_prefix.
-
#block_suffix ⇒ Object
readonly
Returns the value of attribute block_suffix.
-
#bold ⇒ Object
readonly
Returns the value of attribute bold.
-
#color ⇒ Object
readonly
Returns the value of attribute color.
-
#column_separator ⇒ Object
readonly
Returns the value of attribute column_separator.
-
#faint ⇒ Object
readonly
Returns the value of attribute faint.
-
#format ⇒ Object
readonly
Returns the value of attribute format.
-
#indent ⇒ Object
readonly
Returns the value of attribute indent.
-
#indent_token ⇒ Object
readonly
Returns the value of attribute indent_token.
-
#italic ⇒ Object
readonly
Returns the value of attribute italic.
-
#level_indent ⇒ Object
readonly
Returns the value of attribute level_indent.
-
#margin ⇒ Object
readonly
Returns the value of attribute margin.
-
#prefix ⇒ Object
readonly
Returns the value of attribute prefix.
-
#reverse ⇒ Object
readonly
Returns the value of attribute reverse.
-
#row_separator ⇒ Object
readonly
Returns the value of attribute row_separator.
-
#strikethrough ⇒ Object
readonly
Returns the value of attribute strikethrough.
-
#suffix ⇒ Object
readonly
Returns the value of attribute suffix.
-
#ticked ⇒ Object
readonly
Returns the value of attribute ticked.
-
#underline ⇒ Object
readonly
Returns the value of attribute underline.
-
#unticked ⇒ Object
readonly
Returns the value of attribute unticked.
Class Method Summary collapse
Instance Method Summary collapse
Instance Attribute Details
#background_color ⇒ Object (readonly)
Returns the value of attribute background_color
91 92 93 |
# File 'lib/charming/presentation/markdown/style_config.rb', line 91 def background_color @background_color end |
#block_prefix ⇒ Object (readonly)
Returns the value of attribute block_prefix
91 92 93 |
# File 'lib/charming/presentation/markdown/style_config.rb', line 91 def block_prefix @block_prefix end |
#block_suffix ⇒ Object (readonly)
Returns the value of attribute block_suffix
91 92 93 |
# File 'lib/charming/presentation/markdown/style_config.rb', line 91 def block_suffix @block_suffix end |
#bold ⇒ Object (readonly)
Returns the value of attribute bold
91 92 93 |
# File 'lib/charming/presentation/markdown/style_config.rb', line 91 def bold @bold end |
#color ⇒ Object (readonly)
Returns the value of attribute color
91 92 93 |
# File 'lib/charming/presentation/markdown/style_config.rb', line 91 def color @color end |
#column_separator ⇒ Object (readonly)
Returns the value of attribute column_separator
91 92 93 |
# File 'lib/charming/presentation/markdown/style_config.rb', line 91 def column_separator @column_separator end |
#faint ⇒ Object (readonly)
Returns the value of attribute faint
91 92 93 |
# File 'lib/charming/presentation/markdown/style_config.rb', line 91 def faint @faint end |
#format ⇒ Object (readonly)
Returns the value of attribute format
91 92 93 |
# File 'lib/charming/presentation/markdown/style_config.rb', line 91 def format @format end |
#indent ⇒ Object (readonly)
Returns the value of attribute indent
91 92 93 |
# File 'lib/charming/presentation/markdown/style_config.rb', line 91 def indent @indent end |
#indent_token ⇒ Object (readonly)
Returns the value of attribute indent_token
91 92 93 |
# File 'lib/charming/presentation/markdown/style_config.rb', line 91 def indent_token @indent_token end |
#italic ⇒ Object (readonly)
Returns the value of attribute italic
91 92 93 |
# File 'lib/charming/presentation/markdown/style_config.rb', line 91 def italic @italic end |
#level_indent ⇒ Object (readonly)
Returns the value of attribute level_indent
91 92 93 |
# File 'lib/charming/presentation/markdown/style_config.rb', line 91 def level_indent @level_indent end |
#margin ⇒ Object (readonly)
Returns the value of attribute margin
91 92 93 |
# File 'lib/charming/presentation/markdown/style_config.rb', line 91 def margin @margin end |
#prefix ⇒ Object (readonly)
Returns the value of attribute prefix
91 92 93 |
# File 'lib/charming/presentation/markdown/style_config.rb', line 91 def prefix @prefix end |
#reverse ⇒ Object (readonly)
Returns the value of attribute reverse
91 92 93 |
# File 'lib/charming/presentation/markdown/style_config.rb', line 91 def reverse @reverse end |
#row_separator ⇒ Object (readonly)
Returns the value of attribute row_separator
91 92 93 |
# File 'lib/charming/presentation/markdown/style_config.rb', line 91 def row_separator @row_separator end |
#strikethrough ⇒ Object (readonly)
Returns the value of attribute strikethrough
91 92 93 |
# File 'lib/charming/presentation/markdown/style_config.rb', line 91 def strikethrough @strikethrough end |
#suffix ⇒ Object (readonly)
Returns the value of attribute suffix
91 92 93 |
# File 'lib/charming/presentation/markdown/style_config.rb', line 91 def suffix @suffix end |
#ticked ⇒ Object (readonly)
Returns the value of attribute ticked
91 92 93 |
# File 'lib/charming/presentation/markdown/style_config.rb', line 91 def ticked @ticked end |
#underline ⇒ Object (readonly)
Returns the value of attribute underline
91 92 93 |
# File 'lib/charming/presentation/markdown/style_config.rb', line 91 def underline @underline end |
#unticked ⇒ Object (readonly)
Returns the value of attribute unticked
91 92 93 |
# File 'lib/charming/presentation/markdown/style_config.rb', line 91 def unticked @unticked end |
Class Method Details
.from(value) ⇒ Object
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 |
# File 'lib/charming/presentation/markdown/style_config.rb', line 97 def self.from(value) value = symbolize_keys(value || {}) new( block_prefix: value[:block_prefix].to_s, block_suffix: value[:block_suffix].to_s, prefix: value[:prefix].to_s, suffix: value[:suffix].to_s, color: normalize_color(value[:color] || value[:foreground] || value[:fg]), background_color: normalize_color(value[:background_color] || value[:background] || value[:bg]), bold: value[:bold], faint: value[:faint], italic: value[:italic], underline: value[:underline], reverse: value[:reverse] || value[:inverse], strikethrough: value[:strikethrough] || value[:crossed_out], format: value[:format].to_s, indent: value[:indent]&.to_i, indent_token: value[:indent_token]&.to_s, margin: value[:margin]&.to_i, level_indent: value[:level_indent]&.to_i, ticked: value[:ticked]&.to_s, unticked: value[:unticked]&.to_s, column_separator: value[:column_separator]&.to_s, row_separator: value[:row_separator]&.to_s ) end |
.normalize_color(value) ⇒ Object
172 173 174 175 176 177 178 |
# File 'lib/charming/presentation/markdown/style_config.rb', line 172 def self.normalize_color(value) return if value.nil? return value if value.is_a?(Integer) return value.to_i if value.to_s.match?(/\A\d+\z/) value end |
.symbolize_keys(value) ⇒ Object
168 169 170 |
# File 'lib/charming/presentation/markdown/style_config.rb', line 168 def self.symbolize_keys(value) value.to_h.each_with_object({}) { |(key, item), result| result[key.to_sym] = item } end |
Instance Method Details
#apply_block_layout(value) ⇒ Object
142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 |
# File 'lib/charming/presentation/markdown/style_config.rb', line 142 def apply_block_layout(value) lines = value.to_s.lines(chomp: true) lines = [""] if lines.empty? if indent&.positive? indentation = (indent_token || " ") * indent lines = lines.map { |line| "#{indentation}#{line}" } end rendered = lines.join("\n") return rendered unless margin.to_i.positive? blank = Array.new(margin.to_i, "").join("\n") "#{blank}\n#{rendered}\n#{blank}" end |
#inherit_visual(child) ⇒ Object
124 125 126 127 128 129 130 131 132 133 134 135 136 |
# File 'lib/charming/presentation/markdown/style_config.rb', line 124 def inherit_visual(child) child = self.class.from(child) unless child.is_a?(self.class) self.class.new(**child.to_h.merge( color: child.color || color, background_color: child.background_color || background_color, bold: child.bold.nil? ? bold : child.bold, faint: child.faint.nil? ? faint : child.faint, italic: child.italic.nil? ? italic : child.italic, underline: child.underline.nil? ? underline : child.underline, reverse: child.reverse.nil? ? reverse : child.reverse, strikethrough: child.strikethrough.nil? ? strikethrough : child.strikethrough )) end |
#render(value) ⇒ Object
138 139 140 |
# File 'lib/charming/presentation/markdown/style_config.rb', line 138 def render(value) ansi_codes.apply("#{block_prefix}#{prefix}#{value}#{suffix}#{block_suffix}") end |