Skip to content
This repository has been archived by the owner on Oct 1, 2021. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
Rewrote toggle and toggle test functions.
Removed the link-to field from the rails/resource struct.
Added the toggle fiend to the rails/resource struct.
  • Loading branch information
dmexe committed Mar 5, 2009
1 parent 56db889 commit c47425c
Show file tree
Hide file tree
Showing 6 changed files with 163 additions and 173 deletions.
2 changes: 0 additions & 2 deletions bundles/rails-apidock-bundle.el
Expand Up @@ -63,5 +63,3 @@
(candidate-number-limit . 10)
(volatile)
(delayed)))))

(provide 'rails-apidock-bundle)
64 changes: 56 additions & 8 deletions bundles/rails-basic-bundle.el
@@ -1,3 +1,55 @@
(defun rails/basic-bundle/toggle-from-view (root rails-buffer)
(when (eq 'view (rails/resource-buffer-type rails-buffer))
(let ((controllers
(rails/resources/get-associated-items-by-resource
root
rails-buffer
(rails/resources/find 'controller)))
(mailers
(rails/resources/get-associated-items-by-resource
root
rails-buffer
(rails/resources/find 'controller)))
(method (file-name-sans-extension
(file-name-sans-extension
(file-name-nondirectory
(rails/resource-buffer-file rails-buffer)))))
item)
(setq item
(or (car controllers)
(car mailers)))
(when item
(rails/resources/find-file-by-item root item)
(rails/ruby/goto-method-in-current-buffer method)
(rails/resources/notify-item item)
t))))

(defun rails/basic-bundle/toggle-to-view (root rails-buffer)
(when (memq (rails/resource-buffer-type rails-buffer)
'(controller mailer))
(let* ((method (rails/ruby/current-method))
(res-name (rails/resource-buffer-title rails-buffer))
(view (rails/resources/find 'view))
(dir (concat root (rails/resource-dir view) res-name "/"))
(regexp (if method
(concat "^" method "\..*")
".*"))
items
file)
(setq items
(files-ext/directory-files-recursive dir regexp))
(if (= 1 (length items))
(setq file (car items))
(setq file
(ido-completing-read "Select view: "
items)))
(find-file (concat dir file))
(rails/resources/notify-item
nil
"View"
(concat res-name "/" file)))
t))

(rails/defbundle "Basic"
(:menu
(([new] (cons "Create a new view for current file" 'identity))
Expand All @@ -17,23 +69,20 @@
(rails/defresource 'helper "Helper"
:dir "app/helpers"
:file-suffix "_helper"
:file-ext "rb"
:link-to 'controller)
:file-ext "rb")

(rails/defresource 'view "View"
:dir "app/views"
:group 'viewa
:file-pattern "{name}/.*"
:get-action-func '(lambda() (file-name-nondirectory (file-name-sans-extension (buffer-file-name))))
:toggle '(rails/basic-bundle/toggle-to-view . rails/basic-bundle/toggle-from-view)
:group 'viewa
:options 'expand-in-menu
:link-to '(mailer controller)
:weight 2)

(rails/defresource 'migration "Migration"
:dir "db/migrate"
:file-ext "rb"
:file-pattern "[0-9]+_create_{name}"
:link-to 'model)
:file-pattern "[0-9]+_create_{name}")

(rails/defresource 'model "Model"
:dir "app/models"
Expand All @@ -45,7 +94,6 @@
:file-ext "rb"
:file-suffix "_observer"
:weight 2
:link-to 'model
:options 'pluralize)

(rails/defresource 'stylesheet "Stylesheet"
Expand Down
6 changes: 2 additions & 4 deletions bundles/rails-rspec-bundle.el
Expand Up @@ -82,14 +82,12 @@
(rails/defresource 'fixture-spec "RSpec Fixture"
:group 'spec
:dir "spec/fixtures"
:file-ext "yml"
:link-to 'model-spec)
:file-ext "yml")

(rails/defresource 'factory-spec "RSpec Factory"
:dir "spec/factories"
:file-ext "rb"
:options 'pluralize
:link-to 'model-spec)
:options 'pluralize)

(rails/defresource 'view-spec "RSpec View"
:group 'views
Expand Down
3 changes: 1 addition & 2 deletions bundles/rails-test-unit-bundle.el
Expand Up @@ -71,8 +71,7 @@
(rails/defresource 'fixture "Fixture"
:group 'unit-test
:dir "test/fixtures"
:file-ext "yml"
:link-to '(unit-test unit-test-mailer))
:file-ext "yml")

(rails/defresource 'functional-test "Functional Test"
:group 'unit-test
Expand Down
4 changes: 2 additions & 2 deletions rails-lib.el
Expand Up @@ -177,7 +177,7 @@ else return nil"
(list title
menu)))

(defun rails/display-menu-using-ido (title menu)
(defun rails/display-menu-using-ido (title menu &optional dont-require-match)
(let (choices value)
(dolist (item menu) ; filter
(let ((name (car item))
Expand All @@ -189,7 +189,7 @@ else return nil"
(ido-completing-read (format "%s: " title)
(mapcar 'car choices)
nil
t))
(not dont-require-match)))
(cdr (find value choices :test 'string= :key 'car)))))

(defun rails/completing-read (title &optional list require default history)
Expand Down

0 comments on commit c47425c

Please sign in to comment.