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: false, **theme) click to toggle source

@!visibility private

# File lib/mustermann/visualizer/highlight.rb, line 50
def initialize(pattern, type: nil, inspect: false, **theme)
  @pattern = Mustermann.new(pattern, type: type)
  @inspect = 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 131
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 125
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 120
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 79
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 66
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 92
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 110
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 115
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 105
def to_sexp(**options)
  render_with(Renderer::Sexp, **options)
end