Class: Rouge::Theme::Style

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

Instance Method Summary collapse

Constructor Details

#initialize(theme, hsh = {}) ⇒ Style

Returns a new instance of Style.



9
10
11
12
13
# File 'lib/rouge/theme.rb', line 9

def initialize(theme, hsh={})
  super()
  @theme = theme
  merge!(hsh)
end

Instance Method Details

#render(selector) {|"#{selector} {"| ... } ⇒ Object

Yields:

  • ("#{selector} {")


22
23
24
25
26
27
28
29
30
31
32
# File 'lib/rouge/theme.rb', line 22

def render(selector, &b)
  return enum_for(:render, selector).to_a.join("\n") unless b

  return if empty?

  yield "#{selector} {"
  rendered_rules.each do |rule|
    yield "  #{rule};"
  end
  yield "}"
end

#rendered_rules {|"color: #{fg}"| ... } ⇒ Object

Yields:

  • ("color: #{fg}")


34
35
36
37
38
39
40
41
42
43
# File 'lib/rouge/theme.rb', line 34

def rendered_rules(&b)
  return enum_for(:rendered_rules) unless b
  yield "color: #{fg}" if fg
  yield "background-color: #{bg}" if bg
  yield "font-weight: bold" if self[:bold]
  yield "font-style: italic" if self[:italic]
  yield "text-decoration: underline" if self[:underline]

  (self[:rules] || []).each(&b)
end