class CodeRay::Encoders::HTML::CSS

Experimental RBS support (using type sampling data from the type_fusion project).

# sig/coderay/encoders/html/css.rbs

class CodeRay::Encoders::HTML::CSS
  def get_style_for_css_classes: (Array[String] css_classes) -> String
end

:nodoc:

def get_style_for_css_classes css_classes

Experimental RBS support (using type sampling data from the type_fusion project).

def get_style_for_css_classes: (String css_classes) -> String

This signature was generated using 1 sample from 1 application.

def get_style_for_css_classes css_classes
  cl = @styles[css_classes.first]
  return '' unless cl
  style = ''
  1.upto css_classes.size do |offset|
    break if style = cl[css_classes[offset .. -1]]
  end
  # warn 'Style not found: %p' % [styles] if style.empty?
  return style
end

def initialize style = :default

def initialize style = :default
  @styles = Hash.new
  style = CSS.load_stylesheet style
  @stylesheet = [
    style::CSS_MAIN_STYLES,
    style::TOKEN_COLORS.gsub(/^(?!$)/, '.CodeRay ')
  ].join("\n")
  parse style::TOKEN_COLORS
end

def parse stylesheet

def parse stylesheet
  stylesheet.scan CSS_CLASS_PATTERN do |selectors, style, error|
    raise "CSS parse error: '#{error.inspect}' not recognized" if error
    for selector in selectors.split(',')
      classes = selector.scan(/[-\w]+/)
      cl = classes.pop
      @styles[cl] ||= Hash.new
      @styles[cl][classes] = style.to_s.strip.delete(' ').chomp(';')
    end
  end
end