Class: Milkode::CodeRayWrapper
- Inherits:
-
Object
- Object
- Milkode::CodeRayWrapper
- Defined in:
- lib/milkode/cdweb/lib/coderay_wrapper.rb
Instance Attribute Summary collapse
-
#highlight_lines ⇒ Object
readonly
Returns the value of attribute highlight_lines.
-
#line_number_start ⇒ Object
readonly
Returns the value of attribute line_number_start.
Instance Method Summary collapse
- #col_limit(limit_num) ⇒ Object
- #file_type ⇒ Object
-
#initialize(content, filename, match_lines = [], keywords = []) ⇒ CodeRayWrapper
constructor
A new instance of CodeRayWrapper.
- #limit_range(range, array) ⇒ Object
- #set_range(range) ⇒ Object
- #to_html ⇒ Object
- #to_html_anchorlink(url) ⇒ Object
Constructor Details
#initialize(content, filename, match_lines = [], keywords = []) ⇒ CodeRayWrapper
Returns a new instance of CodeRayWrapper.
20 21 22 23 24 25 26 27 |
# File 'lib/milkode/cdweb/lib/coderay_wrapper.rb', line 20 def initialize(content, filename, match_lines = [], keywords = []) @content = content @filename = filename @match_lines = match_lines @highlight_lines = match_lines.map{|v|v.index+1} @line_number_start = 1 @keywords = keywords end |
Instance Attribute Details
#highlight_lines ⇒ Object (readonly)
Returns the value of attribute highlight_lines.
18 19 20 |
# File 'lib/milkode/cdweb/lib/coderay_wrapper.rb', line 18 def highlight_lines @highlight_lines end |
#line_number_start ⇒ Object (readonly)
Returns the value of attribute line_number_start.
17 18 19 |
# File 'lib/milkode/cdweb/lib/coderay_wrapper.rb', line 17 def line_number_start @line_number_start end |
Instance Method Details
#col_limit(limit_num) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/milkode/cdweb/lib/coderay_wrapper.rb', line 29 def col_limit(limit_num) content_a = @content.split("\n") @content = content_a.map{|v| if (v.length > limit_num) v[0...limit_num] + " ..." else v end }.join("\n") end |
#file_type ⇒ Object
82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/milkode/cdweb/lib/coderay_wrapper.rb', line 82 def file_type case File.extname(@filename) when ".php" :php_utf8 when ".el" # :scheme CodeRay::FileType.fetch @filename, :plaintext else CodeRay::FileType.fetch @filename, :plaintext end end |
#limit_range(range, array) ⇒ Object
48 49 50 51 |
# File 'lib/milkode/cdweb/lib/coderay_wrapper.rb', line 48 def limit_range(range, array) Range.new(range.first < 0 ? 0 : range.first, range.last >= array.size ? array.size - 1 : range.last) end |
#set_range(range) ⇒ Object
41 42 43 44 45 46 |
# File 'lib/milkode/cdweb/lib/coderay_wrapper.rb', line 41 def set_range(range) content_a = @content.split("\n") range = limit_range(range, content_a) @content = content_a[range].join("\n") @line_number_start = range.first + 1 end |
#to_html ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/milkode/cdweb/lib/coderay_wrapper.rb', line 53 def to_html CodeRay.scan(@content, file_type). html2( :wrap => nil, :line_numbers => :table, :css => :class, :highlight_lines => @highlight_lines, :line_number_start => @line_number_start, :line_number_anchors => false, :onclick_copy_line_number => true, :onclick_copy_prefix => "/#{@filename}:", :keywords => @keywords ) end |
#to_html_anchorlink(url) ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/milkode/cdweb/lib/coderay_wrapper.rb', line 68 def to_html_anchorlink(url) CodeRay.scan(@content, file_type). html2( :wrap => nil, :line_numbers => :table, :css => :class, :highlight_lines => @highlight_lines, :line_number_start => @line_number_start, :line_number_anchors => 'n', :line_number_anchor_url => url, :keywords => @keywords ) end |