Skip to content

Commit

Permalink
Add style for php 'blade' templates
Browse files Browse the repository at this point in the history
  • Loading branch information
raboof committed Aug 20, 2022
1 parent 540fabe commit dae8afe
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/reuse/_comment.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,13 @@ class BibTexCommentStyle(CommentStyle):

MULTI_LINE = ("@Comment{", "", "}")

class BladeCommentStyle(CommentStyle):
"""Laravel Blade Template comment style."""

_shorthand = "blade"

MULTI_LINE = ("{{--", "", "--}}")
NEWLINE_AFTER = False

class CCommentStyle(CommentStyle):
"""C comment style."""
Expand Down Expand Up @@ -646,6 +653,15 @@ class VimCommentStyle(CommentStyle):
k.lower(): v for k, v in EXTENSION_COMMENT_STYLE_MAP.items()
}

#: A map of (common) double file extensions against comment types.
EXTENSIONS_COMMENT_STYLE_MAP = {
".blade.php": BladeCommentStyle,
}

EXTENSIONS_COMMENT_STYLE_MAP_LOWERCASE = {
k.lower(): v for k, v in EXTENSIONS_COMMENT_STYLE_MAP.items()
}

FILENAME_COMMENT_STYLE_MAP = {
".bashrc": PythonCommentStyle,
".coveragerc": PythonCommentStyle,
Expand Down
3 changes: 3 additions & 0 deletions src/reuse/header.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
from . import SpdxInfo
from ._comment import (
EXTENSION_COMMENT_STYLE_MAP_LOWERCASE,
EXTENSIONS_COMMENT_STYLE_MAP_LOWERCASE,
FILENAME_COMMENT_STYLE_MAP_LOWERCASE,
NAME_STYLE_MAP,
CCommentStyle,
Expand Down Expand Up @@ -330,6 +331,8 @@ def find_and_replace_header(
def _get_comment_style(path: Path) -> Optional[CommentStyle]:
"""Return value of CommentStyle detected for *path* or None."""
style = FILENAME_COMMENT_STYLE_MAP_LOWERCASE.get(path.name.lower())
if style is None:
style = EXTENSIONS_COMMENT_STYLE_MAP_LOWERCASE.get(''.join(path.suffixes).lower())
if style is None:
style = EXTENSION_COMMENT_STYLE_MAP_LOWERCASE.get(path.suffix.lower())
return style
Expand Down

0 comments on commit dae8afe

Please sign in to comment.