Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Highlight Ruby method definitions without arguments #1523

Merged
merged 10 commits into from
Dec 1, 2018
12 changes: 11 additions & 1 deletion components/prism-ruby.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
}
};

delete Prism.languages.ruby.function;

Prism.languages.insertBefore('ruby', 'keyword', {
'regex': [
{
Expand Down Expand Up @@ -75,6 +77,14 @@
'symbol': {
pattern: /(^|[^:]):[a-zA-Z_]\w*(?:[?!]|\b)/,
lookbehind: true
},
'method-definition': {
pattern: /(\bdef\s+)[\w.]+/,
lookbehind: true,
inside: {
'function': /\w+$/,
rest: Prism.languages.ruby
}
}
});

Expand Down Expand Up @@ -128,4 +138,4 @@
}
}
];
}(Prism));
}(Prism));
2 changes: 1 addition & 1 deletion components/prism-ruby.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion tests/languages/crystal/attribute_feature.test
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
]],
["attribute", [
["delimiter", "@["],
["function", "CallConvention"], ["punctuation", "("], ["string", [ "\"X86_StdCall\"" ]], ["punctuation", ")"],
["constant", "CallConvention"], ["punctuation", "("], ["string", [ "\"X86_StdCall\"" ]], ["punctuation", ")"],
["delimiter", "]"]
]]
]
Expand Down
6 changes: 4 additions & 2 deletions tests/languages/crystal/keyword_feature.test
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
abstract alias as asm begin break case
class;
def do else elsif
def;
do else elsif
end ensure enum extend for fun
if include instance_sizeof
.is_a?
Expand All @@ -17,7 +18,8 @@ __FILE__ __LINE__
[
["keyword", "abstract"], ["keyword", "alias"], ["keyword", "as"], ["keyword", "asm"], ["keyword", "begin"], ["keyword", "break"], ["keyword", "case"],
["keyword", "class"], ["punctuation", ";"],
["keyword", "def"], ["keyword", "do"], ["keyword", "else"], ["keyword", "elsif"],
["keyword", "def"], ["punctuation", ";"],
["keyword", "do"], ["keyword", "else"], ["keyword", "elsif"],
["keyword", "end"], ["keyword", "ensure"], ["keyword", "enum"], ["keyword", "extend"], ["keyword", "for"], ["keyword", "fun"],
["keyword", "if"], ["keyword", "include"], ["keyword", "instance_sizeof"],
["punctuation", "."], ["keyword", "is_a?"],
Expand Down
4 changes: 2 additions & 2 deletions tests/languages/erb/erb_in_markup_feature.test
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ ___ERB1___<%= 1 %>___ERB2___<%= 2 %>
["punctuation", "."],
"now",
["punctuation", "."],
["function", "strftime"],
"strftime",
["punctuation", "("],
["string", ["'%A'"]],
["punctuation", ")"],
Expand All @@ -45,4 +45,4 @@ ___ERB1___<%= 1 %>___ERB2___<%= 2 %>

----------------------------------------------------

Checks for ERB inside Markup
Checks for ERB inside Markup
4 changes: 2 additions & 2 deletions tests/languages/haml/tag_feature.test
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@
"%html",
["attributes", [
["punctuation", "{"],
["function", "html_attrs"],
"html_attrs",
["punctuation", "("],
["string", ["'fr-fr'"]],
["punctuation", ")"],
Expand Down Expand Up @@ -158,4 +158,4 @@

Checks for tags: basic element names, attributes, html-style attributes,
attribute methods, boolean attributes, class and id shortcuts,
implicit div elements, empty tags and whitespace removal.
implicit div elements, empty tags and whitespace removal.
6 changes: 3 additions & 3 deletions tests/languages/ruby/keyword_feature.test
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ begin
break
case
class;
def
def;
define_method
defined
do
Expand Down Expand Up @@ -56,7 +56,7 @@ yield
["keyword", "break"],
["keyword", "case"],
["keyword", "class"], ["punctuation", ";"],
["keyword", "def"],
["keyword", "def"], ["punctuation", ";"],
["keyword", "define_method"],
["keyword", "defined"],
["keyword", "do"],
Expand Down Expand Up @@ -100,4 +100,4 @@ yield

----------------------------------------------------

Checks for all keywords.
Checks for all keywords.
82 changes: 82 additions & 0 deletions tests/languages/ruby/method_definition_feature.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
class Circle
def self.of_diameter(diameter)
new diameter / 2
end

def initialize(radius)
@radius = radius
end

def circumference
Math::PI * radius ** 2
end

# Seattle style
def grow_by factor:
@radius = @radius * factor
end
end

----------------------------------------------------

[
["keyword", "class"],
["class-name", ["Circle"]],
["keyword", "def"],
["method-definition", [
["keyword", "self"],
["punctuation", "."],
["function", "of_diameter"]
]],
["punctuation", "("],
"diameter",
["punctuation", ")"],
["keyword", "new"],
["class-name", ["diameter"]],
["operator", "/"],
["number", "2"],
["keyword", "end"],
["keyword", "def"],
["method-definition", [
["function", "initialize"]
]],
["punctuation", "("],
"radius",
["punctuation", ")"],
["variable", "@radius"],
["operator", "="],
" radius\n ",
["keyword", "end"],
["keyword", "def"],
["method-definition", [
["function", "circumference"]
]],
["constant", "Math"],
["punctuation", ":"],
["punctuation", ":"],
["constant", "PI"],
["operator", "*"],
" radius ",
["operator", "*"],
["operator", "*"],
["number", "2"],
["keyword", "end"],
["comment", "# Seattle style"],
["keyword", "def"],
["method-definition", [
["function", "grow_by"]
]],
" factor",
["punctuation", ":"],
["variable", "@radius"],
["operator", "="],
["variable", "@radius"],
["operator", "*"],
" factor\n ",
["keyword", "end"],
["keyword", "end"]
]

----------------------------------------------------

Checks that method definitions are highlighted correctly