Class: Rouge::Theme

Inherits:
Object
  • Object
show all
Includes:
Rouge::Token::Tokens
Defined in:
lib/rouge/theme.rb

Direct Known Subclasses

CSSTheme

Defined Under Namespace

Classes: Style

Constant Summary

Constants included from Rouge::Token::Tokens

Rouge::Token::Tokens::Num, Rouge::Token::Tokens::Str

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Rouge::Token::Tokens

token

Class Method Details

.base_styleObject



98
99
100
# File 'lib/rouge/theme.rb', line 98

def base_style
  get_own_style(Token::Tokens::Text)
end

.find(n) ⇒ Object



109
110
111
# File 'lib/rouge/theme.rb', line 109

def find(n)
  registry[n.to_s]
end

.get_own_style(token) ⇒ Object



86
87
88
89
90
91
92
# File 'lib/rouge/theme.rb', line 86

def get_own_style(token)
  token.token_chain.reverse_each do |anc|
    return Style.new(self, styles[anc]) if styles[anc]
  end

  nil
end

.get_style(token) ⇒ Object



94
95
96
# File 'lib/rouge/theme.rb', line 94

def get_style(token)
  get_own_style(token) || base_style
end

.name(n = nil) ⇒ Object



102
103
104
105
106
107
# File 'lib/rouge/theme.rb', line 102

def name(n=nil)
  return @name if n.nil?

  @name = n.to_s
  Theme.registry[@name] = self
end

.palette(arg = {}) ⇒ Object



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/rouge/theme.rb', line 50

def self.palette(arg={})
  @palette ||= InheritableHash.new(superclass.palette)

  if arg.is_a? Hash
    @palette.merge! arg
    @palette
  else
    case arg
    when /#[0-9a-f]+/i
      arg
    else
      @palette[arg] or raise "not in palette: #{arg.inspect}"
    end
  end
end

.registryObject



113
114
115
# File 'lib/rouge/theme.rb', line 113

def registry
  @registry ||= {}
end

.render(opts = {}, &b) ⇒ Object



73
74
75
# File 'lib/rouge/theme.rb', line 73

def self.render(opts={}, &b)
  new(opts).render(&b)
end

.style(*tokens) ⇒ Object



78
79
80
81
82
83
84
# File 'lib/rouge/theme.rb', line 78

def style(*tokens)
  style = tokens.last.is_a?(Hash) ? tokens.pop : {}

  tokens.each do |tok|
    styles[tok] = style
  end
end

.stylesObject



69
70
71
# File 'lib/rouge/theme.rb', line 69

def self.styles
  @styles ||= InheritableHash.new(superclass.styles)
end

Instance Method Details

#palette(*a) ⇒ Object



66
# File 'lib/rouge/theme.rb', line 66

def palette(*a) self.class.palette(*a) end

#stylesObject



45
46
47
# File 'lib/rouge/theme.rb', line 45

def styles
  @styles ||= self.class.styles.dup
end