forked from rubyburgers/rubyburgers.github.com
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rakefile
67 lines (55 loc) · 1.42 KB
/
Rakefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
desc "compile and run the site"
task :default do
pids = [
spawn("jekyll"),
spawn("scss --watch assets:stylesheets"),
]
trap "INT" do
Process.kill "INT", *pids
exit 1
end
loop do
sleep 1
end
end
desc "Generate a page for your city!"
task :city do
unless name = ENV["NAME"]
abort "Usage: rake city NAME='YOUR_CITY_NAME, COUNTRY' [ADDRESS='number street city state zip']"
end
require 'fileutils'
require 'yaml'
require 'geocoder'
# 'Banana City' => 'banana_city'
# 'Banana City, NY' => 'banana_city'
directory = name.split(',')[0].downcase.gsub(/\s+/, '_')
FileUtils.mkdir_p(directory)
File.open(File.join(directory, "index.markdown"), "w") do |file|
file.write <<-EOF
---
layout: default
title: RubyBurgers - #{name}
---
## #{name}
![Photo of your meetup or city!](/#{directory}/FILL_ME_IN.png)
### Info
Put some info about when and where your meetup is here.
EOF
if ENV["ADDRESS"]
results = Geocoder.search(ENV["ADDRESS"])
else
results = Geocoder.search(name)
end
config = YAML.load_file("_config.yml")
cities = config["cities"]
cities << {directory => {
"name" => name,
"latitude" => results.first.latitude,
"longitude" => results.first.longitude
}}
config["cities"] = cities.map(&:to_a).sort.map { |city| Hash[city] }
File.open("_config.yml", "w") do |file|
file.write config.to_yaml
end
end
end