Skip to content

Commit

Permalink
Merge pull request senny#184 from senny/project_api_improvements
Browse files Browse the repository at this point in the history
Improved project API
  • Loading branch information
jone committed Mar 22, 2013
2 parents 2c63593 + a78d647 commit e7761a7
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion lib/bundles/framework.el
Original file line number Diff line number Diff line change
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

0 comments on commit e7761a7

Please sign in to comment.