Class: FrenchPress::Post::Code
Instance Attribute Summary
Attributes inherited from Generic
#file_name, #parent_blog
Instance Method Summary
collapse
Methods inherited from Generic
#assign_variables, #derive_variables, #initialize, #render_as_quote, #render_with_tags, #tags
Instance Method Details
#lang ⇒ Object
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
# File 'lib/frenchpress/post/code.rb', line 6
def lang
case @file_type
when 'rb'
'ruby'
when 'c'
'c'
when 'css'
'css'
when 'py'
'python'
when 'yml'
'yaml'
when 'swift'
'swift'
when 'rs'
'rust'
when 'go'
'go'
when 'cpp'
'cpp'
else
''
end
end
|
#lexer ⇒ Object
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
# File 'lib/frenchpress/post/code.rb', line 31
def lexer
case lang
when 'ruby'
Rouge::Lexers::Ruby.new
when 'c'
Rouge::Lexers::C.new
when 'css'
Rouge::Lexers::Css.new
when 'python'
Rouge::Lexers::Python.new
when 'yaml'
Rouge::Lexers::Yaml.new
when 'swift'
Rouge::Lexers::Swift.new
when 'rust'
Rouge::Lexers::Rust.new
when 'go'
Rouge::Lexers::Go.new
when 'cpp'
Rouge::Lexers::Cpp.new
end
end
|
#render ⇒ Object
54
55
56
57
58
|
# File 'lib/frenchpress/post/code.rb', line 54
def render
return "<code class=\"code\">#{@content}</code>" unless lexer
renderer = Rouge::Formatters::HTML.new(css_class: 'highlight')
"<div class=\"code\">#{renderer.format(lexer.lex(@content))}</div>"
end
|