0
;; Name functions consistently
0
;; Make rinari a minor mode that doesn't activate for regular ruby-mode.
0
-;; make `rails-find-action' work with rails2-style view filenames
0
-;; make `rails-find-action' which will follow forms (maybe w/prefix?)
0
+;; make `rinari-find-action' work with rails2-style view filenames
0
+;; make `rinari-find-action' which will follow forms (maybe w/prefix?)
0
;; add key-bindings for rinari minor mode
0
(require 'find-file-in-project)
0
-(require 'r
ails-script)
0
+(require 'r
inari-script)
0
-(defun r
ails-rake (&optional arg)
0
+(defun r
inari-rake (&optional arg)
0
(let* ((task (completing-read "Rake: "
0
(message "%s" (shell-command-to-string (concat "rake " rake-args)))))
0
-(defun r
ails-root (&optional dir)
0
+(defun r
inari-root (&optional dir)
0
(or dir (setq dir default-directory))
0
(if (file-exists-p (concat dir "config/environment.rb"))
0
(unless (equal dir "/")
0
- (r
ails-root (expand-file-name (concat dir "../"))))))
0
+ (r
inari-root (expand-file-name (concat dir "../"))))))
0
-(defun rails-find-view ()
0
+ "test the current method"
0
+ (let* ((funname (which-function))
0
+ (method (and (string-match "#\\(.*\\)" funname) (match-string 1 funname)))
0
+ ;; rinari-name-components strips _controller from the end
0
+ (class (rinari-make-dirname (rinari-name-components funname))))
0
+ ((string-match "controller" class)
0
+ (message "controller")
0
+ (find-file (format "%s/test/functional/%s_test.rb" (rinari-root) class))
0
+ (goto-char (point-min))
0
+ (search-forward (format "def %s" method))
0
+(defun rinari-find-view ()
0
"View toggling for rails"
0
(let* ((funname (which-function))
0
(function (and (string-match "#\\(.*\\)" funname) (match-string 1 funname)))
0
- (controller (rails-make-dirname (rails-name-components funname)))
0
- (path (rails-path-to-view controller function))
0
- (appdir (concat (rails-root) "/app/")))
0
+ (controller (rinari-make-dirname (rails-name-components funname)))
0
+ (path (rinari-path-to-view controller function))
0
+ (appdir (concat (rinari-root) "/app/")))
0
(find-file (concat appdir "views/" path ".rhtml"))))
0
-(defun r
ails-path-to-view (controller function)
0
+(defun r
inari-path-to-view (controller function)
0
"Takes a CONTROLLER and FUNCTION and returns the path to the
0
view at which CONTROLLER#FUNCTION points."
0
@@ -115,7 +130,7 @@ view at which CONTROLLER#FUNCTION points."
0
(mapcar 'car renders)))))
0
(goto-char (cdr (assoc render renders)))
0
;; read the hashed arguments to the redirect
0
- (let* ((redirect (r
ails-ruby-hash-to-alist))
0
+ (let* ((redirect (r
inari-ruby-hash-to-alist))
0
(new-function (or (cdr (assoc ":action" redirect))
0
(if (assoc ":partial" redirect)
0
(concat "_" (cdr (assoc ":partial" redirect))))
0
@@ -127,17 +142,17 @@ view at which CONTROLLER#FUNCTION points."
0
(if (and (equalp new-function function)
0
(equalp new-controller controller))
0
(setf path (concat controller "/" function))
0
- (setf path (r
ails-path-to-view new-controller new-function)))))
0
+ (setf path (r
inari-path-to-view new-controller new-function)))))
0
(if (search-backward "render_partial" start t)
0
(setf path (concat controller "/" "_" function)))))))
0
(or path (concat controller "/" function))))
0
-(defvar r
ails-ruby-hash-regexp
0
+(defvar r
inari-ruby-hash-regexp
0
"\\(:[^[:space:]]*?\\)[[:space:]]*\\(=>[[:space:]]*[\"\']?\\([^[:space:]]*?\\)[\"\']?[[:space:]]*\\)?[,){}\n]"
0
;; "\\(:[^[:space:]]*?\\)[[:space:]]*\\(=>[[:space:]]*\\([^[:space:]]*\\)[[:space:]]*\\)?[,){}$]"
0
"Regexp to match subsequent key => value pairs of a ruby hash.")
0
-(defun r
ails-ruby-hash-to-alist ()
0
+(defun r
inari-ruby-hash-to-alist ()
0
"Returns an alist of the key => value pairs on consecutive
0
lines starting at point."
0
(let ((end (save-excursion
0
@@ -146,7 +161,7 @@ lines starting at point."
0
(while (and (< (point) end)
0
- (re-search-forward r
ails-ruby-hash-regexp end t))
0
+ (re-search-forward r
inari-ruby-hash-regexp end t))
0
(cons (cons (match-string 1)
0
(if (> (length (match-string 3)) 0)
0
@@ -155,26 +170,26 @@ lines starting at point."
0
-(defun r
ails-alist-from-form ()
0
+(defun r
inari-alist-from-form ()
0
"If currently inside of a form in a view return an alist of the
0
hash key => values, else return nil."
0
(if (and (re-search-backward "form_\(?:\(?:remote_\)?tag\)" nil t)
0
- (rails-ruby-hash-to-alist))))
0
+ (rinari-ruby-hash-to-alist))))
0
;;; TODO: make this work with rails2-style view filenames
0
-(defun r
ails-find-action ()
0
+(defun r
inari-find-action ()
0
- (let* ((form-alist (r
ails-alist-from-form))
0
+ (let* ((form-alist (r
inari-alist-from-form))
0
(action (or (cdr (assoc ":action" form-alist))
0
(file-name-sans-extension
0
(file-name-nondirectory buffer-file-name))))
0
(controller (or (cdr (assoc ":controller" form-alist))
0
(file-name-nondirectory
0
(expand-file-name ".")))))
0
- (find-file (concat (r
ails-root)
0
+ (find-file (concat (r
inari-root)
0
@@ -182,33 +197,33 @@ lines starting at point."
0
(search-forward-regexp (concat "def *" action))
0
-(defun r
ails-name-components (name)
0
+(defun r
inari-name-components (name)
0
"Helper for view toggling"
0
(let ((case-fold-search nil))
0
- (let ((ind (string-match "\\([A-Z][a-z0-9]+\\)[A-Z]" name in)))
0
- (cons (downcase (match-string 1 name)) (rnc (match-end 1)))))))
0
-(defun rails-make-dirname (comps)
0
+ (let ((ind (string-match "\\([A-Z][a-z0-9]+\\)[A-Z]" name in)))
0
+ (cons (downcase (match-string 1 name)) (rnc (match-end 1)))))))
0
+(defun rinari-make-dirname (comps)
0
"Helper for view toggling"
0
(reduce #'(lambda (str next) (concat str (concat "_" next))) comps))
0
-(defun r
ails-insert-erb-skeleton (no-equals)
0
+(defun r
inari-insert-erb-skeleton (no-equals)
0
(unless no-equals (insert "="))
0
-(defcustom r
ails-browse-url-func
0
+(defcustom r
inari-browse-url-func
0
- "`browse-url' function used by `r
ails-browse-view'.")
0
+ "`browse-url' function used by `r
inari-browse-view'.")
0
-(defun rails-browse-view (arg)
0
- "Browse the url of the current view with `rails-browse-url-func'
0
+(defun rinari-browse-view (arg)
0
+ "Browse the url of the current view with `rinari-browse-url-func'
0
which default to `browse-url'. With a prefix argument allows
0
@@ -224,12 +239,12 @@ editing of the url."
0
(read-from-minibuffer "url: "
0
- (eval (list r
ails-browse-url-func url))))
0
+ (eval (list r
inari-browse-url-func url))))
0
-(defadvice find-file-in-project (around find-file-in-rails-project activate)
0
- "Wrap `find-file-in-project' to use `rails-root' as the base of
0
+(defadvice find-file-in-project (around find-file-in-rinari-project activate)
0
+ "Wrap `find-file-in-project' to use `rinari-root' as the base of
0
- (let ((ffip-project-root (r
ails-root)))
0
+ (let ((ffip-project-root (r
inari-root)))
0
;;--------------------------------------------------------------------
0
@@ -240,20 +255,18 @@ editing of the url."
0
(let ((map (make-sparse-keymap)))
0
"Key map for Rinari minor mode.")
0
-(define-key rinari-minor-mode-map "\C-c'r" 'rails-rake)
0
-(define-key rinari-minor-mode-map "\C-c's" 'rails-script)
0
-(define-key rinari-minor-mode-map "\C-c'c" 'rails-script-console)
0
-(define-key rinari-minor-mode-map "\C-c'w"
0
- (lambda () (interactive) (rails-run-w/compilation
0
- (concat (rails-root) "/script/server"))))
0
-(define-key rinari-minor-mode-map "\C-c'v" 'rails-find-view)
0
-(define-key rinari-minor-mode-map "\C-c'a" 'rails-find-action)
0
-(define-key rinari-minor-mode-map "\C-c'b" 'rails-browse-view)
0
+(define-key rinari-minor-mode-map "\C-c'r" 'rinari-rake)
0
+(define-key rinari-minor-mode-map "\C-c's" 'rinari-script)
0
+(define-key rinari-minor-mode-map "\C-c'c" 'rinari-console)
0
+(define-key rinari-minor-mode-map "\C-c'w" 'rinari-server)
0
+(define-key rinari-minor-mode-map "\C-c'v" 'rinari-find-view)
0
+(define-key rinari-minor-mode-map "\C-c'a" 'rinari-find-action)
0
+(define-key rinari-minor-mode-map "\C-c'b" 'rinari-browse-view)
0
(define-key rinari-minor-mode-map "\C-c't" 'toggle-buffer)
0
(defun rinari-launch ()
0
"Run `rinari-minor-mode' if inside of a rails projcect"
0
- (interactive) (if (r
ails-root) (rinari-minor-mode t)))
0
+ (interactive) (if (r
inari-root) (rinari-minor-mode t)))
0
(add-hook 'ruby-mode-hook
0
(lambda () (rinari-launch)))
Comments
No one has commented yet.