# This configuration was generated by
# `rubocop --auto-gen-config`
-# on 2019-10-07 20:37:25 +0100 using RuboCop version 0.75.0.
+# on 2019-10-19 16:05:52 +0000 using RuboCop version 0.75.0.
# The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new
# versions of RuboCop, may require this file to be generated again.
-# Offense count: 34
+# Offense count: 35
# Configuration parameters: AllowSafeAssignment.
Lint/AssignmentInCondition:
Exclude:
- 'app/controllers/api/amf_controller.rb'
- 'app/controllers/users_controller.rb'
-# Offense count: 700
+# Offense count: 701
Metrics/AbcSize:
Max: 189
Metrics/ClassLength:
Max: 645
-# Offense count: 73
+# Offense count: 74
Metrics/CyclomaticComplexity:
Max: 22
-# Offense count: 721
+# Offense count: 722
# Configuration parameters: CountComments, ExcludedMethods.
Metrics/MethodLength:
Max: 179
# Offense count: 2
# Configuration parameters: CountComments.
Metrics/ModuleLength:
- Max: 107
+ Max: 117
# Offense count: 4
# Configuration parameters: CountKeywordArgs.
Metrics/ParameterLists:
Max: 9
-# Offense count: 71
+# Offense count: 72
Metrics/PerceivedComplexity:
Max: 25
Style/NumericLiterals:
MinDigits: 11
-# Offense count: 3330
+# Offense count: 3338
# Cop supports --auto-correct.
# Configuration parameters: AutoCorrect, AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
# URISchemes: http, https
link_to(w[:title], w[:url], :title => t("browse.tag_details.wikidata_link", :page => w[:title].strip))
end
safe_join(wdt, ";")
+ elsif wmc = wikimedia_commons_link(key, value)
+ link_to h(wmc[:title]), wmc[:url], :title => t("browse.tag_details.wikimedia_commons_link", :page => wmc[:title])
elsif url = wiki_link("tag", "#{key}=#{value}")
link_to h(value), url, :title => t("browse.tag_details.wiki_link.tag", :key => key, :value => value)
elsif phones = telephone_links(key, value)
nil
end
+ def wikimedia_commons_link(key, value)
+ if key == "wikimedia_commons" && value =~ /^(?:file|category):/i
+ return {
+ :url => "//commons.wikimedia.org/wiki/#{value}?uselang=#{I18n.locale}",
+ :title => value
+ }
+ end
+ nil
+ end
+
def telephone_links(_key, value)
# Does it look like a global phone number? eg "+1 (234) 567-8901 "
# or a list of alternate numbers separated by ;
tag: "The wiki description page for the %{key}=%{value} tag"
wikidata_link: "The %{page} item on Wikidata"
wikipedia_link: "The %{page} article on Wikipedia"
+ wikimedia_commons_link: "The %{page} item on Wikimedia Commons"
telephone_link: "Call %{phone_number}"
colour_preview: "Colour %{colour_value} preview"
note:
html = format_value("name:etymology:wikidata", "Q123")
assert_dom_equal "<a title=\"The Q123 item on Wikidata\" href=\"//www.wikidata.org/entity/Q123?uselang=en\">Q123</a>", html
+ html = format_value("wikimedia_commons", "File:Test.jpg")
+ assert_dom_equal "<a title=\"The File:Test.jpg item on Wikimedia Commons\" href=\"//commons.wikimedia.org/wiki/File:Test.jpg?uselang=en\">File:Test.jpg</a>", html
+
html = format_value("colour", "#f00")
assert_dom_equal %(<span class="colour-preview-box" data-colour="#f00" title="Colour #f00 preview"></span>#f00), html
end
assert_nil link
end
+ def test_wikimedia_commons_link
+ link = wikimedia_commons_link("wikimedia_commons", "http://commons.wikimedia.org/wiki/File:Full%20URL.jpg")
+ assert_nil link
+
+ link = wikimedia_commons_link("wikimedia_commons", "https://commons.wikimedia.org/wiki/File:Full%20URL.jpg")
+ assert_nil link
+
+ link = wikimedia_commons_link("wikimedia_commons", "Test.jpg")
+ assert_nil link
+
+ link = wikimedia_commons_link("wikimedia_commons", "File:Test.jpg")
+ assert_equal "//commons.wikimedia.org/wiki/File:Test.jpg?uselang=en", link[:url]
+ assert_equal "File:Test.jpg", link[:title]
+
+ link = wikimedia_commons_link("wikimedia_commons", "Category:Test_Category")
+ assert_equal "//commons.wikimedia.org/wiki/Category:Test_Category?uselang=en", link[:url]
+ assert_equal "Category:Test_Category", link[:title]
+
+ I18n.locale = "pt-BR"
+
+ link = wikimedia_commons_link("wikimedia_commons", "File:Test.jpg")
+ assert_equal "//commons.wikimedia.org/wiki/File:Test.jpg?uselang=pt-BR", link[:url]
+ assert_equal "File:Test.jpg", link[:title]
+
+ link = wikimedia_commons_link("foo", "Test")
+ assert_nil link
+ end
+
def test_telephone_links
links = telephone_links("foo", "Test")
assert_nil links