Skip to content

Instantly share code, notes, and snippets.

@cllns
Created February 26, 2018 04:17
Show Gist options
  • Save cllns/c6d91a5088fe45cd6e2368edbe0bcdfc to your computer and use it in GitHub Desktop.
Save cllns/c6d91a5088fe45cd6e2368edbe0bcdfc to your computer and use it in GitHub Desktop.
Resume builder scripts

Super simple 'server' for rendering HTML from an index.html.erb file, and a data.yml file.

The instance variable to use in the ERB file is just @data. Then you can do things like @data.contact.email.

I just update the file, it's re-generated every second, and I refresh the browser when there's changes I want to see.

Caveats:

  1. If there's a problem with the command, it's just a blank screen, but the terminal will show you what's going on (usually malformed YAML).
  2. Sometimes when refreshing it's blank, I think because it's writing the file the same time you're trying to read it. Refreshing again fixes it.
# Example, can add whatever you want here
name: Sean Collins
contact:
email: sean@cllns.com
experiences:
- employer: Independent Contractor
title: Web Developer
start: January 2014
end: present
bullets:
- 'Work directly with clients to build, update and maintain complex <strong>Ruby on Rails</strong> applications'
#!/usr/bin/env ruby
# A simple command that just converts ERB to html every second
loop do
if system("erb -r ./util index.html.erb > index.html")
puts "Succesfully generated 'index.html' from 'index.html.erb' at #{Time.now}"
end
sleep 1
end
require "yaml"
require "ostruct"
# We use an OpenStruct so we can do dot syntax (methods)
# instead of hash access via strings
def yaml_to_open_struct(file_name)
hash_to_open_struct(YAML.load_file(file_name))
end
# Taken from http://www.dribin.org/dave/blog/archives/2006/11/17/hashes_to_ostruct/
# and renamed
def hash_to_open_struct(object)
case object
when Hash
object = object.clone
object.each do |key, value|
object[key] = hash_to_open_struct(value)
end
OpenStruct.new(object)
when Array
object = object.clone
object.map! { |i| hash_to_open_struct(i) }
else
object
end
end
@data = yaml_to_open_struct("data.yml")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment