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



106
107
108
# File 'lib/rouge/theme.rb', line 106

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

.find(n) ⇒ Object



117
118
119
# File 'lib/rouge/theme.rb', line 117

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

.get_own_style(token) ⇒ Object



94
95
96
97
98
99
100
# File 'lib/rouge/theme.rb', line 94

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



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

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

.name(n = nil) ⇒ Object



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

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



121
122
123
# File 'lib/rouge/theme.rb', line 121

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



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

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

#get_own_style(token) ⇒ Object



77
78
79
# File 'lib/rouge/theme.rb', line 77

def get_own_style(token)
  self.class.get_own_style(token)
end

#get_style(token) ⇒ Object



81
82
83
# File 'lib/rouge/theme.rb', line 81

def get_style(token)
  self.class.get_style(token)
end

#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