Module: Ciridiri::Paths
- Included in:
- Page
- Defined in:
- lib/ciridiri/paths.rb
Instance Method Summary collapse
-
#path_from_uri(uri) ⇒ Object
Convert ‘uri` to `path` in a file system including `content_dir` and a source file extension `/team/pro/chuck-norris` -> `content_dir/team/pro/chuck-norris.text`.
-
#uri_from_path(path) ⇒ Object
Convert ‘path` to `uri` `content_dir/team/pro/chuck-norris.text` -> `/team/pro/chuck-norris`.
Instance Method Details
#path_from_uri(uri) ⇒ Object
Convert ‘uri` to `path` in a file system including `content_dir` and a source file extension `/team/pro/chuck-norris` -> `content_dir/team/pro/chuck-norris.text`
7 8 9 10 11 |
# File 'lib/ciridiri/paths.rb', line 7 def path_from_uri(uri) path = uri.split('/') filename = path.pop File.join(content_dir, path, "#{filename}#{Ciridiri::SOURCE_FILE_EXT}") end |
#uri_from_path(path) ⇒ Object
Convert ‘path` to `uri` `content_dir/team/pro/chuck-norris.text` -> `/team/pro/chuck-norris`
15 16 17 18 19 20 21 22 |
# File 'lib/ciridiri/paths.rb', line 15 def uri_from_path(path) path = File.absolute_path(path) relative_path = Pathname.new(path).relative_path_from(Pathname(content_dir)).to_s relative_uri = relative_path.gsub(File::Separator, '/'). gsub(Regexp.new("#{Ciridiri::SOURCE_FILE_EXT}$"), '') "/#{relative_uri}" end |