@@ -63,8 +63,10 @@ namespace :add do
63
63
category_file = File . join ( __dir__ , '_data/sections.yml' )
64
64
categories = SafeYAML . load_file ( category_file )
65
65
new_section = { }
66
- %w[ id title icon page ] . each do |tag |
67
- new_section [ tag ] = value_prompt ( tag )
66
+ tags = tags_from_schema ( 'sections_schema.yml' , 'category' )
67
+ tags [ 'mapping' ] . each do |tag |
68
+ data = prompt_tag ( tag [ 0 ] , tag [ 1 ] )
69
+ new_section [ tag [ 0 ] ] = data unless data . nil?
68
70
end
69
71
if valid_to_ins ( categories , new_section , 'id' )
70
72
categories [ categories . count ] = new_section
@@ -94,7 +96,8 @@ namespace :add do
94
96
listing = { }
95
97
site = { }
96
98
section_file = prompt_category
97
- tags_from_schema [ 'mapping' ] . each do |index |
99
+ tags = tags_from_schema ( 'websites_schema.yml' , 'site' )
100
+ tags [ 'mapping' ] . each do |index |
98
101
data = prompt_tag ( index [ 0 ] , index [ 1 ] )
99
102
site [ index [ 0 ] ] = data unless data . nil?
100
103
end
@@ -189,10 +192,10 @@ namespace :add do
189
192
end
190
193
# rubocop:enable Semicolon
191
194
192
- def tags_from_schema
193
- schema = YAML . load_file ( File . join ( __dir__ , 'websites_schema.yml' ) )
195
+ def tags_from_schema ( schema_file , class_name )
196
+ schema = YAML . load_file ( File . join ( __dir__ , schema_file ) )
194
197
Kwalify ::Util . traverse_schema ( schema ) do |rule |
195
- return rule if rule [ 'name ' ] == 'Website'
198
+ return rule if rule [ 'class ' ] == class_name
196
199
end
197
200
end
198
201
0 commit comments