# File lib/rouge/theme.rb, line 140 def initialize(opts={}) @scope = opts[:scope] || '.highlight' end
# File lib/rouge/theme.rb, line 144 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
# File lib/rouge/theme.rb, line 156 def render_base(selector, &b) self.class.base_style.render(selector, &b) end
# File lib/rouge/theme.rb, line 160 def style_for(tok) self.class.get_style(tok) end
# File lib/rouge/theme.rb, line 165 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
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 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
# File lib/rouge/theme.rb, line 173 def single_css_selector(token) return @scope if token == Text "#{@scope} .#{token.shortname}" end