Skip to content

Commit

Permalink
rails-snippets-feature.el (rails-snippets-feature:fixture)
Browse files Browse the repository at this point in the history
	(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
dimaexe committed Feb 11, 2008
1 parent e8ad370 commit 52c036d
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 13 deletions.
10 changes: 10 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
2008-02-11 Dmitry Galinsky <[email protected]>

* 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 <[email protected]>

* rails-test.el (rails-test:line-regexp): apply patch [#16714]
Expand Down
12 changes: 4 additions & 8 deletions rails-core.el
Original file line number Diff line number Diff line change
Expand Up @@ -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 ;;;;;;;;;;

Expand Down Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions rails-lib.el
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
10 changes: 5 additions & 5 deletions rails-snippets-feature.el
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 52c036d

Please sign in to comment.