Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unsupported browsers #206

Merged
merged 5 commits into from
Aug 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,5 @@ yarn-debug.log*
.yarn-integrity
.yarn
.pnp.js

/browsers.json
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,5 @@ gem 'country_select'
gem 'browser'

gem 'meta-tags'

gem 'browserslist_useragent'
6 changes: 6 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,9 @@ GEM
msgpack (~> 1.0)
brakeman (5.1.1)
browser (5.3.1)
browserslist_useragent (0.2.0)
semantic
user_agent_parser
builder (3.2.4)
byebug (11.1.3)
capybara (3.35.3)
Expand Down Expand Up @@ -367,6 +370,7 @@ GEM
selenium-webdriver (3.142.7)
childprocess (>= 0.5, < 4.0)
rubyzip (>= 1.2.2)
semantic (1.6.1)
semantic_range (3.0.0)
sidekiq (6.2.1)
connection_pool (>= 2.2.2)
Expand Down Expand Up @@ -411,6 +415,7 @@ GEM
uber (0.1.0)
unicode-display_width (2.0.0)
unicode_utils (1.4.0)
user_agent_parser (2.7.0)
valid_email2 (4.0.0)
activemodel (>= 3.2)
mail (~> 2.5)
Expand Down Expand Up @@ -441,6 +446,7 @@ DEPENDENCIES
bootsnap
brakeman
browser
browserslist_useragent
byebug
capybara (>= 2.15)
configus
Expand Down
9 changes: 9 additions & 0 deletions app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -117,4 +117,13 @@ def get_continue_study_path(slug)
}
mapping.fetch(slug, ExternalLinks.hexlet_profession)
end

def supported_browser?
# NOTE https://github.com/browserslist/browserslist-useragent-ruby#3-add-helper
# rubocop:disable Rails/HelperInstanceVariable
@browsers ||= JSON.parse(File.read('browsers.json'))
matcher = BrowserslistUseragent::Match.new(@browsers, request.user_agent)
matcher.browser? && matcher.version?(allow_higher: true)
# rubocop:enable Rails/HelperInstanceVariable
end
end
2 changes: 2 additions & 0 deletions app/views/layouts/_frontend.html.slim
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- if supported_browser?
= render_javascript_stored_packs
2 changes: 2 additions & 0 deletions app/views/layouts/application.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ html.h-100 lang="#{I18n.locale}"
body.d-flex.flex-column.h-100
- if Rails.env.production?
= render 'layouts/deps/gtm_body'
- unless supported_browser?
= render 'layouts/shared/unsupported_browser_warning'
.container.mb-4
.py-2.border-bottom
= render 'layouts/shared/nav'
Expand Down
2 changes: 1 addition & 1 deletion app/views/layouts/shared/_footer.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,4 @@ footer.bg-dark.text-light.mt-5
a.rounded-circle target="_blank" rel="noopener noreferrer" href=ExternalLinks.hexlet_slack
span.bi.bi-slack.text-white-50

= render_javascript_stored_packs
= render 'layouts/frontend'
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.alert.alert-warning[role="alert"] = t('.unsupported_browser_warning')
2 changes: 1 addition & 1 deletion app/views/layouts/web/admin/application.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ html.h-100 lang="#{I18n.locale}"
= nav_menu_item t('.languages'), admin_languages_path
.col-md-10
= yield
= render_javascript_stored_packs
= render 'layouts/frontend'
4 changes: 3 additions & 1 deletion app/views/layouts/web/languages/lessons.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ html.x-h-md-100 lang="#{I18n.locale}"
= render 'layouts/shared/head'
= Gon::Base.render_data
body.d-flex.flex-column.x-h-md-100
- unless supported_browser?
= render 'layouts/shared/unsupported_browser_warning'
.container-fluid
= render 'layouts/shared/nav'
main.container-fluid.overflow-hidden.mb-1.x-h-md-100
= yield

= render_javascript_stored_packs
= render 'layouts/frontend'
2 changes: 2 additions & 0 deletions config/locales/en.layouts.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,5 @@ en:
recommended_books: Recommended Books
matrix: Matrix
source_code: Source code
unsupported_browser_warning:
unsupported_browser_warning: Browser is not supported. Some features may be disabled.
2 changes: 2 additions & 0 deletions config/locales/ru.layouts.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,5 @@ ru:
recommended_books: Рекомендуемые книги
matrix: Матрица компетентности
source_code: Исходный код
unsupported_browser_warning:
unsupported_browser_warning: Ваш браузер устарел :( Некоторые возможности отключены.
4 changes: 4 additions & 0 deletions config/webpack/environment.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
// @ts-check

const path = require('path');
const browserslist = require('browserslist');
const fs = require('fs');

fs.writeFileSync('./browsers.json', JSON.stringify(browserslist()));

module.exports = {
externals: {
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
"@babel/preset-env": "^7.14.8",
"@babel/preset-react": "^7.14.5",
"@webpack-cli/serve": "^1.5.1",
"browserslist": "^4.16.7",
"css-loader": "^6.2.0",
"eslint": "^7.31.0",
"eslint-config-airbnb": "^18.2.1",
Expand Down
2,210 changes: 1,105 additions & 1,105 deletions yarn.lock

Large diffs are not rendered by default.