Class: Milkode::CodeRayWrapper
- Inherits:
-
Object
- Object
- Milkode::CodeRayWrapper
- Defined in:
- lib/milkode/cdweb/lib/coderay_wrapper.rb
Instance Attribute Summary collapse
-
#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 = []) ⇒ 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 = []) ⇒ CodeRayWrapper
Returns a new instance of CodeRayWrapper.
18 19 20 21 22 23 24 |
# File 'lib/milkode/cdweb/lib/coderay_wrapper.rb', line 18 def initialize(content, filename, match_lines = []) @content = content @filename = filename @match_lines = match_lines @highlight_lines = match_lines.map{|v|v.index+1} @line_number_start = 1 end |
Instance Attribute Details
#line_number_start ⇒ Object (readonly)
Returns the value of attribute line_number_start.
16 17 18 |
# File 'lib/milkode/cdweb/lib/coderay_wrapper.rb', line 16 def line_number_start @line_number_start end |
Instance Method Details
#col_limit(limit_num) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/milkode/cdweb/lib/coderay_wrapper.rb', line 26 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
75 76 77 78 79 80 81 82 83 |
# File 'lib/milkode/cdweb/lib/coderay_wrapper.rb', line 75 def file_type case File.extname(@filename) when ".el" # :scheme CodeRay::FileType.fetch @filename, :plaintext else CodeRay::FileType.fetch @filename, :plaintext end end |
#limit_range(range, array) ⇒ Object
45 46 47 48 |
# File 'lib/milkode/cdweb/lib/coderay_wrapper.rb', line 45 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
38 39 40 41 42 43 |
# File 'lib/milkode/cdweb/lib/coderay_wrapper.rb', line 38 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
50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/milkode/cdweb/lib/coderay_wrapper.rb', line 50 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 ) end |
#to_html_anchorlink(url) ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/milkode/cdweb/lib/coderay_wrapper.rb', line 62 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 ) end |