Module: Mamemose::Path
- Included in:
- Server
- Defined in:
- lib/mamemose/path.rb
Instance Method Summary collapse
-
#docpath(uri) ⇒ Object
returns DOCUMENT_ROOT-rooted path.
-
#escape(text) ⇒ Object
returns escaped characters so that the markdown parser doesn’t interpret it has special meaning.
- #escaped_basename(filename) ⇒ Object
-
#fullpath(uri) ⇒ Object
returns fullpath.
-
#showpath(uri) ⇒ Object
returns DOCUMENT_ROOT-rooted path, but escaped.
-
#uri(path) ⇒ Object
returns /-rooted path.
Instance Method Details
#docpath(uri) ⇒ Object
returns DOCUMENT_ROOT-rooted path. eg. ~/Dropbox/memo/path/to/my_document.md
19 20 21 |
# 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) ⇒ Object
returns escaped characters so that the markdown parser doesn’t interpret it has special meaning.
3 4 5 |
# File 'lib/mamemose/path.rb', line 3 def escape(text) return text.gsub(/[\`*_{}\[\]()#+\-.!]/, "\\\\\\0") end |
#escaped_basename(filename) ⇒ Object
29 30 31 |
# File 'lib/mamemose/path.rb', line 29 def escaped_basename(filename) return escape(File::basename(filename)) end |
#fullpath(uri) ⇒ Object
returns fullpath. eg. /home/daimatz/Dropbox/memo/path/to/my_document.md
14 15 16 |
# File 'lib/mamemose/path.rb', line 14 def fullpath(uri) return File.join(DIR, uri.gsub(DIR, '').gsub('/', File::SEPARATOR)) end |
#showpath(uri) ⇒ Object
returns DOCUMENT_ROOT-rooted path, but escaped. eg. ~/Dropbox/memo/path/to/my_document.md used in user-viewable (HTML) context.
25 26 27 |
# File 'lib/mamemose/path.rb', line 25 def showpath(uri) return escape(docpath(uri)) end |
#uri(path) ⇒ Object
returns /-rooted path. eg. /path/to/my_document.md
8 9 10 11 |
# File 'lib/mamemose/path.rb', line 8 def uri(path) s = File::(path).gsub(DIR, "").gsub(File::SEPARATOR, '/') return s == '' ? '/' : s end |