module Mamemose::Path
Public Instance Methods
docpath(uri)
click to toggle source
returns DOCUMENT_ROOT-rooted path. eg. ~/Dropbox/memo/path/to/my_document.md
# File lib/mamemose/path.rb, line 19 def docpath(uri) return File.join(DOCUMENT_ROOT, uri.gsub('/', File::SEPARATOR)).gsub(/#{File::SEPARATOR}$/, "") end
escape(text)
click to toggle source
returns escaped characters so that the markdown parser doesn't interpret it has special meaning.
# File lib/mamemose/path.rb, line 3 def escape(text) return text.gsub(/[\`*_{}\[\]()#+\-.!]/, "\\\\\\0") end
escaped_basename(filename)
click to toggle source
# File lib/mamemose/path.rb, line 29 def escaped_basename(filename) return escape(File::basename(filename)) end
fullpath(uri)
click to toggle source
returns fullpath. eg. /home/daimatz/Dropbox/memo/path/to/my_document.md
# File lib/mamemose/path.rb, line 14 def fullpath(uri) return File.join(DIR, uri.gsub(DIR, '').gsub('/', File::SEPARATOR)) end
showpath(uri)
click to toggle source
returns DOCUMENT_ROOT-rooted path, but escaped. eg. ~/Dropbox/memo/path/to/my_document.md used in user-viewable (HTML
) context.
# File lib/mamemose/path.rb, line 25 def showpath(uri) return escape(docpath(uri)) end
uri(path)
click to toggle source
returns /-rooted path. eg. /path/to/my_document.md
# File lib/mamemose/path.rb, line 8 def uri(path) s = File::expand_path(path).gsub(DIR, "").gsub(File::SEPARATOR, '/') return s == '' ? '/' : s end