Class: Rouge::Theme

Inherits:
Object
  • Object
show all
Defined in:
lib/rouge/theme.rb

Direct Known Subclasses

CSSTheme

Defined Under Namespace

Classes: Style

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.find(n) ⇒ Object



96
97
98
# File 'lib/rouge/theme.rb', line 96

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

.get_own_style(token) ⇒ Object



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

def get_own_style(token)
  token.ancestors do |anc|
    return styles[anc.name] if styles[anc.name]
  end
end

.get_style(token) ⇒ Object



85
86
87
# File 'lib/rouge/theme.rb', line 85

def get_style(token)
  get_own_style(token) || style['Text']
end

.name(n = nil) ⇒ Object



89
90
91
92
93
94
# File 'lib/rouge/theme.rb', line 89

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

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

.palette(arg = {}) ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/rouge/theme.rb', line 43

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



100
101
102
# File 'lib/rouge/theme.rb', line 100

def registry
  @registry ||= {}
end

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



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

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

.style(*tokens) ⇒ Object



69
70
71
72
73
74
75
76
77
# File 'lib/rouge/theme.rb', line 69

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

  style = Style.new(self, style)

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

.stylesObject



60
61
62
# File 'lib/rouge/theme.rb', line 60

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

Instance Method Details

#stylesObject



38
39
40
# File 'lib/rouge/theme.rb', line 38

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