public
Description: Tomtt's version of the minor mode for editing RubyOnRails code in Emacs
Homepage: http://rubyforge.org/projects/emacs-rails/
Clone URL: git://github.com/tomtt/emacs-rails.git
rails-snippets-feature.el (rails-snippets-feature:fixture)
  (rails-snippets-feature:model-name, rails-snippets-feature:rest):
  replaced `downcase' to `decamelize'.
rails-core.el (rails-core:file-by-class): replaced `downcase' to 
`decamelize'.
rails-lib.el (decamelize): created function.


git-svn-id: svn+ssh://rubyforge.org/var/svn/emacs-rails/trunk@223 
cc5033d0-740f-0410-afc7-949910e492f2
dimaexe (author)
Mon Feb 11 12:32:03 -0800 2008
commit  52c036d1d2c13716b6c5762b9add56de0503b630
tree    bbe7aa277efe9ec896f8e3efc8f374e8de782563
parent  e8ad370301ac3b47ea073ef86af3092b449f0c28
...
 
 
 
 
 
 
 
 
 
 
1
2
3
...
1
2
3
4
5
6
7
8
9
10
11
12
13
0
@@ -1,3 +1,13 @@
0
+2008-02-11 Dmitry Galinsky <dima.exe@gmail.com>
0
+
0
+ * rails-snippets-feature.el (rails-snippets-feature:fixture)
0
+ (rails-snippets-feature:model-name, rails-snippets-feature:rest):
0
+ replaced `downcase' to `decamelize'.
0
+
0
+ * rails-core.el (rails-core:file-by-class): replaced `downcase' to `decamelize'.
0
+
0
+ * rails-lib.el (decamelize): created function.
0
+
0
 2008-02-07 Dmitry Galinsky <dima.exe@gmail.com>
0
 
0
   * rails-test.el (rails-test:line-regexp): apply patch [#16714]
...
61
62
63
64
65
66
67
68
69
 
 
70
71
72
...
149
150
151
152
153
 
 
154
155
156
...
61
62
63
 
 
 
 
 
 
64
65
66
67
68
...
145
146
147
 
 
148
149
150
151
152
0
@@ -61,12 +61,8 @@
0
   "Return the filename associated with CLASSNAME.
0
 If the optional parameter DO-NOT-APPEND-EXT is set this function
0
 will not append \".rb\" to result."
0
- (let* ((case-fold-search nil)
0
- (path (replace-regexp-in-string "::" "/" classname))
0
- (path (replace-regexp-in-string "\\([A-Z]+\\)\\([A-Z][a-z]\\)" "\\1_\\2" path))
0
- (path (replace-regexp-in-string "\\([a-z\\d]\\)\\([A-Z]\\)" "\\1_\\2" path)))
0
- (concat (downcase path)
0
- (unless do-not-append-ext ".rb"))))
0
+ (concat (decamelize (replace-regexp-in-string "::" "/" classname))
0
+ (unless do-not-append-ext ".rb")))
0
 
0
 ;;;;;;;;;; Files ;;;;;;;;;;
0
 
0
@@ -149,8 +145,8 @@ it does not exist, ask to create it using QUESTION as a prompt."
0
 
0
 (defun rails-core:controller-file-by-model (model)
0
   (when model
0
- (let* ((controller (pluralize-string model))
0
- (controller (when controller (capitalize controller))))
0
+ (let* ((controller (pluralize-string model)))
0
+ ;(controller (when controller (capitalize controller))))
0
       (setq controller
0
             (cond
0
              ((rails-core:controller-exist-p controller) controller) ;; pluralized
...
102
103
104
 
 
 
 
 
 
 
 
 
 
105
106
107
...
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
0
@@ -102,6 +102,16 @@ If EXPR is not nil exeutes BODY.
0
                                ($a (substring ,str (match-end 0) (length ,str))))
0
                ,@body)))))))
0
 
0
+(defun decamelize (string)
0
+ "Convert from CamelCaseString to camel_case_string."
0
+ (let ((case-fold-search nil))
0
+ (downcase
0
+ (replace-regexp-in-string
0
+ "\\([A-Z]+\\)\\([A-Z][a-z]\\)" "\\1_\\2"
0
+ (replace-regexp-in-string
0
+ "\\([a-z\\d]\\)\\([A-Z]\\)" "\\1_\\2"
0
+ string)))))
0
+
0
 (defun string-not-empty (str) ;(+)
0
   "Return t if string STR is not empty."
0
   (and (stringp str) (not (or (string-equal "" str)
...
386
387
388
389
390
 
 
391
392
393
394
395
396
 
397
398
399
400
401
402
403
 
 
404
405
406
...
386
387
388
 
 
389
390
391
392
393
394
395
 
396
397
398
399
400
401
 
 
402
403
404
405
406
0
@@ -386,21 +386,21 @@
0
   (let ((controller (rails-core:current-controller))
0
         (model (rails-core:current-model)))
0
     (cond
0
- (controller (downcase controller))
0
- (model (pluralize-string (downcase model)))
0
+ (controller (decamelize controller))
0
+ (model (pluralize-string (decamelize model)))
0
      (t "fixture"))))
0
 
0
 (defun rails-snippets-feature:model-name ()
0
   (let ((controller (rails-core:current-controller)))
0
     (if controller
0
- (singularize-string (downcase controller))
0
+ (singularize-string (decamelize controller))
0
       "model")))
0
 
0
 (defun rails-snippets-feature:rest (action)
0
   (when-bind
0
    (controller (rails-core:current-controller))
0
- (let* ((plural (downcase (pluralize-string controller)))
0
- (singular (downcase (singularize-string controller)))
0
+ (let* ((plural (decamelize (pluralize-string controller)))
0
+ (singular (decamelize (singularize-string controller)))
0
           (model (concat "@" singular)))
0
      (case action
0
        (:index

Comments

    No one has commented yet.