Skip to content

Instantly share code, notes, and snippets.

@emad-elsaid
Created December 6, 2018 12:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save emad-elsaid/be9247be050eeb572c9242d6a59ec0a8 to your computer and use it in GitHub Desktop.
Save emad-elsaid/be9247be050eeb572c9242d6a59ec0a8 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
require 'erb'
require 'tmpdir'
require 'digest'
argv_hash = Digest::MD5.hexdigest(Dir.pwd + ARGV.join)
file = ARGV.shift
if file.nil? || file.empty? || file == '--help'
puts 'Usage: erbview FILE'
exit
end
content = File.read(file)
content = content.lines[1..-1].join
output = ERB.new(content).result
temp = Dir.tmpdir
path = File.join(temp, argv_hash + '.html')
File.write(path, output)
`google-chrome-stable --app=file://#{path}`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment