class Milkode::CodeRayWrapper
Attributes
highlight_lines[R]
line_number_start[R]
Public Class Methods
new(content, filename, match_lines = [], keywords = [])
click to toggle source
# 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
Public Instance Methods
col_limit(limit_num)
click to toggle source
# 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()
click to toggle source
# File lib/milkode/cdweb/lib/coderay_wrapper.rb, line 90 def file_type @setting = WebSetting.new @extname = File.extname(@filename) @p_extname = "^\\#{@extname}$" if @setting.eliminate_extname.split(" ").grep(/#{@p_extname}/).size > 0 @filename = File.basename(@filename, @extname) @extname = File.extname(@filename) end case @extname when ".php" :php_utf8 when ".el" # :scheme CodeRay::FileType.fetch @filename, :plaintext else CodeRay::FileType.fetch @filename, :plaintext end end
limit_range(range, array)
click to toggle source
# 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)
click to toggle source
# 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()
click to toggle source
# File lib/milkode/cdweb/lib/coderay_wrapper.rb, line 53 def to_html setting = WebSetting.new layout_setting = setting.layout_setting 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, :tab_width => layout_setting[:tab_width], ) end
to_html_anchorlink(url)
click to toggle source
# File lib/milkode/cdweb/lib/coderay_wrapper.rb, line 72 def to_html_anchorlink(url) setting = WebSetting.new layout_setting = setting.layout_setting 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, :tab_width => layout_setting[:tab_width], ) end