forked from franzejr/best-ruby
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rakefile
70 lines (54 loc) · 1.83 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
68
69
70
desc "Build README.md from source files"
task :build do
toc = []
tricks = []
File.open("README.md", "w+") do |readme|
Dir.glob("*.rb").sort.each do |file|
filename = File.basename file
heading = File.basename(file, ".rb").tr("_", " ").capitalize
link = heading.tr(" ", "-").downcase
content = File.read file
# Add link to table on contents
toc << "[#{heading}](##{link})"
# Add trick file contents to array of tricks
tricks << %{### #{heading}
```ruby
#{content}
```
[View Source](#{filename})
}
end
# Render intro
readme.puts %{# Ruby Tricks
[![Join the chat at https://gitter.im/franzejr/ruby-tricks](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/franzejr/ruby-tricks?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
The majority of these Ruby Tricks were extracted from James Edward Gray II [talk](https://www.youtube.com/watch?v=aBgnlBoIkVM).
If you know some other tricks, please contribute!
}
# Render table of contents
readme.puts "## Table of Contents"
readme.puts "\n"
toc.each do |link|
readme.puts "- #{link}"
end
readme.puts "\n"
# Render tricks
readme.puts "## Tricks"
readme.puts "\n"
tricks.each do |trick|
readme.puts trick
end
# Render contributors
readme.puts File.read "CONTRIBUTORS.md"
readme.puts "\n"
# Render contributing instructions
readme.puts %{## Contributing
1. Fork it
1. Create your trick branch: `git checkout -b my-ruby-trick`
1. Add your trick to the collection of `.rb` files
1. Regenerate `README.md`: `rake build` (install Rake with `bundle`)
1. Commit your changes: `git commit -am 'Add trick'`
1. Push to the branch: `git push origin my-new-trick`
1. Create new Pull Request and explain why your code is trick
}
end
end