Class: RailsInfo::CodePresenter
- Defined in:
- app/presenters/rails_info/code_presenter.rb
Instance Method Summary collapse
-
#initialize(subject, options = {}) ⇒ CodePresenter
constructor
A new instance of CodePresenter.
- #table ⇒ Object
Methods inherited from Presenter
Constructor Details
#initialize(subject, options = {}) ⇒ CodePresenter
Returns a new instance of CodePresenter.
2 3 4 5 6 7 8 9 10 11 |
# File 'app/presenters/rails_info/code_presenter.rb', line 2 def initialize(subject, = {}) super(subject, ) @code = [:text] @line_number = [:number] @line_numbers = [:line_numbers] @highlighted_line_numbers = [:highlighted_line_numbers] || [] @highlighted_line_numbers = @highlighted_line_numbers.is_a?(Array) ? @highlighted_line_numbers : [@highlighted_line_numbers] @highlighted_number_name = [:highlighted_number_name] end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class RailsInfo::Presenter
Instance Method Details
#table ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'app/presenters/rails_info/code_presenter.rb', line 13 def table outer_html = '' unless @line_numbers.include?(@line_number) outer_html = content_tag(:p) do content_tag :strong do raw( "Line number #{@line_number.inspect} is either an empty line or not included (anymore).<br/>" + "So highlighting the nearest line." ) end end end outer_html + content_tag(:table, cellspacing: 0, cellpadding: 0) do html, visible_line_number = '', 1 @line_numbers.each do |line_number| html += content_tag :tr do tr_html = '' if @highlighted_line_numbers.include?(visible_line_number) #line_number_link = link_to line_number.to_s, "#top", name: @highlighted_number_name.parameterize tr_html = content_tag :td, line_number, class: 'hll' else tr_html = content_tag :td, line_number end if line_number == @line_numbers.first = @highlighted_line_numbers ? {hl_lines: @highlighted_line_numbers } : {} # 1) This Ruby wrapped Python code can cause Ruby segmentation faults. # If you can abandon syntax highlighting deactivate 1) and use 2) instead code = ::Pygments.highlight(@code, lexer: 'ruby', options: ) rescue @code.gsub(/\n/, '<br/>').gsub(' ', ' ') # 2) # code = @code.gsub(/\n/, '<br/>').gsub(' ', ' ') tr_html += content_tag :td, raw(code), rowspan: @line_numbers.length end raw tr_html end visible_line_number += 1 end raw html end end |