class FrenchPress::Post::Code
Public Instance Methods
lang()
click to toggle source
# 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()
click to toggle source
# 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()
click to toggle source
# 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