Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/git/git-scm.com.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeff King <peff@peff.net>2022-10-05 22:28:17 +0300
committerGitHub <noreply@github.com>2022-10-05 22:28:17 +0300
commitb3f3aa2c67f72d530993d8d42f8967ec81defca8 (patch)
treeec87b1650667b2a210f4b042195e229b914593c1
parentc3f88338802a4c4c04841175bb95491e9f6eaae4 (diff)
parent577fe33138c1c8a635266aa7143d044b46ed8806 (diff)
Merge pull request #1736 from git/update-ruby-3
update to ruby 3.1.2
-rw-r--r--.rubocop.yml63
-rw-r--r--.ruby-version2
-rw-r--r--Gemfile14
-rw-r--r--Gemfile.lock200
-rw-r--r--Rakefile3
-rw-r--r--app/controllers/about_controller.rb4
-rw-r--r--app/controllers/application_controller.rb7
-rw-r--r--app/controllers/books_controller.rb18
-rw-r--r--app/controllers/community_controller.rb5
-rw-r--r--app/controllers/doc_controller.rb12
-rw-r--r--app/controllers/downloads_controller.rb19
-rw-r--r--app/controllers/site_controller.rb10
-rw-r--r--app/helpers/application_helper.rb30
-rw-r--r--app/helpers/books_helper.rb2
-rw-r--r--app/helpers/doc_helper.rb4
-rw-r--r--app/helpers/gui_helper.rb4
-rw-r--r--app/helpers/site_helper.rb56
-rw-r--r--app/models/book.rb6
-rw-r--r--app/models/chapter.rb26
-rw-r--r--app/models/doc.rb2
-rw-r--r--app/models/doc_file.rb67
-rw-r--r--app/models/doc_version.rb47
-rw-r--r--app/models/download.rb3
-rw-r--r--app/models/section.rb64
-rw-r--r--app/models/version.rb7
-rw-r--r--app/presenters/gui_presenter.rb9
-rw-r--r--app/services/download_service.rb58
-rw-r--r--app/views/books/show.html.erb2
-rwxr-xr-xbin/bundle2
-rwxr-xr-xbin/rails2
-rwxr-xr-xbin/rake2
-rwxr-xr-xbin/setup2
-rw-r--r--config/environments/production.rb2
-rw-r--r--config/initializers/assets.rb1
-rw-r--r--config/initializers/backtrace_silencers.rb1
-rw-r--r--config/initializers/cookies_serializer.rb1
-rw-r--r--config/initializers/elasticsearch.rb4
-rw-r--r--config/initializers/filter_parameter_logging.rb5
-rw-r--r--config/initializers/timeout.rb5
-rw-r--r--config/initializers/wrap_parameters.rb1
-rw-r--r--config/puma.rb9
-rw-r--r--config/routes.rb14
-rw-r--r--db/migrate/20120415151530_add_version_order.rb4
-rw-r--r--db/migrate/20120417221951_add_book_stuff.rb2
-rw-r--r--db/migrate/20190131210305_add_language_to_doc_version.rb1
-rw-r--r--db/migrate/20201213045819_add_index_to_versions.rb1
-rw-r--r--lib/searchable.rb50
-rw-r--r--lib/tasks/book2.rake151
-rw-r--r--lib/tasks/downloads.rake6
-rw-r--r--lib/tasks/index.rake266
-rw-r--r--lib/tasks/search.rake7
-rwxr-xr-xpublic/book/en/v2/book/07-git-tools/git-credential-read-only33
-rwxr-xr-xscript/doc_importer6
-rwxr-xr-xscript/rails4
-rwxr-xr-xscript/sort-gui17
-rw-r--r--spec/controllers/about_controller_spec.rb2
-rw-r--r--spec/controllers/community_controller_spec.rb2
-rw-r--r--spec/controllers/site_controller_spec.rb4
-rw-r--r--spec/models/book_spec.rb4
-rw-r--r--spec/models/chapter_spec.rb3
-rw-r--r--spec/models/doc_file_spec.rb2
-rw-r--r--spec/models/doc_spec.rb2
-rw-r--r--spec/models/doc_version_spec.rb5
-rw-r--r--spec/models/download_spec.rb2
-rw-r--r--spec/models/section_spec.rb4
-rw-r--r--spec/models/version_spec.rb3
-rw-r--r--spec/rails_helper.rb2
-rw-r--r--spec/services/download_service_spec.rb6
-rw-r--r--spec/support/vcr.rb2
-rw-r--r--test/factories.rb2
-rw-r--r--test/functional/about_controller_test.rb2
-rw-r--r--test/functional/books_controller_test.rb4
-rw-r--r--test/functional/community_controller_test.rb2
-rw-r--r--test/functional/doc_controller_test.rb11
-rw-r--r--test/functional/downloads_controller_test.rb2
-rw-r--r--test/functional/site_controller_test.rb2
-rw-r--r--test/test_helper.rb20
-rw-r--r--test/unit/book_test.rb2
-rw-r--r--test/unit/chapter_test.rb2
-rw-r--r--test/unit/doc_file_test.rb2
-rw-r--r--test/unit/doc_test.rb2
-rw-r--r--test/unit/doc_version_test.rb8
-rw-r--r--test/unit/download_test.rb2
-rw-r--r--test/unit/helpers/application_helper_test.rb2
-rw-r--r--test/unit/helpers/doc_helper_test.rb2
-rw-r--r--test/unit/helpers/site_helper_test.rb17
-rw-r--r--test/unit/section_test.rb2
-rw-r--r--test/unit/version_test.rb6
88 files changed, 703 insertions, 775 deletions
diff --git a/.rubocop.yml b/.rubocop.yml
index 0c3df174..ec1ae45b 100644
--- a/.rubocop.yml
+++ b/.rubocop.yml
@@ -1,26 +1,75 @@
require:
- rubocop-rails
+ - rubocop-performance
-inherit_gem:
- rubocop-github:
- - config/default.yml
- - config/rails.yml
+inherit_mode:
+ merge:
+ - Exclude
AllCops:
- TargetRubyVersion: 2.7
+ TargetRubyVersion: 3.1
+ Exclude:
+ - db/migrate/**
+ SuggestExtensions: false
+ NewCops: enable
Performance:
enabled: true
+Performance/RedundantBlockCall:
+ Enabled: false
-Style/FrozenStringLiteralComment:
+Style:
+ Exclude:
+ - db/schema.rb
+Layout:
Exclude:
- db/schema.rb
+Style/StringLiterals:
+ Enabled: false
+Style/Documentation:
+ Enabled: false
+Style/ConditionalAssignment:
+ Enabled: false
+Style/IfUnlessModifier:
+ Enabled: false
+Style/StringConcatenation:
+ Enabled: false
+Style/NegatedIf:
+ Enabled: false
+Style/NumericPredicate:
+ Enabled: false
+Style/TrailingCommaInArrayLiteral:
+ Enabled: false
+Style/TrailingCommaInHashLiteral:
+ Enabled: false
+Style/RegexpLiteral:
+ Enabled: false
+Style/PerlBackrefs:
+ Enabled: false
+Style/GuardClause:
+ Enabled: false
+Style/ClassVars:
+ Enabled: false
+Layout/LineLength:
+ Enabled: false
+
Rails/HelperInstanceVariable:
Enabled: false
Rails/TimeZone:
Enabled: false
-GitHub/InsecureHashAlgorithm:
+Style/HashSyntax:
+ EnforcedShorthandSyntax: either
+
+Metrics:
+ Enabled: false
+
+Lint/ShadowingOuterLocalVariable:
Enabled: false
+
+Lint/EmptyBlock:
+ Exclude:
+ - spec/**/*
+ - test/**/*
diff --git a/.ruby-version b/.ruby-version
index 2c9b4ef4..ef538c28 100644
--- a/.ruby-version
+++ b/.ruby-version
@@ -1 +1 @@
-2.7.3
+3.1.2
diff --git a/Gemfile b/Gemfile
index 8d89b05d..b2a9b388 100644
--- a/Gemfile
+++ b/Gemfile
@@ -1,10 +1,15 @@
# frozen_string_literal: true
source "https://rubygems.org"
-ruby "2.7.3"
+ruby "3.1.2"
gem "rails", "~> 6.0"
+# hacks for rails6 + ruby 3.1
+gem 'net-imap', require: false
+gem 'net-pop', require: false
+gem 'net-smtp', require: false
+
gem "asciidoctor", "~> 2.0.0"
gem "elasticsearch", "2.0.2"
gem "iso8601"
@@ -13,6 +18,7 @@ gem "puma"
gem "diffy"
gem "nokogiri"
+gem "rss"
# Assets
gem "sass-rails"
@@ -29,7 +35,11 @@ group :development, :test do
gem "dotenv-rails"
gem "listen"
gem "pry-byebug"
- gem "rubocop-github"
+ gem "rubocop"
+ gem "rubocop-discourse"
+ gem "rubocop-performance"
+ gem "rubocop-rails"
+ gem "rubocop-rspec"
gem "ruby-prof"
gem "sqlite3"
end
diff --git a/Gemfile.lock b/Gemfile.lock
index dfc2e31b..5ac20c69 100644
--- a/Gemfile.lock
+++ b/Gemfile.lock
@@ -1,60 +1,60 @@
GEM
remote: https://rubygems.org/
specs:
- actioncable (6.1.4.1)
- actionpack (= 6.1.4.1)
- activesupport (= 6.1.4.1)
+ actioncable (6.1.7)
+ actionpack (= 6.1.7)
+ activesupport (= 6.1.7)
nio4r (~> 2.0)
websocket-driver (>= 0.6.1)
- actionmailbox (6.1.4.1)
- actionpack (= 6.1.4.1)
- activejob (= 6.1.4.1)
- activerecord (= 6.1.4.1)
- activestorage (= 6.1.4.1)
- activesupport (= 6.1.4.1)
+ actionmailbox (6.1.7)
+ actionpack (= 6.1.7)
+ activejob (= 6.1.7)
+ activerecord (= 6.1.7)
+ activestorage (= 6.1.7)
+ activesupport (= 6.1.7)
mail (>= 2.7.1)
- actionmailer (6.1.4.1)
- actionpack (= 6.1.4.1)
- actionview (= 6.1.4.1)
- activejob (= 6.1.4.1)
- activesupport (= 6.1.4.1)
+ actionmailer (6.1.7)
+ actionpack (= 6.1.7)
+ actionview (= 6.1.7)
+ activejob (= 6.1.7)
+ activesupport (= 6.1.7)
mail (~> 2.5, >= 2.5.4)
rails-dom-testing (~> 2.0)
- actionpack (6.1.4.1)
- actionview (= 6.1.4.1)
- activesupport (= 6.1.4.1)
+ actionpack (6.1.7)
+ actionview (= 6.1.7)
+ activesupport (= 6.1.7)
rack (~> 2.0, >= 2.0.9)
rack-test (>= 0.6.3)
rails-dom-testing (~> 2.0)
rails-html-sanitizer (~> 1.0, >= 1.2.0)
- actiontext (6.1.4.1)
- actionpack (= 6.1.4.1)
- activerecord (= 6.1.4.1)
- activestorage (= 6.1.4.1)
- activesupport (= 6.1.4.1)
+ actiontext (6.1.7)
+ actionpack (= 6.1.7)
+ activerecord (= 6.1.7)
+ activestorage (= 6.1.7)
+ activesupport (= 6.1.7)
nokogiri (>= 1.8.5)
- actionview (6.1.4.1)
- activesupport (= 6.1.4.1)
+ actionview (6.1.7)
+ activesupport (= 6.1.7)
builder (~> 3.1)
erubi (~> 1.4)
rails-dom-testing (~> 2.0)
rails-html-sanitizer (~> 1.1, >= 1.2.0)
- activejob (6.1.4.1)
- activesupport (= 6.1.4.1)
+ activejob (6.1.7)
+ activesupport (= 6.1.7)
globalid (>= 0.3.6)
- activemodel (6.1.4.1)
- activesupport (= 6.1.4.1)
- activerecord (6.1.4.1)
- activemodel (= 6.1.4.1)
- activesupport (= 6.1.4.1)
- activestorage (6.1.4.1)
- actionpack (= 6.1.4.1)
- activejob (= 6.1.4.1)
- activerecord (= 6.1.4.1)
- activesupport (= 6.1.4.1)
- marcel (~> 1.0.0)
+ activemodel (6.1.7)
+ activesupport (= 6.1.7)
+ activerecord (6.1.7)
+ activemodel (= 6.1.7)
+ activesupport (= 6.1.7)
+ activestorage (6.1.7)
+ actionpack (= 6.1.7)
+ activejob (= 6.1.7)
+ activerecord (= 6.1.7)
+ activesupport (= 6.1.7)
+ marcel (~> 1.0)
mini_mime (>= 1.1.0)
- activesupport (6.1.4.1)
+ activesupport (6.1.7)
concurrent-ruby (~> 1.0, >= 1.0.2)
i18n (>= 1.6, < 2)
minitest (>= 5.1)
@@ -74,7 +74,7 @@ GEM
builder (3.2.4)
byebug (11.1.3)
coderay (1.1.3)
- concurrent-ruby (1.1.9)
+ concurrent-ruby (1.1.10)
crack (0.4.5)
rexml
crass (1.0.6)
@@ -99,7 +99,7 @@ GEM
elasticsearch-transport (2.0.2)
faraday
multi_json
- erubi (1.10.0)
+ erubi (1.11.0)
execjs (2.8.1)
fabrication (2.22.0)
factory_bot (6.2.0)
@@ -128,36 +128,45 @@ GEM
faraday-rack (1.0.0)
ffi (1.15.4)
foreman (0.87.2)
- globalid (0.5.2)
+ globalid (1.0.0)
activesupport (>= 5.0)
hashdiff (1.0.1)
- i18n (1.8.10)
+ i18n (1.12.0)
concurrent-ruby (~> 1.0)
iso8601 (0.13.0)
+ json (2.6.2)
listen (3.7.0)
rb-fsevent (~> 0.10, >= 0.10.3)
rb-inotify (~> 0.9, >= 0.9.10)
- loofah (2.18.0)
+ loofah (2.19.0)
crass (~> 1.0.2)
nokogiri (>= 1.5.9)
mail (2.7.1)
mini_mime (>= 0.1.1)
marcel (1.0.2)
method_source (1.0.0)
- mini_mime (1.1.1)
+ mini_mime (1.1.2)
mini_portile2 (2.8.0)
- minitest (5.14.4)
+ minitest (5.16.3)
multi_json (1.15.0)
multipart-post (2.1.1)
+ net-imap (0.3.1)
+ net-protocol
+ net-pop (0.1.2)
+ net-protocol
+ net-protocol (0.1.3)
+ timeout
+ net-smtp (0.3.2)
+ net-protocol
nio4r (2.5.8)
- nokogiri (1.13.6)
+ nokogiri (1.13.8)
mini_portile2 (~> 2.8.0)
racc (~> 1.4)
octokit (4.21.0)
faraday (>= 0.9)
sawyer (~> 0.8.0, >= 0.5.3)
parallel (1.21.0)
- parser (3.0.2.0)
+ parser (3.1.2.1)
ast (~> 2.4.1)
pg (1.2.3)
pry (0.13.1)
@@ -170,24 +179,24 @@ GEM
puma (5.6.4)
nio4r (~> 2.0)
racc (1.6.0)
- rack (2.2.3.1)
- rack-test (1.1.0)
- rack (>= 1.0, < 3)
+ rack (2.2.4)
+ rack-test (2.0.2)
+ rack (>= 1.3)
rack-timeout (0.6.0)
- rails (6.1.4.1)
- actioncable (= 6.1.4.1)
- actionmailbox (= 6.1.4.1)
- actionmailer (= 6.1.4.1)
- actionpack (= 6.1.4.1)
- actiontext (= 6.1.4.1)
- actionview (= 6.1.4.1)
- activejob (= 6.1.4.1)
- activemodel (= 6.1.4.1)
- activerecord (= 6.1.4.1)
- activestorage (= 6.1.4.1)
- activesupport (= 6.1.4.1)
+ rails (6.1.7)
+ actioncable (= 6.1.7)
+ actionmailbox (= 6.1.7)
+ actionmailer (= 6.1.7)
+ actionpack (= 6.1.7)
+ actiontext (= 6.1.7)
+ actionview (= 6.1.7)
+ activejob (= 6.1.7)
+ activemodel (= 6.1.7)
+ activerecord (= 6.1.7)
+ activestorage (= 6.1.7)
+ activesupport (= 6.1.7)
bundler (>= 1.15.0)
- railties (= 6.1.4.1)
+ railties (= 6.1.7)
sprockets-rails (>= 2.0.0)
rails-controller-testing (1.0.5)
actionpack (>= 5.0.1.rc1)
@@ -203,11 +212,11 @@ GEM
rails_stdout_logging
rails_serve_static_assets (0.0.5)
rails_stdout_logging (0.0.5)
- railties (6.1.4.1)
- actionpack (= 6.1.4.1)
- activesupport (= 6.1.4.1)
+ railties (6.1.7)
+ actionpack (= 6.1.7)
+ activesupport (= 6.1.7)
method_source
- rake (>= 0.13)
+ rake (>= 12.2)
thor (~> 1.0)
rainbow (3.0.0)
rake (13.0.6)
@@ -250,28 +259,32 @@ GEM
rspec-mocks (~> 3.10)
rspec-support (~> 3.10)
rspec-support (3.10.2)
- rubocop (1.13.0)
+ rss (0.2.9)
+ rexml
+ rubocop (1.36.0)
+ json (~> 2.3)
parallel (~> 1.10)
- parser (>= 3.0.0.0)
+ parser (>= 3.1.2.1)
rainbow (>= 2.2.2, < 4.0)
regexp_parser (>= 1.8, < 3.0)
- rexml
- rubocop-ast (>= 1.2.0, < 2.0)
+ rexml (>= 3.2.5, < 4.0)
+ rubocop-ast (>= 1.20.1, < 2.0)
ruby-progressbar (~> 1.7)
unicode-display_width (>= 1.4.0, < 3.0)
- rubocop-ast (1.12.0)
- parser (>= 3.0.1.1)
- rubocop-github (0.16.2)
- rubocop (<= 1.13.0)
- rubocop-performance (<= 1.11.0)
- rubocop-rails (<= 2.7.1)
+ rubocop-ast (1.21.0)
+ parser (>= 3.1.1.0)
+ rubocop-discourse (3.0)
+ rubocop (>= 1.1.0)
+ rubocop-rspec (>= 2.0.0)
rubocop-performance (1.11.0)
rubocop (>= 1.7.0, < 2.0)
rubocop-ast (>= 0.4.0)
- rubocop-rails (2.7.1)
+ rubocop-rails (2.16.1)
activesupport (>= 4.2.0)
rack (>= 1.1)
- rubocop (>= 0.87.0)
+ rubocop (>= 1.33.0, < 2.0)
+ rubocop-rspec (2.13.2)
+ rubocop (~> 1.33)
ruby-prof (1.4.3)
ruby-progressbar (1.11.0)
ruby2_keywords (0.0.5)
@@ -294,17 +307,18 @@ GEM
shoulda-context (2.0.0)
shoulda-matchers (4.5.1)
activesupport (>= 4.2.0)
- sprockets (4.0.2)
+ sprockets (4.1.1)
concurrent-ruby (~> 1.0)
rack (> 1, < 3)
- sprockets-rails (3.2.2)
- actionpack (>= 4.0)
- activesupport (>= 4.0)
+ sprockets-rails (3.4.2)
+ actionpack (>= 5.2)
+ activesupport (>= 5.2)
sprockets (>= 3.0.0)
sqlite3 (1.4.2)
- thor (1.1.0)
+ thor (1.2.1)
tilt (2.0.10)
- tzinfo (2.0.4)
+ timeout (0.3.0)
+ tzinfo (2.0.5)
concurrent-ruby (~> 1.0)
uglifier (4.2.0)
execjs (>= 0.3.0, < 3)
@@ -317,7 +331,7 @@ GEM
websocket-driver (0.7.5)
websocket-extensions (>= 0.1.0)
websocket-extensions (0.1.5)
- zeitwerk (2.4.2)
+ zeitwerk (2.6.1)
PLATFORMS
ruby
@@ -336,6 +350,9 @@ DEPENDENCIES
foreman
iso8601
listen
+ net-imap
+ net-pop
+ net-smtp
nokogiri
octokit
pg
@@ -347,7 +364,12 @@ DEPENDENCIES
rails_12factor
redis-rails
rspec-rails
- rubocop-github
+ rss
+ rubocop
+ rubocop-discourse
+ rubocop-performance
+ rubocop-rails
+ rubocop-rspec
ruby-prof
sass-rails
shoulda
@@ -357,7 +379,7 @@ DEPENDENCIES
webmock
RUBY VERSION
- ruby 2.7.3p183
+ ruby 3.1.2p20
BUNDLED WITH
- 2.1.4
+ 2.3.22
diff --git a/Rakefile b/Rakefile
index 5366e6e0..2d12a7d9 100644
--- a/Rakefile
+++ b/Rakefile
@@ -1,10 +1,9 @@
-#!/usr/bin/env rake
# frozen_string_literal: true
# Add your own tasks in files placed in lib/tasks ending in .rake,
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
-require File.expand_path("../config/application", __FILE__)
+require File.expand_path('config/application', __dir__)
Rake.application.options.trace = true
diff --git a/app/controllers/about_controller.rb b/app/controllers/about_controller.rb
index 34d5d4f1..5b166533 100644
--- a/app/controllers/about_controller.rb
+++ b/app/controllers/about_controller.rb
@@ -1,10 +1,8 @@
# frozen_string_literal: true
class AboutController < ApplicationController
-
def index
@section = "about"
- set_title "About"
+ title "About"
end
-
end
diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb
index 0821aa7b..3e9171f6 100644
--- a/app/controllers/application_controller.rb
+++ b/app/controllers/application_controller.rb
@@ -1,6 +1,6 @@
# frozen_string_literal: true
-PageNotFound = Class.new(Exception)
+PageNotFound = Class.new(StandardError)
class ApplicationController < ActionController::Base
protect_from_forgery
@@ -13,7 +13,7 @@ class ApplicationController < ActionController::Base
@os = "linux"
end
- def set_title(title)
+ def title(title)
@page_title = "#{title} - Git"
end
@@ -24,7 +24,6 @@ class ApplicationController < ActionController::Base
end
def not_found_template
- Rails.root.join("public/404.html")
+ Rails.public_path.join('404.html')
end
-
end
diff --git a/app/controllers/books_controller.rb b/app/controllers/books_controller.rb
index c5cd7bb7..5476f5f9 100644
--- a/app/controllers/books_controller.rb
+++ b/app/controllers/books_controller.rb
@@ -1,15 +1,17 @@
# frozen_string_literal: true
class BooksController < ApplicationController
- before_action :book_resource, only: [:section, :chapter]
+ before_action :book_resource, only: %i[section chapter]
def show
lang = params[:lang] || "en"
- if edition = params[:edition]
+ edition = params[:edition]
+ if edition
@book = Book.where(code: lang, edition: edition).first
else
@book = Book.where(code: lang).order("percent_complete DESC, edition DESC").first
raise PageNotFound unless @book
+
redirect_to "/book/#{lang}/v#{@book.edition}"
end
raise PageNotFound unless @book
@@ -19,6 +21,7 @@ class BooksController < ApplicationController
link = params[:link]
@book = Book.where(code: params[:lang], edition: params[:edition]).first
raise PageNotFound unless @book
+
xref = @book.xrefs.where(name: link).first
raise PageNotFound unless xref
return redirect_to "/book/#{@book.code}/v#{@book.edition}/#{ERB::Util.url_encode(xref.section.slug)}##{xref.name}" unless @content
@@ -28,7 +31,8 @@ class BooksController < ApplicationController
@content = @book.sections.where(slug: params[:slug]).first
if !@content
@book = Book.where(code: @book.code, edition: 2).first
- if @content = @book.sections.where(slug: params[:slug]).first
+ @content = @book.sections.where(slug: params[:slug]).first
+ if @content
return redirect_to "/book/#{@book.code}/v#{@book.edition}/#{params[:slug]}"
else
return redirect_to "/book/#{@book.code}"
@@ -50,18 +54,20 @@ class BooksController < ApplicationController
chapter = @book.chapters.where(number: chapter).first
@content = chapter.sections.where(number: section).first
raise PageNotFound unless @content
- return redirect_to "/book/#{lang}/v2/#{@content.slug}"
+
+ redirect_to "/book/#{lang}/v2/#{@content.slug}"
end
def book_resource
- if edition = params[:edition]
+ edition = params[:edition]
+ if edition
@book ||= Book.where(code: (params[:lang] || "en"), edition: edition).first
else
@no_edition = true
@book ||= Book.where(code: (params[:lang] || "en")).order("percent_complete DESC, edition DESC").first
end
raise PageNotFound unless @book
+
@book
end
-
end
diff --git a/app/controllers/community_controller.rb b/app/controllers/community_controller.rb
index 8478ac72..6b06872b 100644
--- a/app/controllers/community_controller.rb
+++ b/app/controllers/community_controller.rb
@@ -1,8 +1,5 @@
# frozen_string_literal: true
class CommunityController < ApplicationController
-
- def index
- end
-
+ def index; end
end
diff --git a/app/controllers/doc_controller.rb b/app/controllers/doc_controller.rb
index 264f2b4d..a85ec369 100644
--- a/app/controllers/doc_controller.rb
+++ b/app/controllers/doc_controller.rb
@@ -1,7 +1,6 @@
# frozen_string_literal: true
class DocController < ApplicationController
-
before_action :set_caching
before_action :set_doc_file, only: [:man]
before_action :set_doc_version, only: [:man]
@@ -11,20 +10,21 @@ class DocController < ApplicationController
@videos = Gitscm::VIDEOS
end
- def ref
- end
+ def ref; end
def man
return redirect_to docs_path unless @doc_file
unless @doc_version.respond_to?(:version)
return redirect_to doc_file_path(file: @doc_file.name)
end
+
@version = @doc_version.version
@language = @doc_version.language
@doc = @doc_version.doc
@name = @doc_file.name
@page_title = "Git - #{@doc_file.name} Documentation"
return redirect_to docs_path unless @doc_version
+
@last = @doc_file.doc_versions.latest_version
end
@@ -40,8 +40,7 @@ class DocController < ApplicationController
end
end
- def ext
- end
+ def ext; end
private
@@ -59,7 +58,7 @@ class DocController < ApplicationController
if DocFile.exists?(name: file)
@doc_file = DocFile.where(name: file).limit(1).first
elsif DocFile.exists?(name: "git-#{file}")
- return redirect_to doc_file_path(file: "git-#{file}")
+ redirect_to doc_file_path(file: "git-#{file}")
end
end
@@ -70,6 +69,7 @@ class DocController < ApplicationController
def set_doc_version
return unless @doc_file
+
version = params[:version]
if version && revision?(version)
@doc_version = @doc_file.doc_versions.for_version(version)
diff --git a/app/controllers/downloads_controller.rb b/app/controllers/downloads_controller.rb
index 310f0502..ffa8491b 100644
--- a/app/controllers/downloads_controller.rb
+++ b/app/controllers/downloads_controller.rb
@@ -1,9 +1,7 @@
# frozen_string_literal: true
class DownloadsController < ApplicationController
-
- def index
- end
+ def index; end
def latest
latest = Version.latest_version.name
@@ -13,7 +11,7 @@ class DownloadsController < ApplicationController
def guis
guis_info = GuiPresenter.instance.guis_info
- render "downloads/guis/index", locals: {guis_info: guis_info}
+ render "downloads/guis/index", locals: { guis_info: guis_info }
end
def logos
@@ -26,18 +24,19 @@ class DownloadsController < ApplicationController
guis_info = GuiPresenter.instance.guis_info
- render "downloads/guis/index", locals: {guis_info: guis_info}
+ render "downloads/guis/index", locals: { guis_info: guis_info }
end
def download
@platform = params[:platform]
@platform = "windows" if @platform == "win"
@latest = Version.latest_version
- if @platform == "mac"
+ case @platform
+ when "mac"
@download = Download.latest_for(@platform)
render "downloads/download_mac"
- elsif @platform == "windows"
+ when "windows"
@project_url = "https://git-for-windows.github.io/"
@source_url = "https://github.com/git-for-windows/git"
@@ -46,7 +45,7 @@ class DownloadsController < ApplicationController
@download32portable = Download.latest_for(@platform + "32Portable")
@download64portable = Download.latest_for(@platform + "64Portable")
- if request.env["HTTP_USER_AGENT"] =~ /WOW64|Win64|x64|x86_64/
+ if /WOW64|Win64|x64|x86_64/.match?(request.env["HTTP_USER_AGENT"])
@download = @download64
@bitness = "64-bit"
else
@@ -55,12 +54,12 @@ class DownloadsController < ApplicationController
end
render "downloads/download_windows"
- elsif @platform == "linux"
+ when "linux"
render "downloads/download_linux"
else
redirect_to "/downloads"
end
- rescue
+ rescue StandardError
redirect_to "/downloads"
end
end
diff --git a/app/controllers/site_controller.rb b/app/controllers/site_controller.rb
index ee7de745..968300a1 100644
--- a/app/controllers/site_controller.rb
+++ b/app/controllers/site_controller.rb
@@ -1,7 +1,6 @@
# frozen_string_literal: true
class SiteController < ApplicationController
-
def index
expires_in 10.minutes, public: true
@@ -19,7 +18,7 @@ class SiteController < ApplicationController
# called when you submit your search
def search_results
@term = sname = request.query_parameters["search"].to_s.downcase
- data = search_term(sname, true)
+ data = search_term(sname)
@top = []
@rest = []
data[:results].each do |type|
@@ -36,17 +35,17 @@ class SiteController < ApplicationController
render "site/results"
end
- def search_term(sname, highlight = false)
+ def search_term(sname)
data = {
term: sname,
results: []
}
- if results = Doc.search(sname)
+ if (results = Doc.search(sname))
data[:results] << results
end
- if results = Section.search(sname, lang: "en")
+ if (results = Section.search(sname, lang: "en"))
data[:results] << results
end
@@ -65,5 +64,4 @@ class SiteController < ApplicationController
redirect_to "https://git-scm.com#{current_uri}"
end
end
-
end
diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb
index 86b48d7b..a9583995 100644
--- a/app/helpers/application_helper.rb
+++ b/app/helpers/application_helper.rb
@@ -3,26 +3,21 @@
require "iso8601"
module ApplicationHelper
-
def sidebar_link_options(section)
- if %w( about documentation downloads community
- ).include?(@section) && @section == section ||
- %w( reference book videos external-links
- guis logos
- ).include?(@subsection) && @subsection == section
- {class: "active"}
+ if (%w[about documentation downloads community].include?(@section) && @section == section) ||
+ (%w[ reference book videos external-links
+ guis logos].include?(@subsection) && @subsection == section)
+ { class: "active" }
else
{}
end
end
def latest_version
- begin
@version ||= Version.latest_version
@version.name
- rescue
- ""
- end
+ rescue StandardError
+ ""
end
def latest_mac_installer
@@ -36,16 +31,14 @@ module ApplicationHelper
end
def latest_release_date
- begin
@version ||= Version.latest_version
"(" + @version.committed.strftime("%Y-%m-%d") + ")"
- rescue
- ""
- end
+ rescue StandardError
+ ""
end
def latest_relnote_url
- "https://raw.github.com/git/git/master/Documentation/RelNotes/#{self.latest_version}.txt"
+ "https://raw.github.com/git/git/master/Documentation/RelNotes/#{latest_version}.txt"
end
# Overriding this because we're not using asset pipeline for images,
@@ -55,13 +48,14 @@ module ApplicationHelper
def image_tag(image, options = {})
options = options.symbolize_keys
- src = options[:src] = "/images/#{image}"
+ options[:src] = "/images/#{image}"
- tag("img", options)
+ tag.img(options)
end
def banner_duration(duration)
return "" if duration.blank?
+
ISO8601::Duration.new(duration).to_seconds.round * 1000
end
end
diff --git a/app/helpers/books_helper.rb b/app/helpers/books_helper.rb
index 03f41e73..2a9a99a7 100644
--- a/app/helpers/books_helper.rb
+++ b/app/helpers/books_helper.rb
@@ -1,9 +1,7 @@
# frozen_string_literal: true
module BooksHelper
-
def same_section(content, section)
content.number == section.number && content.chapter.cs_number == section.chapter.cs_number
end
-
end
diff --git a/app/helpers/doc_helper.rb b/app/helpers/doc_helper.rb
index 8bf956f3..1c438a34 100644
--- a/app/helpers/doc_helper.rb
+++ b/app/helpers/doc_helper.rb
@@ -1,10 +1,10 @@
# frozen_string_literal: true
module DocHelper
-
def man(name, text = nil)
if @language && @language != "en"
- link_to text || name.gsub(/^git-/, ""), doc_file_path(file: name,) +"/#{@language}", class: ("active" if @name == name)
+ link_to text || name.gsub(/^git-/, ""), doc_file_path(file: name) + "/#{@language}",
+ class: ("active" if @name == name)
else
link_to text || name.gsub(/^git-/, ""), doc_file_path(file: name), class: ("active" if @name == name)
end
diff --git a/app/helpers/gui_helper.rb b/app/helpers/gui_helper.rb
index 365fccf3..0164577a 100644
--- a/app/helpers/gui_helper.rb
+++ b/app/helpers/gui_helper.rb
@@ -1,11 +1,9 @@
# frozen_string_literal: true
module GuiHelper
-
- @@conv = { "Mac" => "mac", "Windows" => "windows", "Linux" => "linux", "Android" => "android", "iOS" => "ios"}
+ @@conv = { "Mac" => "mac", "Windows" => "windows", "Linux" => "linux", "Android" => "android", "iOS" => "ios" }
def platforms_to_css_class(platforms)
platforms.map { |p| @@conv[p] }
end
-
end
diff --git a/app/helpers/site_helper.rb b/app/helpers/site_helper.rb
index c6d3d5eb..1b76c48b 100644
--- a/app/helpers/site_helper.rb
+++ b/app/helpers/site_helper.rb
@@ -6,60 +6,4 @@ module SiteHelper
.gsub("[highlight]", '<span class="highlight">')
.gsub("[xhighlight]", "</span>")
end
-
- def rchart(title, data, extra = nil)
- git = data[0][1]
- svn = data[1][1]
- out = "<tr>"
- out += "<td nowrap>#{title}</td>"
- out += "<td class='desc'>#{extra}</td>"
- out += "<td class='number'>#{sprintf("%5.2f", git)}</td>"
- out += "<td class='number'>#{sprintf("%5.2f", svn)}</td>"
- out += "<td class='number'>#{(svn / git).floor}x</td>"
- out += "</tr>"
- end
-
- def trchart(title, data, extra = nil)
- git = data[1][1]
- git2 = data[0][1]
- svn = data[2][1]
- out = "<tr>"
- out += "<td nowrap>#{title}</td>"
- out += "<td class='desc'>#{extra}</td>"
- if git2
- out += "<td class='number'>#{sprintf("%5.1f", git2)}</td>"
- else
- out += "<td></td>"
- end
- out += "<td class='number'>#{sprintf("%5.1f", git)}</td>"
- out += "<td class='number'>#{sprintf("%5.1f", svn)}</td>"
- out += "</tr>"
- end
-
-
- def gchart(title, data)
- labels = data.map { |v| v[0] }
- vals = data.map { |v| v[1] }
-
- v = vals.join(",")
- l = labels.join("|")
-
- scale = vals.max
- c = "<img src=\"https://chart.googleapis.com/chart?"
- c += "chxt=x" + "&amp;"
- c += "cht=bvs" + "&amp;"
- c += "chl=#{l}" + "&amp;"
- c += "chd=t:#{v}" + "&amp;"
- c += "chds=0,#{scale}" + "&amp;"
- c += "chs=100x125" + "&amp;"
- if vals.size == 3
- c += "chco=E09FA0|E09FA0|E05F49" + "&amp;"
- else
- c += "chco=E09FA0|E05F49" + "&amp;"
- end
- c += "chf=bg,s,fcfcfa&"
- c += "chtt=#{title}"
- c += "\" alt=\"init benchmarks\" />"
- c
- end
end
diff --git a/app/models/book.rb b/app/models/book.rb
index b61c9b5b..884e304c 100644
--- a/app/models/book.rb
+++ b/app/models/book.rb
@@ -7,7 +7,7 @@ class Book < ApplicationRecord
has_many :sections, through: :chapters
has_many :xrefs, dependent: :delete_all
- @@all_books={
+ @@all_books = {
"az" => "progit2-aze/progit2",
"be" => "progit/progit2-be",
"bg" => "progit/progit2-bg",
@@ -43,7 +43,7 @@ class Book < ApplicationRecord
@@all_books
end
- def has_edition(number)
- Book.where(edition: number, code: self.code).count > 0
+ def edition?(number)
+ Book.where(edition: number, code: code).count > 0
end
end
diff --git a/app/models/chapter.rb b/app/models/chapter.rb
index 6826694c..1c6e954a 100644
--- a/app/models/chapter.rb
+++ b/app/models/chapter.rb
@@ -11,32 +11,36 @@ class Chapter < ApplicationRecord
has_many :chapters, through: :book
def prev
- return false unless self.number
- num = self.number - 1
- return self.chapters.find_by(number: num) if num > 0
+ return false unless number
+
+ num = number - 1
+ return chapters.find_by(number: num) if num > 0
+
false
end
def next
- return false unless self.number
- num = self.number + 1
- return self.chapters.find_by(number: num) if num > 0
+ return false unless number
+
+ num = number + 1
+ return chapters.find_by(number: num) if num > 0
+
false
end
def last_section
- self.sections.reorder("number DESC").first
+ sections.reorder("number DESC").first
end
def first_section
- self.sections.first
+ sections.first
end
def cs_number
- if self.chapter_type == "appendix"
- "A" + self.chapter_number
+ if chapter_type == "appendix"
+ "A" + chapter_number
else
- self.chapter_number
+ chapter_number
end
end
end
diff --git a/app/models/doc.rb b/app/models/doc.rb
index 1d987370..1d1b467d 100644
--- a/app/models/doc.rb
+++ b/app/models/doc.rb
@@ -9,9 +9,7 @@ require "diffy"
# t.text :html
# t.timestamps
class Doc < ApplicationRecord
-
include Searchable
has_many :doc_versions, dependent: :delete_all
-
end
diff --git a/app/models/doc_file.rb b/app/models/doc_file.rb
index 9bb5294a..c8448b77 100644
--- a/app/models/doc_file.rb
+++ b/app/models/doc_file.rb
@@ -1,4 +1,3 @@
-# coding: utf-8
# frozen_string_literal: true
# t.string :name
@@ -7,39 +6,39 @@ class DocFile < ApplicationRecord
has_many :doc_versions, dependent: :delete_all
has_many :versions, through: :doc_versions
- scope :with_includes, -> { includes(doc_versions: [:doc, :version]) }
+ scope :with_includes, -> { includes(doc_versions: %i[doc version]) }
- @@true_lang={
- "de" => "Deutsch",
- "en" => "English",
- "es" => "Español",
- "es_MX" => "Español (Mexico)",
- "fr" => "Français",
- "hu" => "magyar",
- "id" => "Bahasa Indonesia",
- "is" => "Íslenska",
- "it" => "Italiano",
- "ja" => "日本語",
- "mr" => "मराठी",
- "nb_NO" => "Norsk bokmål",
- "nl" => "Nederlands",
- "pl" => "Polski",
- "pt_BR" => "Português (Brasil)",
- "pt_PT" => "Português (Portugal)",
- "ro" => "Română",
- "ru" => "Русский",
- "tr" => "Türkçe",
- "uk" => "українська мова",
- "zh_HANS-CN" =>"简体中文",
- "zh_HANT" =>"繁體中文"
- }
+ @@true_lang = {
+ "de" => "Deutsch",
+ "en" => "English",
+ "es" => "Español",
+ "es_MX" => "Español (Mexico)",
+ "fr" => "Français",
+ "hu" => "magyar",
+ "id" => "Bahasa Indonesia",
+ "is" => "Íslenska",
+ "it" => "Italiano",
+ "ja" => "日本語",
+ "mr" => "मराठी",
+ "nb_NO" => "Norsk bokmål",
+ "nl" => "Nederlands",
+ "pl" => "Polski",
+ "pt_BR" => "Português (Brasil)",
+ "pt_PT" => "Português (Portugal)",
+ "ro" => "Română",
+ "ru" => "Русский",
+ "tr" => "Türkçe",
+ "uk" => "українська мова",
+ "zh_HANS-CN" => "简体中文",
+ "zh_HANT" => "繁體中文"
+ }
def true_lang
@@true_lang
end
def languages
- self.doc_versions.select(:language).distinct.collect do |v|
+ doc_versions.select(:language).distinct.collect do |v|
[v[:language], @@true_lang[v[:language]] || v[:language]]
end
end
@@ -49,21 +48,25 @@ class DocFile < ApplicationRecord
changes = []
doc_versions = self.doc_versions.includes(:version).version_changes.limit(limit_size).to_a
doc_versions.each_with_index do |doc_version, i|
- next unless previous_doc_version = doc_versions[i+1]
+ previous_doc_version = doc_versions[i + 1]
+ next unless previous_doc_version
+
sha2 = doc_version.doc.blob_sha
sha1 = previous_doc_version.doc.blob_sha
if sha1 == sha2
unchanged_versions << doc_version.name
else
- if unchanged_versions.size > 0
+ if !unchanged_versions.empty?
if unchanged_versions.size == 1
- changes << {name: "#{unchanged_versions.first} no changes", changed: false}
+ changes << { name: "#{unchanged_versions.first} no changes", changed: false }
else
- changes << {name: "#{unchanged_versions.last} &rarr; #{unchanged_versions.first} no changes", changed: false}
+ changes << { name: "#{unchanged_versions.last} &rarr; #{unchanged_versions.first} no changes",
+ changed: false }
end
unchanged_versions = []
end
- changes << {name: doc_version.name, time: doc_version.committed, diff: previous_doc_version.diff(doc_version), changed: true}
+ changes << { name: doc_version.name, time: doc_version.committed, diff: previous_doc_version.diff(doc_version),
+ changed: true }
end
end
changes
diff --git a/app/models/doc_version.rb b/app/models/doc_version.rb
index 1b27aafe..5338ac28 100644
--- a/app/models/doc_version.rb
+++ b/app/models/doc_version.rb
@@ -11,9 +11,13 @@ class DocVersion < ApplicationRecord
belongs_to :doc_file
scope :with_includes, -> { includes(:doc) }
- scope :for_version, ->(version) { where(language: "en").joins(:version).where(versions: {name: version}).limit(1).first }
- scope :latest_version, ->(lang = "en") { where(language: lang).joins(:version).order("versions.vorder DESC").limit(1).first }
- scope :version_changes, -> { where(language: "en").with_includes.joins(:version).order("versions.vorder DESC") }
+ scope :for_version, lambda { |version|
+ where(language: "en").joins(:version).where(versions: { name: version }).limit(1).first
+ }
+ scope :latest_version, lambda { |lang = "en"|
+ where(language: lang).joins(:version).order("versions.vorder DESC").limit(1).first
+ }
+ scope :version_changes, -> { where(language: "en").with_includes.joins(:version).order("versions.vorder DESC") }
delegate :name, to: :version
delegate :committed, to: :version
@@ -23,26 +27,24 @@ class DocVersion < ApplicationRecord
# 1: subtractions
# 2: 8 - (add + sub)
def diff(doc_version)
- begin
- diff_out = Diffy::Diff.new(self.doc.plain, doc_version.doc.plain)
- first_chars=diff_out.to_s.gsub(/(.)[^\n]*\n/, '\1')
- adds = first_chars.count("+")
- mins = first_chars.count("-")
- total = mins + adds
- if total > 8
- min = (8.0 / total)
- adds = (adds * min).round
- mins = (mins * min).round
- total = 8
- end
- [adds, mins, 8 - total]
- rescue
- [0, 0, 8]
+ diff_out = Diffy::Diff.new(doc.plain, doc_version.doc.plain)
+ first_chars = diff_out.to_s.gsub(/(.)[^\n]*\n/, '\1')
+ adds = first_chars.count("+")
+ mins = first_chars.count("-")
+ total = mins + adds
+ if total > 8
+ min = (8.0 / total)
+ adds = (adds * min).round
+ mins = (mins * min).round
+ total = 8
end
+ [adds, mins, 8 - total]
+ rescue StandardError
+ [0, 0, 8]
end
def index
- file = self.doc_file
+ file = doc_file
doc = self.doc
client = ElasticClient.instance
@@ -51,13 +53,12 @@ class DocVersion < ApplicationRecord
type: "man_doc",
id: file.name,
body: {
- name: file.name,
- blob_sha: doc.blob_sha,
- text: doc.plain
+ name: file.name,
+ blob_sha: doc.blob_sha,
+ text: doc.plain
}
rescue StandardError
nil
end
end
-
end
diff --git a/app/models/download.rb b/app/models/download.rb
index 6a27984b..713dd6a5 100644
--- a/app/models/download.rb
+++ b/app/models/download.rb
@@ -10,6 +10,7 @@ class Download < ApplicationRecord
belongs_to :version
def self.latest_for(platform)
- includes(:version).where("platform=?", platform).order("versions.vorder DESC").order("downloads.release_date DESC").first
+ includes(:version).where("platform=?",
+ platform).order("versions.vorder DESC").order("downloads.release_date DESC").first
end
end
diff --git a/app/models/section.rb b/app/models/section.rb
index 9539f8f4..e10e0da4 100644
--- a/app/models/section.rb
+++ b/app/models/section.rb
@@ -11,7 +11,6 @@ require "searchable"
# t.belongs_to :chapter
# t.timestamps
class Section < ApplicationRecord
-
include Searchable
default_scope { order(:number) }
@@ -24,72 +23,69 @@ class Section < ApplicationRecord
has_many :xrefs, dependent: :delete_all
def set_slug
- if self.title
- title = (self.chapter.title + "-" + self.title)
- title = self.chapter.title if self.title.empty?
+ if title
+ title = (chapter.title + "-" + self.title)
+ title = chapter.title if self.title.empty?
title = title.gsub(/\(|\)|\./, "").gsub(/\s+/, "-").gsub("&#39;", "-")
self.slug = title
end
end
def prev_slug
- lang = self.book.code
- prev_number = self.number - 1
- if section = self.sections.find_by(number: prev_number)
- return "/book/#{lang}/v#{self.book.edition}/#{ERB::Util.url_encode(section.slug)}"
- else
+ lang = book.code
+ prev_number = number - 1
+ if (section = sections.find_by(number: prev_number))
+ return "/book/#{lang}/v#{book.edition}/#{ERB::Util.url_encode(section.slug)}"
+ elsif (ch = chapter.prev)
# find previous chapter
- if ch = self.chapter.prev
- if section = ch.last_section
- return "/book/#{lang}/v#{self.book.edition}/#{ERB::Util.url_encode(section.slug)}"
- end
+ if (section = ch.last_section)
+ return "/book/#{lang}/v#{book.edition}/#{ERB::Util.url_encode(section.slug)}"
end
end
+
"/book"
end
def next_slug
- lang = self.book.code
- next_number = self.number + 1
- if section = self.sections.find_by(number: next_number)
- return "/book/#{lang}/v#{self.book.edition}/#{ERB::Util.url_encode(section.slug)}"
- else
- if ch = self.chapter.next
- if section = ch.first_section
- return "/book/#{lang}/v#{self.book.edition}/#{ERB::Util.url_encode(section.slug)}"
- end
+ lang = book.code
+ next_number = number + 1
+ if (section = sections.find_by(number: next_number))
+ return "/book/#{lang}/v#{book.edition}/#{ERB::Util.url_encode(section.slug)}"
+ elsif (ch = chapter.next)
+ if (section = ch.first_section)
+ return "/book/#{lang}/v#{book.edition}/#{ERB::Util.url_encode(section.slug)}"
end
# find next chapter
end
- "/book/#{lang}/v#{self.book.edition}"
+
+ "/book/#{lang}/v#{book.edition}"
end
def cs_number
- if self.chapter.chapter_type == "appendix"
- "A" + self.chapter.chapter_number.to_s + "." + self.number.to_s
+ if chapter.chapter_type == "appendix"
+ "A" + chapter.chapter_number.to_s + "." + number.to_s
else
- self.chapter.chapter_number.to_s + "." + self.number.to_s
+ chapter.chapter_number.to_s + "." + number.to_s
end
end
def index
client = ElasticClient.instance
- code = self.book.code
+ code = book.code
begin
client.index index: ELASTIC_SEARCH_INDEX,
type: "book",
- id: "#{code}---#{self.slug}",
+ id: "#{code}---#{slug}",
body: {
- chapter: self.chapter.title,
- section: self.title,
- number: self.cs_number,
- lang: code,
- html: self.html
+ chapter: chapter.title,
+ section: title,
+ number: cs_number,
+ lang: code,
+ html: html
}
rescue StandardError
nil
end
end
-
end
diff --git a/app/models/version.rb b/app/models/version.rb
index 36dd509a..3521d1d3 100644
--- a/app/models/version.rb
+++ b/app/models/version.rb
@@ -15,7 +15,7 @@ class Version < ApplicationRecord
before_save :save_version_order
def save_version_order
- self.vorder = Version.version_to_num(self.name)
+ self.vorder = Version.version_to_num(name)
end
def self.latest_version
@@ -24,13 +24,12 @@ class Version < ApplicationRecord
def self.version_to_num(version)
version_int = 0.0
- mult = 1000000
+ mult = 1_000_000
numbers = version.to_s.split(".")
numbers.each do |x|
version_int += x.to_f * mult
- mult = mult / 100.0
+ mult /= 100.0
end
version_int
end
-
end
diff --git a/app/presenters/gui_presenter.rb b/app/presenters/gui_presenter.rb
index 74da3660..e0551885 100644
--- a/app/presenters/gui_presenter.rb
+++ b/app/presenters/gui_presenter.rb
@@ -1,10 +1,9 @@
# frozen_string_literal: true
class GuiPresenter
-
def read_gui_yaml
yaml = YAML.load_file("resources/guis.yml")
- return yaml["guis"]
+ yaml["guis"]
end
def initialize
@@ -14,14 +13,14 @@ class GuiPresenter
@@instance = GuiPresenter.new
def self.instance
- return @@instance
+ @@instance
end
def guis_info
if Rails.env.production?
- return @guis_info
+ @guis_info
else
- return read_gui_yaml
+ read_gui_yaml
end
end
diff --git a/app/services/download_service.rb b/app/services/download_service.rb
index 974c9f0b..0c9a535a 100644
--- a/app/services/download_service.rb
+++ b/app/services/download_service.rb
@@ -6,10 +6,10 @@ class DownloadService
# [OvD] note that Google uses Atom & Sourceforge uses RSS
# however this isn't relevant when parsing the feeds for
# name, version, url & date with Feedzirra
- SOURCEFORGE_URL = "https://sourceforge.net/projects/git-osx-installer/rss?limit=20".freeze
+ SOURCEFORGE_URL = "https://sourceforge.net/projects/git-osx-installer/rss?limit=20"
GIT_FOR_WINDOWS_REGEX = /^(Portable|)Git-(\d+\.\d+\.\d+(?:\.\d+)?)-(?:.+-)*(32|64)-bit(?:\..*)?\.exe/
- GIT_FOR_WINDOWS_NAME_WITH_OWNER = "git-for-windows/git".freeze
+ GIT_FOR_WINDOWS_NAME_WITH_OWNER = "git-for-windows/git"
class << self
def sourceforge_project_download_url(project, filename)
@@ -34,11 +34,11 @@ class DownloadService
if version
find_or_create_download(
- filename: name,
- platform: "windows#{bitness}#{portable}",
- release_date: date,
- version: version,
- url: url
+ filename: name,
+ platform: "windows#{bitness}#{portable}",
+ release_date: date,
+ version: version,
+ url: url
)
else
Rails.logger.info("Could not find version #{version_name}")
@@ -60,11 +60,11 @@ class DownloadService
if version
find_or_create_download(
- filename: name,
- platform: "mac",
- release_date: Time.parse(date.iso8601),
- version: version,
- url: url
+ filename: name,
+ platform: "mac",
+ release_date: Time.parse(date.iso8601),
+ version: version,
+ url: url
)
else
Rails.logger.info("Could not find version #{name}")
@@ -75,28 +75,28 @@ class DownloadService
private
def files_from_github(repository)
- @octokit = Octokit::Client.new(access_token: ENV["GITHUB_API_TOKEN"])
+ @octokit = Octokit::Client.new(access_token: ENV.fetch("GITHUB_API_TOKEN", nil))
downloads = []
releases = @octokit.releases(repository)
releases
- .reject { |release| release.prerelease || release.draft }
- .each do |release|
- release.assets.each do |asset|
- downloads << [
- asset.name,
- asset.updated_at,
- asset.browser_download_url
- ]
- end
- end
+ .reject { |release| release.prerelease || release.draft }
+ .each do |release|
+ release.assets.each do |asset|
+ downloads << [
+ asset.name,
+ asset.updated_at,
+ asset.browser_download_url
+ ]
+ end
+ end
downloads
end
def files_from_sourceforge(repository)
downloads = []
- rss = URI.open(repository).read
+ rss = URI.parse(repository).open.read
feed = RSS::Parser.parse(rss)
feed.items.each do |item|
@@ -108,11 +108,11 @@ class DownloadService
def find_or_create_download(filename:, platform:, release_date:, version:, url:)
options = {
- filename: filename,
- platform: platform,
+ filename: filename,
+ platform: platform,
release_date: release_date,
- version: version,
- url: url
+ version: version,
+ url: url
}
if (download = Download.find_by(options))
@@ -122,7 +122,7 @@ class DownloadService
download = Download.create!(options)
Rails.logger.info("Download record created #{download.inspect}")
rescue ActiveRecord::RecordInvalid => e
- Rail.logger.error("#{e.message}")
+ Rail.logger.error(e.message.to_s)
end
end
end
diff --git a/app/views/books/show.html.erb b/app/views/books/show.html.erb
index 7707eb4e..762722f5 100644
--- a/app/views/books/show.html.erb
+++ b/app/views/books/show.html.erb
@@ -35,7 +35,7 @@
<div class="book-wrapper">
<img src="/images/books/pro-git@2x.jpg" width="118" height="157"/>
<div>1st Edition (2009)</div>
- <% if @book.has_edition(2) %>
+ <% if @book.edition?(2) %>
<div class="switch"><a href="/book/<%= @book.code %>/v2">Switch to 2nd Edition</a></div>
<% end %>
</div>
diff --git a/bin/bundle b/bin/bundle
index 277e1282..525ef1cc 100755
--- a/bin/bundle
+++ b/bin/bundle
@@ -1,5 +1,5 @@
#!/usr/bin/env ruby
# frozen_string_literal: true
-ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile", __FILE__)
+ENV["BUNDLE_GEMFILE"] ||= File.expand_path('../Gemfile', __dir__)
load Gem.bin_path("bundler", "bundle")
diff --git a/bin/rails b/bin/rails
index 6fb4e405..da601805 100755
--- a/bin/rails
+++ b/bin/rails
@@ -1,4 +1,6 @@
#!/usr/bin/env ruby
+# frozen_string_literal: true
+
APP_PATH = File.expand_path('../config/application', __dir__)
require_relative "../config/boot"
require "rails/commands"
diff --git a/bin/rake b/bin/rake
index 4fbf10b9..e436ea54 100755
--- a/bin/rake
+++ b/bin/rake
@@ -1,4 +1,6 @@
#!/usr/bin/env ruby
+# frozen_string_literal: true
+
require_relative "../config/boot"
require "rake"
Rake.application.run
diff --git a/bin/setup b/bin/setup
index 57923026..cc2bbd3d 100755
--- a/bin/setup
+++ b/bin/setup
@@ -1,4 +1,6 @@
#!/usr/bin/env ruby
+# frozen_string_literal: true
+
require "fileutils"
# path to your application root.
diff --git a/config/environments/production.rb b/config/environments/production.rb
index 8e379444..eddeec2c 100644
--- a/config/environments/production.rb
+++ b/config/environments/production.rb
@@ -91,7 +91,7 @@ Rails.application.configure do
# config.logger = ActiveSupport::TaggedLogging.new(Syslog::Logger.new 'app-name')
if ENV["RAILS_LOG_TO_STDOUT"].present?
- logger = ActiveSupport::Logger.new(STDOUT)
+ logger = ActiveSupport::Logger.new($stdout)
logger.formatter = config.log_formatter
config.logger = ActiveSupport::TaggedLogging.new(logger)
end
diff --git a/config/initializers/assets.rb b/config/initializers/assets.rb
index 3bb606b2..101a2902 100644
--- a/config/initializers/assets.rb
+++ b/config/initializers/assets.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
# Be sure to restart your server when you modify this file.
# Version of your assets, change this if you want to expire all your assets.
diff --git a/config/initializers/backtrace_silencers.rb b/config/initializers/backtrace_silencers.rb
index 9290b504..74f30e88 100644
--- a/config/initializers/backtrace_silencers.rb
+++ b/config/initializers/backtrace_silencers.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
# Be sure to restart your server when you modify this file.
# You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces.
diff --git a/config/initializers/cookies_serializer.rb b/config/initializers/cookies_serializer.rb
index 2a729595..ee8dff9c 100644
--- a/config/initializers/cookies_serializer.rb
+++ b/config/initializers/cookies_serializer.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
# Be sure to restart your server when you modify this file.
# Specify a serializer for the signed and encrypted cookie jars.
diff --git a/config/initializers/elasticsearch.rb b/config/initializers/elasticsearch.rb
index 9fd9a454..42da4fc9 100644
--- a/config/initializers/elasticsearch.rb
+++ b/config/initializers/elasticsearch.rb
@@ -1,15 +1,13 @@
# frozen_string_literal: true
class ElasticClient
-
@@instance = Elasticsearch::Client.new url: (ENV["BONSAI_URL"] || "http://0.0.0.0:9200"), log: false
def self.instance
- return @@instance
+ @@instance
end
private_class_method :new
end
-
ELASTIC_SEARCH_INDEX = "gitscm"
diff --git a/config/initializers/filter_parameter_logging.rb b/config/initializers/filter_parameter_logging.rb
index 8bb8d065..3babc73f 100644
--- a/config/initializers/filter_parameter_logging.rb
+++ b/config/initializers/filter_parameter_logging.rb
@@ -1,7 +1,8 @@
# frozen_string_literal: true
+
# Be sure to restart your server when you modify this file.
# Configure sensitive parameters which will be filtered from the log file.
-Rails.application.config.filter_parameters += [
- :passw, :secret, :token, :_key, :crypt, :salt, :certificate, :otp, :ssn
+Rails.application.config.filter_parameters += %i[
+ passw secret token _key crypt salt certificate otp ssn
]
diff --git a/config/initializers/timeout.rb b/config/initializers/timeout.rb
index 32d44336..db77a082 100644
--- a/config/initializers/timeout.rb
+++ b/config/initializers/timeout.rb
@@ -1,3 +1,6 @@
# frozen_string_literal: true
-Rails.application.config.middleware.insert_before Rack::Runtime, Rack::Timeout, service_timeout: 20 if Rails.env.production?
+if Rails.env.production?
+ Rails.application.config.middleware.insert_before Rack::Runtime, Rack::Timeout,
+ service_timeout: 20
+end
diff --git a/config/initializers/wrap_parameters.rb b/config/initializers/wrap_parameters.rb
index 18c38252..2f3c0db4 100644
--- a/config/initializers/wrap_parameters.rb
+++ b/config/initializers/wrap_parameters.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
# Be sure to restart your server when you modify this file.
# This file contains settings for ActionController::ParamsWrapper which
diff --git a/config/puma.rb b/config/puma.rb
index a776960e..e663c140 100644
--- a/config/puma.rb
+++ b/config/puma.rb
@@ -1,11 +1,12 @@
# frozen_string_literal: true
+
# Puma can serve each request in a thread from an internal thread pool.
# The `threads` method setting takes two numbers: a minimum and maximum.
# Any libraries that use thread pools should be configured to match
# the maximum value specified for Puma. Default is set to 5 threads for minimum
# and maximum; this matches the default thread size of Active Record.
#
-max_threads_count = ENV.fetch("RAILS_MAX_THREADS") { 5 }
+max_threads_count = ENV.fetch("RAILS_MAX_THREADS", 5)
min_threads_count = ENV.fetch("RAILS_MIN_THREADS") { max_threads_count }
threads min_threads_count, max_threads_count
@@ -16,14 +17,14 @@ worker_timeout 3600 if ENV.fetch("RAILS_ENV", "development") == "development"
# Specifies the `port` that Puma will listen on to receive requests; default is 3000.
#
-port ENV.fetch("PORT") { 3000 }
+port ENV.fetch("PORT", 3000)
# Specifies the `environment` that Puma will run in.
#
-environment ENV.fetch("RAILS_ENV") { "development" }
+environment ENV.fetch("RAILS_ENV", "development")
# Specifies the `pidfile` that Puma will use.
-pidfile ENV.fetch("PIDFILE") { "tmp/pids/server.pid" }
+pidfile ENV.fetch("PIDFILE", "tmp/pids/server.pid")
# Specifies the number of `workers` to boot in clustered mode.
# Workers are forked web server processes. If using threads and workers together
diff --git a/config/routes.rb b/config/routes.rb
index e5da1676..aa83b100 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -26,15 +26,15 @@ Rails.application.routes.draw do
"https://github.com/git/git/blob/master/Documentation/howto/#{path_params[:file]}.txt"
}
- get "/:file.html" => "doc#man", :as => :doc_file_html, :file => /[\w\-\.]+/
- get "/:file" => "doc#man", :as => :doc_file, :file => /[\w\-\.]+/
+ get "/:file.html" => "doc#man", :as => :doc_file_html, :file => /[\w\-.]+/
+ get "/:file" => "doc#man", :as => :doc_file, :file => /[\w\-.]+/
get "/:file/:version" => "doc#man", :version => /[^\/]+/
end
%w[man ref git].each do |path|
- get "/#{path}/:file" => redirect("/docs/%{file}")
- get "/#{path}/:file/:version" => redirect("/docs/%{file}/%{version}"), :version => /[^\/]+/
+ get "/#{path}/:file" => redirect("/docs/%<file>s")
+ get "/#{path}/:file/:version" => redirect("/docs/%<file>s/%<version>s"), :version => /[^\/]+/
end
resource :book do
@@ -46,9 +46,9 @@ Rails.application.routes.draw do
nested do
scope ":lang" do
- get "/v1" => redirect("/book/%{lang}/v2")
- get "/v1/:slug" => redirect("/book/%{lang}/v2/%{slug}")
- get "/v1/:chapter/:link" => redirect("/book/%{lang}/v2/%{chapter}/%{link}")
+ get "/v1" => redirect("/book/%<lang>s/v2")
+ get "/v1/:slug" => redirect("/book/%<lang>s/v2/%<slug>s")
+ get "/v1/:chapter/:link" => redirect("/book/%<lang>s/v2/%<chapter>s/%<link>s")
get "/v:edition" => "books#show"
get "/v:edition/:slug" => "books#section"
diff --git a/db/migrate/20120415151530_add_version_order.rb b/db/migrate/20120415151530_add_version_order.rb
index cbb4a3b2..40f5fd6a 100644
--- a/db/migrate/20120415151530_add_version_order.rb
+++ b/db/migrate/20120415151530_add_version_order.rb
@@ -3,9 +3,7 @@
class AddVersionOrder < ActiveRecord::Migration[4.2]
def up
add_column :versions, :vorder, :float
- Version.all.each do |version|
- version.save
- end
+ Version.all.each(&:save)
end
def down
diff --git a/db/migrate/20120417221951_add_book_stuff.rb b/db/migrate/20120417221951_add_book_stuff.rb
index 4af8dee2..684cc9b7 100644
--- a/db/migrate/20120417221951_add_book_stuff.rb
+++ b/db/migrate/20120417221951_add_book_stuff.rb
@@ -3,7 +3,7 @@
class AddBookStuff < ActiveRecord::Migration[4.2]
def up
create_table :books do |t|
- t.string :code
+ t.string :code
t.timestamps
end
add_index :books, [:code]
diff --git a/db/migrate/20190131210305_add_language_to_doc_version.rb b/db/migrate/20190131210305_add_language_to_doc_version.rb
index f955e7a1..0ba0192f 100644
--- a/db/migrate/20190131210305_add_language_to_doc_version.rb
+++ b/db/migrate/20190131210305_add_language_to_doc_version.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
class AddLanguageToDocVersion < ActiveRecord::Migration[4.2]
def change
add_column :doc_versions, :language, :string, default: "en"
diff --git a/db/migrate/20201213045819_add_index_to_versions.rb b/db/migrate/20201213045819_add_index_to_versions.rb
index eb7e1538..77c8debe 100644
--- a/db/migrate/20201213045819_add_index_to_versions.rb
+++ b/db/migrate/20201213045819_add_index_to_versions.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
class AddIndexToVersions < ActiveRecord::Migration[6.1]
def change
remove_index :versions, :name
diff --git a/lib/searchable.rb b/lib/searchable.rb
index 82cef395..d91340a2 100644
--- a/lib/searchable.rb
+++ b/lib/searchable.rb
@@ -4,13 +4,11 @@ module Searchable
extend ActiveSupport::Concern
included do
-
def self.search(keywords, options = {})
-
- # TODO find more OOP solution
+ # TODO: find more OOP solution
# we should never look to search_type variable again here
# nor when adding to index
- class_name = self.name.to_s.downcase
+ class_name = name.to_s.downcase
search_type = (class_name == "section" ? "book" : "man_doc")
type_name = (search_type == "book" ? "section" : "name")
@@ -20,38 +18,55 @@ module Searchable
"size" => 10,
"query" => {
"bool" => {
- "should"=> [],
+ "should" => [],
"minimum_number_should_match" => 1
},
},
"highlight" => {
- "pre_tags" => ["[highlight]"],
+ "pre_tags" => ["[highlight]"],
"post_tags" => ["[xhighlight]"],
- "fields" => { format => { "fragment_size" => 200 } }
+ "fields" => { format => { "fragment_size" => 200 } }
}
}
- lang_options = {"must" => [{ "term" => { "lang" => options[:lang] } }]}
+ lang_options = { "must" => [{ "term" => { "lang" => options[:lang] } }] }
query_options["query"]["bool"].merge!(lang_options) if options[:lang].present?
- keywords.split(/\s|\-/).each do |keyword|
- query_options["query"]["bool"]["should"] << { "prefix" => { type_name => { "value" => keyword, "boost" => 12.0 } } }
+ keywords.split(/\s|-/).each do |keyword|
+ query_options["query"]["bool"]["should"] << { "prefix" => { type_name => { "value" => keyword,
+ "boost" => 12.0 } } }
query_options["query"]["bool"]["should"] << { "term" => { format => keyword } }
end
client = ElasticClient.instance
- search = client.search index: ELASTIC_SEARCH_INDEX, body: query_options rescue nil
+ search = begin
+ client.search index: ELASTIC_SEARCH_INDEX, body: query_options
+ rescue StandardError
+ nil
+ end
if search
ref_hits = []
- results = search["hits"]["hits"] rescue []
+ results = begin
+ search["hits"]["hits"]
+ rescue StandardError
+ []
+ end
results.each do |result|
source = result["_source"]
name = source["section"] || source["chapter"] || source["name"]
slug = result["_id"].gsub("---", "/")
highlight = if search_type == "book"
- result["highlight"]["html"].first rescue nil
+ begin
+ result["highlight"]["html"].first
+ rescue StandardError
+ nil
+ end
else
- result["highlight"]["text"].first rescue nil
+ begin
+ result["highlight"]["text"].first
+ rescue StandardError
+ nil
+ end
end
hit = {
name: name,
@@ -61,13 +76,10 @@ module Searchable
}
ref_hits << hit
end
- if ref_hits.size > 0
- return {category: category_name, term: keywords, matches: ref_hits}
+ if !ref_hits.empty?
+ { category: category_name, term: keywords, matches: ref_hits }
end
end
-
end
-
end
-
end
diff --git a/lib/tasks/book2.rake b/lib/tasks/book2.rake
index 12d447f0..d96f3315 100644
--- a/lib/tasks/book2.rake
+++ b/lib/tasks/book2.rake
@@ -1,19 +1,19 @@
-# rubocop:disable Style/FrozenStringLiteralComment
+# frozen_string_literal: true
require "nokogiri"
require "octokit"
require "pathname"
def expand(content, path, &get_content)
- content.gsub(/include::(\S+)\[\]/) do |line|
- if File.dirname(path)=="."
+ content.gsub(/include::(\S+)\[\]/) do |_line|
+ if File.dirname(path) == "."
new_fname = $1
else
new_fname = (Pathname.new(path).dirname + Pathname.new($1)).cleanpath.to_s
end
new_content = get_content.call(new_fname)
if new_content
- expand(new_content.gsub("\xEF\xBB\xBF".force_encoding("UTF-8"), ""), new_fname) { |c| get_content.call (c) }
+ expand(new_content.gsub("\xEF\xBB\xBF".force_encoding("UTF-8"), ""), new_fname) { |c| get_content.call(c) }
else
puts "#{new_fname} could not be resolved for expansion"
""
@@ -23,10 +23,10 @@ end
desc "Reset book html to trigger re-build"
task reset_book2: :environment do
- Book.where(edition: 2).each do |book|
- book.ebook_html = "0000000000000000000000000000000000000000"
- book.save
- end
+ Book.where(edition: 2).each do |book|
+ book.ebook_html = "0000000000000000000000000000000000000000"
+ book.save
+ end
end
def genbook(code, &get_content)
@@ -38,26 +38,25 @@ def genbook(code, &get_content)
appnumber = 0
chnumber = 0
secnumber = 0
- ids = {}
# The chapter files are historically located in book/<chapter_name>/1-<chapter_name>.asc
# The new localisation of these files are at the root of the project
chapter_files = /(book\/[01A-C].*\/1-[^\/]*?\.asc|(?:ch[0-9]{2}|[ABC])-[^\/]*?\.asc)/
chaps = progit.scan(chapter_files).flatten
- chaps.each_with_index do |filename, index|
+ chaps.each_with_index do |filename, _index|
# select the chapter files
- if filename =~ /(book\/[01].*\/1-[^\/]*\.asc|ch[0-9]{2}-.*\.asc)/
+ if /(book\/[01].*\/1-[^\/]*\.asc|ch[0-9]{2}-.*\.asc)/.match?(filename)
chnumber += 1
- chapters ["ch#{secnumber}"] = ["chapter", chnumber, filename]
+ chapters["ch#{secnumber}"] = ["chapter", chnumber, filename]
secnumber += 1
end
# detect the appendices
- if filename =~ /(book\/[ABC].*\.asc|[ABC].*\.asc)/
- appnumber += 1
- chapters ["ch#{secnumber}"] = ["appendix", appnumber, filename]
- secnumber += 1
- end
+ next unless filename =~ /(book\/[ABC].*\.asc|[ABC].*\.asc)/
+
+ appnumber += 1
+ chapters["ch#{secnumber}"] = ["appendix", appnumber, filename]
+ secnumber += 1
end
# we strip the includes that don't match the chapters we want to include
@@ -71,7 +70,7 @@ def genbook(code, &get_content)
begin
l10n_file = URI.open("https://raw.githubusercontent.com/asciidoctor/asciidoctor/master/data/locale/attributes-#{code}.adoc").read
- rescue
+ rescue StandardError
l10n_file = ""
end
initial_content.gsub!("include::ch01", l10n_file + "\ninclude::ch01")
@@ -80,7 +79,7 @@ def genbook(code, &get_content)
# revert internal links decorations for ebooks
content.gsub!(/<<.*?\#(.*?)>>/, "<<\\1>>")
- asciidoc = Asciidoctor::Document.new(content, attributes: { "lang" => code})
+ asciidoc = Asciidoctor::Document.new(content, attributes: { "lang" => code })
html = asciidoc.render
alldoc = Nokogiri::HTML(html)
number = 1
@@ -94,7 +93,7 @@ def genbook(code, &get_content)
puts "not including #{chapter_title}\n"
break
end
- chapter_type, chapter_number, filename = chapters ["ch#{index}"]
+ chapter_type, chapter_number = chapters["ch#{index}"]
chapter = entry
next if !chapter_title
@@ -123,7 +122,6 @@ def genbook(code, &get_content)
section = 1
chapter.search("div[@class=sect2]").each do |sec|
-
id_xref = sec.at("h3").attribute("id").to_s
section_title = sec.at("h3").content
@@ -137,24 +135,33 @@ def genbook(code, &get_content)
html.gsub!("<h5", "<h4")
html.gsub!(/\/h5>/, "/h4>")
- if xlink = html.scan(/href=\"1-.*?\.html\#(.*?)\"/)
- xlink.each do |link|
- xref = link.first
- html.gsub!(/href=\"1-.*?\.html\##{xref}\"/, "href=\"ch00/#{xref}\"") rescue nil
+ xlink = html.scan(/href="1-.*?\.html\#(.*?)"/)
+ xlink&.each do |link|
+ xref = link.first
+ begin
+ html.gsub!(/href="1-.*?\.html\##{xref}"/, "href=\"ch00/#{xref}\"")
+ rescue StandardError
+ nil
end
end
- if xlink = html.scan(/href=\"\#(.*?)\"/)
- xlink.each do |link|
- xref = link.first
- html.gsub!(/href=\"\##{xref}\"/, "href=\"ch00/#{xref}\"") rescue nil
+ xlink = html.scan(/href="\#(.*?)"/)
+ xlink&.each do |link|
+ xref = link.first
+ begin
+ html.gsub!(/href="\##{xref}"/, "href=\"ch00/#{xref}\"")
+ rescue StandardError
+ nil
end
end
- if subsec = html.scan(/<img src="(.*?)"/)
- subsec.each do |sub|
- sub = sub.first
- html.gsub!(/<img src="#{sub}"/, "<img src=\"/book/en/v2/#{sub}\"") rescue nil
+ subsec = html.scan(/<img src="(.*?)"/)
+ subsec&.each do |sub|
+ sub = sub.first
+ begin
+ html.gsub!(/<img src="#{sub}"/, "<img src=\"/book/en/v2/#{sub}\"")
+ rescue StandardError
+ nil
end
end
@@ -170,7 +177,7 @@ def genbook(code, &get_content)
xref.save
# record all the xrefs
- (sec.search(".//*[@id]")).each do |id|
+ sec.search(".//*[@id]").each do |id|
id_xref = id.attribute("id").to_s
xref = Xref.where(book_id: book.id, name: id_xref).first_or_create
xref.section = csection
@@ -189,67 +196,61 @@ end
desc "Generate book html directly from git repo"
task remote_genbook2: :environment do
- @octokit = Octokit::Client.new(access_token: ENV["GITHUB_API_TOKEN"])
+ @octokit = Octokit::Client.new(access_token: ENV.fetch("GITHUB_API_TOKEN", nil))
if ENV["GENLANG"]
- books = Book.all_books.select { |code, repo| code == ENV["GENLANG"] }
+ books = Book.all_books.select { |code, _repo| code == ENV["GENLANG"] }
else
- books = Book.all_books.select do |code, repo|
+ books = Book.all_books.reject do |code, repo|
repo_head = @octokit.commit(repo, "HEAD").sha
book = Book.where(edition: 2, code: code).first_or_create
- repo_head != book.ebook_html
+ repo_head == book.ebook_html
end
end
books.each do |code, repo|
- begin
- blob_content = Hash.new do |blobs, sha|
- content = Base64.decode64(@octokit.blob(repo, sha, encoding: "base64").content)
- blobs[sha] = content.force_encoding("UTF-8")
- end
- repo_head = @octokit.commit(repo, "HEAD")
- repo_tree = @octokit.tree(repo, repo_head.commit.tree.sha, recursive: true)
- Book.transaction do
- genbook(code) do |filename|
- file_handle = repo_tree.tree.detect { |tree| tree[:path] == filename }
- if file_handle
- blob_content[file_handle[:sha]]
- end
+ blob_content = Hash.new do |blobs, sha|
+ content = Base64.decode64(@octokit.blob(repo, sha, encoding: "base64").content)
+ blobs[sha] = content.force_encoding("UTF-8")
+ end
+ repo_head = @octokit.commit(repo, "HEAD")
+ repo_tree = @octokit.tree(repo, repo_head.commit.tree.sha, recursive: true)
+ Book.transaction do
+ genbook(code) do |filename|
+ file_handle = repo_tree.tree.detect { |tree| tree[:path] == filename }
+ if file_handle
+ blob_content[file_handle[:sha]]
end
+ end
- book = Book.where(edition: 2, code: code).first_or_create
- book.ebook_html = repo_head.sha
+ book = Book.where(edition: 2, code: code).first_or_create
+ book.ebook_html = repo_head.sha
- begin
- rel = @octokit.latest_release(repo)
- get_url = -> (name_re) do
- asset = rel.assets.find { |asset| name_re.match(asset.name) }
- if asset
- asset.browser_download_url
- else
- nil
- end
- end
- book.ebook_pdf = get_url.call(/\.pdf$/)
- book.ebook_epub = get_url.call(/\.epub$/)
- book.ebook_mobi = get_url.call(/\.mobi$/)
- rescue Octokit::NotFound
- book.ebook_pdf = nil
- book.ebook_epub = nil
- book.ebook_mobi = nil
+ begin
+ rel = @octokit.latest_release(repo)
+ get_url = lambda do |name_re|
+ asset = rel.assets.find { |asset| name_re.match(asset.name) }
+ asset&.browser_download_url
end
-
- book.save
+ book.ebook_pdf = get_url.call(/\.pdf$/)
+ book.ebook_epub = get_url.call(/\.epub$/)
+ book.ebook_mobi = get_url.call(/\.mobi$/)
+ rescue Octokit::NotFound
+ book.ebook_pdf = nil
+ book.ebook_epub = nil
+ book.ebook_mobi = nil
end
- rescue StandardError => err
- puts err.message
+
+ book.save
end
+ rescue StandardError => e
+ puts e.message
end
end
desc "Generate book html directly from git repo"
task local_genbook2: :environment do
- if (ENV["GENLANG"] && ENV["GENPATH"])
+ if ENV["GENLANG"] && ENV["GENPATH"]
genbook(ENV["GENLANG"]) do |filename|
File.open(File.join(ENV["GENPATH"], filename), "r") { |infile| File.read(infile) }
end
diff --git a/lib/tasks/downloads.rake b/lib/tasks/downloads.rake
index 6fa57eea..0fb07ef8 100644
--- a/lib/tasks/downloads.rake
+++ b/lib/tasks/downloads.rake
@@ -1,16 +1,16 @@
-# rubocop:disable Style/FrozenStringLiteralComment
+# frozen_string_literal: true
desc "find newest mac and windows binary downloads"
task downloads: %i[windows_downloads mac_downloads]
desc "find latest windows version"
task windows_downloads: :environment do
- Rails.logger = Logger.new(STDOUT)
+ Rails.logger = Logger.new($stdout)
DownloadService.download_windows_versions
end
desc "find latest mac version"
task mac_downloads: :environment do
- Rails.logger = Logger.new(STDOUT)
+ Rails.logger = Logger.new($stdout)
DownloadService.download_mac_versions
end
diff --git a/lib/tasks/index.rake b/lib/tasks/index.rake
index c5c933fe..85ca66bf 100644
--- a/lib/tasks/index.rake
+++ b/lib/tasks/index.rake
@@ -1,4 +1,4 @@
-# rubocop:disable Style/FrozenStringLiteralComment
+# frozen_string_literal: true
require "asciidoctor"
require "octokit"
@@ -7,22 +7,38 @@ require "digest/sha1"
require "set"
def make_asciidoc(content)
- Asciidoctor::Document.new(content,
- attributes: {
- "sectanchors" => "",
- "litdd" => "&\#x2d;&\#x2d;",
- "compat-mode" => "",
- },
- doctype: "book")
+ Asciidoctor::Document.new(content,
+ attributes: {
+ "sectanchors" => "",
+ "litdd" => "&\#x2d;&\#x2d;",
+ "compat-mode" => "",
+ },
+ doctype: "book")
end
-def index_l10n_doc(filter_tags, doc_list, get_content)
+def expand_l10n(path, content, get_f_content, categories)
+ content.gsub!(/include::(\S+)\.txt/) do |line|
+ line.gsub!("include::", "")
+ if categories[line]
+ new_content = categories[line]
+ else
+ new_content, new_path = get_f_content.call(path, line)
+ end
+ if new_content
+ expand_l10n(new_path, new_content, get_f_content, categories)
+ else
+ "\n\n[WARNING]\n====\nMissing `#{new_path}`\n\nSee original version for this content.\n====\n\n"
+ end
+ end
+ content
+end
+def index_l10n_doc(filter_tags, doc_list, get_content)
ActiveRecord::Base.logger.level = Logger::WARN
- rebuild = ENV["REBUILD_DOC"]
+ rebuild = ENV.fetch("REBUILD_DOC", nil)
rerun = ENV["RERUN"] || rebuild || false
- filter_tags.call(rebuild, false).sort_by { |tag| Version.version_to_num(tag.first[1..-1]) }.each do |tag|
+ filter_tags.call(rebuild, false).sort_by { |tag| Version.version_to_num(tag.first[1..]) }.each do |tag|
name, commit_sha, tree_sha, ts = tag
puts "#{name}: #{ts}, #{commit_sha[0, 8]}, #{tree_sha[0, 8]}"
@@ -36,42 +52,25 @@ def index_l10n_doc(filter_tags, doc_list, get_content)
stag.save
tag_files = doc_list.call(tree_sha)
- doc_files = tag_files.select { |ent| ent.first =~
+ doc_files = tag_files.select do |ent|
+ ent.first =~
/^([-_\w]+)\/(
(
git.*
)\.txt)/x
- }
+ end
puts "Found #{doc_files.size} entries"
- doc_limit = ENV["ONLY_BUILD_DOC"]
- get_content_f = Proc.new do |source, target|
+ get_content_f = proc do |source, target|
name = File.join(File.dirname(source), target)
- content_file = tag_files.detect { |ent| ent.first == name }
- if content_file
- new_content = get_content.call (content_file.second)
- else
- puts "Included file #{name} was not translated. Processing anyway\n"
- end
- [new_content, name]
- end
-
- def expand!(path, content, get_f_content , categories)
- content.gsub!(/include::(\S+)\.txt/) do |line|
- line.gsub!("include::", "")
- if categories[line]
- new_content = categories[line]
- else
- new_content, new_path = get_f_content.call(path, line)
- end
- if new_content
- expand!(new_path, new_content, get_f_content, categories)
- else
- "\n\n[WARNING]\n====\nMissing `#{new_path}`\n\nSee original version for this content.\n====\n\n"
- end
+ content_file = tag_files.detect { |ent| ent.first == name }
+ if content_file
+ new_content = get_content.call(content_file.second)
+ else
+ puts "Included file #{name} was not translated. Processing anyway\n"
end
- return content
+ [new_content, name]
end
doc_files.each do |entry|
@@ -79,7 +78,6 @@ def index_l10n_doc(filter_tags, doc_list, get_content)
ids = Set.new([])
lang = File.dirname(full_path)
path = File.basename(full_path, ".txt")
- #next if doc_limit && path !~ /#{doc_limit}/
file = DocFile.where(name: path).first_or_create
@@ -87,7 +85,7 @@ def index_l10n_doc(filter_tags, doc_list, get_content)
content = get_content.call sha
categories = {}
- expand!(full_path, content, get_content_f, categories)
+ expand_l10n(full_path, content, get_content_f, categories)
content.gsub!(/link:(?:technical\/)?(\S*?)\.html(\#\S*?)?\[(.*?)\]/m, "link:/docs/\\1/#{lang}\\2[\\3]")
asciidoc = make_asciidoc(content)
asciidoc_sha = Digest::SHA1.hexdigest(asciidoc.source)
@@ -96,16 +94,14 @@ def index_l10n_doc(filter_tags, doc_list, get_content)
html = asciidoc.render
html.gsub!(/linkgit:(\S+)\[(\d+)\]/) do |line|
x = /^linkgit:(\S+)\[(\d+)\]/.match(line)
- line = "<a href='/docs/#{x[1]}/#{lang}'>#{x[1]}[#{x[2]}]</a>"
+ "<a href='/docs/#{x[1]}/#{lang}'>#{x[1]}[#{x[2]}]</a>"
end
- #HTML anchor on hdlist1 (i.e. command options)
- html.gsub!(/<dt class="hdlist1">(.*?)<\/dt>/) do |m|
+ # HTML anchor on hdlist1 (i.e. command options)
+ html.gsub!(/<dt class="hdlist1">(.*?)<\/dt>/) do |_m|
text = $1.tr("^A-Za-z0-9-", "")
anchor = "#{path}-#{text}"
# handle anchor collisions by appending -1
- while ids.include?(anchor)
- anchor += "-1"
- end
+ anchor += "-1" while ids.include?(anchor)
ids.add(anchor)
"<dt class=\"hdlist1\" id=\"#{anchor}\"> <a class=\"anchor\" href=\"##{anchor}\"></a>#{$1} </dt>"
@@ -123,47 +119,69 @@ def index_l10n_doc(filter_tags, doc_list, get_content)
end
def drop_uninteresting_tags(tags)
- # proceed in reverse-chronological order, as we'll pick only the
- # highest-numbered point release for older versions
- ret = Array.new
- tags.reverse_each do |tag|
- numeric = Version.version_to_num(tag.first[1..-1])
- # drop anything older than v2.0
- next if numeric < 2000000
- # older than v2.17, take only the highest release
- if numeric < 2170000 and !ret.empty?
- old = Version.version_to_num(ret[0].first[1..-1])
- next if old.to_i.div(10000) == numeric.to_i.div(10000)
- end
- # keep everything else
- ret.unshift(tag)
+ # proceed in reverse-chronological order, as we'll pick only the
+ # highest-numbered point release for older versions
+ ret = []
+ tags.reverse_each do |tag|
+ numeric = Version.version_to_num(tag.first[1..])
+ # drop anything older than v2.0
+ next if numeric < 2_000_000
+
+ # older than v2.17, take only the highest release
+ if (numeric < 2_170_000) && !ret.empty?
+ old = Version.version_to_num(ret[0].first[1..])
+ next if old.to_i.div(10_000) == numeric.to_i.div(10_000)
end
- return ret
+ # keep everything else
+ ret.unshift(tag)
+ end
+ ret
+end
+
+def expand_content(content, path, get_f_content, generated)
+ content.gsub(/include::(\S+)\.txt\[\]/) do |_line|
+ if File.dirname(path) == "."
+ new_fname = "#{$1}.txt"
+ else
+ new_fname = (Pathname.new(path).dirname + Pathname.new("#{$1}.txt")).cleanpath.to_s
+ end
+ if generated[new_fname]
+ new_content = generated[new_fname]
+ else
+ new_content = get_f_content.call(new_fname)
+ if new_content
+ expand_content(new_content.force_encoding("UTF-8"), new_fname, get_f_content, generated)
+ else
+ puts "#{new_fname} could not be resolved for expansion"
+ end
+ end
+ new_content
+ end
end
def index_doc(filter_tags, doc_list, get_content)
ActiveRecord::Base.logger.level = Logger::WARN
- rebuild = ENV["REBUILD_DOC"]
+ rebuild = ENV.fetch("REBUILD_DOC", nil)
rerun = ENV["RERUN"] || rebuild || false
- tags = filter_tags.call(rebuild).sort_by { |tag| Version.version_to_num(tag.first[1..-1]) }
+ tags = filter_tags.call(rebuild).sort_by { |tag| Version.version_to_num(tag.first[1..]) }
drop_uninteresting_tags(tags).each do |tag|
name, commit_sha, tree_sha, ts = tag
puts "#{name}: #{ts}, #{commit_sha[0, 8]}, #{tree_sha[0, 8]}"
- stag = Version.where(name: name.gsub("v", "")).first
+ stag = Version.where(name: name.delete("v")).first
next if stag && !rerun
- stag = Version.where(name: name.gsub("v", "")).first_or_create
+ stag = Version.where(name: name.delete("v")).first_or_create
stag.commit_sha = commit_sha
stag.tree_sha = tree_sha
stag.committed = ts
stag.save
-
tag_files = doc_list.call(tree_sha)
- doc_files = tag_files.select { |ent| ent.first =~
+ doc_files = tag_files.select do |ent|
+ ent.first =~
/^Documentation\/(
SubmittingPatches |
MyFirstContribution.txt |
@@ -181,75 +199,62 @@ def index_doc(filter_tags, doc_list, get_content)
pull.* |
technical\/.*
)\.txt)/x
- }
+ end
puts "Found #{doc_files.size} entries"
- doc_limit = ENV["ONLY_BUILD_DOC"]
+ doc_limit = ENV.fetch("ONLY_BUILD_DOC", nil)
# generate command-list content
generated = {}
- cmd = tag_files.detect { |f| f.first =~ /command-list\.txt/ }
+ cmd = tag_files.detect { |f| f.first == "command-list.txt" }
if cmd
- cmd_list = get_content.call(cmd.second).match(/(### command list.*|# command name.*)/m)[0].split("\n").reject { |l| l =~ /^#/ }.inject({}) do |list, cmd|
- name, kind, attr = cmd.split(/\s+/)
- list[kind] ||= []
- list[kind] << [name, attr]
- list
- end
+ cmd_list =
+ get_content
+ .call(cmd.second)
+ .match(/(### command list.*|# command name.*)/m)[0]
+ .split("\n")
+ .grep_v(/^#/)
+ .each_with_object({}) do |cmd, list|
+ name, kind, attr = cmd.split(/\s+/)
+ list[kind] ||= []
+ list[kind] << [name, attr]
+ end
generated = cmd_list.keys.inject({}) do |list, category|
links = cmd_list[category].map do |cmd, attr|
- if cmd_file = tag_files.detect { |ent| ent.first == "Documentation/#{cmd}.txt" }
- content = get_content.call(cmd_file.second)
- section = content.match(/^[a-z0-9-]+\(([1-9])\)/)[1]
- if match = content.match(/NAME\n----\n\S+ - (.*)$/)
- "linkgit:#{cmd}[#{section}]::\n\t#{attr == 'deprecated' ? '(deprecated) ' : ''}#{match[1]}\n"
- end
+ cmd_file = tag_files.detect { |ent| ent.first == "Documentation/#{cmd}.txt" }
+ next unless cmd_file
+
+ content = get_content.call(cmd_file.second)
+ section = content.match(/^[a-z0-9-]+\(([1-9])\)/)[1]
+ match = content.match(/NAME\n----\n\S+ - (.*)$/)
+ if match
+ "linkgit:#{cmd}[#{section}]::\n\t#{attr == 'deprecated' ? '(deprecated) ' : ''}#{match[1]}\n"
end
end
list.merge!("Documentation/cmds-#{category}.txt" => links.compact.join("\n"))
end
- tools = tag_files.select { |ent| ent.first =~/^mergetools\// }.map do |entry|
+ tools = tag_files.select { |ent| ent.first =~ /^mergetools\// }.map do |entry|
path, sha = entry
tool = File.basename path
content = get_content.call sha
- merge = (content.include? "can_merge") ? "" : " * #{tool}\n"
- diff = (content.include? "can_diff") ? "" : " * #{tool}\n"
+ merge = content.include?("can_merge") ? "" : " * #{tool}\n"
+ diff = content.include?("can_diff") ? "" : " * #{tool}\n"
[merge, diff]
end
- can_merge, can_diff = tools.transpose.map { |strs| strs.join "" }
+ can_merge, can_diff = tools.transpose.map(&:join)
generated["Documentation/mergetools-diff.txt"] = can_diff
generated["Documentation/mergetools-merge.txt"] = can_merge
- get_content_f = Proc.new do |name|
+ get_content_f = proc do |name|
content_file = tag_files.detect { |ent| ent.first == name }
if content_file
- new_content = get_content.call (content_file.second)
+ new_content = get_content.call(content_file.second)
end
new_content
end
- def expand_content(content, path, get_f_content , generated)
- content.gsub(/include::(\S+)\.txt\[\]/) do |line|
- if File.dirname(path)=="."
- new_fname = "#{$1}.txt"
- else
- new_fname = (Pathname.new(path).dirname + Pathname.new("#{$1}.txt")).cleanpath.to_s
- end
- if generated[new_fname]
- new_content = generated[new_fname]
- else
- new_content = get_f_content.call(new_fname)
- if new_content
- expand_content(new_content.force_encoding("UTF-8"), new_fname, get_f_content, generated)
- else
- puts "#{new_fname} could not be resolved for expansion"
- end
- end
- end
- end
-
doc_files.each do |entry|
path, sha = entry
ids = Set.new([])
@@ -269,16 +274,14 @@ def index_doc(filter_tags, doc_list, get_content)
html = asciidoc.render
html.gsub!(/linkgit:(\S+)\[(\d+)\]/) do |line|
x = /^linkgit:(\S+)\[(\d+)\]/.match(line)
- line = "<a href='/docs/#{x[1]}'>#{x[1]}[#{x[2]}]</a>"
+ "<a href='/docs/#{x[1]}'>#{x[1]}[#{x[2]}]</a>"
end
- #HTML anchor on hdlist1 (i.e. command options)
- html.gsub!(/<dt class="hdlist1">(.*?)<\/dt>/) do |m|
+ # HTML anchor on hdlist1 (i.e. command options)
+ html.gsub!(/<dt class="hdlist1">(.*?)<\/dt>/) do |_m|
text = $1.tr("^A-Za-z0-9-", "")
anchor = "#{path}-#{text}"
# handle anchor collisions by appending -1
- while ids.include?(anchor)
- anchor += "-1"
- end
+ anchor += "-1" while ids.include?(anchor)
ids.add(anchor)
"<dt class=\"hdlist1\" id=\"#{anchor}\"> <a class=\"anchor\" href=\"##{anchor}\"></a>#{$1} </dt>"
end
@@ -299,7 +302,7 @@ end
def github_index_doc(index_fun, repo)
Octokit.auto_paginate = true
- @octokit = Octokit::Client.new(access_token: ENV["GITHUB_API_TOKEN"])
+ @octokit = Octokit::Client.new(access_token: ENV.fetch("GITHUB_API_TOKEN", nil))
repo = ENV["GIT_REPO"] || repo
@@ -308,15 +311,15 @@ def github_index_doc(index_fun, repo)
blobs[sha] = content.force_encoding("UTF-8")
end
- tag_filter = -> (tagname, gettags = true) do
+ tag_filter = lambda do |tagname, gettags = true|
# find all tags
if gettags
- tags = @octokit.tags(repo).select { |tag| !tag.nil? && tag.name =~ /v\d([\.\d])+$/ } # just get release tags
+ tags = @octokit.tags(repo).select { |tag| !tag.nil? && tag.name =~ /v\d([.\d])+$/ } # just get release tags
if tagname
tags = tags.select { |t| t.name == tagname }
end
else
- tags=[Struct.new(:name).new("HEAD")]
+ tags = [Struct.new(:name).new("HEAD")]
end
tags.collect do |tag|
# extract metadata
@@ -329,9 +332,9 @@ def github_index_doc(index_fun, repo)
end
end
- get_content = -> (sha) do blob_content[sha] end
+ get_content = ->(sha) do blob_content[sha] end
- get_file_list = -> (tree_sha) do
+ get_file_list = lambda do |tree_sha|
tree_info = @octokit.tree(repo, tree_sha, recursive: true)
tree_info.tree.collect { |ent| [ent.path, ent.sha] }
end
@@ -340,45 +343,42 @@ def github_index_doc(index_fun, repo)
end
def local_index_doc(index_fun)
- dir = ENV["GIT_REPO"]
+ dir = ENV.fetch("GIT_REPO", nil)
Dir.chdir(dir) do
-
- tag_filter = -> (tagname, gettags = true) do
+ tag_filter = lambda do |tagname, gettags = true|
if gettags
# find all tags
tags = `git tag | egrep 'v1|v2'`.strip.split("\n")
- tags = tags.select { |tag| tag =~ /v\d([\.\d])+$/ } # just get release tags
+ tags = tags.grep(/v\d([.\d])+$/) # just get release tags
if tagname
tags = tags.select { |t| t == tagname }
end
else
- tags=["HEAD"]
+ tags = ["HEAD"]
end
tags.collect do |tag|
# extract metadata
commit_sha = `git rev-parse #{tag}`.chomp
tree_sha = `git rev-parse #{tag}^{tree}`.chomp
- tagger = `git cat-file commit #{tag} | grep committer`.chomp.split(" ")
- tz = tagger.pop
+ tagger = `git cat-file commit #{tag} | grep committer`.chomp.split
+ _tz = tagger.pop
ts = tagger.pop
ts = Time.at(ts.to_i)
[tag, commit_sha, tree_sha, ts]
end
end
- get_content = -> (sha) do `git cat-file blob #{sha}` end
+ get_content = ->(sha) do `git cat-file blob #{sha}` end
- get_file_list = -> (tree_sha) do
+ get_file_list = lambda do |tree_sha|
entries = `git ls-tree -r #{tree_sha}`.strip.split("\n")
- tree = entries. map do |e|
- mode, type, sha, path = e.split(" ")
+ entries.map do |e|
+ _mode, _type, sha, path = e.split
[path, sha]
-
end
end
send(index_fun, tag_filter, get_file_list, get_content)
-
end
end
diff --git a/lib/tasks/search.rake b/lib/tasks/search.rake
index 47c1eeb3..9d802894 100644
--- a/lib/tasks/search.rake
+++ b/lib/tasks/search.rake
@@ -1,4 +1,4 @@
-# rubocop:disable Style/FrozenStringLiteralComment
+# frozen_string_literal: true
task search_clear: :environment do
# BONSAI.clear
@@ -9,7 +9,6 @@ task search_clear: :environment do
end
client.indices.create index: ELASTIC_SEARCH_INDEX
-
end
task search_index: :environment do
@@ -22,7 +21,5 @@ end
task search_index_book: :environment do
book = Book.where(code: "en", edition: 2).first
- book.sections.each do |sec|
- sec.index
- end
+ book.sections.each(&:index)
end
diff --git a/public/book/en/v2/book/07-git-tools/git-credential-read-only b/public/book/en/v2/book/07-git-tools/git-credential-read-only
deleted file mode 100755
index f26a3bac..00000000
--- a/public/book/en/v2/book/07-git-tools/git-credential-read-only
+++ /dev/null
@@ -1,33 +0,0 @@
-#!/usr/bin/env ruby
-# frozen_string_literal: true
-
-require "optparse"
-
-path = File.expand_path "~/.git-credentials" # <1>
-OptionParser.new do |opts|
- opts.banner = "USAGE: git-credential-read-only [options] <action>"
- opts.on("-f", "--file PATH", "Specify path for backing store") do |argpath|
- path = File.expand_path argpath
- end
-end.parse!
-
-exit(0) unless ARGV[0].downcase == "get" # <2>
-exit(0) unless File.exist? path
-
-known = {} # <3>
-while line = STDIN.gets
- break if line.strip == ""
- k, v = line.strip.split "=", 2
- known[k] = v
-end
-
-File.readlines(path).each do |fileline| # <4>
- prot, user, pass, host = fileline.scan(/^(.*?):\/\/(.*?):(.*?)@(.*)$/).first
- if prot == known["protocol"] and host == known["host"]
- puts "protocol=#{prot}"
- puts "host=#{host}"
- puts "username=#{user}"
- puts "password=#{pass}"
- exit(0)
- end
-end
diff --git a/script/doc_importer b/script/doc_importer
index 19f723b1..208e95e5 100755
--- a/script/doc_importer
+++ b/script/doc_importer
@@ -12,9 +12,7 @@ doc = Asciidoctor::Document.new(content)
html = doc.render
html.gsub!(/linkgit:(.*)\[(\d+)\]/) do |line|
x = /^linkgit:(.*)\[(\d+)\]/.match(line)
- line = "<a href='/docs/#{x[1]}'>#{x[1]}[#{x[2]}]</a>"
+ "<a href='/docs/#{x[1]}'>#{x[1]}[#{x[2]}]</a>"
end
-File.open("./git-diff.html", "w+") do |f|
- f.write html
-end
+File.write("./git-diff.html", html)
diff --git a/script/rails b/script/rails
index 52208887..4ec1af8c 100755
--- a/script/rails
+++ b/script/rails
@@ -3,6 +3,6 @@
# This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.
-APP_PATH = File.expand_path("../../config/application", __FILE__)
-require File.expand_path("../../config/boot", __FILE__)
+APP_PATH = File.expand_path('../config/application', __dir__)
+require File.expand_path('../config/boot', __dir__)
require "rails/commands"
diff --git a/script/sort-gui b/script/sort-gui
index c6d8636b..8203da4f 100755
--- a/script/sort-gui
+++ b/script/sort-gui
@@ -12,6 +12,7 @@
require "yaml"
require "open-uri"
+require "erb"
yaml = YAML.load_file("resources/guis.yml")
guis_info = yaml["guis"]
@@ -33,31 +34,31 @@ puts guis_info
encoded = guis_info.sort_by { |g| g["order"] }.map do |g|
key = g.key?("trend_name") ? g["trend_name"] : g["name"]
- URI::encode(key)
+ ERB::Util.url_encode(key)
end
# Google trends currently one allows up to 5 terms in the comparison
# For comparison we are using 'windows' of 5 elements, where the first element
# of a window, is the last element of the previous window, so that new elements
# can be compared with the previous window
-minIndex = 0
-maxIndex = 4
+min_index = 0
+max_index = 4
# trend_groups is an array of pairs (abstracted as an array of size 2),
# containing the min and max GUI index for the current iteration
trend_groups = []
last_idx = encoded.size - 1
-while minIndex < last_idx do
- trend_groups.push([minIndex, [maxIndex, last_idx].min])
- minIndex += 4
- maxIndex += 4
+while min_index < last_idx
+ trend_groups.push([min_index, [max_index, last_idx].min])
+ min_index += 4
+ max_index += 4
end
# For each pair of indexes we fetch the GUI window and create the Google Trend URL
trend_urls = trend_groups.map do |min_max|
terms = (min_max[0]..min_max[1]).map { |idx| encoded[idx] }
- "https://trends.google.pt/trends/explore?cat=31&q=#{terms.join(",")}&hl=en_us"
+ "https://trends.google.pt/trends/explore?cat=31&q=#{terms.join(',')}&hl=en_us"
end
puts "\n=== Trends URLs (#{trend_urls.size}) ==="
diff --git a/spec/controllers/about_controller_spec.rb b/spec/controllers/about_controller_spec.rb
index f420fc55..12ca3f1f 100644
--- a/spec/controllers/about_controller_spec.rb
+++ b/spec/controllers/about_controller_spec.rb
@@ -3,11 +3,9 @@
require "rails_helper"
RSpec.describe AboutController, type: :controller do
-
it "GET index" do
get :index
expect(assigns(:section)).to eq("about")
expect(response).to render_template("index")
end
-
end
diff --git a/spec/controllers/community_controller_spec.rb b/spec/controllers/community_controller_spec.rb
index a50af48b..8c4e0623 100644
--- a/spec/controllers/community_controller_spec.rb
+++ b/spec/controllers/community_controller_spec.rb
@@ -3,10 +3,8 @@
require "rails_helper"
RSpec.describe CommunityController, type: :controller do
-
it "GET index" do
get :index
expect(response).to render_template("index")
end
-
end
diff --git a/spec/controllers/site_controller_spec.rb b/spec/controllers/site_controller_spec.rb
index 1926625e..2b6786eb 100644
--- a/spec/controllers/site_controller_spec.rb
+++ b/spec/controllers/site_controller_spec.rb
@@ -3,7 +3,6 @@
require "rails_helper"
RSpec.describe SiteController, type: :controller do
-
it "GET index" do
get :index
expect(response).to render_template("index")
@@ -27,7 +26,6 @@ RSpec.describe SiteController, type: :controller do
end
describe "GET /book" do
-
it "get /git-doc" do
request.env["PATH_INFO"] = "/git-doc"
get :redirect_book
@@ -38,7 +36,5 @@ RSpec.describe SiteController, type: :controller do
get :redirect_book
expect(response).to redirect_to("https://git-scm.com/book")
end
-
end
-
end
diff --git a/spec/models/book_spec.rb b/spec/models/book_spec.rb
index 0737cf9e..9019b4da 100644
--- a/spec/models/book_spec.rb
+++ b/spec/models/book_spec.rb
@@ -3,7 +3,6 @@
require "rails_helper"
RSpec.describe Book, type: :model do
-
let(:book) { Fabricate(:book) }
it { should have_many :chapters }
@@ -15,8 +14,7 @@ RSpec.describe Book, type: :model do
end
it "should have 4 chapters" do
- chapter = Fabricate(:chapter, book: book)
+ _chapter = Fabricate(:chapter, book: book)
expect(book.chapters.count).to eql(4)
end
-
end
diff --git a/spec/models/chapter_spec.rb b/spec/models/chapter_spec.rb
index 7d00cd35..d7339caf 100644
--- a/spec/models/chapter_spec.rb
+++ b/spec/models/chapter_spec.rb
@@ -3,14 +3,12 @@
require "rails_helper"
RSpec.describe Chapter, type: :model do
-
let(:book) { Fabricate(:book) }
let(:chapter) { Fabricate(:chapter, book: book) }
it { should belong_to :book }
it { should have_many :sections }
-
it "should have title" do
expect(chapter.title).to eql("Git")
end
@@ -25,5 +23,4 @@ RSpec.describe Chapter, type: :model do
expect(sections.any?).to be_truthy
expect(sections.count).to eql(3)
end
-
end
diff --git a/spec/models/doc_file_spec.rb b/spec/models/doc_file_spec.rb
index d00e931d..559f9fe2 100644
--- a/spec/models/doc_file_spec.rb
+++ b/spec/models/doc_file_spec.rb
@@ -3,7 +3,5 @@
require "rails_helper"
RSpec.describe DocFile, type: :model do
-
it { should have_many :doc_versions }
-
end
diff --git a/spec/models/doc_spec.rb b/spec/models/doc_spec.rb
index 26545105..f0be72f5 100644
--- a/spec/models/doc_spec.rb
+++ b/spec/models/doc_spec.rb
@@ -3,7 +3,5 @@
require "rails_helper"
RSpec.describe Doc, type: :model do
-
it { should have_many :doc_versions }
-
end
diff --git a/spec/models/doc_version_spec.rb b/spec/models/doc_version_spec.rb
index 4dc630cf..f9ba2d48 100644
--- a/spec/models/doc_version_spec.rb
+++ b/spec/models/doc_version_spec.rb
@@ -3,7 +3,6 @@
require "rails_helper"
RSpec.describe DocVersion, type: :model do
-
it { should belong_to :doc }
it { should belong_to :version }
it { should belong_to :doc_file }
@@ -13,7 +12,7 @@ RSpec.describe DocVersion, type: :model do
file = Fabricate(:doc_file, name: "test-command")
docs = range.map { |i| Fabricate(:doc, plain: "Doc #{i}") }
vers = range.map { |i| Fabricate(:version, name: "#{i}.0", vorder: Version.version_to_num("#{i}.0")) }
- dver = range.map { |i| Fabricate(:doc_version, doc_file: file, version: vers[i], doc: docs[i]) }
+ _dver = range.map { |i| Fabricate(:doc_version, doc_file: file, version: vers[i], doc: docs[i]) }
dv = DocVersion.latest_version
expect(docs[3]).to eql(dv.doc)
@@ -24,7 +23,7 @@ RSpec.describe DocVersion, type: :model do
file = Fabricate(:doc_file, name: "test-command")
docs = range.map { |i| Fabricate(:doc, plain: "Doc #{i}") }
vers = range.map { |i| Fabricate(:version, name: "v#{i}.0") }
- dver = range.map { |i| Fabricate(:doc_version, doc_file: file, version: vers[i], doc: docs[i]) }
+ _dver = range.map { |i| Fabricate(:doc_version, doc_file: file, version: vers[i], doc: docs[i]) }
dv = DocVersion.for_version("v2.0")
expect(docs[2]).to eql(dv.doc)
diff --git a/spec/models/download_spec.rb b/spec/models/download_spec.rb
index d96bed45..59641d7c 100644
--- a/spec/models/download_spec.rb
+++ b/spec/models/download_spec.rb
@@ -3,7 +3,6 @@
require "rails_helper"
RSpec.describe Download, type: :model do
-
let(:version) { Fabricate(:version) }
let(:download) { Fabricate(:download, version: version) }
@@ -16,5 +15,4 @@ RSpec.describe Download, type: :model do
it "should have version" do
expect(download.version).to eql(version)
end
-
end
diff --git a/spec/models/section_spec.rb b/spec/models/section_spec.rb
index 9e584ae2..3c596161 100644
--- a/spec/models/section_spec.rb
+++ b/spec/models/section_spec.rb
@@ -3,16 +3,13 @@
require "rails_helper"
RSpec.describe Section, type: :model do
-
let(:book) { Fabricate(:book) }
let(:chapter) { Fabricate(:chapter, book: book) }
let(:section) { Fabricate(:section, chapter: chapter) }
-
it { should belong_to :chapter }
it { should have_one(:book).through(:chapter) }
-
it "should have title" do
expect(section.title).to eql("Git Section")
end
@@ -24,5 +21,4 @@ RSpec.describe Section, type: :model do
it "should have book" do
expect(section.book).to eql(book)
end
-
end
diff --git a/spec/models/version_spec.rb b/spec/models/version_spec.rb
index d5abae12..e709908a 100644
--- a/spec/models/version_spec.rb
+++ b/spec/models/version_spec.rb
@@ -3,7 +3,6 @@
require "rails_helper"
RSpec.describe Version, type: :model do
-
it { should have_many :doc_versions }
it { should have_many(:docs).through(:doc_versions) }
it { should have_many :downloads }
@@ -16,6 +15,4 @@ RSpec.describe Version, type: :model do
expect(v1).to be < v2
expect(v2).to be < v3
end
-
-
end
diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb
index b34713ea..8afa7980 100644
--- a/spec/rails_helper.rb
+++ b/spec/rails_helper.rb
@@ -3,7 +3,7 @@
# This file is copied to spec/ when you run 'rails generate rspec:install'
require "rails_helper"
ENV["RAILS_ENV"] ||= "test"
-require File.expand_path("../../config/environment", __FILE__)
+require File.expand_path('../config/environment', __dir__)
# Prevent database truncation if the environment is production
abort("The Rails environment is running in production mode!") if Rails.env.production?
require "rspec/rails"
diff --git a/spec/services/download_service_spec.rb b/spec/services/download_service_spec.rb
index 0af1d7ab..0f3cd758 100644
--- a/spec/services/download_service_spec.rb
+++ b/spec/services/download_service_spec.rb
@@ -7,7 +7,8 @@ RSpec.describe DownloadService do
context "windows", :vcr do
before do
- mocked_version = Version.new(id: 0, name: "0.0.0", commit_sha: "sha", committed: Time.current, created_at: Time.current, updated_at: Time.current, vorder: Version.version_to_num("0.0.0"))
+ mocked_version = Version.new(id: 0, name: "0.0.0", commit_sha: "sha", committed: Time.current,
+ created_at: Time.current, updated_at: Time.current, vorder: Version.version_to_num("0.0.0"))
allow(Version).to receive(:find_by).with(any_args).and_return(mocked_version)
subject.download_windows_versions
end
@@ -27,7 +28,8 @@ RSpec.describe DownloadService do
context "mac", :vcr do
before do
- mocked_version = Version.new(id: 0, name: "0.0.0", commit_sha: "sha", committed: Time.current, created_at: Time.current, updated_at: Time.current, vorder: Version.version_to_num("0.0.0"))
+ mocked_version = Version.new(id: 0, name: "0.0.0", commit_sha: "sha", committed: Time.current,
+ created_at: Time.current, updated_at: Time.current, vorder: Version.version_to_num("0.0.0"))
allow(Version).to receive(:find_by).with(any_args).and_return(mocked_version)
subject.download_mac_versions
end
diff --git a/spec/support/vcr.rb b/spec/support/vcr.rb
index a00a7be9..1e57238a 100644
--- a/spec/support/vcr.rb
+++ b/spec/support/vcr.rb
@@ -6,7 +6,7 @@ VCR.configure do |c|
c.default_cassette_options = {
serialize_with: :json,
- preserve_exact_body_bytes: true,
+ preserve_exact_body_bytes: true,
decode_compressed_response: true,
record: ENV["TRAVIS"] ? :none : :once
}
diff --git a/test/factories.rb b/test/factories.rb
index 62dc7381..1035d82d 100644
--- a/test/factories.rb
+++ b/test/factories.rb
@@ -1,7 +1,6 @@
# frozen_string_literal: true
FactoryBot.define do
-
sequence :number do |n|
n
end
@@ -57,5 +56,4 @@ FactoryBot.define do
number { FactoryBot.generate(:number) }
title { FactoryBot.generate(:title) }
end
-
end
diff --git a/test/functional/about_controller_test.rb b/test/functional/about_controller_test.rb
index 4d55be82..34c43a27 100644
--- a/test/functional/about_controller_test.rb
+++ b/test/functional/about_controller_test.rb
@@ -3,10 +3,8 @@
require "test_helper"
class AboutControllerTest < ActionController::TestCase
-
test "should get index" do
get :index
assert_response :success
end
-
end
diff --git a/test/functional/books_controller_test.rb b/test/functional/books_controller_test.rb
index e693e648..e0a9399d 100644
--- a/test/functional/books_controller_test.rb
+++ b/test/functional/books_controller_test.rb
@@ -3,14 +3,13 @@
require "test_helper"
class BooksControllerTest < ActionController::TestCase
-
test "redirects old book site" do
get :show, params: { lang: "1_welcome_to_git" }
assert_redirected_to controller: "books", action: "show", lang: "en/Getting-Started"
end
test "gets the book page" do
- book = FactoryBot.create(:book, code: "en")
+ _book = FactoryBot.create(:book, code: "en")
get :show, params: { lang: "en" }
assert_response :success
end
@@ -23,5 +22,4 @@ class BooksControllerTest < ActionController::TestCase
get :chapter, params: { chapter: section.chapter.number, section: section.number }
assert_response :success
end
-
end
diff --git a/test/functional/community_controller_test.rb b/test/functional/community_controller_test.rb
index 16a7d323..a94ec60f 100644
--- a/test/functional/community_controller_test.rb
+++ b/test/functional/community_controller_test.rb
@@ -3,10 +3,8 @@
require "test_helper"
class CommunityControllerTest < ActionController::TestCase
-
test "should get index" do
get :index
assert_response :success
end
-
end
diff --git a/test/functional/doc_controller_test.rb b/test/functional/doc_controller_test.rb
index e6ce5fd5..e89029f3 100644
--- a/test/functional/doc_controller_test.rb
+++ b/test/functional/doc_controller_test.rb
@@ -1,11 +1,10 @@
# frozen_string_literal: true
-require File.expand_path("../../test_helper", __FILE__)
+require File.expand_path('../test_helper', __dir__)
class DocControllerTest < ActionController::TestCase
-
test "should get index" do
- book = FactoryBot.create(:book, code: "en")
+ _book = FactoryBot.create(:book, code: "en")
get :index
assert_response :success
end
@@ -14,7 +13,7 @@ class DocControllerTest < ActionController::TestCase
file = FactoryBot.create(:doc_file, name: "test-command")
doc = FactoryBot.create(:doc, plain: "Doc 1", blob_sha: "d670460b4b4aece5915caf5c68d12f560a9fe3e4")
vers = FactoryBot.create(:version, name: "v1.0", vorder: Version.version_to_num("1.0"))
- dver = FactoryBot.create(:doc_version, doc_file: file, version: vers, doc: doc)
+ _dver = FactoryBot.create(:doc_version, doc_file: file, version: vers, doc: doc)
get :man, params: { file: "test-command" }
assert_response :success
end
@@ -23,7 +22,7 @@ class DocControllerTest < ActionController::TestCase
file = FactoryBot.create(:doc_file, name: "test-command")
doc = FactoryBot.create(:doc, plain: "Doc 1", blob_sha: "d670460b4b4aece5915caf5c68d12f560a9fe3e4")
vers = FactoryBot.create(:version, name: "v1.0", vorder: Version.version_to_num("1.0"))
- dver = FactoryBot.create(:doc_version, doc_file: file, version: vers, doc: doc)
+ _dver = FactoryBot.create(:doc_version, doc_file: file, version: vers, doc: doc)
get :man, params: { file: "test-command", version: "v1.0" }
assert_response :success
end
@@ -32,7 +31,7 @@ class DocControllerTest < ActionController::TestCase
file = FactoryBot.create(:doc_file, name: "git-commit")
doc = FactoryBot.create(:doc, plain: "Doc 1")
vers = FactoryBot.create(:version, name: "v1.0")
- dver = FactoryBot.create(:doc_version, doc_file: file, version: vers, doc: doc)
+ _dver = FactoryBot.create(:doc_version, doc_file: file, version: vers, doc: doc)
get :man, params: { file: "commit", version: "v1.0" }
assert_redirected_to "/docs/git-commit"
end
diff --git a/test/functional/downloads_controller_test.rb b/test/functional/downloads_controller_test.rb
index b2dbc859..15856bb1 100644
--- a/test/functional/downloads_controller_test.rb
+++ b/test/functional/downloads_controller_test.rb
@@ -3,7 +3,6 @@
require "test_helper"
class DownloadsControllerTest < ActionController::TestCase
-
test "should get index page" do
get :index
assert_response :success
@@ -33,5 +32,4 @@ class DownloadsControllerTest < ActionController::TestCase
get :download, params: { platform: "test" }
assert_redirected_to downloads_path
end
-
end
diff --git a/test/functional/site_controller_test.rb b/test/functional/site_controller_test.rb
index 50842db2..596bec7b 100644
--- a/test/functional/site_controller_test.rb
+++ b/test/functional/site_controller_test.rb
@@ -3,7 +3,6 @@
require "test_helper"
class SiteControllerTest < ActionController::TestCase
-
test "should get index" do
get :index
assert_response :success
@@ -34,5 +33,4 @@ class SiteControllerTest < ActionController::TestCase
get :search_results, params: { search: "git-rebase" }
assert_response :success
end
-
end
diff --git a/test/test_helper.rb b/test/test_helper.rb
index ebf83803..332acc1b 100644
--- a/test/test_helper.rb
+++ b/test/test_helper.rb
@@ -1,7 +1,7 @@
# frozen_string_literal: true
ENV["RAILS_ENV"] = "test"
-require File.expand_path("../../config/environment", __FILE__)
+require File.expand_path('../config/environment', __dir__)
require "rails/test_help"
Shoulda::Matchers.configure do |config|
@@ -11,21 +11,23 @@ Shoulda::Matchers.configure do |config|
end
end
-class ActiveSupport::TestCase
- # Setup all fixtures in test/fixtures/*.(yml|csv) for all tests in alphabetical order.
- #
- # Note: You'll currently still have to declare fixtures explicitly in integration tests
- # -- they do not yet inherit this setting
- fixtures :all
+module ActiveSupport
+ class TestCase
+ # Setup all fixtures in test/fixtures/*.(yml|csv) for all tests in alphabetical order.
+ #
+ # Note: You'll currently still have to declare fixtures explicitly in integration tests
+ # -- they do not yet inherit this setting
+ fixtures :all
- # Add more helper methods to be used by all tests here...
+ # Add more helper methods to be used by all tests here...
+ end
end
Faraday.new(url: "http://0.0.0.0:9200") do |builder|
builder.request :json
builder.adapter :test do |stub|
resp = {
- "hits" => {"hits" => []}
+ "hits" => { "hits" => [] }
}
stub.get("/gitscm/doc/_search") { [200, {}, JSON.dump(resp)] }
stub.get("/gitscm/book/_search") { [200, {}, JSON.dump(resp)] }
diff --git a/test/unit/book_test.rb b/test/unit/book_test.rb
index 5c84275e..e2af510c 100644
--- a/test/unit/book_test.rb
+++ b/test/unit/book_test.rb
@@ -3,8 +3,6 @@
require "test_helper"
class BookTest < ActiveSupport::TestCase
-
should have_many :chapters
should have_many(:sections).through(:chapters)
-
end
diff --git a/test/unit/chapter_test.rb b/test/unit/chapter_test.rb
index a0ca2a8e..b6b7203f 100644
--- a/test/unit/chapter_test.rb
+++ b/test/unit/chapter_test.rb
@@ -3,8 +3,6 @@
require "test_helper"
class ChapterTest < ActiveSupport::TestCase
-
should belong_to :book
should have_many :sections
-
end
diff --git a/test/unit/doc_file_test.rb b/test/unit/doc_file_test.rb
index 3c296771..30c7d466 100644
--- a/test/unit/doc_file_test.rb
+++ b/test/unit/doc_file_test.rb
@@ -3,7 +3,5 @@
require "test_helper"
class DocFileTest < ActiveSupport::TestCase
-
should have_many :doc_versions
-
end
diff --git a/test/unit/doc_test.rb b/test/unit/doc_test.rb
index 6a00ea5a..d27334d3 100644
--- a/test/unit/doc_test.rb
+++ b/test/unit/doc_test.rb
@@ -3,7 +3,5 @@
require "test_helper"
class DocTest < ActiveSupport::TestCase
-
should have_many :doc_versions
-
end
diff --git a/test/unit/doc_version_test.rb b/test/unit/doc_version_test.rb
index f1671061..99b7bb33 100644
--- a/test/unit/doc_version_test.rb
+++ b/test/unit/doc_version_test.rb
@@ -1,9 +1,8 @@
# frozen_string_literal: true
-require File.expand_path("../../test_helper", __FILE__)
+require File.expand_path('../test_helper', __dir__)
class DocVersionTest < ActiveSupport::TestCase
-
should belong_to :doc
should belong_to :version
should belong_to :doc_file
@@ -13,7 +12,7 @@ class DocVersionTest < ActiveSupport::TestCase
file = FactoryBot.create(:doc_file, name: "test-command")
docs = range.map { |i| FactoryBot.create(:doc, plain: "Doc #{i}") }
vers = range.map { |i| FactoryBot.create(:version, name: "#{i}.0", vorder: Version.version_to_num("#{i}.0")) }
- dver = range.map { |i| FactoryBot.create(:doc_version, doc_file: file, version: vers[i], doc: docs[i]) }
+ _dver = range.map { |i| FactoryBot.create(:doc_version, doc_file: file, version: vers[i], doc: docs[i]) }
dv = DocVersion.latest_for("test-command")
assert_equal docs[3], dv.doc
@@ -24,10 +23,9 @@ class DocVersionTest < ActiveSupport::TestCase
file = FactoryBot.create(:doc_file, name: "test-command")
docs = range.map { |i| FactoryBot.create(:doc, plain: "Doc #{i}") }
vers = range.map { |i| FactoryBot.create(:version, name: "v#{i}.0") }
- dver = range.map { |i| FactoryBot.create(:doc_version, doc_file: file, version: vers[i], doc: docs[i]) }
+ _dver = range.map { |i| FactoryBot.create(:doc_version, doc_file: file, version: vers[i], doc: docs[i]) }
dv = DocVersion.for_version("test-command", "v2.0")
assert_equal docs[2], dv.doc
end
-
end
diff --git a/test/unit/download_test.rb b/test/unit/download_test.rb
index ca32c08b..e4a03086 100644
--- a/test/unit/download_test.rb
+++ b/test/unit/download_test.rb
@@ -3,7 +3,5 @@
require "test_helper"
class DownloadTest < ActiveSupport::TestCase
-
should belong_to :version
-
end
diff --git a/test/unit/helpers/application_helper_test.rb b/test/unit/helpers/application_helper_test.rb
index 2b22ce99..72436b44 100644
--- a/test/unit/helpers/application_helper_test.rb
+++ b/test/unit/helpers/application_helper_test.rb
@@ -3,7 +3,6 @@
require "test_helper"
class ApplicationHelperTest < ActionView::TestCase
-
test "gets the latest version" do
version = latest_version
assert_equal "MyString", version
@@ -18,5 +17,4 @@ class ApplicationHelperTest < ActionView::TestCase
url = latest_relnote_url
assert_equal "https://raw.github.com/git/git/master/Documentation/RelNotes/MyString.txt", url
end
-
end
diff --git a/test/unit/helpers/doc_helper_test.rb b/test/unit/helpers/doc_helper_test.rb
index 1f620100..82a540a5 100644
--- a/test/unit/helpers/doc_helper_test.rb
+++ b/test/unit/helpers/doc_helper_test.rb
@@ -3,10 +3,8 @@
require "test_helper"
class DocHelperTest < ActionView::TestCase
-
test "should generate man link" do
src = man("git-rebase")
assert_equal '<a href="/docs/git-rebase">rebase</a>', src
end
-
end
diff --git a/test/unit/helpers/site_helper_test.rb b/test/unit/helpers/site_helper_test.rb
index 7bde8a26..cba01d7b 100644
--- a/test/unit/helpers/site_helper_test.rb
+++ b/test/unit/helpers/site_helper_test.rb
@@ -3,26 +3,9 @@
require "test_helper"
class SiteHelperTest < ActionView::TestCase
-
test "should convert highlight markup into html" do
src = highlight_no_html("[highlight]hello[xhighlight]")
expected = tag.span("hello", class: "highlight")
assert_equal expected, src
end
-
- test "should create rchart" do
- src = rchart("git", [[0, 1], [0, 1]])
- assert_equal "<tr><td nowrap>git</td><td class='desc'></td><td class='number'> 1.00</td><td class='number'> 1.00</td><td class='number'>1x</td></tr>", src
- end
-
- test "should create trchart" do
- src = trchart("git", [[0, 1], [0, 1], [0, 1]])
- assert_equal "<tr><td nowrap>git</td><td class='desc'></td><td class='number'> 1.0</td><td class='number'> 1.0</td><td class='number'> 1.0</td></tr>", src
- end
-
- test "should create gchart" do
- src = gchart("git", [[0, 1], [0, 1]])
- assert_equal "<img src=\"https://chart.googleapis.com/chart?chxt=x&amp;cht=bvs&amp;chl=0|0&amp;chd=t:1,1&amp;chds=0,1&amp;chs=100x125&amp;chco=E09FA0|E05F49&amp;chf=bg,s,fcfcfa&chtt=git\" alt=\"init benchmarks\" />", src
- end
-
end
diff --git a/test/unit/section_test.rb b/test/unit/section_test.rb
index 6b336f3d..ac4aa7a3 100644
--- a/test/unit/section_test.rb
+++ b/test/unit/section_test.rb
@@ -3,8 +3,6 @@
require "test_helper"
class SectionTest < ActiveSupport::TestCase
-
should belong_to :chapter
should have_one(:book).through(:chapter)
-
end
diff --git a/test/unit/version_test.rb b/test/unit/version_test.rb
index 0280f703..434e6e97 100644
--- a/test/unit/version_test.rb
+++ b/test/unit/version_test.rb
@@ -3,7 +3,6 @@
require "test_helper"
class VersionTest < ActiveSupport::TestCase
-
should have_many :doc_versions
should have_many(:docs).through(:doc_versions)
should have_many :downloads
@@ -14,8 +13,7 @@ class VersionTest < ActiveSupport::TestCase
v1 = Version.version_to_num("1.0.0")
v2 = Version.version_to_num("1.7.10")
v3 = Version.version_to_num("1.8.0.1")
- assert (v1 < v2)
- assert (v2 < v3)
+ assert(v1 < v2)
+ assert(v2 < v3)
end
-
end