Class: Rouge::Rails::TemplateHandler
- Inherits:
-
Object
- Object
- Rouge::Rails::TemplateHandler
- Defined in:
- lib/rouge/rails/template_handler.rb
Instance Attribute Summary collapse
-
#template ⇒ Object
Returns the value of attribute template.
Class Method Summary collapse
Instance Method Summary collapse
- #call ⇒ Object
- #colorscheme ⇒ Object
- #default_lexer ⇒ Object
- #erb_handler ⇒ Object
-
#initialize(template) ⇒ TemplateHandler
constructor
A new instance of TemplateHandler.
- #lexer ⇒ Object
- #source ⇒ Object
Constructor Details
#initialize(template) ⇒ TemplateHandler
Returns a new instance of TemplateHandler.
9 10 11 |
# File 'lib/rouge/rails/template_handler.rb', line 9 def initialize(template) @template = template end |
Instance Attribute Details
#template ⇒ Object
Returns the value of attribute template.
7 8 9 |
# File 'lib/rouge/rails/template_handler.rb', line 7 def template @template end |
Class Method Details
.call(template) ⇒ Object
3 4 5 |
# File 'lib/rouge/rails/template_handler.rb', line 3 def self.call(template) new(template).call end |
.erb_handler ⇒ Object
45 46 47 |
# File 'lib/rouge/rails/template_handler.rb', line 45 def self.erb_handler @erb_handler ||= ActionView::Template.handler_for_extension(:erb) end |
Instance Method Details
#call ⇒ Object
13 14 15 16 17 18 19 |
# File 'lib/rouge/rails/template_handler.rb', line 13 def call %{ lexer = #{lexer} formatter = Rouge::Formatters::HTML.new(css_class: "#{colorscheme}") formatter.format(lexer.lex(#{source})).html_safe } end |
#colorscheme ⇒ Object
29 30 31 32 33 34 35 |
# File 'lib/rouge/rails/template_handler.rb', line 29 def colorscheme if template.locals.include?("colorscheme") "highlight \#{colorscheme}" else "highlight #{Rouge::Rails.configuration.default_colorscheme}" end end |
#default_lexer ⇒ Object
41 42 43 |
# File 'lib/rouge/rails/template_handler.rb', line 41 def default_lexer "Rouge::Lexers::PlainText" end |
#erb_handler ⇒ Object
49 50 51 |
# File 'lib/rouge/rails/template_handler.rb', line 49 def erb_handler self.class.erb_handler end |
#lexer ⇒ Object
21 22 23 24 25 26 27 |
# File 'lib/rouge/rails/template_handler.rb', line 21 def lexer if template.locals.include?("language") "Rouge::Lexer.find(language) || #{default_lexer}" else default_lexer end end |
#source ⇒ Object
37 38 39 |
# File 'lib/rouge/rails/template_handler.rb', line 37 def source "begin; #{erb_handler.call(template)} end" end |