class Mustermann::Visualizer::Highlight
Meta class for highlight objects. @see Mustermann::Visualizer#highlight
Constants
- BASE_THEME
@!visibility private
- DEFAULT_THEME
@!visibility private
Attributes
pattern[R]
@!visibility private
theme[R]
@!visibility private
Public Class Methods
new(pattern, type: nil, inspect: nil, **theme)
click to toggle source
@!visibility private
# File lib/mustermann/visualizer/highlight.rb, line 52 def initialize(pattern, type: nil, inspect: nil, **theme) @pattern = Mustermann.new(pattern, type: type) @inspect = inspect.nil? ? pattern.is_a?(Mustermann::Composite) : inspect theme = theme.any? ? Hansi::Theme.new(**theme) : DEFAULT_THEME @theme = BASE_THEME.merge(theme) end
Public Instance Methods
render(renderer)
click to toggle source
@!visibility private
# File lib/mustermann/visualizer/highlight.rb, line 133 def render(renderer) Highlighter.highlight(pattern, renderer) end
render_with(renderer, **options)
click to toggle source
@!visibility private
# File lib/mustermann/visualizer/highlight.rb, line 127 def render_with(renderer, **options) options[:inspect] = @inspect if options[:inspect].nil? renderer.new(self, **options).render end
stylesheet(**options)
click to toggle source
@return [String] stylesheet for HTML output from the pattern
# File lib/mustermann/visualizer/highlight.rb, line 122 def stylesheet(**options) Renderer::HTML.new(self, **options).stylesheet end
to_ansi(**options)
click to toggle source
@example
require 'mustermann/visualizer' pattern = Mustermann.new('/:name') highlight = Mustermann::Visualizer.highlight(pattern) puts highlight.to_ansi
@return [String] ANSI colorized version of the pattern
# File lib/mustermann/visualizer/highlight.rb, line 81 def to_ansi(**options) render_with(Renderer::ANSI, **options) end
to_hansi_template(**options)
click to toggle source
@example
require 'mustermann/visualizer' pattern = Mustermann.new('/:name') highlight = Mustermann::Visualizer.highlight(pattern) puts highlight.to_hansi_template
@return [String] Hansi template representation of the pattern
# File lib/mustermann/visualizer/highlight.rb, line 68 def to_hansi_template(**options) render_with(Renderer::HansiTemplate, **options) end
to_html(**options)
click to toggle source
@example
require 'mustermann/visualizer' pattern = Mustermann.new('/:name') highlight = Mustermann::Visualizer.highlight(pattern) puts highlight.to_html
@return [String] HTML rendering of the pattern
# File lib/mustermann/visualizer/highlight.rb, line 94 def to_html(**options) render_with(Renderer::HTML, **options) end
to_pattern()
click to toggle source
@return [Mustermann::Pattern] the pattern used to create the highlight object
# File lib/mustermann/visualizer/highlight.rb, line 112 def to_pattern pattern end
to_s()
click to toggle source
@return [String] string representation of the pattern
# File lib/mustermann/visualizer/highlight.rb, line 117 def to_s pattern.to_s end
to_sexp(**options)
click to toggle source
@example
require 'mustermann/visualizer' pattern = Mustermann.new('/:name') highlight = Mustermann::Visualizer.highlight(pattern) puts highlight.to_sexp
@return [String] s-expression like representation of the pattern
# File lib/mustermann/visualizer/highlight.rb, line 107 def to_sexp(**options) render_with(Renderer::Sexp, **options) end