shortenizer 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/MIT-LICENSE +20 -0
- data/Rakefile +23 -0
- data/app/assets/javascripts/shortenizer/application.js +28 -0
- data/app/assets/stylesheets/shortenizer/application.css +123 -0
- data/app/controllers/shortenizer/application_controller.rb +4 -0
- data/app/controllers/shortenizer/u_controller.rb +36 -0
- data/app/helpers/shortenizer/application_helper.rb +4 -0
- data/app/models/shortenizer/url.rb +19 -0
- data/app/presenters/shortenizer/url_presenter.rb +23 -0
- data/app/views/layouts/shortenizer/application.html.erb +19 -0
- data/app/views/shortenizer/u/new.html.erb +4 -0
- data/app/views/shortenizer/u/show.html.erb +7 -0
- data/config/routes.rb +8 -0
- data/db/migrate/20141015221054_add_shortenizer_urls_table.rb +8 -0
- data/lib/shortenizer.rb +4 -0
- data/lib/shortenizer/engine.rb +26 -0
- data/lib/shortenizer/mount_point.rb +13 -0
- data/lib/shortenizer/version.rb +3 -0
- data/lib/tasks/shortenizer_tasks.rake +4 -0
- data/spec/dummy/README.rdoc +28 -0
- data/spec/dummy/Rakefile +6 -0
- data/spec/dummy/app/assets/javascripts/application.js +13 -0
- data/spec/dummy/app/assets/stylesheets/application.css +15 -0
- data/spec/dummy/app/controllers/application_controller.rb +5 -0
- data/spec/dummy/app/helpers/application_helper.rb +2 -0
- data/spec/dummy/app/views/layouts/application.html.erb +14 -0
- data/spec/dummy/bin/bundle +3 -0
- data/spec/dummy/bin/rails +4 -0
- data/spec/dummy/bin/rake +4 -0
- data/spec/dummy/config.ru +4 -0
- data/spec/dummy/config/application.rb +29 -0
- data/spec/dummy/config/boot.rb +5 -0
- data/spec/dummy/config/database.yml +25 -0
- data/spec/dummy/config/environment.rb +5 -0
- data/spec/dummy/config/environments/development.rb +37 -0
- data/spec/dummy/config/environments/production.rb +82 -0
- data/spec/dummy/config/environments/test.rb +39 -0
- data/spec/dummy/config/initializers/assets.rb +8 -0
- data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/dummy/config/initializers/cookies_serializer.rb +3 -0
- data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -0
- data/spec/dummy/config/initializers/inflections.rb +16 -0
- data/spec/dummy/config/initializers/mime_types.rb +4 -0
- data/spec/dummy/config/initializers/session_store.rb +3 -0
- data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/spec/dummy/config/locales/en.yml +23 -0
- data/spec/dummy/config/routes.rb +4 -0
- data/spec/dummy/config/secrets.yml +22 -0
- data/spec/dummy/db/development.sqlite3 +0 -0
- data/spec/dummy/db/schema.rb +21 -0
- data/spec/dummy/db/test.sqlite3 +0 -0
- data/spec/dummy/log/development.log +37724 -0
- data/spec/dummy/log/test.log +280 -0
- data/spec/dummy/public/404.html +67 -0
- data/spec/dummy/public/422.html +67 -0
- data/spec/dummy/public/500.html +66 -0
- data/spec/dummy/public/favicon.ico +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/0e145c8d9b7a337921cad6e2ac10daf0 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/11cd522cee6431afd456e86bf23b3031 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/143ca05c549c1126abdfc78e4d67b8fa +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/20271ea5ca35664532b622e5bb70f88c +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/2729c3a89e31f64cb31d0721f47afa32 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/3b30147cb780a01beca487d79f0d77e2 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/5717abda788abeec36709efb6ba01d38 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/58a64848570974f113ccd648898d8b17 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/6f127c6d3ff02ab7333529a682402528 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/6f7d6444d8ecd290fc66fcd3cd678225 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/737a1995fb8c894e2735c7266df2e7a6 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/80975fe0bf6c19e4c0044b412114b5e2 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/868252c279d2a5cc2ae71197271a0a9c +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/98afa9eb164be3902512f323968479b4 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/a0de67fb651755110dd375bfab2c5272 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/a1ddc0bf2ca692563c4dbfc805d2f617 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/a483a47ea3543ee94c46303f1b49db5d +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/af1be136c22c7c7a9f6f94b2f78f3b33 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/c7809fd0d1ecae831459b828e00dbbda +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/dfeb7b1afe25213579cffff6909e285f +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/e8521259ab5ca42adabc9f4e7fee338c +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/e9a511a12490493848aa5023b4946b2f +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/fd187d2066d9a8ad2ee217ea70baa138 +0 -0
- data/spec/models/shortenizer/url_spec.rb +23 -0
- data/spec/presenters/shortenizer/url_presenter_spec.rb +13 -0
- data/spec/rails_helper.rb +47 -0
- data/spec/spec_helper.rb +78 -0
- metadata +249 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 24f2635ee4a8200bda114fbc95f53f65f2b44906
|
4
|
+
data.tar.gz: a772c55f1e16b61111dcfcf3ea4efe3fa9238b98
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: b3889936c1603b34a08c5d6f79a657c485aa8860c413417cd019edd04bdd209d554f582732756d1b5c84a0e9bd1f35cb3acdf3b66324180e8abec9a86d7b9328
|
7
|
+
data.tar.gz: 6625c033f02a350275e261669332c895c13424cb38acac6df286b8591db30638584bf733bf593311df8eae7105565bf1db12601b5a6d2580f6aa2388e11e3163
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2014 YOURNAME
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
begin
|
2
|
+
require 'bundler/setup'
|
3
|
+
rescue LoadError
|
4
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
5
|
+
end
|
6
|
+
|
7
|
+
require 'rdoc/task'
|
8
|
+
|
9
|
+
RDoc::Task.new(:rdoc) do |rdoc|
|
10
|
+
rdoc.rdoc_dir = 'rdoc'
|
11
|
+
rdoc.title = 'Shortenizer'
|
12
|
+
rdoc.options << '--line-numbers'
|
13
|
+
rdoc.rdoc_files.include('README.rdoc')
|
14
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
15
|
+
end
|
16
|
+
|
17
|
+
APP_RAKEFILE = File.expand_path("../spec/dummy/Rakefile", __FILE__)
|
18
|
+
load 'rails/tasks/engine.rake'
|
19
|
+
|
20
|
+
|
21
|
+
|
22
|
+
Bundler::GemHelper.install_tasks
|
23
|
+
|
@@ -0,0 +1,28 @@
|
|
1
|
+
// This is a manifest file that'll be compiled into application.js, which will include all the files
|
2
|
+
// listed below.
|
3
|
+
//
|
4
|
+
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
|
5
|
+
// or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
|
6
|
+
//
|
7
|
+
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
|
8
|
+
// compiled file.
|
9
|
+
//
|
10
|
+
// Read Sprockets README (https://github.com/sstephenson/sprockets#sprockets-directives) for details
|
11
|
+
// about supported directives.
|
12
|
+
//
|
13
|
+
//= require jquery
|
14
|
+
//= require zeroclipboard
|
15
|
+
//= require_tree .
|
16
|
+
|
17
|
+
$(document).ready(function(){
|
18
|
+
btn = $('#btn-copy')
|
19
|
+
var client = new ZeroClipboard($(btn));
|
20
|
+
client.on( "ready", function( readyEvent ) {
|
21
|
+
client.on( "aftercopy", function( event ) {
|
22
|
+
$(btn).text('copied');
|
23
|
+
setTimeout(function(){
|
24
|
+
$(btn).text('copy');
|
25
|
+
}, 3000);
|
26
|
+
} );
|
27
|
+
} );
|
28
|
+
});
|
@@ -0,0 +1,123 @@
|
|
1
|
+
/*
|
2
|
+
* This is a manifest file that'll be compiled into application.css, which will include all the files
|
3
|
+
* listed below.
|
4
|
+
*
|
5
|
+
* Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
|
6
|
+
* or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
|
7
|
+
*
|
8
|
+
* You're free to add application-wide styles to this file and they'll appear at the bottom of the
|
9
|
+
* compiled file so the styles you add here take precedence over styles defined in any styles
|
10
|
+
* defined in the other CSS/SCSS files in this directory. It is generally better to create a new
|
11
|
+
* file per style scope.
|
12
|
+
*
|
13
|
+
*= require_tree .
|
14
|
+
*= require_self
|
15
|
+
*/
|
16
|
+
|
17
|
+
html, body {
|
18
|
+
font-family: 'Open Sans', sans-serif;
|
19
|
+
margin: 0;
|
20
|
+
padding: 0;
|
21
|
+
}
|
22
|
+
|
23
|
+
h1, h2, h3, h4, h5, h6 {
|
24
|
+
margin: 0 auto;
|
25
|
+
padding: 0 auto;
|
26
|
+
}
|
27
|
+
|
28
|
+
.shortenizer.form input {
|
29
|
+
font-size: 16px;
|
30
|
+
margin: 0;
|
31
|
+
padding: 10px;
|
32
|
+
}
|
33
|
+
|
34
|
+
.shortenizer.form input[type=text] {
|
35
|
+
-moz-transition: all 0.3s;
|
36
|
+
-webkit-transition: all 0.3s;
|
37
|
+
background: transparent;
|
38
|
+
border-top-left-radius: 3px;
|
39
|
+
border-bottom-left-radius: 3px;
|
40
|
+
border: 1px solid #e62d2d;
|
41
|
+
color: #7f898e;
|
42
|
+
display: inline-block;
|
43
|
+
height: 30px;
|
44
|
+
outline: none;
|
45
|
+
padding: 10px;
|
46
|
+
transition: all 0.3s;
|
47
|
+
width: 450px;
|
48
|
+
}
|
49
|
+
|
50
|
+
.shortenizer.form input[type=text]:focus {
|
51
|
+
border-color: #d42a2a;
|
52
|
+
}
|
53
|
+
|
54
|
+
.shortenizer.form input[type=submit] {
|
55
|
+
-moz-transition: all 0.3s;
|
56
|
+
-o-transition: all 0.3s;
|
57
|
+
-webkit-transition: all 0.3s;
|
58
|
+
background-color: #e62d2d;
|
59
|
+
border-bottom-right-radius: 3px;
|
60
|
+
border-top-right-radius: 3px;
|
61
|
+
border: 1px solid #e62d2d;
|
62
|
+
color: white;
|
63
|
+
display: inline-block;
|
64
|
+
height: 52px;
|
65
|
+
margin-left: -10px;
|
66
|
+
outline: none;
|
67
|
+
padding: 10px;
|
68
|
+
text-transform: uppercase;
|
69
|
+
transition: all 0.3s;
|
70
|
+
width: 130px;
|
71
|
+
}
|
72
|
+
|
73
|
+
.shortenizer.form input[type=submit]:hover, .shortenizer.form .btn-copy:hover {
|
74
|
+
background-color: #d42a2a;
|
75
|
+
}
|
76
|
+
|
77
|
+
.shortenizer.form .btn-new, .btn-copy {
|
78
|
+
-moz-transition: all 0.3s;
|
79
|
+
-o-transition: all 0.3s;
|
80
|
+
-webkit-transition: all 0.3s;
|
81
|
+
border: 1px solid #e62d2d;
|
82
|
+
color: white;
|
83
|
+
display: inline-block;
|
84
|
+
font-size: 16px;
|
85
|
+
height: 16px;
|
86
|
+
margin-left: -6px;
|
87
|
+
outline: none;
|
88
|
+
padding: 17px;
|
89
|
+
text-decoration: none;
|
90
|
+
text-transform: uppercase;
|
91
|
+
transition: all 0.3s;
|
92
|
+
width: 90px;
|
93
|
+
}
|
94
|
+
|
95
|
+
.shortenizer.form .btn-new {
|
96
|
+
background-color: #7f898e !important;
|
97
|
+
border-bottom-right-radius: 3px;
|
98
|
+
border-top-right-radius: 3px;
|
99
|
+
border: 1px solid #7f898e !important;
|
100
|
+
}
|
101
|
+
|
102
|
+
.shortenizer.form .btn-new:hover {
|
103
|
+
background-color: #888 !important;
|
104
|
+
}
|
105
|
+
|
106
|
+
.shortenizer.form .btn-copy {
|
107
|
+
background-color: #e62d2d !important;
|
108
|
+
}
|
109
|
+
|
110
|
+
.shortenizer.wrapper {
|
111
|
+
color: #7f898e;
|
112
|
+
font-size: 20px;
|
113
|
+
margin-top: 300px;
|
114
|
+
text-align: center;
|
115
|
+
}
|
116
|
+
|
117
|
+
.shortenizer.flash-message {
|
118
|
+
color: #d42a2a;
|
119
|
+
font-size: 16px;
|
120
|
+
margin: 0 auto 5px;
|
121
|
+
text-align: left;
|
122
|
+
width: 600px;
|
123
|
+
}
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module Shortenizer
|
2
|
+
class UController < ApplicationController
|
3
|
+
|
4
|
+
def index
|
5
|
+
target = Url.find_by(shortlink: params[:shortlink]).target
|
6
|
+
redirect_to target
|
7
|
+
end
|
8
|
+
|
9
|
+
def new
|
10
|
+
@url = Shortenizer::Url.new
|
11
|
+
end
|
12
|
+
|
13
|
+
def create
|
14
|
+
@url = Shortenizer::Url.new(url_params)
|
15
|
+
|
16
|
+
if @url.save
|
17
|
+
flash[:message] = "Your URL has been shortened..."
|
18
|
+
else
|
19
|
+
flash[:message] = "Error occured, please try again!"
|
20
|
+
end
|
21
|
+
|
22
|
+
redirect_to action: :show, shortlink: @url.shortlink
|
23
|
+
end
|
24
|
+
|
25
|
+
def show
|
26
|
+
url_obj = Url.find_by(shortlink: params[:shortlink])
|
27
|
+
@url = Shortenizer::UrlPresenter.new(url_obj, request)
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
def url_params
|
32
|
+
params.require(:url).permit(:target, :shortlink)
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Shortenizer
|
2
|
+
class Url < ActiveRecord::Base
|
3
|
+
|
4
|
+
before_create :create_unique_identifier
|
5
|
+
before_create :append_https
|
6
|
+
|
7
|
+
def create_unique_identifier
|
8
|
+
begin
|
9
|
+
self.shortlink = SecureRandom.hex(8)
|
10
|
+
end while self.class.exists?(:shortlink => shortlink)
|
11
|
+
end
|
12
|
+
|
13
|
+
def append_https
|
14
|
+
unless self.target =~ /http/i
|
15
|
+
self.target = "http://#{self.target}"
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Shortenizer
|
2
|
+
class UrlPresenter
|
3
|
+
|
4
|
+
def initialize url, request = nil
|
5
|
+
@url = url
|
6
|
+
@request = request
|
7
|
+
end
|
8
|
+
|
9
|
+
def full_url
|
10
|
+
mount_point = Shortenizer::MountPoint.new
|
11
|
+
if mount_point.at_root?
|
12
|
+
"#{@request.base_url}/#{@url.shortlink}"
|
13
|
+
else
|
14
|
+
"#{@request.base_url}#{mount_point.location}/#{@url.shortlink}"
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def shortlink
|
19
|
+
@url.shortlink
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>Shortenizer</title>
|
5
|
+
<%= stylesheet_link_tag "shortenizer/application", media: "all" %>
|
6
|
+
<%= javascript_include_tag "shortenizer/application" %>
|
7
|
+
<%= csrf_meta_tags %>
|
8
|
+
</head>
|
9
|
+
<body>
|
10
|
+
<div class='shortenizer wrapper'>
|
11
|
+
<div class='shortenizer flash-message'>
|
12
|
+
<%= flash[:message] if flash[:message] %>
|
13
|
+
</div>
|
14
|
+
|
15
|
+
<%= yield %>
|
16
|
+
</div>
|
17
|
+
|
18
|
+
</body>
|
19
|
+
</html>
|
@@ -0,0 +1,7 @@
|
|
1
|
+
<%= form_for :url, html: { class: 'shortenizer form' } do |f| %>
|
2
|
+
<%= f.text_field :target, value: @url.full_url %>
|
3
|
+
<%= link_to "Copy", '', class: 'btn-copy', id: 'btn-copy', data: { "clipboard-text" => @url.full_url }, onClick: 'return false' %>
|
4
|
+
<%= link_to "New", new_short_link_path, class: 'btn-new' %>
|
5
|
+
<% end %>
|
6
|
+
|
7
|
+
|
data/config/routes.rb
ADDED
@@ -0,0 +1,8 @@
|
|
1
|
+
Shortenizer::Engine.routes.draw do
|
2
|
+
root 'u#new'
|
3
|
+
|
4
|
+
match '/show', to: 'u#show', via: :get
|
5
|
+
match '/shorten', to: 'u#new', via: :get, as: :new_short_link
|
6
|
+
match '/create', to: 'u#create', via: :post, as: :create_short_link
|
7
|
+
match '/:shortlink', to: 'u#index', via: :get
|
8
|
+
end
|
data/lib/shortenizer.rb
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
require_relative 'mount_point'
|
2
|
+
require 'jquery-rails'
|
3
|
+
require 'zeroclipboard-rails'
|
4
|
+
|
5
|
+
module Shortenizer
|
6
|
+
class Engine < ::Rails::Engine
|
7
|
+
isolate_namespace Shortenizer
|
8
|
+
|
9
|
+
config.generators do |g|
|
10
|
+
g.test_framework :rspec, :fixture => false
|
11
|
+
g.fixture_replacement :factory_girl, :dir => 'spec/factories'
|
12
|
+
g.assets false
|
13
|
+
g.helper false
|
14
|
+
end
|
15
|
+
|
16
|
+
initializer :append_migrations do |app|
|
17
|
+
unless app.root.to_s.match root.to_s
|
18
|
+
config.paths["db/migrate"].expanded.each do |expanded_path|
|
19
|
+
app.config.paths["db/migrate"] << expanded_path
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
== README
|
2
|
+
|
3
|
+
This README would normally document whatever steps are necessary to get the
|
4
|
+
application up and running.
|
5
|
+
|
6
|
+
Things you may want to cover:
|
7
|
+
|
8
|
+
* Ruby version
|
9
|
+
|
10
|
+
* System dependencies
|
11
|
+
|
12
|
+
* Configuration
|
13
|
+
|
14
|
+
* Database creation
|
15
|
+
|
16
|
+
* Database initialization
|
17
|
+
|
18
|
+
* How to run the test suite
|
19
|
+
|
20
|
+
* Services (job queues, cache servers, search engines, etc.)
|
21
|
+
|
22
|
+
* Deployment instructions
|
23
|
+
|
24
|
+
* ...
|
25
|
+
|
26
|
+
|
27
|
+
Please feel free to use a different markup language if you do not plan to run
|
28
|
+
<tt>rake doc:app</tt>.
|