Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 115 lines (103 sloc) 4.992 kb
388fd09 rails.el (rails-apply-for-buffer-type): added support to load new sty…
dimaexe authored
1 ;;; rails-view-minor-mode.el --- minor mode for RubyOnRails views
0bc1504 rename rails-for-rhtml to rails-for-view
dimaexe authored
2
367490f update copyright
dimaexe authored
3 ;; Copyright (C) 2006 Dmitry Galinsky <dima dot exe at gmail dot com>
0bc1504 rename rails-for-rhtml to rails-for-view
dimaexe authored
4
bb7fe6c updated copyright
dimaexe authored
5 ;; Authors: Dmitry Galinsky <dima dot exe at gmail dot com>
6
0bc1504 rename rails-for-rhtml to rails-for-view
dimaexe authored
7 ;; Keywords: ruby rails languages oop
8 ;; $URL$
9 ;; $Id$
10
11 ;;; License
12
13 ;; This program is free software; you can redistribute it and/or
14 ;; modify it under the terms of the GNU General Public License
15 ;; as published by the Free Software Foundation; either version 2
16 ;; of the License, or (at your option) any later version.
17
18 ;; This program is distributed in the hope that it will be useful,
19 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
20 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 ;; GNU General Public License for more details.
22
23 ;; You should have received a copy of the GNU General Public License
24 ;; along with this program; if not, write to the Free Software
25 ;; Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
26
27 ;;; Code:
28
388fd09 rails.el (rails-apply-for-buffer-type): added support to load new sty…
dimaexe authored
29 (defun rails-view-minor-mode:create-partial-from-selection ()
0bc1504 rename rails-for-rhtml to rails-for-view
dimaexe authored
30 "Create a partial from current buffer selection."
31 (interactive)
32 (if mark-active
33 (save-excursion
34 (let ((name (read-string "Partial name (without _ and extension)? "))
35 (content (buffer-substring-no-properties (region-beginning) (region-end)))
36 (modified (buffer-modified-p)))
37 (unless (string-not-empty name)
38 (progn
39 (message "Empty partial name") (return)))
40 (kill-region (region-beginning) (region-end))
41 (insert (concat "<%= render :partial => \"" name "\" %>"))
42 (mmm-parse-region (line-beginning-position) (line-end-position))
43 (insert "\n")
44 (split-window-vertically)
45 (other-window 1)
46 (find-file (concat "_" name ".rhtml"))
47 (goto-char (point-min))
48 (erase-buffer)
49 (insert content)
50 (save-buffer)
51 (fit-window-to-buffer)
52 (other-window -1)
53 (unless modified (save-buffer))
54 (message "type `C-x +` to balance windows")))))
55
388fd09 rails.el (rails-apply-for-buffer-type): added support to load new sty…
dimaexe authored
56 (defun rails-view-minor-mode:create-helper-from-block (&optional helper-name)
0bc1504 rename rails-for-rhtml to rails-for-view
dimaexe authored
57 "Create a helper function from current ERb block (<% .. %>)."
58 (interactive)
59 (let ((current-pos (point))
60 (file buffer-file-name)
61 begin-pos
62 end-pos)
63 (save-excursion
64 (setq begin-pos (search-backward "<%" nil t))
65 (setq end-pos (search-forward "%>" nil t)))
66 (if (and begin-pos
67 end-pos
68 (> current-pos begin-pos)
69 (< current-pos end-pos))
e85430d rails-project.el: created
dimaexe authored
70 (let* ((helper-file (concat (rails-project:root) (rails-core:helper-file (rails-core:current-controller))))
0bc1504 rename rails-for-rhtml to rails-for-view
dimaexe authored
71 (content (replace-regexp-in-string "\\(<%=?\\|-?%>\\)" ""
72 (buffer-substring-no-properties begin-pos end-pos)))
73 (helper-defination (if helper-name helper-name
74 (read-string "Type helper function defination (without `def` keyword): "))))
75 (if (file-exists-p helper-file)
76 (let ((modified (buffer-modified-p))
77 (helper-func-def (concat "def " helper-defination)))
78 (kill-region begin-pos end-pos)
79 (insert (concat "<%= " helper-defination " -%>" ))
80 (mmm-parse-region (line-beginning-position) (line-end-position))
81 (insert "\n")
82 (split-window-vertically)
83 (other-window 1)
84 (find-file helper-file)
85 (goto-char (point-min))
86 (search-forward-regexp "module +[a-zA-Z0-9:]+")
87 (end-of-line)
88 (newline)
89 (ruby-indent-command)
90 (save-excursion
91 (insert (concat helper-func-def "\n" content "\nend\n")))
92 (ruby-indent-exp)
93 (fit-window-to-buffer)
94 (save-buffer)
95 (other-window -1)
96 (unless modified (save-buffer))
97 (message "Type `C-x +` to balance windows"))
98 (message "helper not found")))
99 (message "block not found"))))
100
388fd09 rails.el (rails-apply-for-buffer-type): added support to load new sty…
dimaexe authored
101 (define-minor-mode rails-view-minor-mode
102 "Minor mode for RubyOnRails views."
71655cd rails-model-layout.el (rails-model-layout:keymap): created
dimaexe authored
103 :lighter " View"
104 :keymap (rails-controller-layout:keymap :view)
a18b0ea rails-view-minor-mode.el (rails-view-minor-mode): cleanup and switch …
dimaexe authored
105 (setq rails-primary-switch-func 'rails-controller-layout:toggle-action-view)
106 (setq rails-secondary-switch-func 'rails-controller-layout:menu)
828d437 rails-for-view.el (rails-for-view): remove detect mmm-mode, always ap…
dimaexe authored
107 (if (boundp 'mmm-mode-map)
0bc1504 rename rails-for-rhtml to rails-for-view
dimaexe authored
108 (progn
9d2375e rails-ui.el (rails-minor-mode-prefix-key): created
dimaexe authored
109 (define-key mmm-mode-map (rails-key "p") 'rails-view-minor-mode:create-partial-from-selection)
110 (define-key mmm-mode-map (rails-key "b") 'rails-view-minor-mode:create-helper-from-block))
0bc1504 rename rails-for-rhtml to rails-for-view
dimaexe authored
111 (progn
9d2375e rails-ui.el (rails-minor-mode-prefix-key): created
dimaexe authored
112 (local-set-key (rails-key "p") 'rails-view-minor-mode:create-partial-from-selection)
113 (local-set-key (rails-key "b") 'rails-view-minor-mode:create-helper-from-block))))
0bc1504 rename rails-for-rhtml to rails-for-view
dimaexe authored
114
388fd09 rails.el (rails-apply-for-buffer-type): added support to load new sty…
dimaexe authored
115 (provide 'rails-view-minor-mode)
Something went wrong with that request. Please try again.