Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

rails-model-layout.el (rails-model-layout:keymap): created

rails-core.el (rails-core:buffer-file-match): allow passing nil
rails-controller-layout.el (rails-controller-layout:keymap): created
rails-cmd-proxy.el (rails-cmd-proxy:convert-buffer-from-remote): fixed compilation warning


git-svn-id: svn+ssh://rubyforge.org/var/svn/emacs-rails/trunk@158 cc5033d0-740f-0410-afc7-949910e492f2
  • Loading branch information...
commit 52c7ab7943162c608a307f369bf66776ff383992 1 parent 2bf7edd
dimaexe authored
View
8 ChangeLog
@@ -1,5 +1,13 @@
2007-04-03 Dmitry Galinsky <dima.exe@gmail.com>
+ * rails-model-layout.el (rails-model-layout:keymap): created
+
+ * rails-core.el (rails-core:buffer-file-match): allow passing nil
+
+ * rails-controller-layout.el (rails-controller-layout:keymap): created
+
+ * rails-cmd-proxy.el (rails-cmd-proxy:convert-buffer-from-remote): fixed compilation warning
+
* rails-ruby.el: added flymake support to on the fly syntax check in ruby-mode
* rails-test.el (rails-test:error-regexp-alist): updated
View
3  rails-cmd-proxy.el
@@ -109,7 +109,8 @@ otherwise if set REVERSE convert from remote to local."
(remote (rails-cmd-proxy:struct-remote struct))
(root default-directory)
(remote-with-root (concat remote (substring root (length local))))
- (buffer-read-only nil))
+ (buffer-read-only nil)
+ point)
(while (setq point (re-search-forward (format "^\\s-*\\(%s\\)"
remote-with-root) end t))
(replace-match (format "%s "
View
38 rails-controller-layout.el
@@ -109,6 +109,38 @@ If the action is nil, return all views for the controller."
(setq menu (list)))
menu))
+(defun rails-controller-layout:keymap (type)
+ (let* ((name (capitalize (substring (symbol-name type) 1)))
+ (map (make-sparse-keymap))
+ (menubar (make-sparse-keymap))
+ (controller (rails-core:current-controller))
+ (model (singularize-string controller)))
+ (when type
+ (unless (eq type :mailer)
+ (when (rails-core:model-exist-p model)
+ (when (rails-core:migration-file (concat "Create" controller))
+ (define-key menubar [go-to-migration] '("Go to Migration" . rails-controller-layout:switch-to-migration))
+ (define-key map (kbd "\C-c g") 'rails-controller-layout:switch-to-migration))
+ (define-key menubar [go-to-model] '("Go to Model" . rails-controller-layout:switch-to-model))
+ (define-key map (kbd "\C-c m") 'rails-controller-layout:switch-to-model))
+ (unless (eq type :helper)
+ (define-key menubar [go-to-helper] '("Go to Helper" . rails-controller-layout:switch-to-helper))
+ (define-key map (kbd "\C-c h") 'rails-controller-layout:switch-to-helper))
+ (unless (eq type :functional-test)
+ (define-key menubar [go-to-functional-test] '("Go to Functional Test" . rails-controller-layout:switch-to-functional-test))
+ (define-key map (kbd "\C-c f") 'rails-controller-layout:switch-to-functional-test))
+ (unless (eq type :controller)
+ (define-key menubar [go-to-controller] '("Go to Controller" . rails-controller-layout:switch-to-controller))
+ (define-key map (kbd "\C-c c") 'rails-controller-layout:switch-to-controller)))
+ (when (eq type :mailer)
+ (define-key menubar [go-to-unit-test] '("Go to Unit Test" . rails-model-layout:switch-to-unit-test))
+ (define-key map (kbd "\C-c u") 'rails-model-layout:switch-to-unit-test))
+ (define-key menubar [sep] (rails-core:menu-separator))
+ (define-key menubar [primary-switch] '("Switch to related" . rails-lib:run-primary-switch))
+ (define-key menubar [secondary-switch] '("Switch to related with menu" . rails-lib:run-secondary-switch))
+ (define-key map [menu-bar rails-controller-layout] (cons name menubar)))
+ map))
+
(defun rails-controller-layout:switch-to (type)
(let* ((controller (rails-core:current-controller))
(model (singularize-string controller))
@@ -126,6 +158,12 @@ If the action is nil, return all views for the controller."
(message (format "%s: %s" (substring (symbol-name type) 1) controller)))
(message "File %s not exists" file))))))
+(defun rails-controller-layout:switch-to-helper () (interactive) (rails-controller-layout:switch-to :helper))
+(defun rails-controller-layout:switch-to-functional-test () (interactive) (rails-controller-layout:switch-to :functional-test))
+(defun rails-controller-layout:switch-to-controller () (interactive) (rails-controller-layout:switch-to :controller))
+(defun rails-controller-layout:switch-to-model () (interactive) (rails-controller-layout:switch-to :model))
+(defun rails-controller-layout:switch-to-migration () (interactive) (rails-controller-layout:switch-to :migration))
+
(defun rails-controller-layout:menu ()
(interactive)
(let* ((type (rails-core:buffer-type))
View
5 rails-controller-minor-mode.el
@@ -29,9 +29,8 @@
(define-minor-mode rails-controller-minor-mode
"Minor mode for RubyOnRails controllers."
- nil
- " controller"
- nil
+ :lighter " Controller"
+ :keymap (rails-controller-layout:keymap :controller)
(setq rails-secondary-switch-func 'rails-controller-layout:menu)
(setq rails-primary-switch-func 'rails-controller-layout:toggle-action-view))
View
5 rails-core.el
@@ -447,8 +447,9 @@ If the action is nil, return all views for the controller."
(defun rails-core:buffer-file-match (regexp)
"Match the current buffer file name to RAILS_ROOT + REGEXP."
- (string-match (rails-core:file regexp)
- (buffer-file-name (current-buffer))))
+ (when-bind (file (rails-core:file regexp))
+ (string-match file
+ (buffer-file-name (current-buffer)))))
(defun rails-core:buffer-type ()
"Return the type of the current Rails file or nil if the type
View
7 rails-fixture-minor-mode.el
@@ -28,10 +28,9 @@
(define-minor-mode rails-fixture-minor-mode
"Minor mode for RubyOnRails fixtures."
- nil
- " fixture"
- nil
- (setq rails-primary-switch-func (lambda() (interactive) (rails-model-layout:switch-to :unit-test)))
+ :lighter " Fixture"
+ :keymap (rails-model-layout:keymap :fixture)
+ (setq rails-primary-switch-func 'rails-model-layout:switch-to-unit-test)
(setq rails-secondary-switch-func 'rails-model-layout:menu))
(provide 'rails-fixture-minor-mode)
View
13 rails-functional-test-minor-mode.el
@@ -28,11 +28,12 @@
(define-minor-mode rails-functional-test-minor-mode
"Minor mode for RubyOnRails functional tests."
- nil
- " func-test"
- nil
- (setq rails-primary-switch-func (lambda() (interactive) (rails-controller-layout:switch-to :controller)))
- (setq rails-secondary-switch-func 'rails-controller-layout:menu)
- (local-set-key (kbd "\C-c .") 'rails-test:run-current-method))
+ :lighter " FTest"
+ :keymap (let ((map (rails-controller-layout:keymap :functional-test)))
+ (define-key map (kbd "\C-c .") 'rails-test:run-current-method)
+ (define-key map [menu-bar rails-controller-layout run] '("Test current method" . rails-test:run-current-method))
+ map)
+ (setq rails-primary-switch-func 'rails-controller-layout:switch-to-controller)
+ (setq rails-secondary-switch-func 'rails-controller-layout:menu))
(provide 'rails-functional-test-minor-mode)
View
7 rails-helper-minor-mode.el
@@ -28,10 +28,9 @@
(define-minor-mode rails-helper-minor-mode
"Minor mode for RubyOnRails helpers."
- nil
- " helper"
- nil
- (setq rails-primary-switch-func (lambda() (interactive) (rails-controller-layout:switch-to :controller)))
+ :lighter " Helper"
+ :keymap (rails-controller-layout:keymap :helper)
+ (setq rails-primary-switch-func 'rails-controller-layout:switch-to-controller)
(setq rails-secondary-switch-func 'rails-controller-layout:menu))
(provide 'rails-helper-minor-mode)
View
5 rails-mailer-minor-mode.el
@@ -29,9 +29,8 @@
(define-minor-mode rails-mailer-minor-mode
"Minor mode for RubyOnRails mailers."
- nil
- " mailer"
- nil
+ :lighter " Mailer"
+ :keymap (rails-controller-layout:keymap :mailer)
(setq rails-secondary-switch-func 'rails-controller-layout:menu)
(setq rails-primary-switch-func 'rails-controller-layout:toggle-action-view))
View
5 rails-migration-minor-mode.el
@@ -28,9 +28,8 @@
(define-minor-mode rails-migration-minor-mode
"Minor mode for RubyOnRails migrations."
- nil
- " migration"
- nil
+ :lighter " Migration"
+ :keymap (rails-model-layout:keymap :migration)
(setq rails-primary-switch-func nil)
(setq rails-secondary-switch-func 'rails-model-layout:menu))
View
47 rails-model-layout.el
@@ -26,13 +26,49 @@
;;; Code:
+(defun rails-model-layout:keymap (type)
+ (let* ((name (capitalize (substring (symbol-name type) 1)))
+ (map (make-sparse-keymap))
+ (menubar (make-sparse-keymap))
+ (model (rails-core:current-model))
+ (controller (pluralize-string model)))
+ (when type
+ (unless (rails-core:mailer-p model)
+ (unless (eq type :model)
+ (define-key menubar [go-to-model] '("Go to Model" . rails-model-layout:switch-to-model))
+ (define-key map (kbd "\C-c m") 'rails-model-layout:switch-to-model))
+ (unless (eq type :unit-test)
+ (define-key menubar [go-to-unit-test] '("Go to Unit Test" . rails-model-layout:switch-to-unit-test))
+ (define-key map (kbd "\C-c u") 'rails-model-layout:switch-to-unit-test))
+ (when (and (not (eq type :migration))
+ (rails-core:migration-file (format "Create%s" controller)))
+ (define-key menubar [go-to-migration] '("Go to Migration" . rails-model-layout:switch-to-migration))
+ (define-key map (kbd "\C-c g") 'rails-model-layout:switch-to-migration))
+ (when (and (not (eq type :controller))
+ (rails-core:controller-exist-p controller))
+ (define-key menubar [go-to-controller] '("Go to Controller" . rails-model-layout:switch-to-controller))
+ (define-key map (kbd "\C-c c") 'rails-model-layout:switch-to-controller))
+ (unless (eq type :fixture)
+ (define-key menubar [go-to-fixture] '("Go to Fixture" . rails-model-layout:switch-to-fixture))
+ (define-key map (kbd "\C-c x") 'rails-model-layout:switch-to-fixture)))
+ (when (rails-core:mailer-p model)
+ (define-key menubar [go-to-mailer] '("Go to Mailer" . rails-model-layout:switch-to-mailer))
+ (define-key map (kbd "\C-c n") 'rails-model-layout:switch-to-mailer))
+ (define-key menubar [sep] (rails-core:menu-separator))
+ (define-key menubar [primary-switch] '("Switch to related" . rails-lib:run-primary-switch))
+ (define-key menubar [secondary-switch] '("Switch to related with menu" . rails-lib:run-secondary-switch))
+ (define-key map [menu-bar rails-model-layout] (cons name menubar)))
+ map))
+
(defun rails-model-layout:switch-to (type)
(let* ((model (rails-core:current-model))
+ (controller (rails-core:current-controller))
+ (item (if controller controller model))
(item (case type
(:mailer (rails-core:mailer-file model))
(:controller (rails-core:controller-file (pluralize-string model)))
(:fixture (rails-core:fixture-file model))
- (:unit-test (rails-core:unit-test-file model))
+ (:unit-test (rails-core:unit-test-file item))
(:model (rails-core:model-file model))
(:migration (rails-core:migration-file (concat "Create" (pluralize-string model)))))))
(when item
@@ -40,9 +76,16 @@
(if (file-exists-p file)
(progn
(find-file file)
- (message (format "%s: %s" (substring (symbol-name type) 1) model)))
+ (message (format "%s: %s" (substring (symbol-name type) 1) item)))
(message "File %s not exists" file))))))
+(defun rails-model-layout:switch-to-mailer () (interactive) (rails-model-layout:switch-to :mailer))
+(defun rails-model-layout:switch-to-controller () (interactive) (rails-model-layout:switch-to :controller))
+(defun rails-model-layout:switch-to-fixture () (interactive) (rails-model-layout:switch-to :fixture))
+(defun rails-model-layout:switch-to-unit-test () (interactive) (rails-model-layout:switch-to :unit-test))
+(defun rails-model-layout:switch-to-model () (interactive) (rails-model-layout:switch-to :model))
+(defun rails-model-layout:switch-to-migration () (interactive) (rails-model-layout:switch-to :migration))
+
(defun rails-model-layout:menu ()
(interactive)
(let* ((item (list))
View
7 rails-model-minor-mode.el
@@ -28,10 +28,9 @@
(define-minor-mode rails-model-minor-mode
"Minor mode for RubyOnRails models."
- nil
- " model"
- nil
- (setq rails-primary-switch-func (lambda() (interactive) (rails-model-layout:switch-to :unit-test)))
+ :lighter " Model"
+ :keymap (rails-model-layout:keymap :model)
+ (setq rails-primary-switch-func 'rails-model-layout:switch-to-unit-test)
(setq rails-secondary-switch-func 'rails-model-layout:menu))
(provide 'rails-model-minor-mode)
View
6 rails-ui.el
@@ -87,8 +87,6 @@
([recent] '("Recent tests" . (lambda() (interactive) (rails-test:run "recent"))))
([tests] '("All" . (lambda() (interactive) (rails-test:run "all"))))
([separator] '("--"))
- ([method] '(menu-item "Test current method" rails-test:run-current-method
- :enable (find (rails-core:buffer-type) '(:unit-test :functional-test))))
([toggle] '(menu-item "Toggle output window" rails-script:toggle-output-window
:enable (get-buffer rails-script:buffer-name)))
([run-current] '("Test current model/controller/mailer" . rails-test:run-current))
@@ -208,10 +206,10 @@
((kbd "\C-c \C-c g u") 'rails-nav:goto-unit-tests)
;; Switch
- ((kbd "\C-c <up>") 'rails-lib:run-primary-switch)
- ((kbd "\C-c <down>") 'rails-lib:run-secondary-switch)
((kbd "<M-S-up>") 'rails-lib:run-primary-switch)
((kbd "<M-S-down>") 'rails-lib:run-secondary-switch)
+ ((kbd "\C-c <up>") 'rails-lib:run-primary-switch)
+ ((kbd "\C-c <down>") 'rails-lib:run-secondary-switch)
((kbd "<C-return>") 'rails-goto-file-on-current-line)
;; Scripts & SQL
View
15 rails-unit-test-minor-mode.el
@@ -28,15 +28,16 @@
(define-minor-mode rails-unit-test-minor-mode
"Minor mode for RubyOnRails unit tests."
- nil
- " unit-test"
- nil
+ :lighter " UTest"
+ :keymap (let ((map (rails-model-layout:keymap :unit-test)))
+ (define-key map (kbd "\C-c .") 'rails-test:run-current-method)
+ (define-key map [menu-bar rails-model-layout run] '("Test current method" . rails-test:run-current-method))
+ map)
(setq rails-primary-switch-func (lambda()
(interactive)
(if (rails-core:mailer-p (rails-core:current-model))
- (rails-model-layout:switch-to :mailer)
- (rails-model-layout:switch-to :model))))
- (setq rails-secondary-switch-func 'rails-model-layout:menu)
- (local-set-key (kbd "\C-c .") 'rails-test:run-current-method))
+ (rails-model-layout:switch-to-mailer)
+ (rails-model-layout:switch-to-model))))
+ (setq rails-secondary-switch-func 'rails-model-layout:menu))
(provide 'rails-unit-test-minor-mode)
View
5 rails-view-minor-mode.el
@@ -100,9 +100,8 @@
(define-minor-mode rails-view-minor-mode
"Minor mode for RubyOnRails views."
- nil
- " view"
- nil
+ :lighter " View"
+ :keymap (rails-controller-layout:keymap :view)
(setq rails-primary-switch-func 'rails-controller-layout:toggle-action-view)
(setq rails-secondary-switch-func 'rails-controller-layout:menu)
(if (boundp 'mmm-mode-map)
Please sign in to comment.
Something went wrong with that request. Please try again.