forked from eschulte/rinari
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Put Rails helpers as functions in it's own file.
- Loading branch information
Showing
3 changed files
with
56 additions
and
47 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
(defun rails-version() | ||
"Determine rails version" | ||
(save-excursion | ||
(let ((buffer "*rails-version*")) | ||
(flet ((kill-buffer-and-return-version (buffer version) | ||
(progn | ||
(kill-buffer buffer) | ||
version))) | ||
(progn | ||
(shell-command "rails -v" buffer) | ||
(switch-to-buffer buffer) | ||
(goto-char (point-min)) | ||
(if (search-forward "Rails 2" (point-max) t) | ||
(kill-buffer-and-return-version buffer 2) | ||
(progn | ||
(goto-char (point-min)) | ||
(if (search-forward "Rails 3" (point-max) t) | ||
(kill-buffer-and-return-version buffer 3))))))))) | ||
|
||
(defun generate-app (name) | ||
"Generates a Rails application with NAME." | ||
(let* ((tmp-dir (expand-file-name "tmp" rinari-root-path)) | ||
(app (expand-file-name name tmp-dir))) | ||
(setq current-rails-application app) | ||
(shell-command | ||
(if (= (rails-version) 2) | ||
(concat "rails " app " -q") | ||
(concat "rails new " app " -q"))))) | ||
|
||
(defun generate-scaffold (name) | ||
"Generates a scaffold with name." | ||
(let ((script-dir (expand-file-name "script" current-rails-application))) | ||
(cond ((= (rails-version) 2) | ||
(shell-command | ||
(concat (expand-file-name "generate" script-dir) " scaffold " name))) | ||
(t | ||
(shell-command | ||
(concat (expand-file-name "rails" script-dir) " generate scaffold " name " -q")))))) | ||
|
||
|
||
(provide 'rails-helpers) |
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 |
---|---|---|
@@ -1,39 +1,24 @@ | ||
(Given "Rails application \"\\(.+\\)\"" | ||
(Given "^Rails application \"\\(.+\\)\"$" | ||
(lambda (name) | ||
(let* ((tmp-dir (expand-file-name "tmp" rinari-root-path)) | ||
(app (expand-file-name name tmp-dir))) | ||
(setq current-rails-application app) | ||
(if (= (rails-version) 2) | ||
(progn | ||
(if (not (file-exists-p tmp-dir)) | ||
(make-directory tmp-dir)) | ||
(shell-command (concat "rails " app))) | ||
(shell-command (concat "# rails3 assumed, hence -> rails new " app)))))) | ||
(generate-app name))) | ||
|
||
|
||
(Given "Rinari is \\(active\\|inactive\\)" | ||
(Given "^Rinari is \\(active\\|inactive\\)$" | ||
(lambda (status) | ||
(rinari-minor-mode (if (string= status "active") 1 -1)))) | ||
(rinari-minor-mode (if (string= status "active") 1 -1)))) | ||
|
||
(When "I visit \"\\(.+\\)\"" | ||
(When "^I visit \"\\(.+\\)\"$" | ||
(lambda (file) | ||
(find-file (expand-file-name file current-rails-application)))) | ||
|
||
(Then "Rinari should be active" | ||
(Then "^Rinari should be active$" | ||
(lambda () | ||
(should rinari-minor-mode))) | ||
|
||
|
||
(Given "^I generate scaffold for \"\\(.+\\)\"$" | ||
(lambda (scaffold-name) | ||
(if (= (rails-version) 2) | ||
(shell-command (concat | ||
(file-name-as-directory current-rails-application) | ||
(file-name-as-directory "script") | ||
"generate scaffold " scaffold-name)) | ||
(message "rails3 command should go here")))) | ||
(lambda (name) | ||
(generate-scaffold name))) | ||
|
||
(Then "^I should be in \"\\(.+\\)\"$" | ||
(lambda (buffer) | ||
(string= (buffer-name) buffer))) | ||
(lambda (buffer) | ||
(string= (buffer-name) buffer))) | ||
|
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