Skip to content
This repository
Browse code

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

0 notes on commit 52c036d

Please sign in to comment.
Something went wrong with that request. Please try again.