Class: Sitepress::Path
- Inherits:
-
Object
- Object
- Sitepress::Path
- Defined in:
- lib/sitepress/path.rb
Constant Summary collapse
- HANDLER_EXTENSIONS =
Default handler extensions. Handlers are anything that render or manipulate the contents of the file into a different output, like ERB or HAML.
%i[haml erb md markdown]
- ROOT_NODE_NAME =
The root node name is a blank string.
"".freeze
- ROOT_PATH =
The name of the root path
"/".freeze
Class Attribute Summary collapse
Instance Attribute Summary collapse
-
#basename ⇒ Object
readonly
Returns the value of attribute basename.
-
#dirname ⇒ Object
readonly
Returns the value of attribute dirname.
-
#format ⇒ Object
readonly
Returns the value of attribute format.
-
#handler ⇒ Object
readonly
Returns the value of attribute handler.
-
#node_name ⇒ Object
readonly
Returns the value of attribute node_name.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Instance Method Summary collapse
- #==(path) ⇒ Object
- #exists? ⇒ Boolean
- #expand_path ⇒ Object
-
#initialize(path, path_seperator: File::SEPARATOR, handler_extensions: self.class.handler_extensions) ⇒ Path
constructor
A new instance of Path.
- #node_names ⇒ Object
- #relative_path_from(target) ⇒ Object
-
#to_str ⇒ Object
(also: #to_s)
Necessary for operations like ‘File.read path` where `path` is an instance of this object.
Constructor Details
#initialize(path, path_seperator: File::SEPARATOR, handler_extensions: self.class.handler_extensions) ⇒ Path
Returns a new instance of Path.
29 30 31 32 33 34 |
# File 'lib/sitepress/path.rb', line 29 def initialize(path, path_seperator: File::SEPARATOR, handler_extensions: self.class.handler_extensions) @path = path.to_s @path_seperator = Regexp.new(path_seperator) @handler_extensions = handler_extensions parse end |
Class Attribute Details
.handler_extensions ⇒ Object
24 25 26 |
# File 'lib/sitepress/path.rb', line 24 def handler_extensions @handler_extensions ||= HANDLER_EXTENSIONS end |
Instance Attribute Details
#basename ⇒ Object (readonly)
Returns the value of attribute basename.
17 18 19 |
# File 'lib/sitepress/path.rb', line 17 def basename @basename end |
#dirname ⇒ Object (readonly)
Returns the value of attribute dirname.
17 18 19 |
# File 'lib/sitepress/path.rb', line 17 def dirname @dirname end |
#format ⇒ Object (readonly)
Returns the value of attribute format.
17 18 19 |
# File 'lib/sitepress/path.rb', line 17 def format @format end |
#handler ⇒ Object (readonly)
Returns the value of attribute handler.
17 18 19 |
# File 'lib/sitepress/path.rb', line 17 def handler @handler end |
#node_name ⇒ Object (readonly)
Returns the value of attribute node_name.
17 18 19 |
# File 'lib/sitepress/path.rb', line 17 def node_name @node_name end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
17 18 19 |
# File 'lib/sitepress/path.rb', line 17 def path @path end |
Instance Method Details
#==(path) ⇒ Object
47 48 49 |
# File 'lib/sitepress/path.rb', line 47 def ==(path) to_s == path.to_s end |
#exists? ⇒ Boolean
51 52 53 |
# File 'lib/sitepress/path.rb', line 51 def exists? File.exist? path end |
#expand_path ⇒ Object
55 56 57 |
# File 'lib/sitepress/path.rb', line 55 def File. path end |
#node_names ⇒ Object
36 37 38 |
# File 'lib/sitepress/path.rb', line 36 def node_names @node_names ||= node_name_ancestors.push(node_name) end |
#relative_path_from(target) ⇒ Object
63 64 65 |
# File 'lib/sitepress/path.rb', line 63 def relative_path_from(target) Pathname.new(@path).relative_path_from(target).to_s end |
#to_str ⇒ Object Also known as: to_s
Necessary for operations like ‘File.read path` where `path` is an instance of this object.
42 43 44 |
# File 'lib/sitepress/path.rb', line 42 def to_str @path end |