public
Description: Rinari Is Not A Rails IDE
Homepage: http://rinari.rubyforge.org
Clone URL: git://github.com/technomancy/rinari.git
all function now prefix'd w/rinari
eschulte (author)
Mon Jun 23 18:20:53 -0700 2008
commit  b12e8dbbeeeb9e213da4316e00c1b511f44980af
tree    b815e6e2d899c7ffdd3b6e1ee1b2352cd48e869f
parent  41f635cb2f2bcf93ee06b1f9fb2ce197e89d4ab4
0
...
244
245
246
 
 
247
248
249
...
244
245
246
247
248
249
250
251
0
@@ -244,6 +244,8 @@ going for rails for now
0
 - easier to remember
0
 - easy enough to change later
0
 
0
+switching to rinari
0
+
0
 while I'm doing this I'm going to rename rails-scripts.rl to
0
 rails-script.el (minor)
0
 
...
102
103
104
105
 
106
107
108
...
102
103
104
 
105
106
107
108
0
@@ -102,7 +102,7 @@ directory they are found in so that they are unique."
0
 (defun ffip-uniqueify (file-cons)
0
   "Set the car of the argument to include the directory name plus the file name."
0
   (setcar file-cons
0
- (concat (car file-cons) " - "
0
+ (concat (car file-cons) " "
0
      (cadr (reverse (split-string (cdr file-cons) "/"))))))
0
 
0
 (defun find-file-in-project ()
...
47
48
49
50
51
 
 
52
53
54
...
61
62
63
64
 
65
66
67
 
68
69
70
...
74
75
76
77
 
78
79
80
81
82
 
83
84
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
85
86
87
88
89
90
91
 
 
 
92
93
94
 
95
96
97
...
115
116
117
118
 
119
120
121
...
127
128
129
130
 
131
132
133
134
135
 
136
137
138
139
140
 
141
142
143
...
146
147
148
149
 
150
151
152
...
155
156
157
158
 
159
160
161
162
163
164
165
 
 
166
167
168
 
169
170
 
171
172
173
174
175
176
177
 
178
179
180
...
182
183
184
185
 
186
187
188
189
190
191
192
193
194
195
 
 
 
 
 
 
 
 
196
197
198
199
 
200
201
202
203
204
205
206
 
207
208
 
209
210
211
 
 
212
213
214
...
224
225
226
227
 
228
229
230
 
 
231
232
 
233
234
235
...
240
241
242
243
244
245
246
247
248
249
250
251
 
 
 
 
 
 
 
252
253
254
255
256
 
257
258
259
...
47
48
49
 
 
50
51
52
53
54
...
61
62
63
 
64
65
66
 
67
68
69
70
...
74
75
76
 
77
78
79
80
81
 
82
83
 
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
 
 
 
104
105
106
107
108
 
109
110
111
112
...
130
131
132
 
133
134
135
136
...
142
143
144
 
145
146
147
148
149
 
150
151
152
153
154
 
155
156
157
158
...
161
162
163
 
164
165
166
167
...
170
171
172
 
173
174
175
176
177
178
 
 
179
180
181
182
 
183
184
 
185
186
187
188
189
190
191
 
192
193
194
195
...
197
198
199
 
200
201
202
 
 
 
 
 
 
 
 
203
204
205
206
207
208
209
210
211
212
213
 
214
215
216
217
218
219
220
 
221
222
 
223
224
 
 
225
226
227
228
229
...
239
240
241
 
242
243
 
 
244
245
246
 
247
248
249
250
...
255
256
257
 
 
 
 
 
 
 
 
 
258
259
260
261
262
263
264
265
266
267
268
 
269
270
271
272
0
@@ -47,8 +47,8 @@
0
 
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
 
0
 ;;; Code:
0
@@ -61,10 +61,10 @@
0
 
0
 (require 'find-file-in-project)
0
 (require 'pcmpl-rake)
0
-(require 'rails-script)
0
+(require 'rinari-script)
0
 
0
 ;;;###autoload
0
-(defun rails-rake (&optional arg)
0
+(defun rinari-rake (&optional arg)
0
   (interactive "P")
0
   (let* ((task (completing-read "Rake: "
0
         (pcmpl-rake-tasks)))
0
@@ -74,24 +74,39 @@
0
      task)))
0
     (message "%s" (shell-command-to-string (concat "rake " rake-args)))))
0
 
0
-(defun rails-root (&optional dir)
0
+(defun rinari-root (&optional dir)
0
   (or dir (setq dir default-directory))
0
   (if (file-exists-p (concat dir "config/environment.rb"))
0
       dir
0
     (unless (equal dir "/")
0
- (rails-root (expand-file-name (concat dir "../"))))))
0
+ (rinari-root (expand-file-name (concat dir "../"))))))
0
 
0
-(defun rails-find-view ()
0
+(defun rinari-test ()
0
+ "test the current method"
0
+ (interactive)
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
+ (cond
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
+ ))))
0
+
0
+(defun rinari-find-view ()
0
   "View toggling for rails"
0
   (interactive)
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
 
0
-(defun rails-path-to-view (controller function)
0
+(defun rinari-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
   (let (path)
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 (rails-ruby-hash-to-alist))
0
+ (let* ((redirect (rinari-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 (rails-path-to-view new-controller new-function)))))
0
+ (setf path (rinari-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
 
0
-(defvar rails-ruby-hash-regexp
0
+(defvar rinari-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
 
0
-(defun rails-ruby-hash-to-alist ()
0
+(defun rinari-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
   alist)
0
     (save-excursion
0
       (while (and (< (point) end)
0
- (re-search-forward rails-ruby-hash-regexp end t))
0
+ (re-search-forward rinari-ruby-hash-regexp end t))
0
   (setf alist
0
    (cons (cons (match-string 1)
0
        (if (> (length (match-string 3)) 0)
0
@@ -155,26 +170,26 @@ lines starting at point."
0
      alist))))
0
     alist))
0
 
0
-(defun rails-alist-from-form ()
0
+(defun rinari-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
   (interactive)
0
   (save-excursion
0
     (if (and (re-search-backward "form_\(?:\(?:remote_\)?tag\)" nil t)
0
- (ruby-forward-sexp))
0
- (rails-ruby-hash-to-alist))))
0
+ (ruby-forward-sexp))
0
+ (rinari-ruby-hash-to-alist))))
0
 
0
 ;;; TODO: make this work with rails2-style view filenames
0
-(defun rails-find-action ()
0
+(defun rinari-find-action ()
0
   (interactive)
0
- (let* ((form-alist (rails-alist-from-form))
0
+ (let* ((form-alist (rinari-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 (rails-root)
0
+ (find-file (concat (rinari-root)
0
      "app/controllers/"
0
      controller
0
      "_controller.rb"))
0
@@ -182,33 +197,33 @@ lines starting at point."
0
     (search-forward-regexp (concat "def *" action))
0
     (recenter)))
0
 
0
-(defun rails-name-components (name)
0
+(defun rinari-name-components (name)
0
   "Helper for view toggling"
0
   (let ((case-fold-search nil))
0
- (labels ((rnc (in)
0
- (let ((ind (string-match "\\([A-Z][a-z0-9]+\\)[A-Z]" name in)))
0
- (if (eq ind nil)
0
- nil
0
- (cons (downcase (match-string 1 name)) (rnc (match-end 1)))))))
0
- (rnc 0))))
0
-
0
-(defun rails-make-dirname (comps)
0
+ (labels ((rnc (in)
0
+ (let ((ind (string-match "\\([A-Z][a-z0-9]+\\)[A-Z]" name in)))
0
+ (if (eq ind nil)
0
+ nil
0
+ (cons (downcase (match-string 1 name)) (rnc (match-end 1)))))))
0
+ (rnc 0))))
0
+
0
+(defun rinari-make-dirname (comps)
0
   "Helper for view toggling"
0
   (reduce #'(lambda (str next) (concat str (concat "_" next))) comps))
0
 
0
-(defun rails-insert-erb-skeleton (no-equals)
0
+(defun rinari-insert-erb-skeleton (no-equals)
0
   (interactive "P")
0
   (insert "<%")
0
   (unless no-equals (insert "="))
0
   (insert " %>")
0
   (backward-char 3))
0
 
0
-(defcustom rails-browse-url-func
0
+(defcustom rinari-browse-url-func
0
   'browse-url
0
- "`browse-url' function used by `rails-browse-view'.")
0
+ "`browse-url' function used by `rinari-browse-view'.")
0
 
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
 editing of the url."
0
   (interactive "P")
0
@@ -224,12 +239,12 @@ editing of the url."
0
      (read-from-minibuffer "url: "
0
           (concat base "/"))
0
     base)))
0
- (eval (list rails-browse-url-func url))))
0
+ (eval (list rinari-browse-url-func url))))
0
 
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
   the project."
0
- (let ((ffip-project-root (rails-root)))
0
+ (let ((ffip-project-root (rinari-root)))
0
     ad-do-it))
0
 
0
 ;;--------------------------------------------------------------------
0
@@ -240,20 +255,18 @@ editing of the url."
0
   (let ((map (make-sparse-keymap)))
0
     map)
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
 
0
 (defun rinari-launch ()
0
   "Run `rinari-minor-mode' if inside of a rails projcect"
0
- (interactive) (if (rails-root) (rinari-minor-mode t)))
0
+ (interactive) (if (rinari-root) (rinari-minor-mode t)))
0
 
0
 (add-hook 'ruby-mode-hook
0
    (lambda () (rinari-launch)))

Comments

    No one has commented yet.