Skip to content

Commit

Permalink
rails-model-layout.el (rails-model-layout:keymap): created
Browse files Browse the repository at this point in the history
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
dimaexe committed Apr 3, 2007
1 parent 2bf7edd commit 52c7ab7
Show file tree
Hide file tree
Showing 15 changed files with 130 additions and 46 deletions.
8 changes: 8 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
2007-04-03 Dmitry Galinsky <[email protected]>

* 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
Expand Down
3 changes: 2 additions & 1 deletion rails-cmd-proxy.el
Original file line number Diff line number Diff line change
Expand Up @@ -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 "
Expand Down
38 changes: 38 additions & 0 deletions rails-controller-layout.el
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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))
Expand Down
5 changes: 2 additions & 3 deletions rails-controller-minor-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -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))

Expand Down
5 changes: 3 additions & 2 deletions rails-core.el
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 3 additions & 4 deletions rails-fixture-minor-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -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)
13 changes: 7 additions & 6 deletions rails-functional-test-minor-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -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)
7 changes: 3 additions & 4 deletions rails-helper-minor-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -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)
5 changes: 2 additions & 3 deletions rails-mailer-minor-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -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))

Expand Down
5 changes: 2 additions & 3 deletions rails-migration-minor-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -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))

Expand Down
47 changes: 45 additions & 2 deletions rails-model-layout.el
Original file line number Diff line number Diff line change
Expand Up @@ -26,23 +26,66 @@

;;; 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
(let ((file (rails-core:file item)))
(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))
Expand Down
7 changes: 3 additions & 4 deletions rails-model-minor-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -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)
6 changes: 2 additions & 4 deletions rails-ui.el
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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
Expand Down
15 changes: 8 additions & 7 deletions rails-unit-test-minor-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -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)
5 changes: 2 additions & 3 deletions rails-view-minor-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 52c7ab7

Please sign in to comment.