Permalink
Browse files

first commit

  • Loading branch information...
0 parents commit b8de2e67541be6d86c14035d814e39a04bf1033e @eschulte committed Jul 15, 2008
Showing with 334 additions and 0 deletions.
  1. +17 −0 README
  2. +16 −0 README~
  3. +1 −0 rails-snippets/html-mode
  4. +3 −0 rails-snippets/rhtml-mode/%
  5. +3 −0 rails-snippets/rhtml-mode/%%
  6. +5 −0 rails-snippets/rhtml-mode/%ft
  7. +3 −0 rails-snippets/rhtml-mode/%h
  8. +5 −0 rails-snippets/rhtml-mode/%if
  9. +6 −0 rails-snippets/rhtml-mode/%ifel
  10. +3 −0 rails-snippets/rhtml-mode/%lia
  11. +3 −0 rails-snippets/rhtml-mode/%liai
  12. +3 −0 rails-snippets/rhtml-mode/%lic
  13. +3 −0 rails-snippets/rhtml-mode/%lica
  14. +3 −0 rails-snippets/rhtml-mode/%licai
  15. +5 −0 rails-snippets/rhtml-mode/%unless
  16. +3 −0 rails-snippets/ruby-mode/ae
  17. +3 −0 rails-snippets/ruby-mode/ako
  18. +3 −0 rails-snippets/ruby-mode/ann
  19. +3 −0 rails-snippets/ruby-mode/ar
  20. +3 −0 rails-snippets/ruby-mode/ars
  21. +3 −0 rails-snippets/ruby-mode/art
  22. +3 −0 rails-snippets/ruby-mode/bt
  23. +3 −0 rails-snippets/ruby-mode/flsh
  24. +3 −0 rails-snippets/ruby-mode/hm
  25. +3 −0 rails-snippets/ruby-mode/ho
  26. +3 −0 rails-snippets/ruby-mode/logi
  27. +3 −0 rails-snippets/ruby-mode/par
  28. +3 −0 rails-snippets/ruby-mode/ra
  29. +3 −0 rails-snippets/ruby-mode/ral
  30. +3 −0 rails-snippets/ruby-mode/rcea
  31. +3 −0 rails-snippets/ruby-mode/rcec
  32. +3 −0 rails-snippets/ruby-mode/rceca
  33. +3 −0 rails-snippets/ruby-mode/rea
  34. +3 −0 rails-snippets/ruby-mode/reai
  35. +3 −0 rails-snippets/ruby-mode/rec
  36. +3 −0 rails-snippets/ruby-mode/reca
  37. +3 −0 rails-snippets/ruby-mode/recai
  38. +3 −0 rails-snippets/ruby-mode/rf
  39. +3 −0 rails-snippets/ruby-mode/rfu
  40. +3 −0 rails-snippets/ruby-mode/ri
  41. +3 −0 rails-snippets/ruby-mode/ril
  42. +3 −0 rails-snippets/ruby-mode/rit
  43. +3 −0 rails-snippets/ruby-mode/rl
  44. +3 −0 rails-snippets/ruby-mode/rn
  45. +3 −0 rails-snippets/ruby-mode/rns
  46. +3 −0 rails-snippets/ruby-mode/rp
  47. +3 −0 rails-snippets/ruby-mode/rpc
  48. +3 −0 rails-snippets/ruby-mode/rpl
  49. +3 −0 rails-snippets/ruby-mode/rpo
  50. +3 −0 rails-snippets/ruby-mode/rps
  51. +3 −0 rails-snippets/ruby-mode/rt
  52. +3 −0 rails-snippets/ruby-mode/rtl
  53. +3 −0 rails-snippets/ruby-mode/rtlt
  54. +3 −0 rails-snippets/ruby-mode/rts
  55. +3 −0 rails-snippets/ruby-mode/ses
  56. +3 −0 rails-snippets/ruby-mode/va
  57. +3 −0 rails-snippets/ruby-mode/vc
  58. +3 −0 rails-snippets/ruby-mode/ve
  59. +3 −0 rails-snippets/ruby-mode/vf
  60. +3 −0 rails-snippets/ruby-mode/vn
  61. +3 −0 rails-snippets/ruby-mode/vp
  62. +3 −0 rails-snippets/ruby-mode/vu
  63. +18 −0 setup.el
  64. +96 −0 util/rinari-abbrev-conv.el
17 README
@@ -0,0 +1,17 @@
+yasnippets snippet definitions for use with Ruby on Rails
+
+for information on yasnippets see http://code.google.com/p/yasnippet/
+for information on Ruby on Rails see http://www.rubyonrails.org/
+
+contents:
+
+- setup.el: contains some configuration options for using yasnippets
+ in a Ruby on Rails project, specifically in .rhtml files
+ alongside Rhtml-Mode and MuMaMo-Mode
+
+- rails-snippets: the actual directory of snippets
+
+- util: The file I used to convert these snippets from
+ rinari-abbrevs.el. All credit for their content goes to
+ the creaters of rinari-abbrevs.el... ``Thanks to
+ TextMate, Pete Kazmier, and Galinsky Dmitry''
16 README~
@@ -0,0 +1,16 @@
+yasnippets snippet definitions for use with Ruby on Rails
+
+for information on yasnippets see http://code.google.com/p/yasnippet/
+
+contents:
+
+- setup.el: contains some configuration options for using yasnippets
+ in a Ruby on Rails project, specifically in .rhtml files
+ alongside Rhtml-Mode and MuMaMo-Mode
+
+- rails-snippets: the actual directory of snippets
+
+- util: The file I used to convert these snippets from
+ rinari-abbrevs.el. All credit for their content goes to
+ the creaters of rinari-abbrevs.el... ``Thanks to
+ TextMate, Pete Kazmier, and Galinsky Dmitry''
@@ -0,0 +1,3 @@
+#name : <%$. -%>
+# --
+<%$0 -%>
@@ -0,0 +1,3 @@
+#name : <%=$. %>
+# --
+<%=$0 %>
@@ -0,0 +1,5 @@
+#name : <%= form_tag :action => " ... " %> $. <%= end_form_tag %>
+# --
+<%= form_tag :action => "$0update}" %>
+$0
+<%= end_form_tag %>
@@ -0,0 +1,3 @@
+#name : <%=h ... %>
+# --
+<%=h $0@item} %>
@@ -0,0 +1,5 @@
+#name : <% if ... -%> $. <% end -%>
+# --
+<% if $0cond} -%>
+$0
+<% end -%>
@@ -0,0 +1,6 @@
+#name : <% if ... -%> $. <% else -%> <% end -%>
+# --
+<% if $0cond} -%>
+$0
+<% else -%>
+<% end -%>
@@ -0,0 +1,3 @@
+#name : <%= link_to " ... ", :action => " ... " %>
+# --
+<%= link_to "$0title}", :action => "$0index}" %>
@@ -0,0 +1,3 @@
+#name : <%= link_to " ... ", :action => " ... ", :id => ... %>
+# --
+<%= link_to "$0title}", :action => "$0edit}", :id => $0@item} %>
@@ -0,0 +1,3 @@
+#name : <%= link_to " ... ", :controller => " ... " %>
+# --
+<%= link_to "$0title}", :controller => "$0items}" %>
@@ -0,0 +1,3 @@
+#name : <%= link_to " ... ", :controller => " ... ", :action => " ... " %>
+# --
+<%= link_to "$0title}", :controller => "$0items}", :action => "$0index}" %>
@@ -0,0 +1,3 @@
+#name : <%= link_to " ... ", :controller => " ... ", :action => " ... ", :id => ... %>
+# --
+<%= link_to "$0title}", :controller => "$0items}", :action => "$0edit}", :id => $0@item} %>
@@ -0,0 +1,5 @@
+#name : <% unless ... -%> $. <% end -%>
+# --
+<% unless $0cond} -%>
+$0
+<% end -%>
@@ -0,0 +1,3 @@
+#name : assert_equal ... , ...
+# --
+assert_equal ${expected}, ${actual}
@@ -0,0 +1,3 @@
+#name : assert_kind_of ... , ...
+# --
+assert_kind_of ${class}, ${object}
@@ -0,0 +1,3 @@
+#name : assert_not_nil ...
+# --
+assert_not_nil ${object}
@@ -0,0 +1,3 @@
+#name : assert_raises ... { $. }
+# --
+assert_raises ${Exception} { $. }
@@ -0,0 +1,3 @@
+#name : assert_response : ...
+# --
+assert_response :${success}
@@ -0,0 +1,3 @@
+#name : assert_redirected_to :controller => " ... "
+# --
+assert_redirected_to :controller => "${controller}"
@@ -0,0 +1,3 @@
+#name : belongs_to : ...
+# --
+belongs_to :${class}
@@ -0,0 +1,3 @@
+#name : flash[: ... ] = " ... "
+# --
+flash[:${notice}] = "${Text here...}"
@@ -0,0 +1,3 @@
+#name : has_many : ...
+# --
+has_many :${class}
@@ -0,0 +1,3 @@
+#name : has_one : ...
+# --
+has_one :${class}
@@ -0,0 +1,3 @@
+#name : logger.info " ... "
+# --
+logger.info "${Text here...}"
@@ -0,0 +1,3 @@
+#name : params[: ... ]
+# --
+params[:${id}]
@@ -0,0 +1,3 @@
+#name : render :action => " ... "
+# --
+render :action => "${action}"
@@ -0,0 +1,3 @@
+#name : render :action => " ... ", :layout => " ... "
+# --
+render :action => "${action}", :layout => "${layoutname}"
@@ -0,0 +1,3 @@
+#name : render_component :action => " ... "
+# --
+render_component :action => "${index}"
@@ -0,0 +1,3 @@
+#name : render_component :controller => " ... "
+# --
+render_component :controller => "${items}"
@@ -0,0 +1,3 @@
+#name : render_component :controller => " ... ", :action => " ... "
+# --
+render_component :controller => "${items}", :action => "${index}"
@@ -0,0 +1,3 @@
+#name : redirect_to :action => " ... "
+# --
+redirect_to :action => "${index}"
@@ -0,0 +1,3 @@
+#name : redirect_to :action => " ... ", :id => ...
+# --
+redirect_to :action => "${show}", :id => ${@item}
@@ -0,0 +1,3 @@
+#name : redirect_to :controller => " ... "
+# --
+redirect_to :controller => "${items}"
@@ -0,0 +1,3 @@
+#name : redirect_to :controller => " ... ", :action => " ... "
+# --
+redirect_to :controller => "${items}", :action => "${list}"
@@ -0,0 +1,3 @@
+#name : redirect_to :controller => " ... ", :action => " ... ", :id => ...
+# --
+redirect_to :controller => "${items}", :action => "${show}", :id => ${@item}
@@ -0,0 +1,3 @@
+#name : render :file => " ... "
+# --
+render :file => "${filepath}"
@@ -0,0 +1,3 @@
+#name : render :file => " ... ", :use_full_path => ...
+# --
+render :file => "${filepath}", :use_full_path => ${false}
@@ -0,0 +1,3 @@
+#name : render :inline => " ... "
+# --
+render :inline => "${<%= 'hello' %>}"
@@ -0,0 +1,3 @@
+#name : render :inline => " ... ", :locals => { ... => " ... " }
+# --
+render :inline => "${<%= 'hello' %>}", :locals => { ${name} => "${value}" }
@@ -0,0 +1,3 @@
+#name : render :inline => " ... ", :type => : ... )
+# --
+render :inline => "${<%= 'hello' %>}", :type => :${rxml})
@@ -0,0 +1,3 @@
+#name : render :layout => " ... "
+# --
+render :layout => "${layoutname}"
@@ -0,0 +1,3 @@
+#name : render :nothing => ...
+# --
+render :nothing => ${true}
@@ -0,0 +1,3 @@
+#name : render :nothing => ... , :status => ...
+# --
+render :nothing => ${true}, :status => ${401}
@@ -0,0 +1,3 @@
+#name : render :partial => " ... "
+# --
+render :partial => "${item}"
@@ -0,0 +1,3 @@
+#name : render :partial => " ... ", :collection => ...
+# --
+render :partial => "${item}", :collection => ${items}
@@ -0,0 +1,3 @@
+#name : render :partial => " ... ", :locals => { : ... => " ... "}
+# --
+render :partial => "${item}", :locals => { :${name} => "${value}"}
@@ -0,0 +1,3 @@
+#name : render :partial => " ... ", :object => ...
+# --
+render :partial => "${item}", :object => ${object}
@@ -0,0 +1,3 @@
+#name : render :partial => " ... ", :status => ...
+# --
+render :partial => "${item}", :status => ${500}
@@ -0,0 +1,3 @@
+#name : render :text => " ... "
+# --
+render :text => "${Text here...}"
@@ -0,0 +1,3 @@
+#name : render :text => " ... ", :layout => " ... "
+# --
+render :text => "${Text here...}", :layout => "${layoutname}"
@@ -0,0 +1,3 @@
+#name : render :text => " ... ", :layout => ...
+# --
+render :text => "${Text here...}", :layout => ${true}
@@ -0,0 +1,3 @@
+#name : render :text => " ... ", :status => ...
+# --
+render :text => "${Text here...}", :status => ${401}
@@ -0,0 +1,3 @@
+#name : session[: ... ]
+# --
+session[:${user}]
@@ -0,0 +1,3 @@
+#name : validates_associated : ...
+# --
+validates_associated :${attr}
@@ -0,0 +1,3 @@
+#name : validates_confirmation_of : ...
+# --
+validates_confirmation_of :${attr}
@@ -0,0 +1,3 @@
+#name : validates_exclusion_of : ...
+# --
+validates_exclusion_of :${attr}
@@ -0,0 +1,3 @@
+#name : validates_format_of : ... , :with => / ... /
+# --
+validates_format_of :${attr}, :with => /${regex}/
@@ -0,0 +1,3 @@
+#name : validates_numericality_of : ...
+# --
+validates_numericality_of :${attr}
@@ -0,0 +1,3 @@
+#name : validates_presence_of : ...
+# --
+validates_presence_of :${attr}
@@ -0,0 +1,3 @@
+#name : validates_uniqueness_of : ...
+# --
+validates_uniqueness_of :${attr}
@@ -0,0 +1,18 @@
+;;; setup.el --- setup yasnippets for use with rails
+(require 'yasnippet)
+(yas/initialize)
+(yas/load-directory
+ (concat (file-name-directory (or load-file-name buffer-file-name))
+ "rails-snippets/"))
+
+;;; If you are using MuMaMo or nxml, you will need to tweak the mumamo
+;;; keymap to let tab work for yasnippets
+(setq mumamo-map
+ (let ((map (make-sparse-keymap)))
+ (define-key map [(control meta prior)] 'mumamo-backward-chunk)
+ (define-key map [(control meta next)] 'mumamo-forward-chunk)
+ (define-key map [tab] 'yas/expand)
+ map))
+(mumamo-add-multi-keymap 'mumamo-multi-major-mode mumamo-map)
+
+;;; setup.el ends here
@@ -0,0 +1,96 @@
+(require 'yasnippet)
+
+(mapcar
+ (lambda (abbrev)
+ (let* ((filename (car abbrev))
+ (snip (cdr abbrev))
+ (desc (replace-regexp-in-string
+ "\n" " "
+ (replace-regexp-in-string "\\$\\${\\([^}]*\\)}"
+ " ... "
+ snip)))
+ (body (replace-regexp-in-string
+ "\\$\." "$0"
+ (replace-regexp-in-string "\\$\\${\\([^}]*\\)}"
+ "${\\1}"
+ snip))))
+ (with-temp-file (concat "../rails-snippets/rhtml-mode/" filename)
+ (insert (format "#name : %s\n# --\n" desc))
+ (insert (format "%s\n" body)))))
+ rhtml-mode-snips)
+
+(setq
+ rhtml-mode-snips
+ '(
+ ;; view
+ ("%ft" . "<%= form_tag :action => \"$${update}\" %>\n$.\n<%= end_form_tag %>")
+ ("%lia" . "<%= link_to \"$${title}\", :action => \"$${index}\" %>")
+ ("%liai" . "<%= link_to \"$${title}\", :action => \"$${edit}\", :id => $${@item} %>")
+ ("%lic" . "<%= link_to \"$${title}\", :controller => \"$${items}\" %>")
+ ("%lica" . "<%= link_to \"$${title}\", :controller => \"$${items}\", :action => \"$${index}\" %>")
+ ("%licai" . "<%= link_to \"$${title}\", :controller => \"$${items}\", :action => \"$${edit}\", :id => $${@item} %>")
+ ("%h" . "<%=h $${@item} %>")
+ ("%if" . "<% if $${cond} -%>\n$.\n<% end -%>")
+ ("%ifel" . "<% if $${cond} -%>\n$.\n<% else -%>\n<% end -%>")
+ ("%unless" . "<% unless $${cond} -%>\n$.\n<% end -%>")
+ ("%" . "<%$. -%>")
+ ("%%" . "<%=$. %>")))
+
+(setq
+ ruby-mode-snips
+ '(
+ ;; model
+ ("bt" . "belongs_to :$${class}")
+ ("hm" . "has_many :$${class}")
+ ("ho" . "has_one :$${class}")
+ ;; controller renders
+ ("ra" . "render :action => \"$${action}\"")
+ ("ral" . "render :action => \"$${action}\", :layout => \"$${layoutname}\"")
+ ("rf" . "render :file => \"$${filepath}\"")
+ ("rfu" . "render :file => \"$${filepath}\", :use_full_path => $${false}")
+ ("ri" . "render :inline => \"$${<%= 'hello' %>}\"")
+ ("ril" . "render :inline => \"$${<%= 'hello' %>}\", :locals => { $${name} => \"$${value}\" }")
+ ("rit" . "render :inline => \"$${<%= 'hello' %>}\", :type => :$${rxml})")
+ ("rl" . "render :layout => \"$${layoutname}\"")
+ ("rn" . "render :nothing => $${true}")
+ ("rns" . "render :nothing => $${true}, :status => $${401}")
+ ("rp" . "render :partial => \"$${item}\"")
+ ("rpc" . "render :partial => \"$${item}\", :collection => $${items}")
+ ("rpl" . "render :partial => \"$${item}\", :locals => { :$${name} => \"$${value}\"}")
+ ("rpo" . "render :partial => \"$${item}\", :object => $${object}")
+ ("rps" . "render :partial => \"$${item}\", :status => $${500}")
+ ("rt" . "render :text => \"$${Text here...}\"")
+ ("rtl" . "render :text => \"$${Text here...}\", :layout => \"$${layoutname}\"")
+ ("rtlt" . "render :text => \"$${Text here...}\", :layout => $${true}")
+ ("rts" . "render :text => \"$${Text here...}\", :status => $${401}")
+ ("rcea" . "render_component :action => \"$${index}\"")
+ ("rcec" . "render_component :controller => \"$${items}\"")
+ ("rceca" . "render_component :controller => \"$${items}\", :action => \"$${index}\"")
+ ;; redirects
+ ("rea" . "redirect_to :action => \"$${index}\"")
+ ("reai" . "redirect_to :action => \"$${show}\", :id => $${@item}")
+ ("rec" . "redirect_to :controller => \"$${items}\"")
+ ("reca" . "redirect_to :controller => \"$${items}\", :action => \"$${list}\"")
+ ("recai" . "redirect_to :controller => \"$${items}\", :action => \"$${show}\", :id => $${@item}")
+ ;; assertions
+ ("ae" . "assert_equal $${expected}, $${actual}")
+ ("ann" . "assert_not_nil $${object}")
+ ("ako" . "assert_kind_of $${class}, $${object}")
+ ("ars" . "assert_response :$${success}")
+ ("ar" . "assert_raises $${Exception} { $. }")
+ ("art" . "assert_redirected_to :controller => \"$${controller}\"")
+ ;; validations
+ ("va" . "validates_associated :$${attr}")
+ ("vc" . "validates_confirmation_of :$${attr}")
+ ("ve" . "validates_exclusion_of :$${attr}")
+ ("vp" . "validates_presence_of :$${attr}")
+ ("vu" . "validates_uniqueness_of :$${attr}")
+ ("vn" . "validates_numericality_of :$${attr}")
+ ("vf" . "validates_format_of :$${attr}, :with => /$${regex}/")
+ ;; misc
+ ("flsh" . "flash[:$${notice}] = \"$${Text here...}\"")
+ ("logi" . "logger.info \"$${Text here...}\"")
+ ("par" . "params[:$${id}]")
+ ("ses" . "session[:$${user}]")))
+
+

0 comments on commit b8de2e6

Please sign in to comment.