Skip to content

Commit

Permalink
Merge pull request #3621 from DFE-Digital/improve-internship-generati…
Browse files Browse the repository at this point in the history
…on-process

Create new rake task that utilizes an ERB file to generate the teaching internship providers page and update the documentation
  • Loading branch information
StackedPancakez authored Oct 23, 2023
2 parents cebc727 + f12dfff commit 88622c9
Show file tree
Hide file tree
Showing 7 changed files with 811 additions and 645 deletions.
1,246 changes: 624 additions & 622 deletions app/views/content/is-teaching-right-for-me/teaching-internship-providers.md

Large diffs are not rendered by default.

16 changes: 10 additions & 6 deletions docs/content.md
Original file line number Diff line number Diff line change
Expand Up @@ -431,10 +431,14 @@ Check your filename only contains lower case characters, numbers and underscores
## Internship providers
Occasionally we are sent a new spreadsheet to update the list of internship providers on the `teaching-internship-providers.md` page. We have a rake task to make this easy to do:
#### Warning! Do not edit the `teaching-internship-providers.md` page directly.
- Export the XLSX to CSV
- Rename it `internship_providers.csv` and place it in the root application directory
- Run `bundle exec rake csv_to_yaml:internship_providers`
- Overwrite the regions in `teaching-internship-providers.md` with the output of the task
- Delete the `internship_providers.csv` file as you don't need to commit it
Unlike the other content pages the internship providers page is a fully generated page.
This is because occasionally we are sent a new spreadsheet to update the list of internship providers on the `teaching-internship-providers.md` page and the numbers can be large, and need to be grouped by provider region and sorted, which would be a large and time consuming manual task. We have a rake task to make this easy to do, but this means it should not be edited directly. Instead any changes to content for the page should be made to the `lib/tasks/support/teaching-internship-providers.md.erb` file and then the page should be regenerated:
- Run `bundle exec rake teaching_internship_providers:generate` in your terminal.
When updating not just the text content within the file, but the actual list of providers (which will be provided as an XLSX file), you will need to update the CSV file that the rake task uses to generate the page. To do this:
- Export the XLSX to CSV with filename `internship_providers.csv`
- Place it in the `lib/tasks/support` directory.
- Run `bundle exec rake teaching_internship_providers:generate`.
2 changes: 1 addition & 1 deletion lib/internship_provider.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ def initialize(data)
@data = data

data.tap do |d|
@school_name = d["school_name"]
@school_name = d[0] # TODO: Currently errors if this is string key. Investigate and fix.
@region = d["region"]
@school_website = d["school_website"]
@contact_name = d["contact_name"]
Expand Down
16 changes: 0 additions & 16 deletions lib/tasks/csv_to_yaml.rake
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,6 @@ require "agency"

desc "CSV to Yaml import"
namespace :csv_to_yaml do
desc "Convert internship providers CSV to Yaml"
task internship_providers: :environment do
csv = CSV.read("internship_providers.csv", headers: true)

providers = csv.each.with_object({}) do |r, h|
ip = InternshipProvider.new(r)
h[ip.region.to_s] ||= {}
h[ip.region.to_s]["providers"] ||= []
h[ip.region.to_s]["providers"] << ip.to_h
end

providers.transform_values! { |v| { "providers" => v["providers"].sort_by { |a| a["header"] } } }

puts providers.sort.to_h.to_yaml
end

desc "Convert agencies CSV to Yaml"
task agencies: :environment do
csv = CSV.read("agencies.csv", headers: true)
Expand Down
24 changes: 24 additions & 0 deletions lib/tasks/generate_teaching_internship_providers.rake
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
require "csv"
require "yaml"
require "internship_provider"

namespace :teaching_internship_providers do
desc "Generate the teaching internship providers page"
task generate: :environment do
csv = CSV.read("lib/tasks/support/internship_providers.csv", headers: true)

providers = csv.each.with_object({}) do |r, h|
ip = InternshipProvider.new(r)
h[ip.region.to_s] ||= {}
h[ip.region.to_s]["providers"] ||= []
h[ip.region.to_s]["providers"] << ip.to_h
end

providers.transform_values! { |v| v["providers"].sort_by { |a| a["header"] } }
provider_groups = providers.sort

File.open("app/views/content/is-teaching-right-for-me/teaching-internship-providers.md", "w") do |f|
f.write ERB.new(File.read("lib/tasks/support/teaching-internship-providers.md.erb"), trim_mode: "<>").result(binding)
end
end
end
Loading

0 comments on commit 88622c9

Please sign in to comment.