Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions source/.rspec
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
--require spec_helper
5 changes: 5 additions & 0 deletions source/Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,8 @@ gem 'spring', group: :development
# gem 'debugger', group: [:development, :test]
gem 'rspec-rails', group: [:development, :test]

gem 'pry-rails', :group => [:development, :test]

group :development, :test do
gem "factory_girl_rails", "~> 4.0"
end
119 changes: 70 additions & 49 deletions source/Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -28,33 +28,48 @@ GEM
thread_safe (~> 0.1)
tzinfo (~> 1.1)
arel (5.0.1.20140414130214)
builder (3.2.2)
builder (3.2.3)
coderay (1.1.1)
coffee-rails (4.0.1)
coffee-script (>= 2.2.0)
railties (>= 4.0.0, < 5.0)
coffee-script (2.3.0)
coffee-script (2.4.1)
coffee-script-source
execjs
coffee-script-source (1.8.0)
diff-lcs (1.2.5)
coffee-script-source (1.12.2)
diff-lcs (1.3)
erubis (2.7.0)
execjs (2.2.1)
execjs (2.7.0)
factory_girl (4.8.0)
activesupport (>= 3.0.0)
factory_girl_rails (4.8.0)
factory_girl (~> 4.8.0)
railties (>= 3.0.0)
hike (1.2.3)
i18n (0.6.11)
jbuilder (2.2.2)
activesupport (>= 3.0.0, < 5)
multi_json (~> 1.2)
jquery-rails (3.1.2)
i18n (0.8.6)
jbuilder (2.6.4)
activesupport (>= 3.0.0)
multi_json (>= 1.2)
jquery-rails (3.1.4)
railties (>= 3.0, < 5.0)
thor (>= 0.14, < 2.0)
json (1.8.1)
mail (2.6.1)
mime-types (>= 1.16, < 3)
mime-types (2.4.1)
minitest (5.4.2)
multi_json (1.10.1)
rack (1.5.2)
rack-test (0.6.2)
json (1.8.6)
mail (2.6.6)
mime-types (>= 1.16, < 4)
method_source (0.8.2)
mime-types (3.1)
mime-types-data (~> 3.2015)
mime-types-data (3.2016.0521)
minitest (5.10.2)
multi_json (1.12.1)
pry (0.10.4)
coderay (~> 1.1.0)
method_source (~> 0.8.1)
slop (~> 3.4)
pry-rails (0.3.6)
pry (>= 0.10.4)
rack (1.5.5)
rack-test (0.6.3)
rack (>= 1.0)
rails (4.1.6)
actionmailer (= 4.1.6)
Expand All @@ -71,63 +86,66 @@ GEM
activesupport (= 4.1.6)
rake (>= 0.8.7)
thor (>= 0.18.1, < 2.0)
rake (10.3.2)
rdoc (4.1.2)
json (~> 1.4)
rspec-core (3.1.6)
rspec-support (~> 3.1.0)
rspec-expectations (3.1.2)
rake (12.0.0)
rdoc (4.3.0)
rspec-core (3.6.0)
rspec-support (~> 3.6.0)
rspec-expectations (3.6.0)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.1.0)
rspec-mocks (3.1.3)
rspec-support (~> 3.1.0)
rspec-rails (3.1.0)
rspec-support (~> 3.6.0)
rspec-mocks (3.6.0)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.6.0)
rspec-rails (3.6.0)
actionpack (>= 3.0)
activesupport (>= 3.0)
railties (>= 3.0)
rspec-core (~> 3.1.0)
rspec-expectations (~> 3.1.0)
rspec-mocks (~> 3.1.0)
rspec-support (~> 3.1.0)
rspec-support (3.1.2)
rspec-core (~> 3.6.0)
rspec-expectations (~> 3.6.0)
rspec-mocks (~> 3.6.0)
rspec-support (~> 3.6.0)
rspec-support (3.6.0)
sass (3.2.19)
sass-rails (4.0.3)
sass-rails (4.0.5)
railties (>= 4.0.0, < 5.0)
sass (~> 3.2.0)
sprockets (~> 2.8, <= 2.11.0)
sass (~> 3.2.2)
sprockets (~> 2.8, < 3.0)
sprockets-rails (~> 2.0)
sdoc (0.4.1)
sdoc (0.4.2)
json (~> 1.7, >= 1.7.7)
rdoc (~> 4.0)
spring (1.1.3)
sprockets (2.11.0)
slop (3.6.0)
spring (1.7.2)
sprockets (2.12.4)
hike (~> 1.2)
multi_json (~> 1.0)
rack (~> 1.0)
tilt (~> 1.1, != 1.3.0)
sprockets-rails (2.2.0)
sprockets-rails (2.3.3)
actionpack (>= 3.0)
activesupport (>= 3.0)
sprockets (>= 2.8, < 4.0)
sqlite3 (1.3.9)
thor (0.19.1)
thread_safe (0.3.4)
sqlite3 (1.3.13)
thor (0.19.4)
thread_safe (0.3.6)
tilt (1.4.1)
turbolinks (2.4.0)
coffee-rails
tzinfo (1.2.2)
turbolinks (5.0.1)
turbolinks-source (~> 5)
turbolinks-source (5.0.3)
tzinfo (1.2.3)
thread_safe (~> 0.1)
uglifier (2.5.3)
execjs (>= 0.3.0)
json (>= 1.8.0)
uglifier (3.2.0)
execjs (>= 0.3.0, < 3)

PLATFORMS
ruby

DEPENDENCIES
coffee-rails (~> 4.0.0)
factory_girl_rails (~> 4.0)
jbuilder (~> 2.0)
jquery-rails
pry-rails
rails (= 4.1.6)
rspec-rails
sass-rails (~> 4.0.3)
Expand All @@ -136,3 +154,6 @@ DEPENDENCIES
sqlite3
turbolinks
uglifier (>= 1.3.0)

BUNDLED WITH
1.15.1
Empty file.
1 change: 1 addition & 0 deletions source/app/assets/javascripts/sessions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

3 changes: 0 additions & 3 deletions source/app/assets/javascripts/sessions.js.coffee

This file was deleted.

3 changes: 3 additions & 0 deletions source/app/assets/stylesheets/links.css.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Place all the styles related to the links controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/
88 changes: 88 additions & 0 deletions source/app/assets/stylesheets/scaffolds.css.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
body {
background-color: #fff;
color: #333;
font-family: verdana, arial, helvetica, sans-serif;
font-size: 13px;
line-height: 18px;
text-align: center;
}

hr {
width: 65%;
}

table {
width: 30%;
margin-left: auto;
margin-right: auto;
font-size: 20px;
}

input {
text-align: center;
font-size: 15px;
}

p, ol, ul, td {
text-align: center;
font-family: verdana, arial, helvetica, sans-serif;
font-size: 20px;
line-height: 18px;
//border: 1px solid black
}

pre {
background-color: #eee;
padding: 10px;
font-size: 11px;
}

a {
color: #000;
&:visited {
color: #666;
}
&:hover {
color: #fff;
background-color: #000;
}
}

div {
&.field, &.actions {
margin-bottom: 10px;
}
}

#notice {
color: green;
}

.field_with_errors {
padding: 2px;
background-color: red;
display: table;
}

#error_explanation {
width: 450px;
border: 2px solid red;
padding: 7px;
padding-bottom: 0;
margin-bottom: 20px;
background-color: #f0f0f0;
h2 {
text-align: left;
font-weight: bold;
padding: 5px 5px 5px 15px;
font-size: 12px;
margin: -7px;
margin-bottom: 0px;
background-color: #c00;
color: #fff;
}
ul li {
font-size: 12px;
list-style: square;
}
}
29 changes: 29 additions & 0 deletions source/app/controllers/links_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
class LinksController < ApplicationController

def index
@links = Link.all
@link = Link.new
end

def show
@link = Link.find_by new_url: params[:new_url]
@link.update_column(:counter, @link.counter + 1)
redirect_to @link.old_url
end

def create
@link = Link.new(link_params)
respond_to do |format|
if @link.save
format.html { redirect_to links_path }
else
format.html { render :new }
end
end
end

private
def link_params
params.require(:link).permit(:old_url, :new_url, :counter)
end
end
2 changes: 2 additions & 0 deletions source/app/helpers/links_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module LinksHelper
end
17 changes: 17 additions & 0 deletions source/app/models/link.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
class Link < ActiveRecord::Base
before_save :assign

# validates :old_url, presence: true, format: { with: /.com|.org|.edu|.net|.uk/,
# message: "The filed must filled with a URL using .com, .net, .edu, .org, etc." }

def random_end(length=5)
chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'
text = ''
length.times { text << chars[rand(chars.size)] }
text
end

def assign
self.new_url = random_end
end
end
25 changes: 25 additions & 0 deletions source/app/views/links/_form.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<%= form_for(@link) do |f| %>
<% if @link.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(@link.errors.count, "error") %> prohibited this link from being saved:</h2>

<ul>
<% @link.errors.full_messages.each do |message| %>
<li><%= message %></li>
<% end %>
</ul>
</div>
<% end %>

<div class="field">
<%= f.label :old_url %><br>
<%= f.text_field :old_url, id: :link_old %>
</div>
<div class="field">
<%= f.label :new_url %><br>
<%= f.text_field :new_url, id: :link_new %>
</div>
<div class="actions">
<%= f.submit %>
</div>
<% end %>
2 changes: 2 additions & 0 deletions source/app/views/links/_link.json.jbuilder
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
json.extract! link, :id, :old_url, :new_url, :created_at, :updated_at
json.url link_url(link, format: :json)
30 changes: 30 additions & 0 deletions source/app/views/links/index.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<h1>Welcome To A Bitly Clone</h1>

<br><hr><h3>Enter The Link You Want To Shorten, Then Press The 'Generate Shorter Link' Button To Get The Shortened Link</h3><hr><br>
<%= form_for @link do |f| %>
<table style="width:50%">
<tr>
<td colspan="4", height="30"><b>Old URL</b></td>
<td colspan="4", height="30"><%= f.text_field :old_url, type: 'url', id: 'link_old' %></td>
<td colspan="4", height="30"><%= f.submit 'Generate Shorter Link', id: 'sub_button', :class => 'button' %></td>
</tr>
</table>
<% end %>

<br><hr>

<table style="width:60%">
<tr>
<th colspan="50", width="40%", height="30">Old URL</th>
<th colspan="10", width="10%", height="30"></th>
<th colspan="25", width="30%", height="30">New URL</th>
<th colspan="10", width="10%", height="30">Times Clicked</th>
<% @links.each do |link| %>
<tr>
<td colspan="50", width="40%", height="30"><%= link.old_url %></td>
<td colspan="10", width="10%", height="30"></td>
<td colspan="25", width="30%", height="30"><%= link_to "localhost:3000/#{link.new_url}", link_path(new_url: link.new_url) %></td>
<td colspan="10", width="10%", height="30"><%= link.counter %></td>
</tr>
<% end %>
</table>
1 change: 1 addition & 0 deletions source/app/views/links/index.json.jbuilder
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
json.array! @links, partial: 'links/link', as: :link
Loading