Created
October 11, 2017 15:09
-
-
Save steventux/3aec03abe7fcc4345f0fd4b2a3f2f800 to your computer and use it in GitHub Desktop.
Gets all links property keys for all frontend schemas (from alphagov/govuk-content-schemas).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Requires alphagov/govuk-content-schemas to be checked out in the same dir as this script. | |
# $ ruby links_by_schema.rb | |
# writes csv output to ./schema-links.csv | |
require 'csv' | |
require 'json' | |
def schema_name_from_file(schema_file) | |
schema_file.split("/")[4] | |
end | |
CSV.open("./schema-links.csv", "w") do |csv| | |
Dir["./govuk-content-schemas/dist/formats/*/frontend/schema.json"].each do |schema_file| | |
json = File.read(schema_file) | |
hash = JSON.parse(json) | |
schema_name = schema_name_from_file(schema_file) | |
if links = hash["properties"]["links"] | |
csv << [schema_name, links["properties"].keys.join(",")] | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment