-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathexamples.runfile
More file actions
70 lines (58 loc) · 1.67 KB
/
examples.runfile
File metadata and controls
70 lines (58 loc) · 1.67 KB
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
require 'filewatcher'
summary "Generate examples"
usage 'watch [--dev]'
help 'Watch example files and rerun them on change'
option '--dev', 'Watch the dev folder instead of the examples folder'
action :watch do |args|
folder = args['--dev'] ? 'dev' : 'examples'
glob = "#{folder}/*.rb"
say "g`watch`: #{glob}"
Filewatcher.new(glob).watch do |files|
files.each do |filename, event|
say "g`#{event}`: #{filename}"
next if event == :delete
Dir.chdir folder do
filename = File.basename filename
say "g`write`: #{filename}"
system "ruby #{filename}"
end
end
end
end
help 'Regenerate all SVG examples'
action :build do
File.delete *Dir['examples/*.svg']
Dir.chdir 'examples' do
Dir['*.rb'].each do |filename|
say "g`write`: #{filename}"
system "ruby #{filename}"
end
end
end
help "Generate readme for examples folder"
action :readme do
result = ["# Examples\n"]
Dir['examples/*.rb'].each do |file|
basename = File.basename file, '.rb'
next if basename == "vertical_status_leds"
say "g`read`: #{file}"
title = basename.tr '_', ' '
code = File.read(file).strip
if File.exist? "examples/#{basename}.svg"
image = "[](#{file}.svg)"
else
image = false
end
result.push "## #{title}\n"
result.push "```ruby"
result.push code
result.push "```\n"
result.push image if image
result.push "\n"
end
result.push "\n---\n"
result.push "This file was generated automatically with `run examples readme`."
result = result.join "\n"
File.write 'examples/README.md', result
say 'g`write`: examples/README.md'
end