Class: JekyllAdmin::Directory
- Inherits:
-
Object
- Object
- JekyllAdmin::Directory
- Extended by:
- Forwardable
- Defined in:
- lib/jekyll-admin/directory.rb
Constant Summary collapse
- TYPE =
:directory
Constants included from APIable
Instance Attribute Summary collapse
-
#base ⇒ Object
readonly
Returns the value of attribute base.
-
#content_type ⇒ Object
readonly
Returns the value of attribute content_type.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#splat ⇒ Object
readonly
Returns the value of attribute splat.
Instance Method Summary collapse
- #directories ⇒ Object
- #http_url ⇒ Object
-
#initialize(path, base: nil, content_type: nil, splat: nil) ⇒ Directory
constructor
Arguments:.
- #relative_path ⇒ Object
- #resource_path ⇒ Object (also: #url)
- #to_liquid ⇒ Object
Methods included from APIable
Methods included from URLable
Constructor Details
#initialize(path, base: nil, content_type: nil, splat: nil) ⇒ Directory
Arguments:
path - full path of the directory which its entries will be listed
base - passes site.source to generate ‘relative_path` needed for `to_api`
content_type - type of the requested directory entries, this is used to generate API endpoint of the directory along with ‘splat`
splat - the requested directory path relative to content namespace
24 25 26 27 28 29 |
# File 'lib/jekyll-admin/directory.rb', line 24 def initialize(path, base: nil, content_type: nil, splat: nil) @base = Pathname.new base @content_type = content_type @splat = Pathname.new splat @path = Pathname.new path end |
Instance Attribute Details
#base ⇒ Object (readonly)
Returns the value of attribute base.
6 7 8 |
# File 'lib/jekyll-admin/directory.rb', line 6 def base @base end |
#content_type ⇒ Object (readonly)
Returns the value of attribute content_type.
6 7 8 |
# File 'lib/jekyll-admin/directory.rb', line 6 def content_type @content_type end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
6 7 8 |
# File 'lib/jekyll-admin/directory.rb', line 6 def path @path end |
#splat ⇒ Object (readonly)
Returns the value of attribute splat.
6 7 8 |
# File 'lib/jekyll-admin/directory.rb', line 6 def splat @splat end |
Instance Method Details
#directories ⇒ Object
62 63 64 65 66 67 68 69 70 71 |
# File 'lib/jekyll-admin/directory.rb', line 62 def directories path.entries.map do |entry| next if [".", ".."].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_url ⇒ Object
58 59 60 |
# File 'lib/jekyll-admin/directory.rb', line 58 def http_url nil end |
#relative_path ⇒ Object
40 41 42 43 44 45 46 |
# File 'lib/jekyll-admin/directory.rb', line 40 def relative_path if content_type == "drafts" path.relative_path_from(base).to_s.sub("_drafts/", "") else path.relative_path_from(base).to_s end end |
#resource_path ⇒ Object Also known as: url
48 49 50 51 52 53 54 55 |
# File 'lib/jekyll-admin/directory.rb', line 48 def resource_path types = %w(pages data drafts static_files templates theme) if types.include?(content_type) "/#{content_type}/#{splat}/#{name}" else "/collections/#{content_type}/entries/#{splat}/#{name}" end end |
#to_liquid ⇒ Object
31 32 33 34 35 36 37 38 |
# File 'lib/jekyll-admin/directory.rb', line 31 def to_liquid { :name => name, :modified_time => modified_time, :path => relative_path, :type => TYPE, } end |