-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extract seeding of ColorSchemes, add to db seed
- Loading branch information
Showing
3 changed files
with
39 additions
and
26 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
class ColorSchemes::Seed | ||
def seed_all | ||
seed_1500 | ||
seed_ui | ||
end | ||
|
||
def seed_ui | ||
hex_json_uicolors = JSON.parse(File.read("./script/colors/data/uicolors-palette-hex.json")) | ||
hex_json_uicolors.each do |name, weights| | ||
custom_name = "Custom #{name.titleize}" | ||
ColorScheme.find_or_create_by!(name: custom_name) do |cs| | ||
weights.each do |weight, css| | ||
cs.set_weight(weight, css) | ||
end | ||
end | ||
end | ||
end | ||
|
||
def seed_1500 | ||
# Generate ColorScheme rows from precalcated JSON | ||
# "hex json" files are expected to represent JSON objects of color scales: { name: { weight: color, ... }, ... | ||
|
||
if !File.exist?("./script/colors/tmp/1500-palette-hex.json") | ||
puts "Run `rake color_schemes:generate_1500` first to generate 1500-palette-hex.json" | ||
exit | ||
end | ||
|
||
hex_json_1500 = JSON.parse(File.read("./script/colors/tmp/1500-palette-hex.json")) | ||
hex_json_1500.each do |name, weights| | ||
ColorScheme.find_or_create_by!(name: name) do |cs| | ||
weights.each do |weight, css| | ||
cs.set_weight(weight, css) | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains 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
This file contains 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