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

Improved project API #184

Merged
merged 3 commits into from Mar 22, 2013
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 13 additions & 1 deletion lib/bundles/framework.el
Expand Up @@ -43,6 +43,10 @@
'("Rakefile" ".git" "Gemfile")
"list of file-/directory-names which indicate a root of a project")

(defun cabbage-project-p ()
"Returns whether cabbage has access to a project root or not"
(stringp (cabbage-project-root)))

(defun cabbage-project-parent-directory (a-directory)
"Returns the directory of which a-directory is a child"
(file-name-directory (directory-file-name a-directory)))
Expand All @@ -53,12 +57,20 @@

(defun cabbage-project-root (&optional directory)
"Finds the root directory of the project by walking the directory tree until it finds a project root indicator."
(let* ((directory (file-name-as-directory (or directory default-directory)))
(let* ((directory (file-name-as-directory (or directory (expand-file-name default-directory))))
(present-files (directory-files directory)))
(cond ((cabbage-project-root-directory-p directory) nil)
((> (length (intersection present-files cabbage-project-root-indicators :test 'string=)) 0) directory)
(t (cabbage-project-root (file-name-directory (directory-file-name directory)))))))

(defun cabbage-project-expand-path (&rest segments)
"Construct a path relative to the cabbage-project-root"
(let ((project-root (cabbage-project-root)))
(when (not project-root) (error "Could not detect project root"))
(let ((path (mapconcat 'identity segments "/"))
(installation-dir (replace-regexp-in-string "/$" "" project-root)))
(expand-file-name (concat installation-dir "/" path)))))

;; API: integrated testing
(defvar cabbage-testing--last-project-root nil
"cache for the project-root of the last executed spec-file")
Expand Down