| 1 |
;;; rails-snippets-feature.el --- snippets for rails related modes
|
| 2 |
|
| 3 |
;; Copyright (C) 2006 Dmitry Galinsky <dima dot exe at gmail dot com>
|
| 4 |
|
| 5 |
;; Authors: Dmitry Galinsky <dima dot exe at gmail dot com>,
|
| 6 |
|
| 7 |
;; Keywords: ruby rails languages oop
|
| 8 |
;; $URL: svn+ssh://rubyforge/var/svn/emacs-rails/trunk/rails-snippets.el $
|
| 9 |
;; $Id: rails-snippets.el 155 2007-04-01 17:37:48Z dimaexe $
|
| 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 |
(require 'snippet)
|
| 28 |
|
| 29 |
(defconst rails-snippets-feature:list
|
| 30 |
'((0 "ruby")
|
| 31 |
(1 "loops" ruby-mode-abbrev-table
|
| 32 |
("end" "$>$.\nend$>" "end") ;; to avoid expanding when i want to indent
|
| 33 |
("while" "while $${condition}\n$>$.\nend$>" "while ... end")
|
| 34 |
("when" "when $${condition}\n$>$." "when ...")
|
| 35 |
("w" "attr_writer :$${attr_names}" "attr_writer ...")
|
| 36 |
("upt" "upto($${0}) { |$${n}|$. }" "upto(1.0/0.0) { |n| ... }")
|
| 37 |
("until" "until $${condition}\n$>$.\nend$>" "until ... end")
|
| 38 |
("tim" "times { |$${n}|$. }" "times { |n| ... }")
|
| 39 |
("ste" "step($${2}) { |$${n}|$. }" "step(2) { |e| ... }")
|
| 40 |
("forin" "for $${element} in $${collection}\n$>$${element}.$.\nend$>" "for ... in ... end")
|
| 41 |
("dow" "downto($${0}) { |$${n}|$. }" "downto(0) { |n| ... }")) ; loops
|
| 42 |
(1 "general" ruby-mode-abbrev-table
|
| 43 |
("asr" "assert_raise $${Exception} { $. }" "assert_raise(...) { ... }")
|
| 44 |
("asnr" "assert_nothing_raised $${Exception} { $. }" "assert_nothing_raised(...) { ... }")
|
| 45 |
("asn" "assert_nil $${instance}" "assert_nil(...)")
|
| 46 |
("ase" "assert_equal $${expected}, $${actual}" "assert_equal(...)")
|
| 47 |
("asne" "assert_not_equal $${unexpected}, $${actual}" "assert_not_equal(...)")
|
| 48 |
("asm" "assert_match(/$${expected_pattern}/, $${actual_string})" "assert_match(...)")
|
| 49 |
("asnm" "assert_no_match(/$${unexpected_pattern}/, $${actual_string})" "assert_no_match(...)")
|
| 50 |
("asnn" "assert_not_nil $${instance}" "assert_not_nil(...)")
|
| 51 |
("ha" "{ $>:$. }" "{ :key => 'value' }")
|
| 52 |
(":" ":$${key} => '$${value}'" ":key => 'value'")
|
| 53 |
("yl" "File.open($${yaml}) { |$${file}| YAML.load($${file}) }" "YAML.load(file)")
|
| 54 |
("yd" "File.open($${yaml}, \"w\") { |$${file}| YAML.dump($${obj}, $${file}) }" "YAML.dump(..., file)")
|
| 55 |
("y" " :yields: $${arguments}" ":yields:")
|
| 56 |
("verren" "verify :only => [:$${1}], :method => :post, :render => {:status => 500, :text => \"use HTTP-POST\"}\n" "verify -- render")
|
| 57 |
("verred" "verify :only => [:$${1}], :session => :user, :params => :id, :redirect_to => {:action => '$${index}'}\n" "verify -- redirect")
|
| 58 |
("tra" "transaction$${1} { $. }" "transaction( ... ) { ... }")
|
| 59 |
("sub" "sub(/$${pattern}/) { |$${match}|$. }" "sub(/.../) { |match| ... }")
|
| 60 |
("sca" "scan(/$${pattern}/) { |$${match}| $. }" "scan(/.../) { |match| ... }")
|
| 61 |
("rep" "results.report(\"$${name}:\") { TESTS.times { $. } }" "results.report(...) { ... }")
|
| 62 |
("rb" "#!/usr/bin/env ruby -w\n\n" "#!/usr/local/bin/ruby -w")
|
| 63 |
("r" "attr_reader :$${attr_names}" "attr_reader ...")
|
| 64 |
("pn" "PStore.new($${file_name})" "PStore.new( ... )")
|
| 65 |
("patfh" "File.join(File.dirname(__FILE__), *%w[$${here}])" "path_from_here( ... )")
|
| 66 |
("ope" "open($${pipe}) { |$${io}| $. }" "open(\"path/or/url\", \"w\") { |io| ... }")
|
| 67 |
("ml" "File.open($${dump}) { |$${file}| Marshal.load($${file}) }" "Marshal.load(obj)")
|
| 68 |
("min" "min { |a, b| $. }" "min { |a, b| ... }")
|
| 69 |
("max" "max { |a, b| $. }" "max { |a, b| ... }")
|
| 70 |
("md" "File.open($${dump}, \"w\") { |$${file}| Marshal.dump($${obj}, $${file}) }" "Marshal.dump(..., file)")
|
| 71 |
("lam" "lambda { |$${args}|$. }" "lambda { |args| ... }")
|
| 72 |
("gsu" "gsub(/$${pattern}/) { |$${match}|$. }" "gsub(/.../) { |match| ... }")
|
| 73 |
("gre" "grep($${pattern}) { |$${match}| $. }" "grep(/pattern/) { |match| ... }")
|
| 74 |
("fl" "flunk('$${message}')" "flunk(...)")
|
| 75 |
("file" "File.foreach($${file}) { |$${line}| $. }" "File.foreach (\"...\") { |line| ... }")
|
| 76 |
("dir" "Dir.glob($${glob}) { |$${file}| $. }" "Dir.glob(\"...\") { |file| ... }")
|
| 77 |
("b" "=begin rdoc\n$>$.\n=end" "New Block")
|
| 78 |
("begin" "begin\n$>$${paste}\nrescue $${Exception} => $${e}\n$>$.\nend$>\n" "begin ... rescue ... end")
|
| 79 |
("bm" "TESTS = $${10_000}\nBenchmark.bmbm($${10}) do |results|\n $.\nend$>" "Benchmark.bmbm(...) do ... end")
|
| 80 |
("am" "alias_method :$${new_name}, :$${old_name}" "alias_method ...")
|
| 81 |
("amc" "alias_method_chain :$${first_method}, :$${second_method}" "alias_method_chain ...")) ; general
|
| 82 |
(1 "definitions" ruby-mode-abbrev-table
|
| 83 |
("ts" "require \"test/unit\"\n\nrequire \"tc_$${test_case_file}\"\nrequire \"tc_$${test_case_file}\"\n" "require \"tc_...\" ...")
|
| 84 |
("tc" "require \"test/unit\"\n\nrequire \"$${library_file_name}\"\n\nclass Test$${amp} < Test::Unit::TestCase\n$>def test_$${case_name}\n$>$>$.\nend$>\nend$>" "class ... < Test::Unit::TestCase ... end")
|
| 85 |
("sin" "class << self; self end" "singleton_class()")
|
| 86 |
("rw" "attr_accessor :$${attr_names}" "attr_accessor ...")
|
| 87 |
("req" "require \"$.\"" "require \"...\"")
|
| 88 |
("modf" "module $${ModuleName}\n$>module ClassMethods\n$>$>$.\nend$>\n$>\n$>extend ClassMethods\n$>\n$>def self.included(receiver)\n$>$>receiver.extend(ClassMethods)\nend$>\n$>\n$>\nend$>" "module ... ClassMethods ... end")
|
| 89 |
("mods" "module $${ModuleName}\n$>$.\nend$>" "module ... end")
|
| 90 |
("modu" "module $${ModuleName}\n$>module_function\n$>\n$>$.\nend$>" "module ... module_function ... end")
|
| 91 |
("mm" "def method_missing(meth, *args, &block)\n$>$.\nend$>" "def method_missing ... end")
|
| 92 |
("hash" "Hash.new { |$${hash}, $${key}| $${hash}[$${key}] = $. }" "Hash.new { |hash, key| hash[key] = ... }")
|
| 93 |
("forw" "extend Forwardable" "extend Forwardable")
|
| 94 |
("enum" "include Enumerable\n\ndef each(&block)\n$>$.\nend$>" "include Enumerable ...")
|
| 95 |
("elsif" "elsif $${condition}\n$>$." "elsif ...")
|
| 96 |
("doo" "do |$${object}|\n$>$.\nend$>" "Insert do |object| ... end")
|
| 97 |
("do" "do\n$>$.\nend$>" "do ... end")
|
| 98 |
("defd" "def_delegator :$${del_obj}, :$${del_meth}, :$${new_name}" "def_delegator ...")
|
| 99 |
("defds" "def_delegators :$${del_obj}, :$${del_methods}" "def_delegators ...")
|
| 100 |
("defs" "def self.$${class_method_name}\n$>$.\nend$>" "def self ... end")
|
| 101 |
("deft" "def test_$${case_name}\n$>$.\nend$>" "def test_ ... end")
|
| 102 |
("dee" "Marshal.load(Marshal.dump($${obj_to_copy}))" "deep_copy(...)")
|
| 103 |
("comp" "include Comparable\n\ndef <=>(other)\n$>$.\nend$>" "include Comparable ...")
|
| 104 |
("cladl" "class $${ClassName} < DelegateClass($${ParentClass})\n$>def initialize$${1}\n$>$>super($${del_obj})\n$>$>\n$>$>$.\nend$>\n$>\n$>\nend$>" "class ... < DelegateClass ... initialize ... end")
|
| 105 |
("clapr" "class $${ClassName} < $${ParentClass}\n$>def initialize$${1}\n$>$>$.\nend$>\n$>\n$>\nend$>" "class ... < ParentClass ... initialize ... end")
|
| 106 |
("clast" "class $${ClassName} < Struct.new(:$${attr_names})\n$>def initialize(*args)\n$>$>super\n$>$>\n$>$>$.\nend$>\n$>\n$>\nend$>" "class ... < Struct ... initialize ... end")
|
| 107 |
("class" "class $${ClassName}\n$>$.\nend$>" "class ... end")
|
| 108 |
("classi" "class $${ClassName}\n$>def initialize$${1}\n$>$>$.\nend$>\n$>\n$>\nend$>" "class ... initialize ... end")
|
| 109 |
("clasf" "class << $${self}\n$>$.\nend$>" "class << self ... end")) ; definitions
|
| 110 |
(1 "collections" ruby-mode-abbrev-table
|
| 111 |
("zip" "zip($${enums}) { |$${row}| $. }" "zip(enums) { |row| ... }")
|
| 112 |
("sorb" "sort_by { |$${e}| $. }" "sort_by { |e| ... }")
|
| 113 |
("sor" "sort { |a, b| $. }" "sort { |a, b| ... }")
|
| 114 |
("select" "select { |$${element}| $${element}.$${2} }$." "select element")
|
| 115 |
("sel" "select { |$${e}| $. }" "select { |e| ... }")
|
| 116 |
("reve" "reverse_each { |$${e}| $. }" "reverse_each { |e| ... }")
|
| 117 |
("reject" "reject { |$${element}| $${element}.$. }" "reject element")
|
| 118 |
("rej" "reject { |$${e}| $. }" "reject { |e| ... }")
|
| 119 |
("ran" "sort_by { rand }" "randomize()")
|
| 120 |
("mapwi" "enum_with_index.map { |$${e}, $${i}| $. }" "map_with_index { |e, i| ... }")
|
| 121 |
("map" "map { |$${e}| $. }" "map { |e| ... }")
|
| 122 |
("inject" "inject($${object}) { |$${injection}, $${element}| $${4} }$." "inject object")
|
| 123 |
("inj" "inject($${init}) { |$${mem}, $${var}| $. }" "inject(init) { |mem, var| ... }")
|
| 124 |
("flao" "inject(Array.new) { |$${arr}, $${a}| $${arr}.push(*$${a}) }" "flatten_once()")
|
| 125 |
("fina" "find_all { |$${e}| $. }" "find_all { |e| ... }")
|
| 126 |
("fin" "find { |$${e}| $. }" "find { |e| ... }")
|
| 127 |
("fil" "fill($${range}) { |$${i}|$. }" "fill(range) { |i| ... }")
|
| 128 |
("fet" "fetch($${name}) { |$${key}|$. }" "fetch(name) { |key| ... }")
|
| 129 |
("eawi" "each_with_index { |$${e}, $${i}| $. }" "each_with_index { |e, i| ... }")
|
| 130 |
("eai" "each_index { |$${i}| $. }" "each_index { |i| ... }")
|
| 131 |
("eak" "each_key { |$${key}| $. }" "each_key { |key| ... }")
|
| 132 |
("eal" "each_line$${1} { |$${line}| $. }" "each_line { |line| ... }")
|
| 133 |
("eap" "each_pair { |$${name}, $${val}| $. }" "each_pair { |name, val| ... }")
|
| 134 |
("eas" "each_slice($${2}) { |$${group}| $. }" "each_slice(...) { |group| ... }")
|
| 135 |
("eav" "each_value { |$${val}| $. }" "each_value { |val| ... }")
|
| 136 |
("each" "each { |$${element}| $${element}.$. }" "each element")
|
| 137 |
("eac" "each_cons($${2}) { |$${group}| $. }" "each_cons(...) { |group| ... }")
|
| 138 |
("eab" "each_byte { |$${byte}| $. }" "each_byte { |byte| ... }")
|
| 139 |
("ea" "each { |$${e}| $. }" "each { |e| ... }")
|
| 140 |
("det" "detect { |$${e}| $. }" "detect { |e| ... }")
|
| 141 |
("deli" "delete_if { |$${e}| $. }" "delete_if { |e| ... }")
|
| 142 |
("collect" "collect { |$${element}| $${element}.$. }" "collect element")
|
| 143 |
("col" "collect { |$${e}| $. }" "collect { |e| ... }")
|
| 144 |
("cl" "classify { |$${e}| $. }" "classify { |e| ... }")
|
| 145 |
("array" "Array.new($${10}) { |$${i}|$. }" "Array.new(10) { |i| ... }")
|
| 146 |
("any" "any? { |$${e}| $. }" "any? { |e| ... }")
|
| 147 |
("all" "all? { |$${e}| $. }" "all? { |e| ... }")) ; collections
|
| 148 |
(0 "erb" html-mode-abbrev-table html-helper-mode-abbrev-table nxml-mode-abbrev-table rhtml-mode-abbrev-tables
|
| 149 |
("title" "<title>$${title}</title>" "title")
|
| 150 |
("textarea" "<textarea name=\"$${Name}\" rows=\"$${8}\" cols=\"$${40}\">$.</textarea>" "textarea")
|
| 151 |
("table" "<table border=\"$${0}\" $${cellpadding}>\n$><tr><th>$${Header}</th></tr>\n$><tr><td>$${Data}</td></tr>\n</table>" "table")
|
| 152 |
("style" "<style type=\"text/css\" media=\"screen\">\n$>$.\n</style>" "style")
|
| 153 |
("scriptsrc" "<script src=\"$${1}\" type=\"text/javascript\" charset=\"$${utf}\"></script>" "script with source")
|
| 154 |
("script" "<script type=\"text/javascript\" charset=\"utf-8\">\n$>$.\n</script>" "script")
|
| 155 |
("movie" "<object width=\"$${2}\" height=\"$${3}\" classid=\"clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B\" codebase=\"http://www.apple.com/qtactivex/qtplugin.cab\">\n$><param name=\"src\" value=\"$${1}\"/>\n$><param name=\"controller\" value=\"$${4}\"/>\n$><param name=\"autoplay\" value=\"$${5}\"/>\n$><embed src=\"$${movie}\"\n$>$>width=\"$${320}\" height=\"$${240}\"\n$>$>controller=\"$${true}\" autoplay=\"$${true}\"\n$>$>scale=\"tofit\" cache=\"true\"\n$>$>pluginspage=\"http://www.apple.com/quicktime/download/\"\n$>/>\n</object>" "quicktime")
|
| 156 |
("meta" "<meta name=\"$${name}\" content=\"$${content}\"/>" "meta")
|
| 157 |
("mailto" "<a href=\"mailto:$${example}?subject=$${feedback}\">$${email}</a>" "mailto")
|
| 158 |
("link" "<link rel=\"$${stylesheet}\" href=\"$${master}\" type=\"text/css\" media=\"$${screen}\" title=\"$${title}\" charset=\"$${utf}\"/>" "link")
|
| 159 |
("licai" "<%= link_to \"$${text}\", :controller => \"$${items}\", :action => \"$${edit}\", :id => $${item} %>" "link_to (controller, action, id)")
|
| 160 |
("lica" "<%= link_to \"$${text}\", :controller => \"$${items}\", :action => \"$${index}\" %>" "link_to (controller, action)")
|
| 161 |
("lica" "<%= link_to \"$${text}\", :controller => \"$${items}\", :action => \"$${index}\" %>" "link_to (controller, action)")
|
| 162 |
("liai" "<%= link_to \"$${text}\", :action => \"$${edit}\", :id => $${item} %>" "link_to (action, id)")
|
| 163 |
("lic" "<%= link_to \"$${text}\", :controller => \"$${items}\" %>" "link_to (controller)")
|
| 164 |
("lia" "<%= link_to \"$${text}\", :action => \"$${index}\" %>" "link_to (action)")
|
| 165 |
("input" "<input type=\"$${button}\" name=\"$${some_name}\" value=\"$${3}\"$${id}>" "input")
|
| 166 |
("head" "<head>\n$><meta http-equiv=\"Content-type\" content=\"text/html; charset=utf-8\"/>\n$><title>$${title}</title>\n$>$.\n</head>" "head")
|
| 167 |
("h" "<h1 id=\"$${alpha}\">$${paste}</h1>" "heading")
|
| 168 |
("ft" "<%= form_tag :action => \"$${update}\" %>\n$.\n<%= end_form_tag %>" "form_tag")
|
| 169 |
("ff" "<% form_for :$${item}, :action => \"$${update}\" do |f| -%>\n$.\n<% end -%>" "form_for")
|
| 170 |
("slt" "<%= stylesheet_link_tag \"$${1}\" %>" "stylesheet_link_tag")
|
| 171 |
("jit" "<%= javascript_include_tag \"$${1}\" %>" "javascript_include_tag")
|
| 172 |
("form" "<form action=\"$${action}\" method=\"$${post}\" accept-charset=\"utf-8\">\n$>$.\n\n$><p><input type=\"submit\" value=\"Continue →\"/></p>\n</form>" "form")
|
| 173 |
("dtht" "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN\"\n$>\"http://www.w3.org/TR/html4/strict.dtd\">\n" "HTML -- 4.01 Strict")
|
| 174 |
("dchttr" "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\"\n$>\"http://www.w3.org/TR/html4/loose.dtd\">\n" "HTML -- 4.01 Transitional")
|
| 175 |
("dcxmlf" "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Frameset//EN\"\n$>\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd\">\n" "XHTML -- 1.0 Frameset")
|
| 176 |
("dcxmls" "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"\n$>\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">\n" "XHTML -- 1.0 Strict")
|
| 177 |
("dcxmlt" "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\"\n$>\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n" "XHTML -- 1.0 Transitional")
|
| 178 |
("dcxml1" "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.1//EN\"\n$>\"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd\">\n" "XHTML -- 1.1")
|
| 179 |
("body" "<body id=\"$${id}\" $${onload}>\n$>$.\n</body>" "body")
|
| 180 |
("div" "<div>\n$>$${paste}\n</div>" "div")
|
| 181 |
("%h" "<%=h $${@item} %>" "<% h ... %>")
|
| 182 |
("%if" "<% if $${cond} -%>\n$.\n<% end -%>" "<% if/end %>")
|
| 183 |
("%ifel" "<% if $${cond} -%>\n$.\n<% else -%>\n<% end -%>" "<% if/else/end %>")
|
| 184 |
("%unless" "<% unless $${cond} -%>\n$.\n<% end -%>" "<% unless/end %>")
|
| 185 |
("%for" "<% for $${elem} in @$${list} %>\n$>$.\n<% end %>$>" "<% for/end %>")
|
| 186 |
("han" "$${Model}.human_attribute_name('$${title}')" "human_attribute_name")
|
| 187 |
("hn" "$${Model}.human_name" "human_name")
|
| 188 |
("%" "<% $. -%>" "<% ... %>")
|
| 189 |
("%%" "<%= $. %>" "<%= ... %>")) ; erb
|
| 190 |
(0 "controller" rails-controller-minor-mode-abbrev-table
|
| 191 |
("ru" "render :update do |page|\n$>$.\nend$>" "render :update ...")
|
| 192 |
("bf" "before_filter :$${filter}" "refore_filter")
|
| 193 |
("af" "after_filter :$${filter}" "after_filter")
|
| 194 |
("arf" "around_filter :$${filter}" "around_filter")) ; controller
|
| 195 |
(0 "RESTful" rails-controller-minor-mode-abbrev-table
|
| 196 |
rails-view-minor-mode-abbrev-table
|
| 197 |
rails-helper-minor-mode-abbrev-table
|
| 198 |
rails-functional-test-minor-mode-abbrev-table
|
| 199 |
rails-integration-test-minor-mode-abbrev-table
|
| 200 |
("rest" "respond_to do |format|\n$>format.html$>$.\nend$>" "respond_to ..." rails-controller-minor-mode-abbrev-table)
|
| 201 |
("rindex" "$${,rails-snippets-feature:rest-index}" "models_url")
|
| 202 |
("rshow" "$${,rails-snippets-feature:rest-show}" "model_url(@model)")
|
| 203 |
("rnew" "$${,rails-snippets-feature:rest-new}" "new_model_url")
|
| 204 |
("redit" "$${,rails-snippets-feature:rest-edit}" "edit_model_url(@model)")
|
| 205 |
("rcreate" "$${,rails-snippets-feature:rest-create}" "models_url")
|
| 206 |
("rupdate" "$${,rails-snippets-feature:rest-update}" "model_url(@model)")
|
| 207 |
("rdestroy" "$${,rails-snippets-feature:rest-destroy}" "model_url(@model)")) ; RESTFul
|
| 208 |
(0 "render" rails-controller-minor-mode-abbrev-table
|
| 209 |
rails-view-minor-mode-abbrev-table
|
| 210 |
rails-helper-minor-mode-abbrev-table
|
| 211 |
("rps" "render :partial => '$${item}', :status => $${500}" "render (partial, status)")
|
| 212 |
("rt" "render :text => '$${render}'" "render (text)")
|
| 213 |
("rtl" "render :text => '$${render}', :layout => '$${layoutname}'" "render (text, layout)")
|
| 214 |
("rtlt" "render :text => '$${render}', :layout => $${true}" "render (text, layout => true)")
|
| 215 |
("rts" "render :text => '$${render}', :status => $${401}" "render (text, status)")
|
| 216 |
("rf" "render :file => '$${filepath}'" "render (file)")
|
| 217 |
("rfu" "render :file => '$${filepath}', :use_full_path => $${false}" "render (file, use_full_path)")
|
| 218 |
("ri" "render :inline => '$${hello}'" "render (inline)")
|
| 219 |
("ril" "render :inline => '$${hello}', :locals => { $${name} => '$${value}'$${4} }" "render (inline, locals)")
|
| 220 |
("rit" "render :inline => '$${hello}', :type => $${rxml}" "render (inline, type)")
|
| 221 |
("rl" "render :layout => '$${layoutname}'" "render (layout)")
|
| 222 |
("rn" "render :nothing => $${true}" "render (nothing)")
|
| 223 |
("rns" "render :nothing => $${true}, :status => $${401}" "render (nothing, status)")
|
| 224 |
("rp" "render :partial => '$${item}'" "render (partial)")
|
| 225 |
("rpc" "render :partial => '$${item}', :collection => $${items}" "render (partial, collection)")
|
| 226 |
("rpl" "render :partial => '$${item}', :locals => { :$${name} => $${value} }" "render (partial, locals)")
|
| 227 |
("rpo" "render :partial => '$${item}', :object => $${object}" "render (partial, object)")
|
| 228 |
("rcea" "render_component :action => '$${index}'" "render_component (action)")
|
| 229 |
("rcec" "render_component :controller => '$${items}'" "render_component (controller)")
|
| 230 |
("rceca" "render_component :controller => '$${items}', :action => '$${index}'" "render_component (controller, action)")
|
| 231 |
("ra" "render :action => '$${index}'" "render (action)")
|
| 232 |
("ral" "render :action => '$${index}', :layout => '{default}'" "render (action, layout)")) ; render
|
| 233 |
(0 "redirect_to" rails-controller-minor-mode-abbrev-table
|
| 234 |
rails-view-minor-mode-abbrev-table
|
| 235 |
rails-helper-minor-mode-abbrev-table
|
| 236 |
("rea" "redirect_to :action => '$${index}'" "redirect_to (action)")
|
| 237 |
("reai" "redirect_to :action => '$${show}', :id => $${item}" "redirect_to (action, id)")
|
| 238 |
("rec" "redirect_to :controller => '$${items}'" "redirect_to (controller)")
|
| 239 |
("reca" "redirect_to :controller => '$${items}', :action => '$${list}'" "redirect_to (controller, action)")
|
| 240 |
("recai" "redirect_to :controller => '$${items}', :action => '$${show}', :id => $${item}" "redirect_to (controller, action, id)")) ; redirecto_to
|
| 241 |
(0 "rails" ruby-mode-abbrev-table
|
| 242 |
("rdl" "RAILS_DEFAULT_LOGGER.debug '$${message}'$." "RAILS_DEFAULT_LOGGER.debug")
|
| 243 |
("nr" "@$${item}.new_record?" "item.new_record?")) ; rails
|
| 244 |
(0 "model" rails-model-minor-mode-abbrev-table
|
| 245 |
("ns" "named_scope :$${name}, :conditions => {:$${attribute} => $${value}}" "named_scope")
|
| 246 |
("nsl" "named_scope :$${name}, lambda {|$${param}| { :conditions => ['$${attribute} > ?', $${param}]} }" "named_scope_lamba")
|
| 247 |
("va" "validates_associated :$${attribute}" "validates_associated")
|
| 248 |
("vc" "validates_confirmation_of :$${attribute}" "validates_confirmation_of")
|
| 249 |
("ve" "validates_exclusion_of :$${attribute}" "validates_exclusion_of")
|
| 250 |
("vu" "validates_uniqueness_of :$${attribute}" "validates_uniqueness_of")
|
| 251 |
("vpif" "validates_presence_of :$${attribute}, :if => proc { |obj| $${condition} }" "validates_presence_of if")
|
| 252 |
("vp" "validates_presence_of :$${attribute}" "validates_presence_of")
|
| 253 |
("vl" "validates_length_of :$${attribute}, :within => $${20}" "validates_length_of")
|
| 254 |
("bt" "belongs_to :$${model}" "belongs_to")
|
| 255 |
("hm" "has_many :$${objects}" "has_many")
|
| 256 |
("hmt" "has_many :$${objects}, :through => :$${,rails-snippets-feature:prev-has-many-table-name}" "has_many :through")
|
| 257 |
("ho" "has_one :$${object}" "has_one")
|
| 258 |
("habtm" "has_and_belongs_to_many :$${object}, :join_table => '$${table_name}', :foreign_key => '$${foreign_key}'" "has_and_belongs_to_many")) ; model
|
| 259 |
(0 "migrations" rails-migration-minor-mode-abbrev-table
|
| 260 |
("tcls" "t.column :$${title}, :$${string}\n$>tcls$." "create several columns")
|
| 261 |
("tcl" "t.column :$${title}, :$${string}$." "create column")
|
| 262 |
("tcln" "t.column :$${title}, :$${string}, :null => false$." "create column :null => false")
|
| 263 |
("acl" "add_column :$${,rails-snippets-feature:migration-table-name}, :$${column}, :$${string}" "add column")
|
| 264 |
("ai" "add_index :$${,rails-snippets-feature:migration-table-name}, $${column}" "add index")
|
| 265 |
("aiu" "add_index :$${,rails-snippets-feature:migration-table-name}, $${column}, :unique => true" "add unique index")
|
| 266 |
("rmi" "remove_index :$${,rails-snippets-feature:migration-table-name}, $${column}" "remove index")
|
| 267 |
("rmcl" "remove_column :$${,rails-snippets-feature:migration-table-name}, :$${column}" "remove column")
|
| 268 |
("recl" "rename_column :$${column}, :$${new_column}" "rename column")
|
| 269 |
("dt" "drop_table :$${,rails-snippets-feature:migration-table-name}$." "drop table")
|
| 270 |
("ct" "create_table :$${,rails-snippets-feature:migration-table-name} do |t|\n$>tcls$.\nend$>" "create_table")
|
| 271 |
("ret" "rename_table :$${,rails-snippets-feature:migration-table-name}, :$${new_name}$." "rename table")) ; migrations
|
| 272 |
(0 "environment" ruby-mode-abbrev-table
|
| 273 |
("logd" "logger.debug '$${message}'$." "logger.debug")
|
| 274 |
("loge" "logger.error '$${message}'$." "logger.error")
|
| 275 |
("logf" "logger.fatal '$${message}'$." "logger.fatal")
|
| 276 |
("logi" "logger.info '$${message}'$." "logger.info")
|
| 277 |
("logw" "logger.warn '$${message}'$." "logger.warn")
|
| 278 |
("par" "params[:$${id}]" "params[...]")
|
| 279 |
("session" "session[:$${User}]" "session[...]")
|
| 280 |
("flash" "flash[:$${notice}] = '$${Successfully}'$." "flash[...]")) ; environment
|
| 281 |
(0 "tests" rails-functional-test-minor-mode-abbrev-table rails-unit-test-minor-mode-abbrev-table rails-integration-test-minor-mode-abbrev-table
|
| 282 |
("fix" "$${,rails-snippets-feature:fixture}(:$${one})$." "models(:name)")
|
| 283 |
("rth" "require File.dirname(__FILE__) + '/../test_helper'" "require tst_helper")
|
| 284 |
) ; functional tests
|
| 285 |
(0 "shoulda" rails-functional-test-minor-mode-abbrev-table rails-unit-test-minor-mode-abbrev-table rails-integration-test-minor-mode-abbrev-table
|
| 286 |
("cont" "context \"$${description}\" do\n$>setup do\n$>$${setup}\nend$>\n\n$>should$.\nend$>" "context block with setup")
|
| 287 |
("should" "should \"$${description}\" do\n$>$.\nend$>" "should block")
|
| 288 |
("shoulds" "should \"$${description}\" do\n$>flunk\nend$>\n\n$>shoulds$." "several should blocks")
|
| 289 |
("shoulde" "should_eventually \"$${description}\" do\n $>$.\nend$>" "should_eventually block")
|
| 290 |
("shouldes" "should_eventually \"$${description}\"\n$>shouldes$." "several should_eventually statements")
|
| 291 |
("laf" "fixtures :all" "fixtures :all")
|
| 292 |
("sat" "should_assign_to :$${variable}" "should_assign_to")
|
| 293 |
("savf" "should_allow_values_for :$${attribute}" "should_allow_values_for")
|
| 294 |
("sbt" "should_belong_to :$${object}" "should_belong_to")
|
| 295 |
("sbr" "should_be_restful do |$${resource}|\n $>$${resource}.$.\nend$>" "should_be_restful {|resource| ... }")
|
| 296 |
("selir" "should_ensure_length_in_range :$${attribute}, ($${range})" "should_ensure_length_in_range")
|
| 297 |
("sevir" "should_ensure_value_in_range :$${attribute}, ($${range})" "should_ensure_value_in_range")
|
| 298 |
("sho" "should_have_one :$${object}" "should_have_one")
|
| 299 |
("shabtm" "should_have_and_belong_to_many :$${objects}" "should_have_and_belong_to_many")
|
| 300 |
("shm" "should_have_many :$${objects}" "should_have_many")
|
| 301 |
("snstf" "should_not_set_the_flash" "should_not_set_the_flash")
|
| 302 |
("snat" "should_not_assign_to :$${variable}" "should_not_assign_to")
|
| 303 |
("snavf" "should_not_allow_values_for :$${attribute}" "should_not_allow_values_for")
|
| 304 |
("soanvf" "should_only_allow_numeric_values_for :$${attribute}" "should_only_allow_numeric_values_for")
|
| 305 |
("sraf" "should_render_a_form" "should_render_a_form")
|
| 306 |
("srdt" "should_redirect_to $${redirect}" "should_redirect_to")
|
| 307 |
("srt" "should_render_template :$${template}" "should_render_template")
|
| 308 |
("sra" "should_require_attributes :$${attribute}" "should_require_attributes")
|
| 309 |
("srua" "should_require_unique_attributes :$${attribute}" "should_require_unique_attributes")
|
| 310 |
("srw" "should_respond_with :$${response}" "should_respond_with")
|
| 311 |
("sstft" "should_set_the_flash_to $${value}" "should_set_the_flash_to")) ; shoulda tests
|
| 312 |
(0 "assertions" rails-functional-test-minor-mode-abbrev-table rails-unit-test-minor-mode-abbrev-table rails-integration-test-minor-mode-abbrev-table
|
| 313 |
("art" "assert_redirected_to :action => '$${index}'" "assert_redirected_to")
|
| 314 |
("as" "assert $${test}" "assert(...)")
|
| 315 |
("asa" "assert assigns(:$${,rails-snippets-feature:model-name})" "assert assigns(...)")
|
| 316 |
("asid" "assert_in_delta $${expected_float}, $${actual_float}, $${20}" "assert_in_delta(...)")
|
| 317 |
("asio" "assert_instance_of $${ExpectedClass}, $${actual_instance}" "assert_instance_of(...)")
|
| 318 |
("asko" "assert_kind_of $${ExpectedKind}, $${actual_instance}" "assert_kind_of(...)")
|
| 319 |
("asns" "assert_not_same $${unexpected}, $${actual}" "assert_not_same(...)")
|
| 320 |
("asnt" "assert_nothing_thrown { $. }" "assert_nothing_thrown { ... }")
|
| 321 |
("aso" "assert_operator $${left}, :$${operator}, $${right}" "assert_operator(...)")
|
| 322 |
("asre" "assert_response :$${success}" "assert_response")
|
| 323 |
("asrt" "assert_respond_to $${object}, :$${method}" "assert_respond_to(...)")
|
| 324 |
("ass" "assert_same $${expected}, $${actual}" "assert_same(...)")
|
| 325 |
("assd" "assert_send [$${object}, :$${message}, $${args}]" "assert_send(...)")
|
| 326 |
("asd" "assert_difference \"$${count}\", $${1} do\n$>$.\nend$>" "assert_difference .. do .. end")
|
| 327 |
("asnd" "assert_no_difference \"$${count}\" do\n$>$.\nend$>" "assert_no_difference .. do .. end")
|
| 328 |
("ast" "assert_throws :$${expected} { $. }" "assert_throws(...) { ... }")
|
| 329 |
("astm" "assert_template '$${index}'" "assert_template"))))
|
| 330 |
|
| 331 |
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
| 332 |
;;
|
| 333 |
;; Snippets functions
|
| 334 |
;;
|
| 335 |
|
| 336 |
(defmacro rails-snippets-feature:create-lambda (str)
|
| 337 |
`(lambda () (interactive) (snippet-insert ,(symbol-value str))))
|
| 338 |
|
| 339 |
(defun rails-snippets-feature:create-keymap ()
|
| 340 |
(let ((keymap (make-sparse-keymap "Snippets"))
|
| 341 |
ret level stack)
|
| 342 |
(dolist (line rails-snippets-feature:list)
|
| 343 |
(let ((cur-level (nth 0 line)) ; current the menu livel
|
| 344 |
(menu-item (nth 1 line)) ; current the menu item name
|
| 345 |
(line (cddr line)) ; skip level and menu name
|
| 346 |
(abbrev-tables))
|
| 347 |
;; fill stack
|
| 348 |
(cond
|
| 349 |
((not level)
|
| 350 |
(setq level cur-level)
|
| 351 |
(setq stack (list menu-item)))
|
| 352 |
((= cur-level level)
|
| 353 |
(setq stack (append (reverse (cdr (reverse stack))) (list menu-item))))
|
| 354 |
((> cur-level level)
|
| 355 |
(setq level cur-level)
|
| 356 |
(setq stack (append stack (list menu-item))))
|
| 357 |
((< cur-level level)
|
| 358 |
(setq stack (append (reverse (nthcdr (+ 1 (- level cur-level)) (reverse stack)))
|
| 359 |
(list menu-item)))))
|
| 360 |
(let ((cur-keymap (vconcat (mapcar #'make-symbol stack))))
|
| 361 |
;; make a menu entry for group of snippets
|
| 362 |
(define-key keymap cur-keymap
|
| 363 |
(cons menu-item (make-sparse-keymap menu-item)))
|
| 364 |
;; scan abbrev tables
|
| 365 |
(while (not (listp (car line)))
|
| 366 |
(setq abbrev-tables (append abbrev-tables (list (car line))))
|
| 367 |
(setq line (cdr line)))
|
| 368 |
(when abbrev-tables
|
| 369 |
;; sort and scan snippets
|
| 370 |
(dolist (snip-line (sort line (lambda(x y) (not (string< (car x)(car y))))))
|
| 371 |
(let* ((abbr (nth 0 snip-line))
|
| 372 |
(snip (nth 1 snip-line))
|
| 373 |
(desc (nth 2 snip-line))
|
| 374 |
(loc-abbrev-table (nth 3 snip-line))
|
| 375 |
(abbrev-tables (if loc-abbrev-table
|
| 376 |
(list loc-abbrev-table)
|
| 377 |
abbrev-tables))
|
| 378 |
(compiled-snip (rails-snippets-feature:create-lambda snip)))
|
| 379 |
;; create a menu entry for a snippet
|
| 380 |
(define-key keymap (vconcat cur-keymap (list (make-symbol abbr)))
|
| 381 |
(cons (format "%s \t%s" abbr desc) compiled-snip))
|
| 382 |
;; create abbrevs for a snippet
|
| 383 |
(dolist (table abbrev-tables)
|
| 384 |
(unless (boundp table)
|
| 385 |
(define-abbrev-table table ()))
|
| 386 |
(define-abbrev (symbol-value table) abbr "" compiled-snip))))))))
|
| 387 |
keymap))
|
| 388 |
|
| 389 |
(defadvice snippet-insert (before snippet-insert-before-advice first (template) activate)
|
| 390 |
(let ((pos 0))
|
| 391 |
(while (setq pos (string-match (snippet-field-regexp) template pos))
|
| 392 |
(let ((match (match-string 2 template))
|
| 393 |
(beg (match-beginning 2))
|
| 394 |
(end (match-end 2))
|
| 395 |
(repl))
|
| 396 |
(setq pos end)
|
| 397 |
(when (= 44 (car (string-to-list match))) ;; 44 - [,]
|
| 398 |
(save-match-data
|
| 399 |
(setq repl (apply (intern (substring match 1)) (list)))))
|
| 400 |
(when repl
|
| 401 |
(setq template
|
| 402 |
(concat (substring template 0 beg)
|
| 403 |
repl
|
| 404 |
(substring template end (length template))))
|
| 405 |
(setq pos (- pos
|
| 406 |
(- (length match) (length repl)))))))))
|
| 407 |
|
| 408 |
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
| 409 |
;;
|
| 410 |
;; Functions for dynamic snippets
|
| 411 |
;;
|
| 412 |
|
| 413 |
(defun rails-snippets-feature:migration-table-name ()
|
| 414 |
(let (str)
|
| 415 |
(string=~ "[0-9]+_create_\\([^\\.]+\\)\\.rb$" (buffer-name)
|
| 416 |
(setq str $1))
|
| 417 |
(if str str "table")))
|
| 418 |
|
| 419 |
(defun rails-snippets-feature:prev-has-many-table-name ()
|
| 420 |
(save-excursion
|
| 421 |
(if (search-backward-regexp "has_many :\\(\\w+\\)" nil t)
|
| 422 |
(match-string-no-properties 1)
|
| 423 |
"table")))
|
| 424 |
|
| 425 |
(defun rails-snippets-feature:fixture ()
|
| 426 |
(let ((controller (rails-core:current-controller))
|
| 427 |
(model (rails-core:current-model)))
|
| 428 |
(cond
|
| 429 |
(controller (decamelize controller))
|
| 430 |
(model (pluralize-string (decamelize model)))
|
| 431 |
(t "fixture"))))
|
| 432 |
|
| 433 |
(defun rails-snippets-feature:model-name ()
|
| 434 |
(let ((controller (rails-core:current-controller)))
|
| 435 |
(if controller
|
| 436 |
(singularize-string (decamelize controller))
|
| 437 |
"model")))
|
| 438 |
|
| 439 |
(defun rails-snippets-feature:rest (action)
|
| 440 |
(when-bind
|
| 441 |
(controller (rails-core:current-controller))
|
| 442 |
(let* ((plural (decamelize (pluralize-string controller)))
|
| 443 |
(singular (decamelize (singularize-string controller)))
|
| 444 |
(model (concat "@" singular)))
|
| 445 |
(case action
|
| 446 |
(:index
|
| 447 |
(tooltip-show (format "GET /%s" plural))
|
| 448 |
(format "%s_path" plural))
|
| 449 |
(:show
|
| 450 |
(tooltip-show (format "GET /%s/1" plural))
|
| 451 |
(format "%s_path(%s)" singular model))
|
| 452 |
(:new
|
| 453 |
(tooltip-show (format "GET /%s/new" plural))
|
| 454 |
(format "new_%s_path" singular))
|
| 455 |
(:edit
|
| 456 |
(tooltip-show (format "GET /%s/1;edit" plural))
|
| 457 |
(format "edit_%s_path(%s)" singular model))
|
| 458 |
(:create
|
| 459 |
(tooltip-show (format "POST /%s" plural))
|
| 460 |
(format "%s_path" plural))
|
| 461 |
(:update
|
| 462 |
(tooltip-show (format "PUT /%s/1" plural))
|
| 463 |
(format "%s_path(%s)" singular model))
|
| 464 |
(:destroy
|
| 465 |
(tooltip-show (format "DELETE /%s/1" plural))
|
| 466 |
(format "%s_path(%s)" singular model))))))
|
| 467 |
|
| 468 |
(defun rails-snippets-feature:rest-index ()
|
| 469 |
(rails-snippets-feature:rest :index))
|
| 470 |
|
| 471 |
(defun rails-snippets-feature:rest-show ()
|
| 472 |
(rails-snippets-feature:rest :show))
|
| 473 |
|
| 474 |
(defun rails-snippets-feature:rest-new ()
|
| 475 |
(rails-snippets-feature:rest :new))
|
| 476 |
|
| 477 |
(defun rails-snippets-feature:rest-edit ()
|
| 478 |
(rails-snippets-feature:rest :edit))
|
| 479 |
|
| 480 |
(defun rails-snippets-feature:rest-create ()
|
| 481 |
(rails-snippets-feature:rest :create))
|
| 482 |
|
| 483 |
(defun rails-snippets-feature:rest-update ()
|
| 484 |
(rails-snippets-feature:rest :update))
|
| 485 |
|
| 486 |
(defun rails-snippets-feature:rest-destroy ()
|
| 487 |
(rails-snippets-feature:rest :destroy))
|
| 488 |
|
| 489 |
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
| 490 |
;;
|
| 491 |
;; Install function
|
| 492 |
;;
|
| 493 |
|
| 494 |
(defun rails-snippets-feature:install ()
|
| 495 |
(define-key rails-minor-mode-map
|
| 496 |
[menu-bar rails-snippets]
|
| 497 |
(cons "Snippets" (rails-snippets-feature:create-keymap))))
|
| 498 |
|
| 499 |
(provide 'rails-snippets-feature)
|