# File 'lib/jekyll/readers/data_reader.rb', line 4definitialize(site)@site=site@content={}end
Instance Attribute Details
#content ⇒ Object(readonly)
Returns the value of attribute content.
3
4
5
# File 'lib/jekyll/readers/data_reader.rb', line 3defcontent@contentend
#site ⇒ Object(readonly)
Returns the value of attribute site.
3
4
5
# File 'lib/jekyll/readers/data_reader.rb', line 3defsite@siteend
Instance Method Details
#read(dir) ⇒ Object
Read all the files in //_drafts and create a new Draft
object with each one.
dir - The String relative path of the directory to read.
Returns nothing.
15
16
17
18
19
# File 'lib/jekyll/readers/data_reader.rb', line 15defread(dir)base=site.in_source_dir(dir)read_data_to(base,@content)@contentend
#read_data_file(path) ⇒ Object
Determines how to read a data file.
Returns the contents of the data file.
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/jekyll/readers/data_reader.rb', line 51defread_data_file(path)caseFile.extname(path).downcasewhen'.csv'CSV.read(path,{:headers=>true,:encoding=>site.config['encoding']}).map(&:to_hash)elseSafeYAML.load_file(path)endend
#read_data_to(dir, data) ⇒ Object
Read and parse all yaml files under
and add them to the
variable.
dir - The string absolute path of the directory to read.
data - The variable to which data will be added.
# File 'lib/jekyll/readers/data_reader.rb', line 28defread_data_to(dir,data)returnunlessFile.directory?(dir)&&(!site.safe||!File.symlink?(dir))entries=Dir.chdir(dir)doDir['*.{yaml,yml,json,csv}']+Dir['*'].select{|fn|File.directory?(fn)}endentries.eachdo|entry|path=@site.in_source_dir(dir,entry)nextifFile.symlink?(path)&&site.safekey=sanitize_filename(File.basename(entry,'.*'))ifFile.directory?(path)read_data_to(path,data[key]={})elsedata[key]=read_data_file(path)endendend
#sanitize_filename(name) ⇒ Object
63
64
65
66
67
# File 'lib/jekyll/readers/data_reader.rb', line 63defsanitize_filename(name)name.gsub!(/[^\w\s-]+/,'')name.gsub!(/(^|\b\s)\s+($|\s?\b)/,'\\1\\2')name.gsub(/\s+/,'_')end