_plugins/page_generator.rb
# Read and parse the JSON file under the data directory
# +filename+ is the String name of the file to be read
Read and parse the JSON file under the data directory
+filename+ is the String name of the file to be read
Read and parse the JSON file under the data directory + filename + is the String name of the file to be read
def read_data_object( filename )
      data_dir = self.config['data_dir'] || '_data'
      data_path = File.join(self.config['source'], data_dir)
      if File.symlink?(data_path)
        return "Data directory '#{data_path}' cannot be a symlink"
      end
      file = File.join(data_path, filename)
      return "File #{file} could not be found" if !File.exists?( file )
      result = nil
      Dir.chdir(data_path) do
        rows = []
        CSV.foreach(filename, headers: true, col_sep: ',') do |row|
          rows << row.to_hash
        end
        result = rows
      end
      puts "## Error: No data in #{file}" if result.nil?
      result = JSON.parse( result.to_json ) if result
      { 'data' => result,
        'mtime' => File.mtime(file) }
    end
def read_data_object ( filename ) data_dir = self . config [ 'data_dir' ] || '_data' data_path = File . join ( self . config [ 'source' ] , data_dir ) if File . symlink? ( data_path ) return "Data directory '#{data_path}' cannot be a symlink" end file = File . join ( data_path , filename ) return "File #{file} could not be found" if ! File . exists? ( file ) result = nil Dir . chdir ( data_path ) do rows = [ ] CSV . foreach ( filename , headers : true , col_sep : ',' ) do | row | rows << row . to_hash end result = rows end puts "## Error: No data in #{file}" if result . nil? result = JSON . parse ( result . to_json ) if result { 'data' => result , 'mtime' => File . mtime ( file ) } end
Read and parse the JSON file under the data directory
+filename+ is the String name of the file to be read
Read and parse the JSON file under the data directory + filename + is the String name of the file to be read
filename
<not_specific>