Sha256: 17e5c61ced370af06da78560a82a3d921ba8dbf493d6d2ae4578bf6f6646e36b
Contents?: true
Size: 752 Bytes
Versions: 5
Compression:
Stored size: 752 Bytes
Contents
#!/usr/bin/env ruby if ARGV[0].nil? puts "Usage: #{$PROGRAM_NAME} file.md" exit end File.open(ARGV[0]) do |f| title = nil setup = "" example = "" f.each_line do |line| case line when /^#+ *(.*)/ new_title = Regexp.last_match(1) # write previous example unless example.empty? basename = title.downcase.gsub(/ +/, "_") if basename == "setting_up" setup = example else File.open("#{basename}.rb", "w") do |e| e.write setup e.write example e.chmod(0o755) end end end # set new title = new_title example = "" when /^ (.*)/ example << Regexp.last_match(1) << "\n" end end end
Version data entries
5 entries across 5 versions & 1 rubygems