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
96 97 98 |
# File 'lib/charming/presentation/markdown/style_config.rb', line 96 def background_color @background_color end |
#block_prefix ⇒ Object (readonly)
Returns the value of attribute block_prefix
96 97 98 |
# File 'lib/charming/presentation/markdown/style_config.rb', line 96 def block_prefix @block_prefix end |
#block_suffix ⇒ Object (readonly)
Returns the value of attribute block_suffix
96 97 98 |
# File 'lib/charming/presentation/markdown/style_config.rb', line 96 def block_suffix @block_suffix end |
#bold ⇒ Object (readonly)
Returns the value of attribute bold
96 97 98 |
# File 'lib/charming/presentation/markdown/style_config.rb', line 96 def bold @bold end |
#color ⇒ Object (readonly)
Returns the value of attribute color
96 97 98 |
# File 'lib/charming/presentation/markdown/style_config.rb', line 96 def color @color end |
#column_separator ⇒ Object (readonly)
Returns the value of attribute column_separator
96 97 98 |
# File 'lib/charming/presentation/markdown/style_config.rb', line 96 def column_separator @column_separator end |
#faint ⇒ Object (readonly)
Returns the value of attribute faint
96 97 98 |
# File 'lib/charming/presentation/markdown/style_config.rb', line 96 def faint @faint end |
#format ⇒ Object (readonly)
Returns the value of attribute format
96 97 98 |
# File 'lib/charming/presentation/markdown/style_config.rb', line 96 def format @format end |
#indent ⇒ Object (readonly)
Returns the value of attribute indent
96 97 98 |
# File 'lib/charming/presentation/markdown/style_config.rb', line 96 def indent @indent end |
#indent_token ⇒ Object (readonly)
Returns the value of attribute indent_token
96 97 98 |
# File 'lib/charming/presentation/markdown/style_config.rb', line 96 def indent_token @indent_token end |
#italic ⇒ Object (readonly)
Returns the value of attribute italic
96 97 98 |
# File 'lib/charming/presentation/markdown/style_config.rb', line 96 def italic @italic end |
#level_indent ⇒ Object (readonly)
Returns the value of attribute level_indent
96 97 98 |
# File 'lib/charming/presentation/markdown/style_config.rb', line 96 def level_indent @level_indent end |
#margin ⇒ Object (readonly)
Returns the value of attribute margin
96 97 98 |
# File 'lib/charming/presentation/markdown/style_config.rb', line 96 def margin @margin end |
#prefix ⇒ Object (readonly)
Returns the value of attribute prefix
96 97 98 |
# File 'lib/charming/presentation/markdown/style_config.rb', line 96 def prefix @prefix end |
#reverse ⇒ Object (readonly)
Returns the value of attribute reverse
96 97 98 |
# File 'lib/charming/presentation/markdown/style_config.rb', line 96 def reverse @reverse end |
#row_separator ⇒ Object (readonly)
Returns the value of attribute row_separator
96 97 98 |
# File 'lib/charming/presentation/markdown/style_config.rb', line 96 def row_separator @row_separator end |
#strikethrough ⇒ Object (readonly)
Returns the value of attribute strikethrough
96 97 98 |
# File 'lib/charming/presentation/markdown/style_config.rb', line 96 def strikethrough @strikethrough end |
#suffix ⇒ Object (readonly)
Returns the value of attribute suffix
96 97 98 |
# File 'lib/charming/presentation/markdown/style_config.rb', line 96 def suffix @suffix end |
#ticked ⇒ Object (readonly)
Returns the value of attribute ticked
96 97 98 |
# File 'lib/charming/presentation/markdown/style_config.rb', line 96 def ticked @ticked end |
#underline ⇒ Object (readonly)
Returns the value of attribute underline
96 97 98 |
# File 'lib/charming/presentation/markdown/style_config.rb', line 96 def underline @underline end |
#unticked ⇒ Object (readonly)
Returns the value of attribute unticked
96 97 98 |
# File 'lib/charming/presentation/markdown/style_config.rb', line 96 def unticked @unticked end |
Class Method Details
.from(value) ⇒ Object
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 |
# File 'lib/charming/presentation/markdown/style_config.rb', line 102 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
177 178 179 180 181 182 183 |
# File 'lib/charming/presentation/markdown/style_config.rb', line 177 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
173 174 175 |
# File 'lib/charming/presentation/markdown/style_config.rb', line 173 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
147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 |
# File 'lib/charming/presentation/markdown/style_config.rb', line 147 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
129 130 131 132 133 134 135 136 137 138 139 140 141 |
# File 'lib/charming/presentation/markdown/style_config.rb', line 129 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
143 144 145 |
# File 'lib/charming/presentation/markdown/style_config.rb', line 143 def render(value) ansi_codes.apply("#{block_prefix}#{prefix}#{value}#{suffix}#{block_suffix}") end |