Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
eschulte committed Jul 15, 2008
0 parents commit b8de2e6
Show file tree
Hide file tree
Showing 64 changed files with 334 additions and 0 deletions.
17 changes: 17 additions & 0 deletions README
Original file line number Diff line number Diff line change
@@ -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 changes: 16 additions & 0 deletions README~
Original file line number Diff line number Diff line change
@@ -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''
1 change: 1 addition & 0 deletions rails-snippets/html-mode
3 changes: 3 additions & 0 deletions rails-snippets/rhtml-mode/%
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#name : <%$. -%>
# --
<%$0 -%>
3 changes: 3 additions & 0 deletions rails-snippets/rhtml-mode/%%
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#name : <%=$. %>
# --
<%=$0 %>
5 changes: 5 additions & 0 deletions rails-snippets/rhtml-mode/%ft
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#name : <%= form_tag :action => " ... " %> $. <%= end_form_tag %>
# --
<%= form_tag :action => "$0update}" %>
$0
<%= end_form_tag %>
3 changes: 3 additions & 0 deletions rails-snippets/rhtml-mode/%h
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#name : <%=h ... %>
# --
<%=h $0@item} %>
5 changes: 5 additions & 0 deletions rails-snippets/rhtml-mode/%if
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#name : <% if ... -%> $. <% end -%>
# --
<% if $0cond} -%>
$0
<% end -%>
6 changes: 6 additions & 0 deletions rails-snippets/rhtml-mode/%ifel
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#name : <% if ... -%> $. <% else -%> <% end -%>
# --
<% if $0cond} -%>
$0
<% else -%>
<% end -%>
3 changes: 3 additions & 0 deletions rails-snippets/rhtml-mode/%lia
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#name : <%= link_to " ... ", :action => " ... " %>
# --
<%= link_to "$0title}", :action => "$0index}" %>
3 changes: 3 additions & 0 deletions rails-snippets/rhtml-mode/%liai
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#name : <%= link_to " ... ", :action => " ... ", :id => ... %>
# --
<%= link_to "$0title}", :action => "$0edit}", :id => $0@item} %>
3 changes: 3 additions & 0 deletions rails-snippets/rhtml-mode/%lic
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#name : <%= link_to " ... ", :controller => " ... " %>
# --
<%= link_to "$0title}", :controller => "$0items}" %>
3 changes: 3 additions & 0 deletions rails-snippets/rhtml-mode/%lica
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#name : <%= link_to " ... ", :controller => " ... ", :action => " ... " %>
# --
<%= link_to "$0title}", :controller => "$0items}", :action => "$0index}" %>
3 changes: 3 additions & 0 deletions rails-snippets/rhtml-mode/%licai
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#name : <%= link_to " ... ", :controller => " ... ", :action => " ... ", :id => ... %>
# --
<%= link_to "$0title}", :controller => "$0items}", :action => "$0edit}", :id => $0@item} %>
5 changes: 5 additions & 0 deletions rails-snippets/rhtml-mode/%unless
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#name : <% unless ... -%> $. <% end -%>
# --
<% unless $0cond} -%>
$0
<% end -%>
3 changes: 3 additions & 0 deletions rails-snippets/ruby-mode/ae
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#name : assert_equal ... , ...
# --
assert_equal ${expected}, ${actual}
3 changes: 3 additions & 0 deletions rails-snippets/ruby-mode/ako
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#name : assert_kind_of ... , ...
# --
assert_kind_of ${class}, ${object}
3 changes: 3 additions & 0 deletions rails-snippets/ruby-mode/ann
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#name : assert_not_nil ...
# --
assert_not_nil ${object}
3 changes: 3 additions & 0 deletions rails-snippets/ruby-mode/ar
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#name : assert_raises ... { $. }
# --
assert_raises ${Exception} { $. }
3 changes: 3 additions & 0 deletions rails-snippets/ruby-mode/ars
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#name : assert_response : ...
# --
assert_response :${success}
3 changes: 3 additions & 0 deletions rails-snippets/ruby-mode/art
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#name : assert_redirected_to :controller => " ... "
# --
assert_redirected_to :controller => "${controller}"
3 changes: 3 additions & 0 deletions rails-snippets/ruby-mode/bt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#name : belongs_to : ...
# --
belongs_to :${class}
3 changes: 3 additions & 0 deletions rails-snippets/ruby-mode/flsh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#name : flash[: ... ] = " ... "
# --
flash[:${notice}] = "${Text here...}"
3 changes: 3 additions & 0 deletions rails-snippets/ruby-mode/hm
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#name : has_many : ...
# --
has_many :${class}
3 changes: 3 additions & 0 deletions rails-snippets/ruby-mode/ho
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#name : has_one : ...
# --
has_one :${class}
3 changes: 3 additions & 0 deletions rails-snippets/ruby-mode/logi
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#name : logger.info " ... "
# --
logger.info "${Text here...}"
3 changes: 3 additions & 0 deletions rails-snippets/ruby-mode/par
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#name : params[: ... ]
# --
params[:${id}]
3 changes: 3 additions & 0 deletions rails-snippets/ruby-mode/ra
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#name : render :action => " ... "
# --
render :action => "${action}"
3 changes: 3 additions & 0 deletions rails-snippets/ruby-mode/ral
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#name : render :action => " ... ", :layout => " ... "
# --
render :action => "${action}", :layout => "${layoutname}"
3 changes: 3 additions & 0 deletions rails-snippets/ruby-mode/rcea
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#name : render_component :action => " ... "
# --
render_component :action => "${index}"
3 changes: 3 additions & 0 deletions rails-snippets/ruby-mode/rcec
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#name : render_component :controller => " ... "
# --
render_component :controller => "${items}"
3 changes: 3 additions & 0 deletions rails-snippets/ruby-mode/rceca
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#name : render_component :controller => " ... ", :action => " ... "
# --
render_component :controller => "${items}", :action => "${index}"
3 changes: 3 additions & 0 deletions rails-snippets/ruby-mode/rea
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#name : redirect_to :action => " ... "
# --
redirect_to :action => "${index}"
3 changes: 3 additions & 0 deletions rails-snippets/ruby-mode/reai
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#name : redirect_to :action => " ... ", :id => ...
# --
redirect_to :action => "${show}", :id => ${@item}
3 changes: 3 additions & 0 deletions rails-snippets/ruby-mode/rec
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#name : redirect_to :controller => " ... "
# --
redirect_to :controller => "${items}"
3 changes: 3 additions & 0 deletions rails-snippets/ruby-mode/reca
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#name : redirect_to :controller => " ... ", :action => " ... "
# --
redirect_to :controller => "${items}", :action => "${list}"
3 changes: 3 additions & 0 deletions rails-snippets/ruby-mode/recai
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#name : redirect_to :controller => " ... ", :action => " ... ", :id => ...
# --
redirect_to :controller => "${items}", :action => "${show}", :id => ${@item}
3 changes: 3 additions & 0 deletions rails-snippets/ruby-mode/rf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#name : render :file => " ... "
# --
render :file => "${filepath}"
3 changes: 3 additions & 0 deletions rails-snippets/ruby-mode/rfu
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#name : render :file => " ... ", :use_full_path => ...
# --
render :file => "${filepath}", :use_full_path => ${false}
3 changes: 3 additions & 0 deletions rails-snippets/ruby-mode/ri
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#name : render :inline => " ... "
# --
render :inline => "${<%= 'hello' %>}"
3 changes: 3 additions & 0 deletions rails-snippets/ruby-mode/ril
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#name : render :inline => " ... ", :locals => { ... => " ... " }
# --
render :inline => "${<%= 'hello' %>}", :locals => { ${name} => "${value}" }
3 changes: 3 additions & 0 deletions rails-snippets/ruby-mode/rit
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#name : render :inline => " ... ", :type => : ... )
# --
render :inline => "${<%= 'hello' %>}", :type => :${rxml})
3 changes: 3 additions & 0 deletions rails-snippets/ruby-mode/rl
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#name : render :layout => " ... "
# --
render :layout => "${layoutname}"
3 changes: 3 additions & 0 deletions rails-snippets/ruby-mode/rn
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#name : render :nothing => ...
# --
render :nothing => ${true}
3 changes: 3 additions & 0 deletions rails-snippets/ruby-mode/rns
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#name : render :nothing => ... , :status => ...
# --
render :nothing => ${true}, :status => ${401}
3 changes: 3 additions & 0 deletions rails-snippets/ruby-mode/rp
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#name : render :partial => " ... "
# --
render :partial => "${item}"
3 changes: 3 additions & 0 deletions rails-snippets/ruby-mode/rpc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#name : render :partial => " ... ", :collection => ...
# --
render :partial => "${item}", :collection => ${items}
3 changes: 3 additions & 0 deletions rails-snippets/ruby-mode/rpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#name : render :partial => " ... ", :locals => { : ... => " ... "}
# --
render :partial => "${item}", :locals => { :${name} => "${value}"}
3 changes: 3 additions & 0 deletions rails-snippets/ruby-mode/rpo
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#name : render :partial => " ... ", :object => ...
# --
render :partial => "${item}", :object => ${object}
3 changes: 3 additions & 0 deletions rails-snippets/ruby-mode/rps
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#name : render :partial => " ... ", :status => ...
# --
render :partial => "${item}", :status => ${500}
3 changes: 3 additions & 0 deletions rails-snippets/ruby-mode/rt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#name : render :text => " ... "
# --
render :text => "${Text here...}"
3 changes: 3 additions & 0 deletions rails-snippets/ruby-mode/rtl
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#name : render :text => " ... ", :layout => " ... "
# --
render :text => "${Text here...}", :layout => "${layoutname}"
3 changes: 3 additions & 0 deletions rails-snippets/ruby-mode/rtlt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#name : render :text => " ... ", :layout => ...
# --
render :text => "${Text here...}", :layout => ${true}
3 changes: 3 additions & 0 deletions rails-snippets/ruby-mode/rts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#name : render :text => " ... ", :status => ...
# --
render :text => "${Text here...}", :status => ${401}
3 changes: 3 additions & 0 deletions rails-snippets/ruby-mode/ses
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#name : session[: ... ]
# --
session[:${user}]
3 changes: 3 additions & 0 deletions rails-snippets/ruby-mode/va
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#name : validates_associated : ...
# --
validates_associated :${attr}
3 changes: 3 additions & 0 deletions rails-snippets/ruby-mode/vc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#name : validates_confirmation_of : ...
# --
validates_confirmation_of :${attr}
3 changes: 3 additions & 0 deletions rails-snippets/ruby-mode/ve
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#name : validates_exclusion_of : ...
# --
validates_exclusion_of :${attr}
3 changes: 3 additions & 0 deletions rails-snippets/ruby-mode/vf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#name : validates_format_of : ... , :with => / ... /
# --
validates_format_of :${attr}, :with => /${regex}/
3 changes: 3 additions & 0 deletions rails-snippets/ruby-mode/vn
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#name : validates_numericality_of : ...
# --
validates_numericality_of :${attr}
3 changes: 3 additions & 0 deletions rails-snippets/ruby-mode/vp
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#name : validates_presence_of : ...
# --
validates_presence_of :${attr}
3 changes: 3 additions & 0 deletions rails-snippets/ruby-mode/vu
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#name : validates_uniqueness_of : ...
# --
validates_uniqueness_of :${attr}
18 changes: 18 additions & 0 deletions setup.el
Original file line number Diff line number Diff line change
@@ -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
96 changes: 96 additions & 0 deletions util/rinari-abbrev-conv.el
Original file line number Diff line number Diff line change
@@ -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.