class JekyllAdmin::DataFile
Constants
- EXTENSIONS
- METHODS_FOR_LIQUID
Attributes
ext[R]
extension[R]
id[R]
relative_path[R]
Public Class Methods
all()
click to toggle source
# File lib/jekyll-admin/data_file.rb, line 73 def self.all data_dir = Jekyll.sanitized_path(JekyllAdmin.site.source, DataFile.data_dir) data_dir = Pathname.new(data_dir) Dir["#{data_dir}/**/*.{#{EXTENSIONS.join(",")}}"].map do |path| new(Pathname.new(path).relative_path_from(data_dir).to_s) end end
data_dir()
click to toggle source
Relative path to data directory within site source
# File lib/jekyll-admin/data_file.rb, line 82 def self.data_dir JekyllAdmin.site.config["data_dir"] end
new(id)
click to toggle source
Initialize a new DataFile
object
id - the file ID as passed from the API. This may or may not have an extension
# File lib/jekyll-admin/data_file.rb, line 18 def initialize(id) extname = File.extname(id) if extname.empty? @id = "#{id}.yml" @ext = ".yml" else @id = id @ext = extname end end
Public Instance Methods
absolute_path()
click to toggle source
# File lib/jekyll-admin/data_file.rb, line 62 def absolute_path sanitized_path(path) end
Also aliased as: file_path
content()
click to toggle source
Returnes (re)parsed content using Jekyll's native parsing mechanism
# File lib/jekyll-admin/data_file.rb, line 43 def content @content ||= data_reader.read_data_file(absolute_path) end
exists?()
click to toggle source
# File lib/jekyll-admin/data_file.rb, line 33 def exists? @exists ||= File.exist?(absolute_path) end
path()
click to toggle source
Returns path relative to site source
# File lib/jekyll-admin/data_file.rb, line 58 def path @path ||= File.join(DataFile.data_dir, relative_path) end
raw_content()
click to toggle source
Returns unparsed content as it exists on disk
# File lib/jekyll-admin/data_file.rb, line 38 def raw_content @raw_content ||= File.open(absolute_path, "r:UTF-8", &:read) end
slug()
click to toggle source
Returns the file's sanitized slug (as used in `site.data`)
# File lib/jekyll-admin/data_file.rb, line 48 def slug @slug ||= data_reader.sanitize_filename(basename) end
title()
click to toggle source
Returns the human-readable title of the data file
# File lib/jekyll-admin/data_file.rb, line 53 def title @title ||= Jekyll::Utils.titleize_slug(slug.tr("_", "-")) end
to_liquid()
click to toggle source
Mimics Jekyll's native to_liquid
functionality by returning a hash of data file metadata
# File lib/jekyll-admin/data_file.rb, line 69 def to_liquid @to_liquid ||= METHODS_FOR_LIQUID.map { |key| [key, public_send(key)] }.to_h end
Private Instance Methods
basename()
click to toggle source
# File lib/jekyll-admin/data_file.rb, line 92 def basename @basename ||= File.basename(id, ".*") end
basename_with_extension()
click to toggle source
# File lib/jekyll-admin/data_file.rb, line 96 def basename_with_extension "#{basename}#{extension}" end
Also aliased as: name
data_reader()
click to toggle source
# File lib/jekyll-admin/data_file.rb, line 88 def data_reader @data_reader = Jekyll::DataReader.new(JekyllAdmin.site) end
namespace()
click to toggle source
# File lib/jekyll-admin/data_file.rb, line 102 def namespace "data" end