Skip to content

Commit 6c06660

Browse files
committed
Add rake task for generate profiles
1 parent 8305cf3 commit 6c06660

File tree

2 files changed

+57
-0
lines changed

2 files changed

+57
-0
lines changed

Rakefile

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,37 @@ PadrinoTasks.init
55

66
desc 'Run tests for all'
77
task :default => :spec
8+
9+
desc 'Generate profile files of kaja'
10+
task :generate_profiles => :environment do
11+
require 'csv'
12+
source_file = Padrino.root('tmp', 'source.csv')
13+
abort "#{source_file} is not found." unless File.exist?(source_file)
14+
15+
headers = %w[
16+
timestamp
17+
community
18+
email
19+
judged_by
20+
dummy
21+
comment
22+
name
23+
contact
24+
profile
25+
reason_for
26+
github
27+
twitter
28+
image
29+
supplement
30+
]
31+
csv_table = CSV.table(source_file, headers: headers, write_headers: true)
32+
csv_table.each_with_index do |profile, index|
33+
next if index == 0
34+
35+
template = File.read(Padrino.root('data', 'template.yaml.erb'))
36+
erb = ERB.new(template)
37+
38+
File.write(Padrino.root('data', '2014', "#{profile[:github]}.yaml"), erb.result(binding))
39+
end
40+
41+
end

data/template.yaml.erb

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
name:
2+
<%= profile[:name] %>
3+
github:
4+
<%= profile[:github] %>
5+
twitter:
6+
<%= profile[:twitter] %>
7+
image:
8+
<%= profile[:github] %>
9+
profile: |-
10+
"<%= profile[:profile] %>"
11+
supplement: |-
12+
"<%= profile[:supplement] %>"
13+
community:
14+
<%= profile[:community] %>
15+
description: |-
16+
"<%= profile[''] %>"
17+
judged_by: |-
18+
"<%= profile[:judged_by] %>"
19+
reason_for: |-
20+
"<%= profile[:reason_for] %>"
21+
comment: |-
22+
"<%= profile[:comment] %>"
23+

0 commit comments

Comments
 (0)