Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
B
brew
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to JiHu GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
KMSCAKKSCFKA AKFACAMADCAS
brew
Commits
013f33be
Commit
013f33be
authored
8 years ago
by
Markus Reiter
Browse files
Options
Downloads
Patches
Plain Diff
Change language DSL to only allow strings.
parent
b5531e8e
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
Library/Homebrew/cask/lib/hbc/dsl.rb
+10
-22
10 additions, 22 deletions
Library/Homebrew/cask/lib/hbc/dsl.rb
Library/Homebrew/cask/test/cask/dsl_test.rb
+38
-23
38 additions, 23 deletions
Library/Homebrew/cask/test/cask/dsl_test.rb
with
48 additions
and
45 deletions
Library/Homebrew/cask/lib/hbc/dsl.rb
+
10
−
22
View file @
013f33be
require
"set"
require
"locale"
require
"hbc/dsl/appcast"
require
"hbc/dsl/base"
...
...
@@ -99,9 +100,10 @@ module Hbc
@homepage
||=
homepage
end
def
language
(
*
args
,
&
block
)
def
language
(
*
args
,
default:
false
,
&
block
)
if
!
args
.
empty?
&&
block_given?
@language_blocks
||=
{}
@language_blocks
.
default
=
block
if
default
@language_blocks
[
args
]
=
block
else
language_eval
...
...
@@ -114,29 +116,15 @@ module Hbc
return
unless
instance_variable_defined?
(
:@language_blocks
)
default_key
=
@language_blocks
.
keys
.
detect
{
|
key
|
key
.
include?
(
:default
)
}
MacOS
.
languages
.
map
(
&
Locale
.
method
(
:parse
)).
any?
{
|
locale
|
key
=
@language_blocks
.
keys
.
detect
{
|
strings
|
strings
.
any?
{
|
string
|
locale
.
include?
(
string
)
}
}
MacOS
.
languages
.
each
do
|
language
|
@language_blocks
.
each
do
|
regexes_or_strings
,
block
|
if
regexes_or_strings
.
include?
(
:default
)
regexes_or_strings
=
regexes_or_strings
-
[
:default
]
+
[
%r{^en}
]
end
return
@language
=
@language_blocks
[
key
].
call
unless
key
.
nil?
}
regexes_or_strings
.
each
do
|
regex_or_string
|
if
regex_or_string
.
class
==
language
.
class
next
unless
regex_or_string
==
language
else
next
unless
regex_or_string
=~
language
end
@language
=
block
.
call
return
end
end
end
# fallback to :default
@language
=
default_key
.
nil?
?
nil
:
@language_blocks
[
default_key
].
call
@language
=
@language_blocks
.
default
.
call
end
def
url
(
*
args
,
&
block
)
...
...
This diff is collapsed.
Click to expand it.
Library/Homebrew/cask/test/cask/dsl_test.rb
+
38
−
23
View file @
013f33be
...
...
@@ -124,36 +124,51 @@ describe Hbc::DSL do
describe
"language stanza"
do
it
"allows multilingual casks"
do
cask
=
lambda
{
cask
=
lambda
do
Hbc
::
Cask
.
new
(
"cask-with-apps"
)
do
language
"FIRST_LANGUAGE"
do
:first
language
"zh"
do
sha256
"abc123"
"zh-CN"
end
language
%r{SECOND_LANGUAGE}
do
:second
language
"en-US"
,
default:
true
do
sha256
"xyz789"
"en-US"
end
language
:default
do
:default
end
url
"https://example.org/
#{
language
}
.zip"
end
}
MacOS
.
stubs
(
languages:
[
"FIRST_LANGUAGE"
])
cask
.
call
.
language
.
must_equal
:first
MacOS
.
stubs
(
languages:
[
"SECOND_LANGUAGE"
])
cask
.
call
.
language
.
must_equal
:second
MacOS
.
stubs
(
languages:
[
"THIRD_LANGUAGE"
])
cask
.
call
.
language
.
must_equal
:default
MacOS
.
stubs
(
languages:
[
"THIRD_LANGUAGE"
,
"SECOND_LANGUAGE"
,
"FIRST_LANGUAGE"
])
cask
.
call
.
language
.
must_equal
:second
end
MacOS
.
stubs
(
languages:
[
"THIRD_LANGUAGE"
,
"FIRST_LANGUAGE"
,
"SECOND_LANGUAGE"
])
cask
.
call
.
language
.
must_equal
:first
MacOS
.
stubs
(
languages:
[
"zh"
])
cask
.
call
.
language
.
must_equal
"zh-CN"
cask
.
call
.
sha256
.
must_equal
"abc123"
cask
.
call
.
url
.
to_s
.
must_equal
"https://example.org/zh-CN.zip"
MacOS
.
stubs
(
languages:
[
"zh-XX"
])
cask
.
call
.
language
.
must_equal
"zh-CN"
cask
.
call
.
sha256
.
must_equal
"abc123"
cask
.
call
.
url
.
to_s
.
must_equal
"https://example.org/zh-CN.zip"
MacOS
.
stubs
(
languages:
[
"en"
])
cask
.
call
.
language
.
must_equal
"en-US"
cask
.
call
.
sha256
.
must_equal
"xyz789"
cask
.
call
.
url
.
to_s
.
must_equal
"https://example.org/en-US.zip"
MacOS
.
stubs
(
languages:
[
"xx-XX"
])
cask
.
call
.
language
.
must_equal
"en-US"
cask
.
call
.
sha256
.
must_equal
"xyz789"
cask
.
call
.
url
.
to_s
.
must_equal
"https://example.org/en-US.zip"
MacOS
.
stubs
(
languages:
[
"xx-XX"
,
"zh"
,
"en"
])
cask
.
call
.
language
.
must_equal
"zh-CN"
cask
.
call
.
sha256
.
must_equal
"abc123"
cask
.
call
.
url
.
to_s
.
must_equal
"https://example.org/zh-CN.zip"
MacOS
.
stubs
(
languages:
[
"xx-XX"
,
"en-US"
,
"zh"
])
cask
.
call
.
language
.
must_equal
"en-US"
cask
.
call
.
sha256
.
must_equal
"xyz789"
cask
.
call
.
url
.
to_s
.
must_equal
"https://example.org/en-US.zip"
end
end
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment