darjeelink 0.11.7 → 0.11.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 63e8111415e3c11dc2745f67ce99c154b81d6240219029060acfced765679508
4
- data.tar.gz: 1d3f6fd83547d183d3c2f0e7bcf89fc561b2a3c93da7a05715f5679d92e0c984
3
+ metadata.gz: 5f077cd42297ac6611f454687f572c0ba3b2b5b0e6adbaedbbcae1bd905b16c8
4
+ data.tar.gz: 5b7879fc14f7e65438b3196a20f05d3a052f43aa3959617f8cb0276c59a7aaf1
5
5
  SHA512:
6
- metadata.gz: a0b3ec0270dca0e055a2c9feec467d0a9d26433e5b4c11a166b63f8eb53479a1bef926a16616bbc32ac40b1a54e8ac6023fca0517bc685a6a32aeebdc4a72a66
7
- data.tar.gz: 3c53ab8eeae32482df7ba4ea4961928fd6627dbe56c7c7f50e0c11163e172729b1ff3bcf080874ba9fcc5fc1b8fb5589e61f553b39f7b1acdcce3fdc4f620232
6
+ metadata.gz: 5a69637a14edf0be055e45e615117c794dfc5bb6d86661d1e92105d56dc874a12542a667fc0f27a5edc983c0e26662f5411cb01c99b82278356f1b91011e9319
7
+ data.tar.gz: 46d895118941de94c2b2134d809003d7c63c3acbb6fb0e581ad4c23b27c818f3c70d9cf1ee77ad00407a3be83111915429c735630ba597161c7290ed99ac6f84
data/README.md CHANGED
@@ -19,17 +19,6 @@ There is a UTM generator, where you can provide:
19
19
  - a campaign identifier
20
20
  And you can get a link with UTM params all filled in, and shortern it with one click.
21
21
 
22
- ## Development
23
- The recommended approach is to use Vagrant. `vagrant up` will create an isolated darjeelink instance
24
-
25
- ### Setup development environment
26
- Run `cp .env.sample spec/dummy/.env.development`
27
- Nothing else required
28
-
29
- ### Setup test environment
30
- Run `cp .env.sample spec/dummy/.env.test`
31
- Change the database url to be different to the development one i.e. `postgres://darjeelink_dbuser:password@localhost/darjeelink-test`
32
-
33
22
  ## Installation
34
23
  ### Gemfile
35
24
  Add these lines to your app's Gemfile
@@ -67,7 +56,21 @@ In `config/initializers/darjeelink.rb` edit the `config.source_mediums` hash.
67
56
 
68
57
  Each key is a hyphenated source-medium. If you just want the source then omit the hyphen and medium.
69
58
 
70
- Each value is a slightly more readable version for display
59
+ Each value is a slightly more readable version for display.
60
+
61
+ ## Development
62
+ The recommended approach is to use Vagrant. `vagrant up` will create an isolated darjeelink instance.
63
+ Before you run `vagrant up`, make sure to create `.env.development` & `.env.test` files as detailed below.
64
+
65
+ ### Setup development environment
66
+ Run `cp .env.sample spec/dummy/.env.development`
67
+
68
+ Nothing else required
69
+
70
+ ### Setup test environment
71
+ Run `cp .env.sample spec/dummy/.env.test`
72
+
73
+ Change the database url to be different to the development one i.e. `postgres://darjeelink_dbuser:password@localhost/darjeelink-test`
71
74
 
72
75
  ## GDPR
73
76
  No personally identifiable data is stored about the public by this gem.
@@ -1,5 +1,10 @@
1
1
  function generateTrackingLink(){
2
- var url = $('#url').val();
2
+ var url = $('#base-url').val();
3
+ if (!url) {
4
+ document.getElementById("long_url").value = "";
5
+ return;
6
+ }
7
+
3
8
  var sourceMedium = $('#source-medium').val();
4
9
  var source = sourceMedium.split('-')[0];
5
10
  var medium = sourceMedium.split('-')[1];
@@ -28,7 +33,7 @@ $(document).ready(function(){
28
33
  generateTrackingLink();
29
34
  });
30
35
 
31
- $("#tracking").keypress(function(){
36
+ $("#tracking").keyup(function(){
32
37
  generateTrackingLink();
33
38
  });
34
39
 
@@ -5,8 +5,8 @@ module Darjeelink
5
5
  skip_before_action :check_ip_whitelist, only: :show
6
6
  skip_before_action :authenticate, only: :show
7
7
 
8
- before_action :check_url_present, only: :create
9
- before_action :check_url_valid, only: :create
8
+ before_action :check_url_present, only: %i[create update]
9
+ before_action :check_url_valid, only: %i[create update]
10
10
 
11
11
  class ShortLinkNotFoundError < StandardError
12
12
  end
@@ -18,17 +18,13 @@ module Darjeelink
18
18
  end
19
19
 
20
20
  def new
21
+ @short_link = Darjeelink::ShortLink.new
21
22
  end
22
23
 
23
24
  def create
24
- begin
25
- Darjeelink::ShortLink.create!(url: params[:url], shortened_path: params[:shortened_path])
26
- rescue ActiveRecord::RecordNotUnique
27
- flash[:error] = "#{params[:shortened_path]} already used! Choose a different custom path"
28
- return redirect_to(darjeelink.new_short_link_path)
25
+ handle_create_or_update(error_redirect_path: darjeelink.new_short_link_path) do
26
+ Darjeelink::ShortLink.create!(short_link_params)
29
27
  end
30
-
31
- redirect_to(darjeelink.short_links_path)
32
28
  end
33
29
 
34
30
  def edit
@@ -37,9 +33,10 @@ module Darjeelink
37
33
 
38
34
  def update
39
35
  @short_link = Darjeelink::ShortLink.find(params[:id])
40
- @short_link.update!(short_link_params)
41
36
 
42
- redirect_to(darjeelink.short_links_path)
37
+ handle_create_or_update(error_redirect_path: darjeelink.edit_short_link_path(@short_link)) do
38
+ @short_link.update!(short_link_params)
39
+ end
43
40
  end
44
41
 
45
42
  def show
@@ -57,6 +54,22 @@ module Darjeelink
57
54
 
58
55
  private
59
56
 
57
+ def handle_create_or_update(error_redirect_path:)
58
+ return unless block_given?
59
+
60
+ begin
61
+ yield
62
+ rescue ActiveRecord::RecordNotUnique
63
+ flash[:error] = "#{params[:shortened_path]} already used! Choose a different custom path"
64
+ return redirect_to(error_redirect_path)
65
+ rescue ActiveRecord::RecordInvalid => e
66
+ flash[:error] = e.message.to_s
67
+ return redirect_to(error_redirect_path)
68
+ end
69
+
70
+ redirect_to(darjeelink.short_links_path)
71
+ end
72
+
60
73
  def log_missing_shortlink(shortened_path)
61
74
  Rails.logger.warn("ShortLink not found: #{shortened_path}")
62
75
  end
@@ -95,14 +108,14 @@ module Darjeelink
95
108
  end
96
109
 
97
110
  def check_url_present
98
- return if params[:url].present?
111
+ return if params[:short_link].present? && params[:short_link][:url].present?
99
112
 
100
113
  flash[:error] = 'URL cannot be blank'
101
114
  redirect_to(darjeelink.new_short_link_path)
102
115
  end
103
116
 
104
117
  def check_url_valid
105
- return if params[:url] =~ URI::DEFAULT_PARSER.make_regexp
118
+ return if params[:short_link].present? && params[:short_link][:url] =~ URI::DEFAULT_PARSER.make_regexp
106
119
 
107
120
  flash[:error] = 'URL is not valid. Does it have https:// and are there any spaces?'
108
121
  redirect_to(darjeelink.new_short_link_path)
@@ -3,6 +3,7 @@
3
3
  module Darjeelink
4
4
  class TrackingLinksController < Darjeelink::ApplicationController
5
5
  def new
6
+ @short_link = Darjeelink::ShortLink.new
6
7
  end
7
8
  end
8
9
  end
@@ -3,9 +3,12 @@
3
3
  module Darjeelink
4
4
  class ShortLink < ApplicationRecord
5
5
  after_save :generate_short_link
6
- before_validation :strip_white_space
7
6
 
8
7
  validates_presence_of :url
8
+ validates :url, :shortened_path, format: {
9
+ without: /\s/,
10
+ message: 'must not contain any whitespace (spaces, tabs, etc)'
11
+ }
9
12
 
10
13
  class << self
11
14
  def search(query)
@@ -49,10 +52,5 @@ module Darjeelink
49
52
 
50
53
  generated_path.join('').reverse
51
54
  end
52
-
53
- def strip_white_space
54
- url&.strip!
55
- shortened_path&.strip!
56
- end
57
55
  end
58
56
  end
@@ -7,18 +7,21 @@
7
7
  </div>
8
8
  <% end %>
9
9
 
10
- <%= form_with url: darjeelink.short_links_path, local: true do |f| %>
11
- <div class="form-group">
12
- <label for="url">Url</label>
13
- <input type="url" class="form-control" id="long_url" name="url">
14
- </div>
15
- <div class="form-group">
16
- <label for="shortened_path">Custom Path</label>
17
- <input type="text" class="form-control" name="shortened_path">
18
- </div>
19
- <div>
20
- <button type="submit">Shorten</button>
21
- </div>
22
- <% end %>
10
+ <div class="form-group">
11
+ <%= f.label :url %>
12
+ <%= f.url_field :url,
13
+ class: "form-control", id: 'long_url', value: short_link.url, required: true,
14
+ pattern: 'https?://[^\s]+', placeholder: 'https://www.example.com',
15
+ title: 'URL, starting http:// or https:// - no whitespace (space, tab, etc) allowed'
16
+ %>
17
+ </div>
18
+
19
+ <div class="form-group">
20
+ <%= f.label :custom_path %>
21
+ <%= f.text_field :shortened_path,
22
+ class: "form-control", id: 'shortened_path', value: short_link.shortened_path,
23
+ pattern: '[^\s]*', title: 'Short path - no whitespace (space, tab, etc) allowed'
24
+ %>
25
+ </div>
23
26
  </div>
24
27
  </div>
@@ -13,16 +13,9 @@
13
13
  <div class="row">
14
14
  <div class="col-md-12">
15
15
  <%= form_for @short_link, url: darjeelink.short_link_path do |f| %>
16
- <div class="form-group">
17
- <%= f.label :url %>
18
- <%= f.url_field :url, class: "form-control", value: @short_link.url %>
19
- </div>
20
- <div class="form-group">
21
- <%= f.label :custom_path %>
22
- <%= f.text_field :shortened_path, class: "form-control", value: @short_link.shortened_path %>
23
- </div>
16
+ <%= render partial: 'short_link_form', locals: { f: f, short_link: @short_link } %>
24
17
  <div>
25
- <button type="submit">Update</button>
18
+ <%= f.submit "Update Shortlink", class: "btn btn-primary" %>
26
19
  </div>
27
20
  <% end %>
28
21
  </div>
@@ -9,4 +9,9 @@
9
9
  <h1>New Short Link</h1>
10
10
  </div>
11
11
  </div>
12
- <%= render partial: 'short_link_form' %>
12
+ <%= form_for @short_link, url: darjeelink.short_links_path, local: true do |f| %>
13
+ <%= render partial: 'short_link_form', locals: { f: f, short_link: @short_link } %>
14
+ <div>
15
+ <%= f.submit "Create Shortlink", class: "btn btn-primary" %>
16
+ </div>
17
+ <% end %>
@@ -14,35 +14,46 @@
14
14
  </div>
15
15
  </div>
16
16
 
17
- <div class="row">
18
- <div class="col-md-12">
19
- <form id="tracking">
17
+ <%= form_for @short_link, url: darjeelink.short_links_path, local: true do |f| %>
18
+ <div class="row" id="tracking">
19
+ <div class="col-md-12">
20
20
  <div class="form-group">
21
- <label for="url">URL</label>
22
- <input type="text" class="form-control" id="url">
23
- <label for="source">Source - Medium</label>
24
- <select class="form-control" id="source-medium">
25
- <% Darjeelink.source_mediums.each do |key, value| %>
26
- <option value="<%= key %>"><%= value %></option>
27
- <% end %>
21
+ <label for="base-url">URL</label>
22
+ <input
23
+ type="text" class="form-control" id="base-url" name="base-url" required=true
24
+ pattern="https?://[^\s]+" placeholder="https://www.example.com"
25
+ title="URL, starting http:// or https:// - no whitespace (space, tab, etc) allowed"
26
+ >
27
+
28
+ <label for="source-medium">Source - Medium</label>
29
+ <select class="form-control" id="source-medium" name="source-medium">
30
+ <%= options_for_select(Darjeelink.source_mediums.map { |k,v| [v,k] }) %>
28
31
  </select>
32
+
29
33
  <label for="campaign">ID / Identifier (lower-case, underscores only)</label>
30
- <input type="text" class="form-control" id="campaign">
34
+ <input
35
+ type="text" class="form-control" id="campaign" name="campaign" pattern="[^\s]*"
36
+ title="ID for the campaign - no whitespace (space, tab, etc) allowed"
37
+ >
31
38
  </div>
32
- </form>
39
+ </div>
33
40
  </div>
34
- </div>
35
41
 
36
- <div class="row">
37
- <div class="col-md-12">
38
- <h2>Your tracking link</h2>
39
- <button id="copy-btn" class="btn btn-info btn-sm" data-clipboard-target="#long_url">
40
- <span class="glyphicon glyphicon-copy"></span>
41
- </button>
42
+ <div class="row">
43
+ <div class="col-md-12">
44
+ <h2>Your tracking link</h2>
45
+ <button id="copy-btn" class="btn btn-info btn-sm" data-clipboard-target="#long_url">
46
+ <span class="glyphicon glyphicon-copy"></span>
47
+ </button>
48
+ </div>
42
49
  </div>
43
- </div>
44
50
 
45
- <%= render partial: 'darjeelink/short_links/short_link_form' %>
51
+ <%= render partial: 'darjeelink/short_links/short_link_form', locals: { f: f, short_link: @short_link } %>
52
+
53
+ <div>
54
+ <%= f.submit "Create Tracking Link", class: "btn btn-primary" %>
55
+ </div>
56
+ <% end %>
46
57
 
47
58
  <script>
48
59
  new ClipboardJS('#copy-btn');
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Darjeelink
4
- VERSION = '0.11.7'
4
+ VERSION = '0.11.8'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: darjeelink
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.11.7
4
+ version: 0.11.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Hulme
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-06-16 00:00:00.000000000 Z
11
+ date: 2020-06-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: omniauth-google-oauth2
@@ -228,8 +228,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
228
228
  - !ruby/object:Gem::Version
229
229
  version: '0'
230
230
  requirements: []
231
- rubyforge_project:
232
- rubygems_version: 2.7.8
231
+ rubygems_version: 3.0.8
233
232
  signing_key:
234
233
  specification_version: 4
235
234
  summary: URL Shortener