Class: Sitepress::Path

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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_extensionsObject



24
25
26
# File 'lib/sitepress/path.rb', line 24

def handler_extensions
  @handler_extensions ||= HANDLER_EXTENSIONS
end

Instance Attribute Details

#basenameObject (readonly)

Returns the value of attribute basename.



17
18
19
# File 'lib/sitepress/path.rb', line 17

def basename
  @basename
end

#dirnameObject (readonly)

Returns the value of attribute dirname.



17
18
19
# File 'lib/sitepress/path.rb', line 17

def dirname
  @dirname
end

#formatObject (readonly)

Returns the value of attribute format.



17
18
19
# File 'lib/sitepress/path.rb', line 17

def format
  @format
end

#handlerObject (readonly)

Returns the value of attribute handler.



17
18
19
# File 'lib/sitepress/path.rb', line 17

def handler
  @handler
end

#node_nameObject (readonly)

Returns the value of attribute node_name.



17
18
19
# File 'lib/sitepress/path.rb', line 17

def node_name
  @node_name
end

#pathObject (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

Returns:

  • (Boolean)


51
52
53
# File 'lib/sitepress/path.rb', line 51

def exists?
  File.exist? path
end

#expand_pathObject



55
56
57
# File 'lib/sitepress/path.rb', line 55

def expand_path
  File.expand_path path
end

#node_namesObject



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_strObject 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