Class: CodeRay::Encoders::HTML::CSS

Inherits:
Object
  • Object
show all
Defined in:
lib/coderay/encoders/html/css.rb

Constant Summary collapse

DEFAULT_STYLESHEET_ID =
:cycnus

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(style = :default) ⇒ CSS

Returns a new instance of CSS.



15
16
17
18
19
20
21
22
23
# File 'lib/coderay/encoders/html/css.rb', line 15

def initialize style = :default
	@classes = Hash.new
	style = CSS.load_stylesheet style
	@stylesheet = [
		style::CSS_MAIN_STYLES,
		style::TOKEN_COLORS.gsub(/^(?!$)/, '.CodeRay ')
	].join("\n")
	parse style::TOKEN_COLORS
end

Instance Attribute Details

#stylesheetObject (readonly)

Returns the value of attribute stylesheet.



8
9
10
# File 'lib/coderay/encoders/html/css.rb', line 8

def stylesheet
  @stylesheet
end

Class Method Details

.load_stylesheet(style = :default) ⇒ Object



10
11
12
13
# File 'lib/coderay/encoders/html/css.rb', line 10

def CSS.load_stylesheet style = :default
	style = DEFAULT_STYLESHEET_ID if style == :default
	CodeRay::Styles[style]
end

Instance Method Details

#[](*styles) ⇒ Object



25
26
27
28
29
30
31
32
33
34
# File 'lib/coderay/encoders/html/css.rb', line 25

def [] *styles
	cl = @classes[styles.first]
	return '' unless cl
	style = ''
	1.upto(styles.size) do |offset|
		break if style = cl[styles[offset .. -1]]
	end
	raise 'Style not found: %p' % [styles] if $DEBUG and style.empty?
	return style
end