diff --git a/source/.DS_Store b/source/.DS_Store new file mode 100644 index 0000000..df43d34 Binary files /dev/null and b/source/.DS_Store differ diff --git a/source/Gemfile b/source/Gemfile index 9627b8b..0e0d323 100644 --- a/source/Gemfile +++ b/source/Gemfile @@ -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 @@ -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 @@ -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 @@ -38,4 +40,3 @@ gem 'spring', group: :development # Use debugger # gem 'debugger', group: [:development, :test] gem 'rspec-rails', group: [:development, :test] - diff --git a/source/Gemfile.lock b/source/Gemfile.lock index fcf8b98..fcb75bd 100644 --- a/source/Gemfile.lock +++ b/source/Gemfile.lock @@ -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) @@ -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) @@ -136,3 +150,6 @@ DEPENDENCIES sqlite3 turbolinks uglifier (>= 1.3.0) + +BUNDLED WITH + 1.16.1 diff --git a/source/app/assets/javascripts/application.js b/source/app/assets/javascripts/application.js index d6925fa..04c7d4a 100644 --- a/source/app/assets/javascripts/application.js +++ b/source/app/assets/javascripts/application.js @@ -12,5 +12,6 @@ // //= require jquery //= require jquery_ujs +//= require bootstrap-sprockets //= require turbolinks //= require_tree . diff --git a/source/app/assets/stylesheets/custom.css.scss b/source/app/assets/stylesheets/custom.css.scss new file mode 100644 index 0000000..9cdae43 --- /dev/null +++ b/source/app/assets/stylesheets/custom.css.scss @@ -0,0 +1,8 @@ +$navbar-default-bg: lightblue; + +@import "bootstrap-sprockets"; +@import "bootstrap"; + +.form-horizontal, .jumbotron, .table-bordered { + margin-top: 75px; +} diff --git a/source/app/controllers/urls_controller.rb b/source/app/controllers/urls_controller.rb index ef26710..1a198f2 100644 --- a/source/app/controllers/urls_controller.rb +++ b/source/app/controllers/urls_controller.rb @@ -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 diff --git a/source/app/models/url.rb b/source/app/models/url.rb new file mode 100644 index 0000000..ac2734f --- /dev/null +++ b/source/app/models/url.rb @@ -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 diff --git a/source/app/views/layouts/_messages.html.erb b/source/app/views/layouts/_messages.html.erb new file mode 100644 index 0000000..743c387 --- /dev/null +++ b/source/app/views/layouts/_messages.html.erb @@ -0,0 +1,10 @@ +