lib/rouge/theme.rb in rouge-0.4.0 vs lib/rouge/theme.rb in rouge-0.5.0

- old
+ new

@@ -1,7 +1,9 @@ module Rouge class Theme + include Token::Tokens + class Style < Hash def initialize(theme, hsh={}) super() @theme = theme merge!(hsh) @@ -73,22 +75,24 @@ style = tokens.last.is_a?(Hash) ? tokens.pop : {} style = Style.new(self, style) tokens.each do |tok| - styles[tok.to_s] = style + styles[tok] = style end end def get_own_style(token) - token.ancestors do |anc| - return styles[anc.name] if styles[anc.name] + token.token_chain.each do |anc| + return styles[anc] if styles[anc] end + + nil end def get_style(token) - get_own_style(token) || style['Text'] + get_own_style(token) || styles[Token::Tokens::Text] end def name(n=nil) return @name if n.nil? @@ -138,19 +142,17 @@ # shared styles for tableized line numbers yield "#{@scope} table { border-spacing: 0; }" yield "#{@scope} table td { padding: 5px; }" yield "#{@scope} table .gutter { text-align: right; }" - styles.each do |tokname, style| - style.render(css_selector(Token[tokname]), &b) + styles.each do |tok, style| + style.render(css_selector(tok), &b) end end def style_for(tok) - styles.fetch(tok.name) do - tok.parent ? style_for(tok.parent) : Style.new(self) - end + self.class.get_style(tok) end private def css_selector(token) inflate_token(token).map do |tok| @@ -173,10 +175,10 @@ 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.name] + next if styles[st] inflate_token(st, &b) end end end