class Rugments::CSSTheme

Public Class Methods

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

Public Instance Methods

render() { |"| ... } click to toggle source
# File lib/rugments/theme.rb, line 143
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.render(css_selector(tok), &b)
  end
end
render_base(selector, &b) click to toggle source
# File lib/rugments/theme.rb, line 155
def render_base(selector, &b)
  self.class.base_style.render(selector, &b)
end
style_for(tok) click to toggle source
# File lib/rugments/theme.rb, line 159
def style_for(tok)
  self.class.get_style(tok)
end

Private Instance Methods

css_selector(token) click to toggle source
# File lib/rugments/theme.rb, line 165
def css_selector(token)
  inflate_token(token).map do |tok|
    fail "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/rugments/theme.rb, line 183
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/rugments/theme.rb, line 173
def single_css_selector(token)
  return @scope if token == Text

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