-
Notifications
You must be signed in to change notification settings - Fork 102
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor and extract functions in alchemist-project
I extracted a bunch of functions from alchemist-project to alchemist-utils and added tests for them.
- Loading branch information
1 parent
26bb9b9
commit dd3e9be
Showing
3 changed files
with
38 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -107,6 +107,29 @@ It walks the directory tree until it finds a elixir project root indicator." | |
(let* ((modules (mapconcat #'identity modules ","))) | ||
(format "[%s]" modules))) | ||
|
||
(defun alchemist-utils--snakecase-to-camelcase (str) | ||
"Convert a snake_case string `STR' to a CamelCase string. | ||
This function is useful for converting file names like my_module to Elixir | ||
module names (MyModule)." | ||
(mapconcat 'capitalize (split-string str "_") "")) | ||
|
||
(defun alchemist-utils--add-ext-to-path-if-not-present (path ext) | ||
"Add `EXT' to `PATH' if `PATH' doesn't already ends with `EXT'." | ||
(if (string-suffix-p ext path) | ||
This comment has been minimized.
Sorry, something went wrong. |
||
path | ||
(concat path ext))) | ||
|
||
(defun alchemist-utils--path-to-module-name (path) | ||
"Convert `PATH' to its Elixir module name equivalent. | ||
For example, convert 'my_app/my_module.ex' to 'MyApp.MyModule'." | ||
(let* ((path (file-name-sans-extension path)) | ||
(path (split-string path "/")) | ||
(path (remove-if (lambda (str) (equal str "")) path))) | ||
This comment has been minimized.
Sorry, something went wrong.
whatyouhide
Author
Contributor
|
||
(mapconcat #'alchemist-utils--snakecase-to-camelcase path "."))) | ||
|
||
|
||
(provide 'alchemist-utils) | ||
|
||
;;; alchemist-utils.el ends here |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
string-suffix-p
is builtin in >= 24.4, so we should be fine.