Permalink
Browse files

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...
1 parent e8ad370 commit 52c036d1d2c13716b6c5762b9add56de0503b630 dimaexe committed Feb 11, 2008
Showing with 29 additions and 13 deletions.
  1. +10 −0 ChangeLog
  2. +4 −8 rails-core.el
  3. +10 −0 rails-lib.el
  4. +5 −5 rails-snippets-feature.el
View
@@ -1,3 +1,13 @@
+2008-02-11 Dmitry Galinsky <dima.exe@gmail.com>
+
+ * 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.
+
2008-02-07 Dmitry Galinsky <dima.exe@gmail.com>
* rails-test.el (rails-test:line-regexp): apply patch [#16714]
View
@@ -61,12 +61,8 @@
"Return the filename associated with CLASSNAME.
If the optional parameter DO-NOT-APPEND-EXT is set this function
will not append \".rb\" to result."
- (let* ((case-fold-search nil)
- (path (replace-regexp-in-string "::" "/" classname))
- (path (replace-regexp-in-string "\\([A-Z]+\\)\\([A-Z][a-z]\\)" "\\1_\\2" path))
- (path (replace-regexp-in-string "\\([a-z\\d]\\)\\([A-Z]\\)" "\\1_\\2" path)))
- (concat (downcase path)
- (unless do-not-append-ext ".rb"))))
+ (concat (decamelize (replace-regexp-in-string "::" "/" classname))
+ (unless do-not-append-ext ".rb")))
;;;;;;;;;; Files ;;;;;;;;;;
@@ -149,8 +145,8 @@ it does not exist, ask to create it using QUESTION as a prompt."
(defun rails-core:controller-file-by-model (model)
(when model
- (let* ((controller (pluralize-string model))
- (controller (when controller (capitalize controller))))
+ (let* ((controller (pluralize-string model)))
+ ;(controller (when controller (capitalize controller))))
(setq controller
(cond
((rails-core:controller-exist-p controller) controller) ;; pluralized
View
@@ -102,6 +102,16 @@ If EXPR is not nil exeutes BODY.
($a (substring ,str (match-end 0) (length ,str))))
,@body)))))))
+(defun decamelize (string)
+ "Convert from CamelCaseString to camel_case_string."
+ (let ((case-fold-search nil))
+ (downcase
+ (replace-regexp-in-string
+ "\\([A-Z]+\\)\\([A-Z][a-z]\\)" "\\1_\\2"
+ (replace-regexp-in-string
+ "\\([a-z\\d]\\)\\([A-Z]\\)" "\\1_\\2"
+ string)))))
+
(defun string-not-empty (str) ;(+)
"Return t if string STR is not empty."
(and (stringp str) (not (or (string-equal "" str)
@@ -386,21 +386,21 @@
(let ((controller (rails-core:current-controller))
(model (rails-core:current-model)))
(cond
- (controller (downcase controller))
- (model (pluralize-string (downcase model)))
+ (controller (decamelize controller))
+ (model (pluralize-string (decamelize model)))
(t "fixture"))))
(defun rails-snippets-feature:model-name ()
(let ((controller (rails-core:current-controller)))
(if controller
- (singularize-string (downcase controller))
+ (singularize-string (decamelize controller))
"model")))
(defun rails-snippets-feature:rest (action)
(when-bind
(controller (rails-core:current-controller))
- (let* ((plural (downcase (pluralize-string controller)))
- (singular (downcase (singularize-string controller)))
+ (let* ((plural (decamelize (pluralize-string controller)))
+ (singular (decamelize (singularize-string controller)))
(model (concat "@" singular)))
(case action
(:index

0 comments on commit 52c036d

Please sign in to comment.