Class: JekyllAdmin::Directory

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
Enumerable, APIable, URLable
Defined in:
lib/jekyll-admin/directory.rb

Constant Summary

Constants included from APIable

APIable::API_SCAFFOLD, APIable::CONTENT_FIELDS

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from APIable

#to_api

Methods included from URLable

#api_url, #entries_url

Constructor Details

#initialize(path, base:, splat:, content_type:) ⇒ Directory

Parameters:

path - The full path of the directory at which its entries will be listed.

Named parameters:

        base: - The full path to the directory from source.
       splat: - The requested directory path relative to content namespace.
content_type: - The type of the requested directory entries. Corresponds to
                the resources' API namespace.


27
28
29
30
31
32
# File 'lib/jekyll-admin/directory.rb', line 27

def initialize(path, base:, splat:, content_type:)
  @path  = Pathname.new path
  @base  = Pathname.new base
  @splat = Pathname.new splat
  @content_type = content_type
end

Instance Attribute Details

#baseObject (readonly)

Returns the value of attribute base.



8
9
10
# File 'lib/jekyll-admin/directory.rb', line 8

def base
  @base
end

#content_typeObject (readonly)

Returns the value of attribute content_type.



8
9
10
# File 'lib/jekyll-admin/directory.rb', line 8

def content_type
  @content_type
end

#pathObject (readonly)

Returns the value of attribute path.



8
9
10
# File 'lib/jekyll-admin/directory.rb', line 8

def path
  @path
end

#splatObject (readonly)

Returns the value of attribute splat.



8
9
10
# File 'lib/jekyll-admin/directory.rb', line 8

def splat
  @splat
end

Instance Method Details

#directoriesObject



60
61
62
63
64
65
66
67
68
69
70
# File 'lib/jekyll-admin/directory.rb', line 60

def directories
  path.entries.map do |entry|
    next if DOT_DIRECTORIES.include? entry.to_s
    next unless path.join(entry).directory?

    self.class.new(
      path.join(entry),
      :base => base, :content_type => content_type, :splat => splat
    )
  end.compact!
end

#http_urlObject



56
57
58
# File 'lib/jekyll-admin/directory.rb', line 56

def http_url
  nil
end

#relative_pathObject



43
44
45
# File 'lib/jekyll-admin/directory.rb', line 43

def relative_path
  @relative_path ||= path.relative_path_from(base).to_s
end

#resource_pathObject Also known as: url



47
48
49
50
51
52
53
# File 'lib/jekyll-admin/directory.rb', line 47

def resource_path
  if RESOURCE_TYPES.include?(content_type)
    "/#{content_type}/#{splat}/#{name}"
  else
    "/collections/#{content_type}/entries/#{splat}/#{name}"
  end
end

#to_liquidObject



34
35
36
37
38
39
40
41
# File 'lib/jekyll-admin/directory.rb', line 34

def to_liquid
  {
    "name"          => name,
    "modified_time" => modified_time,
    "path"          => relative_path,
    "type"          => "directory",
  }
end