Module: MerbFootnotes::Formatter

Defined in:
lib/merb_footnotes/formatter.rb

Overview

Copyright © 2008 FiveRuns Corporation

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Class Method Summary collapse

Class Method Details

TODO: Refactor



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 'lib/merb_footnotes/formatter.rb', line 39

def self.editor_link_line(line, show_filename_only = false)
  filename, number, extra = line.match(/^(.+?):(\d+)(?::in\b(.*?))?/)[1, 2]
  in_app, line = strip_root(line)
  name = if line.size > 87
    "…#{CGI.escapeHTML line.sub(/^.*?(.{84})$/, '\1')}"
  else 
    line
  end
  name = if in_app
    if name =~ /`/
      name.sub(/^(.*?)\s+`(.*?)'$/, %q(<span class='tuneup-app-line'>\1</span> `<b class='tuneup-app-line'>\2</b>'))
    else
      %(<span class='tuneup-app-line'>#{name}</span>)
    end
  else
    name.sub(/([^\/\\]+\.\S+:\d+:in)\s+`(.*?)'$/, %q(\1 `<b>\2</b>'))
  end
  
  if show_filename_only
    name = name.to_s.split("/").last
  end
  
  %(<a title='%s' href='txmt://open/?url=file://%s&line=%d'>%s</a>%s) % [CGI.escapeHTML(line), filename, number, name, extra]
end

.strip_root(text) ⇒ Object

def self.pretty(value)

CGI.escapeHTML(PP.pp(value, ''))

end



27
28
29
30
31
32
33
34
35
36
# File 'lib/merb_footnotes/formatter.rb', line 27

def self.strip_root(text)
  pattern = /^#{Regexp.quote Merb.root}\/?/o
  if text =~ pattern
    result = text.sub(pattern, '')
    in_app = result !~ /^gems\//
    return [in_app, result]
  end
  
  [false, text]
end