class Rouge::CSSTheme

Public Class Methods

new(opts={}) click to toggle source
# File lib/rouge/theme.rb, line 159
def initialize(opts={})
  @scope = opts[:scope] || '.highlight'
end

Public Instance Methods

render() { |"#{scope} table td { padding: 5px; }"| ... } click to toggle source
# File lib/rouge/theme.rb, line 163
def render(&b)
  return enum_for(:render).to_a.join("\n") unless b

  # shared styles for tableized line numbers
  yield "#{@scope} table td { padding: 5px; }"
  yield "#{@scope} table pre { margin: 0; }"

  styles.each do |tok, style|
    Style.new(self, style).render(css_selector(tok), &b)
  end
end
render_base(selector, &b) click to toggle source
# File lib/rouge/theme.rb, line 175
def render_base(selector, &b)
  self.class.base_style.render(selector, &b)
end
style_for(tok) click to toggle source
# File lib/rouge/theme.rb, line 179
def style_for(tok)
  self.class.get_style(tok)
end

Private Instance Methods

css_selector(token) click to toggle source
# File lib/rouge/theme.rb, line 184
def css_selector(token)
  inflate_token(token).map do |tok|
    raise "unknown token: #{tok.inspect}" if tok.shortname.nil?

    single_css_selector(tok)
  end.join(', ')
end
inflate_token(tok) { |tok| ... } click to toggle source

yield all of the tokens that should be styled the same as the given token. Essentially this recursively all of the subtokens, except those which are more specifically styled.

# File lib/rouge/theme.rb, line 202
def inflate_token(tok, &b)
  return enum_for(:inflate_token, tok) unless block_given?

  yield tok
  tok.sub_tokens.each do |(_, st)|
    next if styles[st]

    inflate_token(st, &b)
  end
end
single_css_selector(token) click to toggle source
# File lib/rouge/theme.rb, line 192
def single_css_selector(token)
  return @scope if token == Text

  "#{@scope} .#{token.shortname}"
end