diff --git a/.browserslistrc b/.browserslistrc new file mode 100644 index 0000000..e94f814 --- /dev/null +++ b/.browserslistrc @@ -0,0 +1 @@ +defaults diff --git a/.gitignore b/.gitignore index 65e6478..1af0556 100644 --- a/.gitignore +++ b/.gitignore @@ -1,21 +1,31 @@ -# See https://help.github.com/articles/ignoring-files for more about ignoring files. -# -# If you find yourself ignoring temporary files generated by your text editor -# or operating system, you probably want to add a global ignore instead: -# git config --global core.excludesfile '~/.gitignore_global' - -# Ignore bundler config. -/.bundle - -# Ignore the default SQLite database. -/db/*.sqlite3 -/db/*.sqlite3-journal - -# Ignore all logfiles and tempfiles. -/log/* -!/log/.keep -/tmp -/.idea/* -.idea/.generators -.DS_Store +# See https://help.github.com/articles/ignoring-files for more about ignoring files. +# +# If you find yourself ignoring temporary files generated by your text editor +# or operating system, you probably want to add a global ignore instead: +# git config --global core.excludesfile '~/.gitignore_global' + +# Ignore bundler config. +/.bundle + +# Ignore the default SQLite database. +/db/*.sqlite3 +/db/*.sqlite3-journal + +# Ignore all logfiles and tempfiles. +/log/* +!/log/.keep +/tmp +/.idea/* +.idea/.generators +.DS_Store *.pem +public/assets/* +vendor/bundle/* +linkhack.pid + +/public/packs +/public/packs-test +/node_modules +/yarn-error.log +yarn-debug.log* +.yarn-integrity diff --git a/.ruby-version b/.ruby-version new file mode 100644 index 0000000..0444f32 --- /dev/null +++ b/.ruby-version @@ -0,0 +1 @@ +3.2.1 \ No newline at end of file diff --git a/Gemfile b/Gemfile index f9b0fff..7d87b26 100644 --- a/Gemfile +++ b/Gemfile @@ -1,40 +1,41 @@ source 'https://rubygems.org' - # Bundle edge Rails instead: gem 'rails', github: 'rails/rails' -gem 'rails', '~> 5.0.3' +gem 'rails', '~> 6.1.7.4' # Use sqlite3 as the database for Active Record -gem 'sqlite3' +gem 'sqlite3', '~> 1.6' # Use SCSS for stylesheets -gem 'sass-rails', '~> 5.0' +gem 'sass-rails', '~> 6.0' # Use Uglifier as compressor for JavaScript assets gem 'uglifier', '>= 1.3.0' # Use CoffeeScript for .coffee assets and views -gem 'coffee-rails' +gem 'coffee-rails', '~> 5.0.0' # See https://github.com/sstephenson/execjs#readme for more supported runtimes # gem 'therubyracer', platforms: :ruby -gem 'levenshtein-ffi', :require => 'levenshtein' - # Add URL validation gem 'validate_url' -gem 'rack-cors', :require => 'rack/cors' +gem 'webpacker', '~> 5.4.4' + +gem 'rack-cors', '~> 1.1.0', require: 'rack/cors' # 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 -gem 'turbolinks' +gem 'jquery-rails', '~> 4.4.0' # Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder gem 'jbuilder', '~> 2.0' # bundle exec rake doc:rails generates the API under doc/api. -gem 'sdoc', '~> 0.4.0', group: :doc +gem 'sdoc', '~> 2.6', group: :doc gem 'bootstrap-sass' gem 'autoprefixer-rails' +gem 'mini_racer', '~> 0.6.3' gem 'will_paginate' # Use ActiveModel has_secure_password # gem 'bcrypt', '~> 3.1.7' +gem 'puma', '~> 6.1' +gem 'listen', '~> 3.8' + # Use Unicorn as the app server # gem 'unicorn' @@ -46,7 +47,7 @@ group :development, :test do gem 'byebug' # Access an IRB console on exception pages or by using <%= console %> in views - gem 'web-console' + gem 'web-console', '~> 3.7.0' # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring gem 'spring' diff --git a/Gemfile.lock b/Gemfile.lock index 9b2701f..c4b1bf9 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,214 +1,275 @@ GEM remote: https://rubygems.org/ specs: - actioncable (5.0.6) - actionpack (= 5.0.6) - nio4r (>= 1.2, < 3.0) - websocket-driver (~> 0.6.1) - actionmailer (5.0.6) - actionpack (= 5.0.6) - actionview (= 5.0.6) - activejob (= 5.0.6) + actioncable (6.1.7.4) + actionpack (= 6.1.7.4) + activesupport (= 6.1.7.4) + nio4r (~> 2.0) + websocket-driver (>= 0.6.1) + actionmailbox (6.1.7.4) + actionpack (= 6.1.7.4) + activejob (= 6.1.7.4) + activerecord (= 6.1.7.4) + activestorage (= 6.1.7.4) + activesupport (= 6.1.7.4) + mail (>= 2.7.1) + actionmailer (6.1.7.4) + actionpack (= 6.1.7.4) + actionview (= 6.1.7.4) + activejob (= 6.1.7.4) + activesupport (= 6.1.7.4) mail (~> 2.5, >= 2.5.4) rails-dom-testing (~> 2.0) - actionpack (5.0.6) - actionview (= 5.0.6) - activesupport (= 5.0.6) - rack (~> 2.0) - rack-test (~> 0.6.3) + actionpack (6.1.7.4) + actionview (= 6.1.7.4) + activesupport (= 6.1.7.4) + rack (~> 2.0, >= 2.0.9) + rack-test (>= 0.6.3) rails-dom-testing (~> 2.0) - rails-html-sanitizer (~> 1.0, >= 1.0.2) - actionview (5.0.6) - activesupport (= 5.0.6) + rails-html-sanitizer (~> 1.0, >= 1.2.0) + actiontext (6.1.7.4) + actionpack (= 6.1.7.4) + activerecord (= 6.1.7.4) + activestorage (= 6.1.7.4) + activesupport (= 6.1.7.4) + nokogiri (>= 1.8.5) + actionview (6.1.7.4) + activesupport (= 6.1.7.4) builder (~> 3.1) - erubis (~> 2.7.0) + erubi (~> 1.4) rails-dom-testing (~> 2.0) - rails-html-sanitizer (~> 1.0, >= 1.0.3) - activejob (5.0.6) - activesupport (= 5.0.6) + rails-html-sanitizer (~> 1.1, >= 1.2.0) + activejob (6.1.7.4) + activesupport (= 6.1.7.4) globalid (>= 0.3.6) - activemodel (5.0.6) - activesupport (= 5.0.6) - activerecord (5.0.6) - activemodel (= 5.0.6) - activesupport (= 5.0.6) - arel (~> 7.0) - activesupport (5.0.6) + activemodel (6.1.7.4) + activesupport (= 6.1.7.4) + activerecord (6.1.7.4) + activemodel (= 6.1.7.4) + activesupport (= 6.1.7.4) + activestorage (6.1.7.4) + actionpack (= 6.1.7.4) + activejob (= 6.1.7.4) + activerecord (= 6.1.7.4) + activesupport (= 6.1.7.4) + marcel (~> 1.0) + mini_mime (>= 1.1.0) + activesupport (6.1.7.4) concurrent-ruby (~> 1.0, >= 1.0.2) - i18n (~> 0.7) - minitest (~> 5.1) - tzinfo (~> 1.1) - addressable (2.5.2) - public_suffix (>= 2.0.2, < 4.0) - annotate (2.7.2) - activerecord (>= 3.2, < 6.0) - rake (>= 10.4, < 13.0) - arel (7.1.4) - autoprefixer-rails (7.2.5) + i18n (>= 1.6, < 2) + minitest (>= 5.1) + tzinfo (~> 2.0) + zeitwerk (~> 2.3) + annotate (3.1.1) + activerecord (>= 3.2, < 7.0) + rake (>= 10.4, < 14.0) + autoprefixer-rails (10.2.4.0) execjs - bindex (0.5.0) - bootstrap-sass (3.3.7) + bindex (0.8.1) + bootstrap-sass (3.4.1) autoprefixer-rails (>= 5.2.1) - sass (>= 3.3.4) - builder (3.2.3) - byebug (9.1.0) - coffee-rails (4.2.2) + sassc (>= 2.0.0) + builder (3.2.4) + byebug (11.1.3) + coffee-rails (5.0.0) coffee-script (>= 2.2.0) - railties (>= 4.0.0) + railties (>= 5.2.0) coffee-script (2.4.1) coffee-script-source execjs coffee-script-source (1.12.2) - concurrent-ruby (1.0.5) - crass (1.0.3) - diff-lcs (1.3) - erubis (2.7.0) + concurrent-ruby (1.2.0) + crass (1.0.6) + date (3.3.3) + diff-lcs (1.4.4) + erubi (1.12.0) execjs (2.7.0) - ffi (1.9.18) - globalid (0.4.1) - activesupport (>= 4.2.0) - i18n (0.9.3) + ffi (1.15.0) + globalid (1.1.0) + activesupport (>= 5.0) + i18n (1.12.0) concurrent-ruby (~> 1.0) - jbuilder (2.7.0) - activesupport (>= 4.2.0) - multi_json (>= 1.2) - jquery-rails (4.3.1) + jbuilder (2.11.2) + activesupport (>= 5.0.0) + jquery-rails (4.4.0) rails-dom-testing (>= 1, < 3) railties (>= 4.2.0) thor (>= 0.14, < 2.0) - json (1.8.6) - levenshtein-ffi (1.1.0) - ffi (~> 1.9) - loofah (2.1.1) + libv8-node (16.10.0.0-arm64-darwin) + libv8-node (16.10.0.0-x86_64-darwin) + libv8-node (16.10.0.0-x86_64-darwin-19) + libv8-node (16.10.0.0-x86_64-linux) + listen (3.8.0) + rb-fsevent (~> 0.10, >= 0.10.3) + rb-inotify (~> 0.9, >= 0.9.10) + loofah (2.19.1) crass (~> 1.0.2) nokogiri (>= 1.5.9) - mail (2.7.0) + mail (2.8.1) mini_mime (>= 0.1.1) - method_source (0.9.0) - mini_mime (1.0.0) - mini_portile2 (2.3.0) - minitest (5.11.1) - multi_json (1.13.1) - nio4r (2.2.0) - nokogiri (1.8.1) - mini_portile2 (~> 2.3.0) - public_suffix (3.0.1) - rack (2.0.3) - rack-cors (1.0.2) - rack-test (0.6.3) - rack (>= 1.0) - rails (5.0.6) - actioncable (= 5.0.6) - actionmailer (= 5.0.6) - actionpack (= 5.0.6) - actionview (= 5.0.6) - activejob (= 5.0.6) - activemodel (= 5.0.6) - activerecord (= 5.0.6) - activesupport (= 5.0.6) - bundler (>= 1.3.0) - railties (= 5.0.6) + net-imap + net-pop + net-smtp + marcel (1.0.2) + method_source (1.0.0) + mini_mime (1.1.2) + mini_racer (0.6.3) + libv8-node (~> 16.10.0.0) + minitest (5.17.0) + net-imap (0.3.6) + date + net-protocol + net-pop (0.1.2) + net-protocol + net-protocol (0.2.1) + timeout + net-smtp (0.3.3) + net-protocol + nio4r (2.5.8) + nokogiri (1.14.2-arm64-darwin) + racc (~> 1.4) + nokogiri (1.14.2-x86_64-darwin) + racc (~> 1.4) + nokogiri (1.14.2-x86_64-linux) + racc (~> 1.4) + psych (5.1.0) + stringio + public_suffix (4.0.6) + puma (6.1.0) + nio4r (~> 2.0) + racc (1.6.2) + rack (2.2.6.4) + rack-cors (1.1.1) + rack (>= 2.0.0) + rack-proxy (0.7.6) + rack + rack-test (2.0.2) + rack (>= 1.3) + rails (6.1.7.4) + actioncable (= 6.1.7.4) + actionmailbox (= 6.1.7.4) + actionmailer (= 6.1.7.4) + actionpack (= 6.1.7.4) + actiontext (= 6.1.7.4) + actionview (= 6.1.7.4) + activejob (= 6.1.7.4) + activemodel (= 6.1.7.4) + activerecord (= 6.1.7.4) + activestorage (= 6.1.7.4) + activesupport (= 6.1.7.4) + bundler (>= 1.15.0) + railties (= 6.1.7.4) sprockets-rails (>= 2.0.0) rails-dom-testing (2.0.3) activesupport (>= 4.2.0) nokogiri (>= 1.6) - rails-html-sanitizer (1.0.3) - loofah (~> 2.0) - railties (5.0.6) - actionpack (= 5.0.6) - activesupport (= 5.0.6) + rails-html-sanitizer (1.5.0) + loofah (~> 2.19, >= 2.19.1) + railties (6.1.7.4) + actionpack (= 6.1.7.4) + activesupport (= 6.1.7.4) method_source - rake (>= 0.8.7) - thor (>= 0.18.1, < 2.0) - rake (12.3.0) - rb-fsevent (0.10.2) - rb-inotify (0.9.10) - ffi (>= 0.5.0, < 2) - rdoc (4.3.0) - rspec (3.7.0) - rspec-core (~> 3.7.0) - rspec-expectations (~> 3.7.0) - rspec-mocks (~> 3.7.0) - rspec-core (3.7.1) - rspec-support (~> 3.7.0) - rspec-expectations (3.7.0) + rake (>= 12.2) + thor (~> 1.0) + rake (13.0.6) + rb-fsevent (0.10.4) + rb-inotify (0.10.1) + ffi (~> 1.0) + rdoc (6.5.0) + psych (>= 4.0.0) + rspec (3.10.0) + rspec-core (~> 3.10.0) + rspec-expectations (~> 3.10.0) + rspec-mocks (~> 3.10.0) + rspec-core (3.10.1) + rspec-support (~> 3.10.0) + rspec-expectations (3.10.1) diff-lcs (>= 1.2.0, < 2.0) - rspec-support (~> 3.7.0) - rspec-mocks (3.7.0) + rspec-support (~> 3.10.0) + rspec-mocks (3.10.2) diff-lcs (>= 1.2.0, < 2.0) - rspec-support (~> 3.7.0) - rspec-support (3.7.0) - sass (3.5.5) - sass-listen (~> 4.0.0) - sass-listen (4.0.0) - rb-fsevent (~> 0.9, >= 0.9.4) - rb-inotify (~> 0.9, >= 0.9.7) - sass-rails (5.0.7) - railties (>= 4.0.0, < 6) - sass (~> 3.1) - sprockets (>= 2.8, < 4.0) - sprockets-rails (>= 2.0, < 4.0) - tilt (>= 1.1, < 3) - sdoc (0.4.2) - json (~> 1.7, >= 1.7.7) - rdoc (~> 4.0) - spring (2.0.2) - activesupport (>= 4.2) - sprockets (3.7.1) + rspec-support (~> 3.10.0) + rspec-support (3.10.2) + sass-rails (6.0.0) + sassc-rails (~> 2.1, >= 2.1.1) + sassc (2.4.0) + ffi (~> 1.9) + sassc-rails (2.1.2) + railties (>= 4.0.0) + sassc (>= 2.0) + sprockets (> 3.0) + sprockets-rails + tilt + sdoc (2.6.1) + rdoc (>= 5.0) + semantic_range (3.0.0) + spring (2.1.1) + sprockets (3.7.2) concurrent-ruby (~> 1.0) rack (> 1, < 3) - sprockets-rails (3.2.1) - actionpack (>= 4.0) - activesupport (>= 4.0) + sprockets-rails (3.4.2) + actionpack (>= 5.2) + activesupport (>= 5.2) sprockets (>= 3.0.0) - sqlite3 (1.3.13) - thor (0.20.0) - thread_safe (0.3.6) - tilt (2.0.8) - turbolinks (5.1.0) - turbolinks-source (~> 5.1) - turbolinks-source (5.1.0) - tzinfo (1.2.4) - thread_safe (~> 0.1) - uglifier (4.1.4) + sqlite3 (1.6.0-arm64-darwin) + sqlite3 (1.6.0-x86_64-darwin) + sqlite3 (1.6.0-x86_64-linux) + stringio (3.0.5) + thor (1.2.1) + tilt (2.0.11) + timeout (0.4.0) + tzinfo (2.0.6) + concurrent-ruby (~> 1.0) + uglifier (4.2.0) execjs (>= 0.3.0, < 3) - validate_url (1.0.2) + validate_url (1.0.13) activemodel (>= 3.0.0) - addressable - web-console (3.5.1) + public_suffix + web-console (3.7.0) actionview (>= 5.0) activemodel (>= 5.0) bindex (>= 0.4.0) railties (>= 5.0) - websocket-driver (0.6.5) + webpacker (5.4.4) + activesupport (>= 5.2) + rack-proxy (>= 0.6.1) + railties (>= 5.2) + semantic_range (>= 2.3.0) + websocket-driver (0.7.5) websocket-extensions (>= 0.1.0) - websocket-extensions (0.1.3) - will_paginate (3.1.6) + websocket-extensions (0.1.5) + will_paginate (3.3.0) + zeitwerk (2.6.7) PLATFORMS - ruby + arm64-darwin-22 + x86_64-darwin-19 + x86_64-darwin-20 + x86_64-linux DEPENDENCIES annotate autoprefixer-rails bootstrap-sass byebug - coffee-rails + coffee-rails (~> 5.0.0) jbuilder (~> 2.0) - jquery-rails - levenshtein-ffi - rack-cors - rails (~> 5.0.3) + jquery-rails (~> 4.4.0) + listen (~> 3.8) + mini_racer (~> 0.6.3) + puma (~> 6.1) + rack-cors (~> 1.1.0) + rails (~> 6.1.7.4) rspec - sass-rails (~> 5.0) - sdoc (~> 0.4.0) + sass-rails (~> 6.0) + sdoc (~> 2.6) spring - sqlite3 - turbolinks + sqlite3 (~> 1.6) uglifier (>= 1.3.0) validate_url - web-console + web-console (~> 3.7.0) + webpacker (~> 5.4.4) will_paginate BUNDLED WITH - 1.15.4 + 2.4.7 diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index b9e4ee5..67cab93 100644 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -12,6 +12,5 @@ // //= require jquery //= require jquery_ujs -//= require turbolinks //= require bootstrap-sprockets //= require_tree . diff --git a/app/controllers/links_controller.rb b/app/controllers/links_controller.rb index fcda4e2..792a68d 100644 --- a/app/controllers/links_controller.rb +++ b/app/controllers/links_controller.rb @@ -13,7 +13,7 @@ def show end def new - return unless params.member? :link + return unless params.key? :link @relevant_links = Link .levenshtein_distances(link_params[:shortlink]) @@ -57,6 +57,6 @@ def load_link end def link_params - params.require(:link).permit(:url, :shortlink, :argsstr, :description, :type) + params.permit(:url, :shortlink, :argsstr, :description, :type) end end diff --git a/app/javascript/packs/application.js b/app/javascript/packs/application.js new file mode 100644 index 0000000..7c3021d --- /dev/null +++ b/app/javascript/packs/application.js @@ -0,0 +1,18 @@ +/* eslint no-console:0 */ +// This file is automatically compiled by Webpack, along with any other files +// present in this directory. You're encouraged to place your actual application logic in +// a relevant structure within app/javascript and only use these pack files to reference +// that code so it'll be compiled. +// +// To reference this file, add <%= javascript_pack_tag 'application' %> to the appropriate +// layout file, like app/views/layouts/application.html.erb + + +// Uncomment to copy all static images under ../images to the output folder and reference +// them with the image_pack_tag helper in views (e.g <%= image_pack_tag 'rails.png' %>) +// or the `imagePath` JavaScript helper below. +// +// const images = require.context('../images', true) +// const imagePath = (name) => images(name, true) + +console.log('Hello World from Webpacker') diff --git a/app/models/link.rb b/app/models/link.rb index 2a43e7a..2330c34 100644 --- a/app/models/link.rb +++ b/app/models/link.rb @@ -1,5 +1,4 @@ require 'uri' -require 'levenshtein' class Link < ActiveRecord::Base validates :shortlink, presence: true, uniqueness: true diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 20a167e..c537e79 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -2,8 +2,8 @@ Linkhack - <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %> - <%= javascript_include_tag 'application', 'data-turbolinks-track' => true %> + <%= stylesheet_link_tag 'application', media: 'all' %> + <%= javascript_include_tag 'application' %> <%= csrf_meta_tags %> diff --git a/app/views/links/edit.html.erb b/app/views/links/edit.html.erb index 4bdfc69..2b99b2f 100644 --- a/app/views/links/edit.html.erb +++ b/app/views/links/edit.html.erb @@ -8,29 +8,29 @@ <% end %>
- <%= form_for :link, url: link_path(@link), method: :patch do |l| %> + <%= form_with url: link_path(@link), method: :patch do |l| %>
<% if @link.type %>Yes<% else %>No<% end %>
- <%= l.text_field :shortlink, class: "form-control" %> + <%= l.text_field :shortlink, class: "form-control", value: @link.shortlink %> The code you'll use to redirect to your chosen site (go/MY_SHORTLINK)
- <%= l.text_field :url, class: "form-control" %> + <%= l.text_field :url, class: "form-control", value: @link.url %> The URL to which you want to redirect
- <%= l.text_field :argsstr, class: "form-control" %> + <%= l.text_field :argsstr, class: "form-control", value: @link.argsstr %> If you want, you can allow additional parameters to be passed to your url. Put an additional string here with a "%s" in it and anything after the second slash when using the shortlink will get insterted in place of the '%s' and then appended to the original URL.
- <%= l.text_area :description, class: "form-control" %> + <%= l.text_area :description, class: "form-control", value: @link.description %> Any information users of this link should know about.
<%= l.submit 'Save', class: "btn btn-primary" %> diff --git a/app/views/links/new.html.erb b/app/views/links/new.html.erb index 0694190..fb5572a 100644 --- a/app/views/links/new.html.erb +++ b/app/views/links/new.html.erb @@ -1,4 +1,5 @@

Create a new ShortLink!

+<%= debug @link %> <% if @link && @link.errors.any? %>

@@ -37,7 +38,7 @@