Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
WIP - things looking good now
  • Loading branch information
Abhishek Yadav committed Dec 22, 2010
1 parent ac09faa commit e81d56f
Show file tree
Hide file tree
Showing 65 changed files with 11,256 additions and 45 deletions.
14 changes: 7 additions & 7 deletions .gitignore
@@ -1,14 +1,14 @@
#ignore the log files
rc3/log/*
log/*

#ignore the tmp files
rc3/tmp/**/*

#ignore the user_data files
data/*
tmp/**/*

#ignore the database.yml file so that passwords are not exposed on github
rc3/config/database.yml
config/database.yml

# ignore the sqlite databases -
rc3/rc/db/*.sqlite3
db/*.sqlite3

# ignore the data folder - contains random data
data/*
2 changes: 2 additions & 0 deletions Gemfile
Expand Up @@ -12,6 +12,8 @@ gem 'mysql2', :require => 'mysql2'
gem 'kramdown', :require => 'kramdown' # MArkdown extensions. Pure ruby. Slow
gem 'pdfkit', :require => 'pdfkit'

gem 'devise'

# Use unicorn as the web server
# gem 'unicorn'

Expand Down
9 changes: 9 additions & 0 deletions Gemfile.lock
Expand Up @@ -30,7 +30,11 @@ GEM
activesupport (3.0.0)
arel (1.0.1)
activesupport (~> 3.0.0)
bcrypt-ruby (2.1.2)
builder (2.1.2)
devise (1.1.3)
bcrypt-ruby (~> 2.1.2)
warden (~> 0.10.7)
erubis (2.6.6)
abstract (>= 1.0.0)
i18n (0.4.1)
Expand All @@ -40,6 +44,7 @@ GEM
mime-types
treetop (>= 1.4.5)
mime-types (1.16)
mysql2 (0.2.4)
pdfkit (0.4.6)
polyglot (0.3.1)
rack (1.2.1)
Expand Down Expand Up @@ -67,13 +72,17 @@ GEM
treetop (1.4.8)
polyglot (>= 0.3.1)
tzinfo (0.3.23)
warden (0.10.7)
rack (>= 1.0.0)

PLATFORMS
ruby
x86-mingw32

DEPENDENCIES
devise
kramdown
mysql2
pdfkit
rails (= 3.0.0)
sqlite3-ruby
16 changes: 16 additions & 0 deletions app/controllers/application_controller.rb
@@ -1,3 +1,19 @@
class ApplicationController < ActionController::Base
protect_from_forgery

def admin
User.find_by_email "admin@rc.com"
end

# Returns the default style object
# Currently set to the first style object
def default_style
Style.find 1
end

# Returns true if the request is a part of a demo - user is unauthenticated
def demo?
true unless user_signed_in?
end
helper_method :demo?
end
17 changes: 17 additions & 0 deletions app/controllers/home_controller.rb
@@ -1,5 +1,22 @@
class HomeController < ApplicationController

layout "demo"
# show the welcome page if user isn't logged in,
# redirect the user to resume index if she is logged in
def index
redirect_to resumes_path if user_signed_in?
# show welcome page - Render home/index.html.erb
end

# create a demo resume for the (existing) admin user,
# and direct him to the resume edit page
def demo
if params[:r].blank?
r = admin.resumes.create(:content => "Copy-paste your resume here", :is_demo => true)
else
r = admin.resumes.find(params[:r])
end
redirect_to edit_resume_path(r)
end

end
46 changes: 33 additions & 13 deletions app/controllers/resumes_controller.rb
@@ -1,8 +1,11 @@
class ResumesController < ApplicationController

before_filter :authenticate_user!, :except => [:html, :pdf, :edit, :update]

# GET /resumes
# GET /resumes.xml
def index
@resumes = Resume.all
@resumes = current_user.resumes.all

respond_to do |format|
format.html # index.html.erb
Expand All @@ -13,7 +16,7 @@ def index
# GET /resumes/1
# GET /resumes/1.xml
def show
@resume = Resume.find(params[:id])
@resume = current_user.resume.find(params[:id])

respond_to do |format|
format.html # show.html.erb
Expand All @@ -24,7 +27,7 @@ def show
# GET /resumes/new
# GET /resumes/new.xml
def new
@resume = Resume.new
@resume = current_user.resume.new

respond_to do |format|
format.html # new.html.erb
Expand All @@ -33,14 +36,20 @@ def new
end

# GET /resumes/1/edit
# This method is open for unauthenticated users also,
# only demo resumes can be accessed/edited without authentication
# This is slightly insecure as one demo user can access/edit another demo user's resumes. But that's by design
def edit
@resume = Resume.find(params[:id])
user = demo? ? admin : current_user
@resume = user.resumes.find(params[:id])
@style = @resume.style || default_style
render :layout => "demo" if demo?
end

# POST /resumes
# POST /resumes.xml
def create
@resume = Resume.new(params[:resume])
@resume = current_user.resume.new(params[:resume])

respond_to do |format|
if @resume.save
Expand All @@ -55,12 +64,19 @@ def create

# PUT /resumes/1
# PUT /resumes/1.xml
# This method is open for unauthenticated users also,
# only demo resumes can be updated without authentication
# This is slightly insecure as one demo user can update another demo user's resumes. But that's by design
def update
@resume = Resume.find(params[:id])
user = demo? ? admin : current_user
@resume = user.resumes.find(params[:id])
@resume.update_count += 1

respond_to do |format|
if @resume.update_attributes(params[:resume])
format.html { redirect_to(@resume, :notice => 'Resume was successfully updated.') }
format.html {
redirect_to(html_resume_path(@resume), :notice => 'updated')
}
format.xml { head :ok }
else
format.html { render :action => "edit" }
Expand All @@ -71,8 +87,10 @@ def update

# DELETE /resumes/1
# DELETE /resumes/1.xml
# Note that there is no unauthenticated access for this action -
# unauthenticated users can't destroy their own demo resumes also. That's by design.
def destroy
@resume = Resume.find(params[:id])
@resume = current_user.resume.find(params[:id])
@resume.destroy

respond_to do |format|
Expand All @@ -82,14 +100,17 @@ def destroy
end

# GET /resumes/1/html
# Unless otherwise configured (TODO), this method is accessible to unauthenticated users - publically visible.
def html
@resume = Resume.find(params[:id])
#@html_resume = RDiscount.new(@resume.content).to_html # Markdown only. C binary. Fast
#@html_resume = RedCloth.new(@resume.content).to_html # Textile. C binary. Fast
@html_resume = Kramdown::Document.new(@resume.content).to_html # MArkdown extensions. Pure ruby. Slow
#@html_resume = RDiscount.new(@resume.content).to_html # Markdown only. C binary. Fast
#@html_resume = RedCloth.new(@resume.content).to_html # Textile. C binary. Fast
@html_resume = Kramdown::Document.new(@resume.content).to_html # MArkdown extensions. Pure ruby. Slow
render :layout => "output"
end

# GET /resumes/1/pdf
# Unless otherwise configured (TODO), this method is accessible to unauthenticated users - publically visible.
def pdf
@resume = Resume.find(params[:id])
html = Kramdown::Document.new(@resume.content).to_html
Expand All @@ -99,7 +120,6 @@ def pdf
file_path = "#{RAILS_ROOT}/tmp/#{@resume.id}.pdf"
file = kit.to_file(file_path)
send_file file_path, :type => 'pdf', :disposition => 'inline'

end

end
86 changes: 86 additions & 0 deletions app/controllers/styles_controller.rb
@@ -0,0 +1,86 @@
class StylesController < ApplicationController

before_filter :authenticate_user!

# GET /styles
# GET /styles.xml
def index
@styles = Style.all

respond_to do |format|
format.html # index.html.erb
format.xml { render :xml => @styles }
end
end

# GET /styles/1
# GET /styles/1.xml
def show
@style = Style.find(params[:id])

respond_to do |format|
format.html # show.html.erb
format.xml { render :xml => @style }
end
end

# GET /styles/new
# GET /styles/new.xml
def new
@style = Style.new

respond_to do |format|
format.html # new.html.erb
format.xml { render :xml => @style }
end
end

# GET /styles/1/edit
def edit
@style = Style.find(params[:id])
end

# POST /styles
# POST /styles.xml
def create
@style = Style.new(params[:style])

respond_to do |format|
if @style.save
format.html { redirect_to(@style, :notice => 'Style was successfully created.') }
format.xml { render :xml => @style, :status => :created, :location => @style }
else
format.html { render :action => "new" }
format.xml { render :xml => @style.errors, :status => :unprocessable_entity }
end
end
end

# PUT /styles/1
# PUT /styles/1.xml
def update
@style = Style.find(params[:id])

respond_to do |format|
if @style.update_attributes(params[:style])
format.html { redirect_to(@style, :notice => 'Style was successfully updated.') }
format.xml { head :ok }
else
format.html { render :action => "edit" }
format.xml { render :xml => @style.errors, :status => :unprocessable_entity }
end
end
end

# DELETE /styles/1
# DELETE /styles/1.xml
def destroy
@style = Style.find(params[:id])
@style.destroy

respond_to do |format|
format.html { redirect_to(styles_url) }
format.xml { head :ok }
end
end
end
1 change: 1 addition & 0 deletions app/helpers/application_helper.rb
@@ -1,2 +1,3 @@
module ApplicationHelper

end
2 changes: 2 additions & 0 deletions app/helpers/styles_helper.rb
@@ -0,0 +1,2 @@
module StylesHelper
end
11 changes: 11 additions & 0 deletions app/models/resume.rb
@@ -1,2 +1,13 @@
class Resume < ActiveRecord::Base
belongs_to :user
has_one :style_attachment, :dependent => :destroy
has_one :style, :through => :style_attachment

after_create :add_style

def add_style
default_style = Style.find_by_title "default"
#StyleAttachment.create!(:resume => self, :style => default_style)
build_style_attachment(:style => default_style)
end
end
14 changes: 14 additions & 0 deletions app/models/style.rb
@@ -0,0 +1,14 @@
class Style < ActiveRecord::Base
# Styles are the templates associated with the resume.
# Style associate to a resume through a style_attachment table, so -
# - a resume can have one style_attachment, that is one style
# - a style can have many style_attachments, that is, can be applied to many resumes
# They contain the css and some meta data
# Every user can create/edit/destroy her styles
# User can also read/copy/use another user's styles
# Styles are marked default, featured
# Styles have to be rated/rated - based on usage, editorial
belongs_to :user
has_many :style_attachments, :dependent => :destroy
has_many :resumes, :through => :style_attachments
end
4 changes: 4 additions & 0 deletions app/models/style_attachment.rb
@@ -0,0 +1,4 @@
class StyleAttachment < ActiveRecord::Base
belongs_to :resume
belongs_to :style
end
16 changes: 16 additions & 0 deletions app/models/user.rb
@@ -0,0 +1,16 @@
class User < ActiveRecord::Base
# Include default devise modules. Others available are:
# :token_authenticatable, :confirmable, :lockable and :timeoutable
devise :database_authenticatable, # encrypts and stores a password in the database to validate the authenticity of an user while signing in.
:registerable, # handles signing up users through a registration process, also allowing them to edit and destroy their account.
:recoverable, # resets the user password and sends reset instructions.
:rememberable, # manages generating and clearing a token for remembering the user from a saved cookie.
:trackable, # tracks sign in count, timestamps and IP address.
:validatable # provides validations of email and password

# Setup accessible (or protected) attributes for your model
attr_accessible :email, :password, :password_confirmation, :remember_me

has_many :resumes, :foreign_key => "user_id"
has_many :styles, :foreign_key => "user_id"
end
9 changes: 7 additions & 2 deletions app/views/home/index.html.erb
@@ -1,2 +1,7 @@
<h1>Home#index</h1>
<p>Find me in app/views/home/index.html.erb</p>
<h1>rC</h1>
<h2>resumeCreator helps you create nice looking resumes online. Fast</h2>

<%= link_to "sign_in", new_user_session_path %> /
<%= link_to "sign up", new_user_registration_path %>
<br/>or<br/>
<%= link_to "get started ...", demo_path %>

0 comments on commit e81d56f

Please sign in to comment.