Skip to content

Commit

Permalink
tidy vars
Browse files Browse the repository at this point in the history
  • Loading branch information
mnyrop committed May 27, 2022
1 parent 18d8c2f commit 5174d73
Show file tree
Hide file tree
Showing 15 changed files with 101 additions and 41 deletions.
8 changes: 4 additions & 4 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require 'rainbow'
require 'yaml'

@config = File.file?('_config.yml') ? YAML.load_file('_config.yml') : {}
@secrets = File.file?('.secrets.yml') ? YAML.load_file('.secrets.yml') : {}
@data_dir = ['.', @config.dig('source'), '_data'].compact.join('/')
@baseurl = ENV['BASEURL'] || @config.dig('baseurl')
$config = File.file?('_config.yml') ? YAML.load_file('_config.yml') : {}
$secrets = File.file?('.secrets.yml') ? YAML.load_file('.secrets.yml') : {}
$data_dir = ['.', $config.dig('source'), '_data'].compact.join('/')
$baseurl = ENV['BASEURL'] || $config.dig('baseurl')

Dir.glob("#{lib}/tasks/**/*.rake").each { |r| load r }
5 changes: 5 additions & 0 deletions lib/linters/courses.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module Linters
module Courses

end
end
Empty file added lib/linters/default.rb
Empty file.
5 changes: 5 additions & 0 deletions lib/linters/people.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module Linters
module People

end
end
5 changes: 5 additions & 0 deletions lib/linters/projects.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module Linters
module Projects

end
end
2 changes: 1 addition & 1 deletion lib/parsers/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def self.split_semicolon_string(string)

def self.split_arrays(data, keys)
data.map do |hash|
keys.each { |k| hash[k] = split_semicolon_string(hash[k]) if hash.has_key?(k) }
keys.each { |k| hash[k] = split_semicolon_string(hash[k]) if hash.has_key?(k) }
hash
end
end
Expand Down
15 changes: 6 additions & 9 deletions lib/tasks/fetch/courses.rake
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,20 @@ require 'rainbow'
require 'parsers/courses'
require 'parsers/default'
require 'utils'
require 'vars'

namespace :fetch do
desc 'fetch courses sheet from google drive as csv'
task :courses do
sheet_key = ENV['COURSES_SHEET_KEY'] || @secrets.dig('COURSES_SHEET_KEY')
csv_file = "#{@data_dir}/.tmp/courses.csv"
yml_file = "#{@data_dir}/courses.yml"

next puts Rainbow("No courses sheet key found. Is .secrets.yml present?").magenta if sheet_key.nil?
next puts Rainbow("No courses sheet key found. Is .secrets.yml present?").magenta if Vars::Courses.sheet_key.nil?

puts "Fetching courses from Google Drive" unless ENV['SKIP_WGET']
Utils.wget_sheet(sheet_key, csv_file) unless ENV['SKIP_WGET']
Utils.wget_sheet(Vars::Courses.sheet_key, Vars::Courses.csv_file) unless ENV['SKIP_WGET']

data = Utils.csv_open(csv_file)
data = Utils.csv_open(Vars::Courses.csv_file)
data = Parsers::Default.parse data

puts "Parsing courses into #{yml_file}"
Utils.write_to_file(data.to_yaml, yml_file)
puts "Parsing courses into #{Vars::Courses.yml_file}"
Utils.write_to_file(data.to_yaml, Vars::Courses.yml_file)
end
end
18 changes: 7 additions & 11 deletions lib/tasks/fetch/people.rake
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,22 @@ require 'rainbow'
require 'parsers/default'
require 'parsers/people'
require 'utils'
require 'vars'

namespace :fetch do
desc 'fetch people sheet from google drive as csv'
task :people do
sheet_key = ENV['PEOPLE_SHEET_KEY'] || @secrets.dig('PEOPLE_SHEET_KEY')
csv_file = "#{@data_dir}/.tmp/people.csv"
yml_file = "#{@data_dir}/people.yml"
array_keys = %w(site_roles)

next puts Rainbow("No people sheet key found. Is .secrets.yml present?").magenta if sheet_key.nil?
next puts Rainbow("No people sheet key found. Is .secrets.yml present?").magenta if Vars::People.sheet_key.nil?

puts "Fetching people from Google Drive" unless ENV['SKIP_WGET']
Utils.wget_sheet(sheet_key, csv_file) unless ENV['SKIP_WGET']
Utils.wget_sheet(Vars::People.sheet_key, Vars::People.csv_file) unless ENV['SKIP_WGET']

data = Utils.csv_open csv_file
data = Parsers::Default.parse data, array_keys
data = Utils.csv_open Vars::People.csv_file
data = Parsers::Default.parse data, array_keys=%w(site_roles)
data = Parsers::People.parse data

puts "Parsing people into #{yml_file}"
Utils.write_to_file(data.to_yaml, yml_file)
puts "Parsing people into #{Vars::People.yml_file}"
Utils.write_to_file data.to_yaml, Vars::People.yml_file

puts Rainbow("Done ✓").green
end
Expand Down
24 changes: 9 additions & 15 deletions lib/tasks/fetch/projects.rake
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,26 @@ require 'rainbow'
require 'parsers/default'
require 'parsers/projects'
require 'utils'

require 'vars'

namespace :fetch do
desc 'fetch projects sheet from google drive as csv'
task :projects do
sheet_key = ENV['PROJECTS_SHEET_KEY'] || @secrets.dig('PROJECTS_SHEET_KEY')
csv_file = "#{@data_dir}/.tmp/projects.csv"
yml_file = "#{@data_dir}/projects.yml"
tags_file = "#{@data_dir}/project_tags.yml"
array_keys = %w(pis tags)

next puts Rainbow("No projects sheet key found. Is .secrets.yml present?").magenta if sheet_key.nil?
next puts Rainbow("No projects sheet key found. Is .secrets.yml present?").magenta if Vars::Projects.sheet_key.nil?

puts "Fetching projects from Google Drive" unless ENV['SKIP_WGET']
Utils.wget_sheet(sheet_key, csv_file) unless ENV['SKIP_WGET']
Utils.wget_sheet(Vars::Projects.sheet_key, Vars::Projects.csv_file) unless ENV['SKIP_WGET']

data = Utils.csv_open csv_file
data = Parsers::Default.parse data, array_keys
data = Utils.csv_open Vars::Projects.csv_file
data = Parsers::Default.parse data, array_keys=%w(pis tags)
data = Parsers::Projects.parse data
tags = Parsers::Projects.pull_tags data

puts "Parsing project tags into #{tags_file}"
Utils.write_to_file(tags.to_yaml, tags_file)
puts "Parsing project tags into #{Vars::Projects.tags_file}"
Utils.write_to_file(tags.to_yaml, Vars::Projects.tags_file)

puts "Parsing projects into #{yml_file}"
Utils.write_to_file(data.to_yaml, yml_file)
puts "Parsing projects into #{Vars::Projects.yml_file}"
Utils.write_to_file(data.to_yaml, Vars::Projects.yml_file)

sh "bundle exec jekyll pagemaster projects --force"
sh "bundle exec jekyll pagemaster project_tags --force"
Expand Down
6 changes: 6 additions & 0 deletions lib/tasks/lint/all.rake
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace :lint do
desc 'lint all the fetched yaml data'
task :all do
puts 'here'
end
end
Empty file added lib/tasks/lint/courses.rake
Empty file.
Empty file added lib/tasks/lint/people.rake
Empty file.
Empty file added lib/tasks/lint/projects.rake
Empty file.
50 changes: 50 additions & 0 deletions lib/vars.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
module Vars
module Courses
#
def self.sheet_key
ENV['COURSES_SHEET_KEY'] || $secrets.dig('COURSES_SHEET_KEY')
end
#
def self.csv_file
"#{$data_dir}/.tmp/courses.csv"
end
#
def self.yml_file
"#{$data_dir}/courses.yml"
end
end

module People
#
def self.sheet_key
ENV['PEOPLE_SHEET_KEY'] || $secrets.dig('PEOPLE_SHEET_KEY')
end
#
def self.csv_file
"#{$data_dir}/.tmp/people.csv"
end
#
def self.yml_file
"#{$data_dir}/people.yml"
end
end

module Projects
#
def self.sheet_key
ENV['PROJECTS_SHEET_KEY'] || $secrets.dig('PROJECTS_SHEET_KEY')
end
#
def self.csv_file
"#{$data_dir}/.tmp/projects.csv"
end
#
def self.yml_file
"#{$data_dir}/projects.yml"
end
#
def self.tags_file
"#{$data_dir}/project_tags.yml"
end
end
end
4 changes: 3 additions & 1 deletion source/_data/people.yml
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,9 @@
- pid: stec
done: true
name: Helen Frances Stec
titles: Graduate Student in Cinema Studies
titles: 'Graduate student in Experimental Humanities
'
site_roles:
- fellow
order: '034'
Expand Down

0 comments on commit 5174d73

Please sign in to comment.