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
Binary file added source/.DS_Store
Binary file not shown.
5 changes: 3 additions & 2 deletions source/Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ source 'https://rubygems.org'
gem 'rails', '4.1.6'
# Use sqlite3 as the database for Active Record
gem 'sqlite3'
gem 'pry'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 4.0.3'
# Use Uglifier as compressor for JavaScript assets
Expand All @@ -13,7 +14,7 @@ gem 'uglifier', '>= 1.3.0'
gem 'coffee-rails', '~> 4.0.0'
# See https://github.com/sstephenson/execjs#readme for more supported runtimes
# gem 'therubyracer', platforms: :ruby

gem 'bootstrap-sass'
# Use jquery as the JavaScript library
gem 'jquery-rails'
# Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks
Expand All @@ -23,6 +24,7 @@ gem 'jbuilder', '~> 2.0'
# bundle exec rake doc:rails generates the API under doc/api.
gem 'sdoc', '~> 0.4.0', group: :doc


# Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
gem 'spring', group: :development

Expand All @@ -38,4 +40,3 @@ gem 'spring', group: :development
# Use debugger
# gem 'debugger', group: [:development, :test]
gem 'rspec-rails', group: [:development, :test]

115 changes: 66 additions & 49 deletions source/Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -28,33 +28,45 @@ GEM
thread_safe (~> 0.1)
tzinfo (~> 1.1)
arel (5.0.1.20140414130214)
builder (3.2.2)
autoprefixer-rails (8.5.0)
execjs
bootstrap-sass (3.3.5)
autoprefixer-rails (>= 5.0.0.1)
sass (>= 3.2.19)
builder (3.2.3)
coderay (1.1.2)
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)
concurrent-ruby (1.0.5)
diff-lcs (1.3)
erubis (2.7.0)
execjs (2.2.1)
execjs (2.7.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.9.5)
concurrent-ruby (~> 1.0)
jbuilder (2.6.4)
activesupport (>= 3.0.0)
multi_json (>= 1.2)
jquery-rails (3.1.5)
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.7.0)
mini_mime (>= 0.1.1)
method_source (0.9.0)
mini_mime (1.0.0)
minitest (5.11.3)
multi_json (1.13.1)
pry (0.11.3)
coderay (~> 1.1.0)
method_source (~> 0.9.0)
rack (1.5.5)
rack-test (0.6.3)
rack (>= 1.0)
rails (4.1.6)
actionmailer (= 4.1.6)
Expand All @@ -71,63 +83,65 @@ 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.3.1)
rdoc (4.3.0)
rspec-core (3.7.1)
rspec-support (~> 3.7.0)
rspec-expectations (3.7.0)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.7.0)
rspec-mocks (3.7.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.7.0)
rspec-rails (3.7.2)
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.7.0)
rspec-expectations (~> 3.7.0)
rspec-mocks (~> 3.7.0)
rspec-support (~> 3.7.0)
rspec-support (3.7.1)
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)
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.20.0)
thread_safe (0.3.6)
tilt (1.4.1)
turbolinks (2.4.0)
coffee-rails
tzinfo (1.2.2)
turbolinks (5.1.1)
turbolinks-source (~> 5.1)
turbolinks-source (5.1.0)
tzinfo (1.2.5)
thread_safe (~> 0.1)
uglifier (2.5.3)
execjs (>= 0.3.0)
json (>= 1.8.0)
uglifier (4.1.10)
execjs (>= 0.3.0, < 3)

PLATFORMS
ruby

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

BUNDLED WITH
1.16.1
1 change: 1 addition & 0 deletions source/app/assets/javascripts/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@
//
//= require jquery
//= require jquery_ujs
//= require bootstrap-sprockets
//= require turbolinks
//= require_tree .
8 changes: 8 additions & 0 deletions source/app/assets/stylesheets/custom.css.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
$navbar-default-bg: lightblue;

@import "bootstrap-sprockets";
@import "bootstrap";

.form-horizontal, .jumbotron, .table-bordered {
margin-top: 75px;
}
52 changes: 52 additions & 0 deletions source/app/controllers/urls_controller.rb
Original file line number Diff line number Diff line change
@@ -1,2 +1,54 @@
class UrlsController < ApplicationController
before_action :set_url, only: [:show]

def index
if Url.all.size == 0
flash.now[:danger] = "There aren't any yet. Why don't you start us off?"
render 'home'
else
@urls = Url.all
end
end

def new
@url = Url.new
end

def create
@url = Url.new(url_params)
if check_url? && @url.save
redirect_to urls_path
else
flash.now[:danger] = "Something went wrong with your URL. . ."
render 'new'
end
end

def short_url
@url = Url.find_by(short_url: params[:short_url])
@url.click_count += 1
@url.save
redirect_to @url.long_url
end

def show

end

def home
end

private
def url_params
params.require(:url).permit(:long_url)
end

def check_url?
url = URI.parse(@url.long_url)
url.is_a?(URI::HTTP) && !url.host.nil?
end

def set_url
@url = Url.find_by(params[:id])
end
end
10 changes: 10 additions & 0 deletions source/app/models/url.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
class Url < ActiveRecord::Base
validates :long_url, presence: true
before_create :trim_url

private
def trim_url
self.short_url = SecureRandom.hex(3)
end

end
10 changes: 10 additions & 0 deletions source/app/views/layouts/_messages.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<div class="row">
<div class="col-md-10 col-md-offset-1">
<% flash.each do |name, msg| %>
<div align="center" class="alert alert-<%= name %>">
<a href="#" class="close" data-dismiss="alert">&#215;</a>
<%= msg %>
</div>
<% end %>
</div>
</div>
19 changes: 19 additions & 0 deletions source/app/views/layouts/_navigation.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<nav class="navbar navbar-default">
<div class="container-fluid">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-expanded="false">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
</div>
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav">
<li><%= link_to "It's too long!", root_path, class: "navbar-brand" %></li>
<li><%= link_to "New URL", new_url_path %></li>
</ul>
</div>
</div>
</nav>
7 changes: 6 additions & 1 deletion source/app/views/layouts/application.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,12 @@
</head>
<body>

<%= yield %>
<%= render 'layouts/navigation' %>
<%= render 'layouts/messages' %>
<div class="container">
<%= yield %>

</div>

</body>
</html>
11 changes: 11 additions & 0 deletions source/app/views/urls/home.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<div class="jumbotron" align="center">
<h2 align="center">URL too long? Snip it.</h2>
<div class="row">
<div align="center" class="col-md-3 col-md-offset-3">
<%= link_to "Create A Shorty", new_url_path, class: "btn btn-primary" %>
</div>
<div align="center" class="col-md-3">
<%= link_to "View Existing URLs", urls_path, class: "btn btn-primary" %>
</div>
</div>
</div>
19 changes: 19 additions & 0 deletions source/app/views/urls/index.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<h1 align="center">URL too long? Snip it.</h1>
<h2 align="center">Check these out.</h2>
<div class="col-md-8 col-md-offset-2">
<table class="table table-bordered">
<tr>
<th>Long Url</th>
<th>Short Url</th>
</tr>
<% @urls.each do |url| %>
<tr>
<td><%= link_to url.long_url, url_path(url) %></td>
<td><%= link_to url.short_url, short_url_path(url.short_url) %></td>
</tr>
<% end %>
</table>
<div align="center">
[ <%= link_to "Home", root_path %> ]
</div>
</div>
23 changes: 23 additions & 0 deletions source/app/views/urls/new.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<div class="row">
<div class="col-md-8 col-md-offset-2">
<%= form_for(@url, :html => { class: "form-horizontal", role: "form" }) do |f| %>
<div class="form-group">
<div class="control-label col-md-4">
<%= f.label :long_url %>
</div>
<div class="col-md-4">
<%= f.text_field :long_url, class: "form-control", placeholder: "https://your-long-url.com",
autofocus: true %>
</div>
</div>
<div class="form-group">
<div align="center">
<%= f.submit class: "btn btn-primary" %>
</div>
</div>
<% end %>
<div align="center">
[ <%= link_to "Cancel and go home", root_path %> ]
</div>
</div>
</div>
18 changes: 18 additions & 0 deletions source/app/views/urls/show.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<div class="col-md-10 col-md-offset-1">
<table class="table table-bordered">
<tr>
<th>Long Url</th>
<th>Short Url</th>
<th>Click Count</th>
</tr>
<tr>
<td><%= @url.long_url %></td>
<td><%= link_to @url.short_url, short_url_path(@url.short_url) %></td>
<td><%= @url.click_count %></td>
</td>
</tr>
</table>
<div align="center">
[ <%= link_to "Home", root_path %> ]
</div>
</div>
Loading