ruby.js 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935
  1. ace.define("ace/snippets/ruby",["require","exports","module"], function(require, exports, module) {
  2. "use strict";
  3. exports.snippetText = "########################################\n\
  4. # Ruby snippets - for Rails, see below #\n\
  5. ########################################\n\
  6. \n\
  7. # encoding for Ruby 1.9\n\
  8. snippet enc\n\
  9. # encoding: utf-8\n\
  10. \n\
  11. # #!/usr/bin/env ruby\n\
  12. snippet #!\n\
  13. #!/usr/bin/env ruby\n\
  14. # encoding: utf-8\n\
  15. \n\
  16. # New Block\n\
  17. snippet =b\n\
  18. =begin rdoc\n\
  19. ${1}\n\
  20. =end\n\
  21. snippet y\n\
  22. :yields: ${1:arguments}\n\
  23. snippet rb\n\
  24. #!/usr/bin/env ruby -wKU\n\
  25. snippet beg\n\
  26. begin\n\
  27. ${3}\n\
  28. rescue ${1:Exception} => ${2:e}\n\
  29. end\n\
  30. \n\
  31. snippet req require\n\
  32. require \"${1}\"${2}\n\
  33. snippet #\n\
  34. # =>\n\
  35. snippet end\n\
  36. __END__\n\
  37. snippet case\n\
  38. case ${1:object}\n\
  39. when ${2:condition}\n\
  40. ${3}\n\
  41. end\n\
  42. snippet when\n\
  43. when ${1:condition}\n\
  44. ${2}\n\
  45. snippet def\n\
  46. def ${1:method_name}\n\
  47. ${2}\n\
  48. end\n\
  49. snippet deft\n\
  50. def test_${1:case_name}\n\
  51. ${2}\n\
  52. end\n\
  53. snippet if\n\
  54. if ${1:condition}\n\
  55. ${2}\n\
  56. end\n\
  57. snippet ife\n\
  58. if ${1:condition}\n\
  59. ${2}\n\
  60. else\n\
  61. ${3}\n\
  62. end\n\
  63. snippet elsif\n\
  64. elsif ${1:condition}\n\
  65. ${2}\n\
  66. snippet unless\n\
  67. unless ${1:condition}\n\
  68. ${2}\n\
  69. end\n\
  70. snippet while\n\
  71. while ${1:condition}\n\
  72. ${2}\n\
  73. end\n\
  74. snippet for\n\
  75. for ${1:e} in ${2:c}\n\
  76. ${3}\n\
  77. end\n\
  78. snippet until\n\
  79. until ${1:condition}\n\
  80. ${2}\n\
  81. end\n\
  82. snippet cla class .. end\n\
  83. class ${1:`substitute(Filename(), '\\(_\\|^\\)\\(.\\)', '\\u\\2', 'g')`}\n\
  84. ${2}\n\
  85. end\n\
  86. snippet cla class .. initialize .. end\n\
  87. class ${1:`substitute(Filename(), '\\(_\\|^\\)\\(.\\)', '\\u\\2', 'g')`}\n\
  88. def initialize(${2:args})\n\
  89. ${3}\n\
  90. end\n\
  91. end\n\
  92. snippet cla class .. < ParentClass .. initialize .. end\n\
  93. class ${1:`substitute(Filename(), '\\(_\\|^\\)\\(.\\)', '\\u\\2', 'g')`} < ${2:ParentClass}\n\
  94. def initialize(${3:args})\n\
  95. ${4}\n\
  96. end\n\
  97. end\n\
  98. snippet cla ClassName = Struct .. do .. end\n\
  99. ${1:`substitute(Filename(), '\\(_\\|^\\)\\(.\\)', '\\u\\2', 'g')`} = Struct.new(:${2:attr_names}) do\n\
  100. def ${3:method_name}\n\
  101. ${4}\n\
  102. end\n\
  103. end\n\
  104. snippet cla class BlankSlate .. initialize .. end\n\
  105. class ${1:BlankSlate}\n\
  106. instance_methods.each { |meth| undef_method(meth) unless meth =~ /\\A__/ }\n\
  107. end\n\
  108. snippet cla class << self .. end\n\
  109. class << ${1:self}\n\
  110. ${2}\n\
  111. end\n\
  112. # class .. < DelegateClass .. initialize .. end\n\
  113. snippet cla-\n\
  114. class ${1:`substitute(Filename(), '\\(_\\|^\\)\\(.\\)', '\\u\\2', 'g')`} < DelegateClass(${2:ParentClass})\n\
  115. def initialize(${3:args})\n\
  116. super(${4:del_obj})\n\
  117. \n\
  118. ${5}\n\
  119. end\n\
  120. end\n\
  121. snippet mod module .. end\n\
  122. module ${1:`substitute(Filename(), '\\(_\\|^\\)\\(.\\)', '\\u\\2', 'g')`}\n\
  123. ${2}\n\
  124. end\n\
  125. snippet mod module .. module_function .. end\n\
  126. module ${1:`substitute(Filename(), '\\(_\\|^\\)\\(.\\)', '\\u\\2', 'g')`}\n\
  127. module_function\n\
  128. \n\
  129. ${2}\n\
  130. end\n\
  131. snippet mod module .. ClassMethods .. end\n\
  132. module ${1:`substitute(Filename(), '\\(_\\|^\\)\\(.\\)', '\\u\\2', 'g')`}\n\
  133. module ClassMethods\n\
  134. ${2}\n\
  135. end\n\
  136. \n\
  137. module InstanceMethods\n\
  138. \n\
  139. end\n\
  140. \n\
  141. def self.included(receiver)\n\
  142. receiver.extend ClassMethods\n\
  143. receiver.send :include, InstanceMethods\n\
  144. end\n\
  145. end\n\
  146. # attr_reader\n\
  147. snippet r\n\
  148. attr_reader :${1:attr_names}\n\
  149. # attr_writer\n\
  150. snippet w\n\
  151. attr_writer :${1:attr_names}\n\
  152. # attr_accessor\n\
  153. snippet rw\n\
  154. attr_accessor :${1:attr_names}\n\
  155. snippet atp\n\
  156. attr_protected :${1:attr_names}\n\
  157. snippet ata\n\
  158. attr_accessible :${1:attr_names}\n\
  159. # include Enumerable\n\
  160. snippet Enum\n\
  161. include Enumerable\n\
  162. \n\
  163. def each(&block)\n\
  164. ${1}\n\
  165. end\n\
  166. # include Comparable\n\
  167. snippet Comp\n\
  168. include Comparable\n\
  169. \n\
  170. def <=>(other)\n\
  171. ${1}\n\
  172. end\n\
  173. # extend Forwardable\n\
  174. snippet Forw-\n\
  175. extend Forwardable\n\
  176. # def self\n\
  177. snippet defs\n\
  178. def self.${1:class_method_name}\n\
  179. ${2}\n\
  180. end\n\
  181. # def method_missing\n\
  182. snippet defmm\n\
  183. def method_missing(meth, *args, &blk)\n\
  184. ${1}\n\
  185. end\n\
  186. snippet defd\n\
  187. def_delegator :${1:@del_obj}, :${2:del_meth}, :${3:new_name}\n\
  188. snippet defds\n\
  189. def_delegators :${1:@del_obj}, :${2:del_methods}\n\
  190. snippet am\n\
  191. alias_method :${1:new_name}, :${2:old_name}\n\
  192. snippet app\n\
  193. if __FILE__ == $PROGRAM_NAME\n\
  194. ${1}\n\
  195. end\n\
  196. # usage_if()\n\
  197. snippet usai\n\
  198. if ARGV.${1}\n\
  199. abort \"Usage: #{$PROGRAM_NAME} ${2:ARGS_GO_HERE}\"${3}\n\
  200. end\n\
  201. # usage_unless()\n\
  202. snippet usau\n\
  203. unless ARGV.${1}\n\
  204. abort \"Usage: #{$PROGRAM_NAME} ${2:ARGS_GO_HERE}\"${3}\n\
  205. end\n\
  206. snippet array\n\
  207. Array.new(${1:10}) { |${2:i}| ${3} }\n\
  208. snippet hash\n\
  209. Hash.new { |${1:hash}, ${2:key}| $1[$2] = ${3} }\n\
  210. snippet file File.foreach() { |line| .. }\n\
  211. File.foreach(${1:\"path/to/file\"}) { |${2:line}| ${3} }\n\
  212. snippet file File.read()\n\
  213. File.read(${1:\"path/to/file\"})${2}\n\
  214. snippet Dir Dir.global() { |file| .. }\n\
  215. Dir.glob(${1:\"dir/glob/*\"}) { |${2:file}| ${3} }\n\
  216. snippet Dir Dir[\"..\"]\n\
  217. Dir[${1:\"glob/**/*.rb\"}]${2}\n\
  218. snippet dir\n\
  219. Filename.dirname(__FILE__)\n\
  220. snippet deli\n\
  221. delete_if { |${1:e}| ${2} }\n\
  222. snippet fil\n\
  223. fill(${1:range}) { |${2:i}| ${3} }\n\
  224. # flatten_once()\n\
  225. snippet flao\n\
  226. inject(Array.new) { |${1:arr}, ${2:a}| $1.push(*$2)}${3}\n\
  227. snippet zip\n\
  228. zip(${1:enums}) { |${2:row}| ${3} }\n\
  229. # downto(0) { |n| .. }\n\
  230. snippet dow\n\
  231. downto(${1:0}) { |${2:n}| ${3} }\n\
  232. snippet ste\n\
  233. step(${1:2}) { |${2:n}| ${3} }\n\
  234. snippet tim\n\
  235. times { |${1:n}| ${2} }\n\
  236. snippet upt\n\
  237. upto(${1:1.0/0.0}) { |${2:n}| ${3} }\n\
  238. snippet loo\n\
  239. loop { ${1} }\n\
  240. snippet ea\n\
  241. each { |${1:e}| ${2} }\n\
  242. snippet ead\n\
  243. each do |${1:e}|\n\
  244. ${2}\n\
  245. end\n\
  246. snippet eab\n\
  247. each_byte { |${1:byte}| ${2} }\n\
  248. snippet eac- each_char { |chr| .. }\n\
  249. each_char { |${1:chr}| ${2} }\n\
  250. snippet eac- each_cons(..) { |group| .. }\n\
  251. each_cons(${1:2}) { |${2:group}| ${3} }\n\
  252. snippet eai\n\
  253. each_index { |${1:i}| ${2} }\n\
  254. snippet eaid\n\
  255. each_index do |${1:i}|\n\
  256. ${2}\n\
  257. end\n\
  258. snippet eak\n\
  259. each_key { |${1:key}| ${2} }\n\
  260. snippet eakd\n\
  261. each_key do |${1:key}|\n\
  262. ${2}\n\
  263. end\n\
  264. snippet eal\n\
  265. each_line { |${1:line}| ${2} }\n\
  266. snippet eald\n\
  267. each_line do |${1:line}|\n\
  268. ${2}\n\
  269. end\n\
  270. snippet eap\n\
  271. each_pair { |${1:name}, ${2:val}| ${3} }\n\
  272. snippet eapd\n\
  273. each_pair do |${1:name}, ${2:val}|\n\
  274. ${3}\n\
  275. end\n\
  276. snippet eas-\n\
  277. each_slice(${1:2}) { |${2:group}| ${3} }\n\
  278. snippet easd-\n\
  279. each_slice(${1:2}) do |${2:group}|\n\
  280. ${3}\n\
  281. end\n\
  282. snippet eav\n\
  283. each_value { |${1:val}| ${2} }\n\
  284. snippet eavd\n\
  285. each_value do |${1:val}|\n\
  286. ${2}\n\
  287. end\n\
  288. snippet eawi\n\
  289. each_with_index { |${1:e}, ${2:i}| ${3} }\n\
  290. snippet eawid\n\
  291. each_with_index do |${1:e},${2:i}|\n\
  292. ${3}\n\
  293. end\n\
  294. snippet reve\n\
  295. reverse_each { |${1:e}| ${2} }\n\
  296. snippet reved\n\
  297. reverse_each do |${1:e}|\n\
  298. ${2}\n\
  299. end\n\
  300. snippet inj\n\
  301. inject(${1:init}) { |${2:mem}, ${3:var}| ${4} }\n\
  302. snippet injd\n\
  303. inject(${1:init}) do |${2:mem}, ${3:var}|\n\
  304. ${4}\n\
  305. end\n\
  306. snippet map\n\
  307. map { |${1:e}| ${2} }\n\
  308. snippet mapd\n\
  309. map do |${1:e}|\n\
  310. ${2}\n\
  311. end\n\
  312. snippet mapwi-\n\
  313. enum_with_index.map { |${1:e}, ${2:i}| ${3} }\n\
  314. snippet sor\n\
  315. sort { |a, b| ${1} }\n\
  316. snippet sorb\n\
  317. sort_by { |${1:e}| ${2} }\n\
  318. snippet ran\n\
  319. sort_by { rand }\n\
  320. snippet all\n\
  321. all? { |${1:e}| ${2} }\n\
  322. snippet any\n\
  323. any? { |${1:e}| ${2} }\n\
  324. snippet cl\n\
  325. classify { |${1:e}| ${2} }\n\
  326. snippet col\n\
  327. collect { |${1:e}| ${2} }\n\
  328. snippet cold\n\
  329. collect do |${1:e}|\n\
  330. ${2}\n\
  331. end\n\
  332. snippet det\n\
  333. detect { |${1:e}| ${2} }\n\
  334. snippet detd\n\
  335. detect do |${1:e}|\n\
  336. ${2}\n\
  337. end\n\
  338. snippet fet\n\
  339. fetch(${1:name}) { |${2:key}| ${3} }\n\
  340. snippet fin\n\
  341. find { |${1:e}| ${2} }\n\
  342. snippet find\n\
  343. find do |${1:e}|\n\
  344. ${2}\n\
  345. end\n\
  346. snippet fina\n\
  347. find_all { |${1:e}| ${2} }\n\
  348. snippet finad\n\
  349. find_all do |${1:e}|\n\
  350. ${2}\n\
  351. end\n\
  352. snippet gre\n\
  353. grep(${1:/pattern/}) { |${2:match}| ${3} }\n\
  354. snippet sub\n\
  355. ${1:g}sub(${2:/pattern/}) { |${3:match}| ${4} }\n\
  356. snippet sca\n\
  357. scan(${1:/pattern/}) { |${2:match}| ${3} }\n\
  358. snippet scad\n\
  359. scan(${1:/pattern/}) do |${2:match}|\n\
  360. ${3}\n\
  361. end\n\
  362. snippet max\n\
  363. max { |a, b| ${1} }\n\
  364. snippet min\n\
  365. min { |a, b| ${1} }\n\
  366. snippet par\n\
  367. partition { |${1:e}| ${2} }\n\
  368. snippet pard\n\
  369. partition do |${1:e}|\n\
  370. ${2}\n\
  371. end\n\
  372. snippet rej\n\
  373. reject { |${1:e}| ${2} }\n\
  374. snippet rejd\n\
  375. reject do |${1:e}|\n\
  376. ${2}\n\
  377. end\n\
  378. snippet sel\n\
  379. select { |${1:e}| ${2} }\n\
  380. snippet seld\n\
  381. select do |${1:e}|\n\
  382. ${2}\n\
  383. end\n\
  384. snippet lam\n\
  385. lambda { |${1:args}| ${2} }\n\
  386. snippet doo\n\
  387. do\n\
  388. ${1}\n\
  389. end\n\
  390. snippet dov\n\
  391. do |${1:variable}|\n\
  392. ${2}\n\
  393. end\n\
  394. snippet :\n\
  395. :${1:key} => ${2:\"value\"}${3}\n\
  396. snippet ope\n\
  397. open(${1:\"path/or/url/or/pipe\"}, \"${2:w}\") { |${3:io}| ${4} }\n\
  398. # path_from_here()\n\
  399. snippet fpath\n\
  400. File.join(File.dirname(__FILE__), *%2[${1:rel path here}])${2}\n\
  401. # unix_filter {}\n\
  402. snippet unif\n\
  403. ARGF.each_line${1} do |${2:line}|\n\
  404. ${3}\n\
  405. end\n\
  406. # option_parse {}\n\
  407. snippet optp\n\
  408. require \"optparse\"\n\
  409. \n\
  410. options = {${1:default => \"args\"}}\n\
  411. \n\
  412. ARGV.options do |opts|\n\
  413. opts.banner = \"Usage: #{File.basename($PROGRAM_NAME)}\n\
  414. snippet opt\n\
  415. opts.on( \"-${1:o}\", \"--${2:long-option-name}\", ${3:String},\n\
  416. \"${4:Option description.}\") do |${5:opt}|\n\
  417. ${6}\n\
  418. end\n\
  419. snippet tc\n\
  420. require \"test/unit\"\n\
  421. \n\
  422. require \"${1:library_file_name}\"\n\
  423. \n\
  424. class Test${2:$1} < Test::Unit::TestCase\n\
  425. def test_${3:case_name}\n\
  426. ${4}\n\
  427. end\n\
  428. end\n\
  429. snippet ts\n\
  430. require \"test/unit\"\n\
  431. \n\
  432. require \"tc_${1:test_case_file}\"\n\
  433. require \"tc_${2:test_case_file}\"${3}\n\
  434. snippet as\n\
  435. assert ${1:test}, \"${2:Failure message.}\"${3}\n\
  436. snippet ase\n\
  437. assert_equal ${1:expected}, ${2:actual}${3}\n\
  438. snippet asne\n\
  439. assert_not_equal ${1:unexpected}, ${2:actual}${3}\n\
  440. snippet asid\n\
  441. assert_in_delta ${1:expected_float}, ${2:actual_float}, ${3:2 ** -20}${4}\n\
  442. snippet asio\n\
  443. assert_instance_of ${1:ExpectedClass}, ${2:actual_instance}${3}\n\
  444. snippet asko\n\
  445. assert_kind_of ${1:ExpectedKind}, ${2:actual_instance}${3}\n\
  446. snippet asn\n\
  447. assert_nil ${1:instance}${2}\n\
  448. snippet asnn\n\
  449. assert_not_nil ${1:instance}${2}\n\
  450. snippet asm\n\
  451. assert_match /${1:expected_pattern}/, ${2:actual_string}${3}\n\
  452. snippet asnm\n\
  453. assert_no_match /${1:unexpected_pattern}/, ${2:actual_string}${3}\n\
  454. snippet aso\n\
  455. assert_operator ${1:left}, :${2:operator}, ${3:right}${4}\n\
  456. snippet asr\n\
  457. assert_raise ${1:Exception} { ${2} }\n\
  458. snippet asrd\n\
  459. assert_raise ${1:Exception} do\n\
  460. ${2}\n\
  461. end\n\
  462. snippet asnr\n\
  463. assert_nothing_raised ${1:Exception} { ${2} }\n\
  464. snippet asnrd\n\
  465. assert_nothing_raised ${1:Exception} do\n\
  466. ${2}\n\
  467. end\n\
  468. snippet asrt\n\
  469. assert_respond_to ${1:object}, :${2:method}${3}\n\
  470. snippet ass assert_same(..)\n\
  471. assert_same ${1:expected}, ${2:actual}${3}\n\
  472. snippet ass assert_send(..)\n\
  473. assert_send [${1:object}, :${2:message}, ${3:args}]${4}\n\
  474. snippet asns\n\
  475. assert_not_same ${1:unexpected}, ${2:actual}${3}\n\
  476. snippet ast\n\
  477. assert_throws :${1:expected} { ${2} }\n\
  478. snippet astd\n\
  479. assert_throws :${1:expected} do\n\
  480. ${2}\n\
  481. end\n\
  482. snippet asnt\n\
  483. assert_nothing_thrown { ${1} }\n\
  484. snippet asntd\n\
  485. assert_nothing_thrown do\n\
  486. ${1}\n\
  487. end\n\
  488. snippet fl\n\
  489. flunk \"${1:Failure message.}\"${2}\n\
  490. # Benchmark.bmbm do .. end\n\
  491. snippet bm-\n\
  492. TESTS = ${1:10_000}\n\
  493. Benchmark.bmbm do |results|\n\
  494. ${2}\n\
  495. end\n\
  496. snippet rep\n\
  497. results.report(\"${1:name}:\") { TESTS.times { ${2} }}\n\
  498. # Marshal.dump(.., file)\n\
  499. snippet Md\n\
  500. File.open(${1:\"path/to/file.dump\"}, \"wb\") { |${2:file}| Marshal.dump(${3:obj}, $2) }${4}\n\
  501. # Mashal.load(obj)\n\
  502. snippet Ml\n\
  503. File.open(${1:\"path/to/file.dump\"}, \"rb\") { |${2:file}| Marshal.load($2) }${3}\n\
  504. # deep_copy(..)\n\
  505. snippet deec\n\
  506. Marshal.load(Marshal.dump(${1:obj_to_copy}))${2}\n\
  507. snippet Pn-\n\
  508. PStore.new(${1:\"file_name.pstore\"})${2}\n\
  509. snippet tra\n\
  510. transaction(${1:true}) { ${2} }\n\
  511. # xmlread(..)\n\
  512. snippet xml-\n\
  513. REXML::Document.new(File.read(${1:\"path/to/file\"}))${2}\n\
  514. # xpath(..) { .. }\n\
  515. snippet xpa\n\
  516. elements.each(${1:\"//Xpath\"}) do |${2:node}|\n\
  517. ${3}\n\
  518. end\n\
  519. # class_from_name()\n\
  520. snippet clafn\n\
  521. split(\"::\").inject(Object) { |par, const| par.const_get(const) }\n\
  522. # singleton_class()\n\
  523. snippet sinc\n\
  524. class << self; self end\n\
  525. snippet nam\n\
  526. namespace :${1:`Filename()`} do\n\
  527. ${2}\n\
  528. end\n\
  529. snippet tas\n\
  530. desc \"${1:Task description}\"\n\
  531. task :${2:task_name => [:dependent, :tasks]} do\n\
  532. ${3}\n\
  533. end\n\
  534. # block\n\
  535. snippet b\n\
  536. { |${1:var}| ${2} }\n\
  537. snippet begin\n\
  538. begin\n\
  539. raise 'A test exception.'\n\
  540. rescue Exception => e\n\
  541. puts e.message\n\
  542. puts e.backtrace.inspect\n\
  543. else\n\
  544. # other exception\n\
  545. ensure\n\
  546. # always executed\n\
  547. end\n\
  548. \n\
  549. #debugging\n\
  550. snippet debug\n\
  551. require 'ruby-debug'; debugger; true;\n\
  552. snippet pry\n\
  553. require 'pry'; binding.pry\n\
  554. \n\
  555. #############################################\n\
  556. # Rails snippets - for pure Ruby, see above #\n\
  557. #############################################\n\
  558. snippet art\n\
  559. assert_redirected_to ${1::action => \"${2:index}\"}\n\
  560. snippet artnp\n\
  561. assert_redirected_to ${1:parent}_${2:child}_path(${3:@$1}, ${4:@$2})\n\
  562. snippet artnpp\n\
  563. assert_redirected_to ${1:parent}_${2:child}_path(${3:@$1})\n\
  564. snippet artp\n\
  565. assert_redirected_to ${1:model}_path(${2:@$1})\n\
  566. snippet artpp\n\
  567. assert_redirected_to ${1:model}s_path\n\
  568. snippet asd\n\
  569. assert_difference \"${1:Model}.${2:count}\", $1 do\n\
  570. ${3}\n\
  571. end\n\
  572. snippet asnd\n\
  573. assert_no_difference \"${1:Model}.${2:count}\" do\n\
  574. ${3}\n\
  575. end\n\
  576. snippet asre\n\
  577. assert_response :${1:success}, @response.body${2}\n\
  578. snippet asrj\n\
  579. assert_rjs :${1:replace}, \"${2:dom id}\"\n\
  580. snippet ass assert_select(..)\n\
  581. assert_select '${1:path}', :${2:text} => '${3:inner_html' ${4:do}\n\
  582. snippet bf\n\
  583. before_filter :${1:method}\n\
  584. snippet bt\n\
  585. belongs_to :${1:association}\n\
  586. snippet crw\n\
  587. cattr_accessor :${1:attr_names}\n\
  588. snippet defcreate\n\
  589. def create\n\
  590. @${1:model_class_name} = ${2:ModelClassName}.new(params[:$1])\n\
  591. \n\
  592. respond_to do |wants|\n\
  593. if @$1.save\n\
  594. flash[:notice] = '$2 was successfully created.'\n\
  595. wants.html { redirect_to(@$1) }\n\
  596. wants.xml { render :xml => @$1, :status => :created, :location => @$1 }\n\
  597. else\n\
  598. wants.html { render :action => \"new\" }\n\
  599. wants.xml { render :xml => @$1.errors, :status => :unprocessable_entity }\n\
  600. end\n\
  601. end\n\
  602. end${3}\n\
  603. snippet defdestroy\n\
  604. def destroy\n\
  605. @${1:model_class_name} = ${2:ModelClassName}.find(params[:id])\n\
  606. @$1.destroy\n\
  607. \n\
  608. respond_to do |wants|\n\
  609. wants.html { redirect_to($1s_url) }\n\
  610. wants.xml { head :ok }\n\
  611. end\n\
  612. end${3}\n\
  613. snippet defedit\n\
  614. def edit\n\
  615. @${1:model_class_name} = ${2:ModelClassName}.find(params[:id])\n\
  616. end\n\
  617. snippet defindex\n\
  618. def index\n\
  619. @${1:model_class_name} = ${2:ModelClassName}.all\n\
  620. \n\
  621. respond_to do |wants|\n\
  622. wants.html # index.html.erb\n\
  623. wants.xml { render :xml => @$1s }\n\
  624. end\n\
  625. end${3}\n\
  626. snippet defnew\n\
  627. def new\n\
  628. @${1:model_class_name} = ${2:ModelClassName}.new\n\
  629. \n\
  630. respond_to do |wants|\n\
  631. wants.html # new.html.erb\n\
  632. wants.xml { render :xml => @$1 }\n\
  633. end\n\
  634. end${3}\n\
  635. snippet defshow\n\
  636. def show\n\
  637. @${1:model_class_name} = ${2:ModelClassName}.find(params[:id])\n\
  638. \n\
  639. respond_to do |wants|\n\
  640. wants.html # show.html.erb\n\
  641. wants.xml { render :xml => @$1 }\n\
  642. end\n\
  643. end${3}\n\
  644. snippet defupdate\n\
  645. def update\n\
  646. @${1:model_class_name} = ${2:ModelClassName}.find(params[:id])\n\
  647. \n\
  648. respond_to do |wants|\n\
  649. if @$1.update_attributes(params[:$1])\n\
  650. flash[:notice] = '$2 was successfully updated.'\n\
  651. wants.html { redirect_to(@$1) }\n\
  652. wants.xml { head :ok }\n\
  653. else\n\
  654. wants.html { render :action => \"edit\" }\n\
  655. wants.xml { render :xml => @$1.errors, :status => :unprocessable_entity }\n\
  656. end\n\
  657. end\n\
  658. end${3}\n\
  659. snippet flash\n\
  660. flash[:${1:notice}] = \"${2}\"\n\
  661. snippet habtm\n\
  662. has_and_belongs_to_many :${1:object}, :join_table => \"${2:table_name}\", :foreign_key => \"${3}_id\"${4}\n\
  663. snippet hm\n\
  664. has_many :${1:object}\n\
  665. snippet hmd\n\
  666. has_many :${1:other}s, :class_name => \"${2:$1}\", :foreign_key => \"${3:$1}_id\", :dependent => :destroy${4}\n\
  667. snippet hmt\n\
  668. has_many :${1:object}, :through => :${2:object}\n\
  669. snippet ho\n\
  670. has_one :${1:object}\n\
  671. snippet i18\n\
  672. I18n.t('${1:type.key}')${2}\n\
  673. snippet ist\n\
  674. <%= image_submit_tag(\"${1:agree.png}\", :id => \"${2:id}\"${3} %>\n\
  675. snippet log\n\
  676. Rails.logger.${1:debug} ${2}\n\
  677. snippet log2\n\
  678. RAILS_DEFAULT_LOGGER.${1:debug} ${2}\n\
  679. snippet logd\n\
  680. logger.debug { \"${1:message}\" }${2}\n\
  681. snippet loge\n\
  682. logger.error { \"${1:message}\" }${2}\n\
  683. snippet logf\n\
  684. logger.fatal { \"${1:message}\" }${2}\n\
  685. snippet logi\n\
  686. logger.info { \"${1:message}\" }${2}\n\
  687. snippet logw\n\
  688. logger.warn { \"${1:message}\" }${2}\n\
  689. snippet mapc\n\
  690. ${1:map}.${2:connect} '${3:controller/:action/:id}'\n\
  691. snippet mapca\n\
  692. ${1:map}.catch_all \"*${2:anything}\", :controller => \"${3:default}\", :action => \"${4:error}\"${5}\n\
  693. snippet mapr\n\
  694. ${1:map}.resource :${2:resource}\n\
  695. snippet maprs\n\
  696. ${1:map}.resources :${2:resource}\n\
  697. snippet mapwo\n\
  698. ${1:map}.with_options :${2:controller} => '${3:thing}' do |$3|\n\
  699. ${4}\n\
  700. end\n\
  701. snippet mbs\n\
  702. before_save :${1:method}\n\
  703. snippet mcht\n\
  704. change_table :${1:table_name} do |t|\n\
  705. ${2}\n\
  706. end\n\
  707. snippet mp\n\
  708. map(&:${1:id})\n\
  709. snippet mrw\n\
  710. mattr_accessor :${1:attr_names}\n\
  711. snippet oa\n\
  712. order(\"${1:field}\")\n\
  713. snippet od\n\
  714. order(\"${1:field} DESC\")\n\
  715. snippet pa\n\
  716. params[:${1:id}]${2}\n\
  717. snippet ra\n\
  718. render :action => \"${1:action}\"\n\
  719. snippet ral\n\
  720. render :action => \"${1:action}\", :layout => \"${2:layoutname}\"\n\
  721. snippet rest\n\
  722. respond_to do |wants|\n\
  723. wants.${1:html} { ${2} }\n\
  724. end\n\
  725. snippet rf\n\
  726. render :file => \"${1:filepath}\"\n\
  727. snippet rfu\n\
  728. render :file => \"${1:filepath}\", :use_full_path => ${2:false}\n\
  729. snippet ri\n\
  730. render :inline => \"${1:<%= 'hello' %>}\"\n\
  731. snippet ril\n\
  732. render :inline => \"${1:<%= 'hello' %>}\", :locals => { ${2::name} => \"${3:value}\"${4} }\n\
  733. snippet rit\n\
  734. render :inline => \"${1:<%= 'hello' %>}\", :type => ${2::rxml}\n\
  735. snippet rjson\n\
  736. render :json => ${1:text to render}\n\
  737. snippet rl\n\
  738. render :layout => \"${1:layoutname}\"\n\
  739. snippet rn\n\
  740. render :nothing => ${1:true}\n\
  741. snippet rns\n\
  742. render :nothing => ${1:true}, :status => ${2:401}\n\
  743. snippet rp\n\
  744. render :partial => \"${1:item}\"\n\
  745. snippet rpc\n\
  746. render :partial => \"${1:item}\", :collection => ${2:@$1s}\n\
  747. snippet rpl\n\
  748. render :partial => \"${1:item}\", :locals => { :${2:$1} => ${3:@$1}\n\
  749. snippet rpo\n\
  750. render :partial => \"${1:item}\", :object => ${2:@$1}\n\
  751. snippet rps\n\
  752. render :partial => \"${1:item}\", :status => ${2:500}\n\
  753. snippet rt\n\
  754. render :text => \"${1:text to render}\"\n\
  755. snippet rtl\n\
  756. render :text => \"${1:text to render}\", :layout => \"${2:layoutname}\"\n\
  757. snippet rtlt\n\
  758. render :text => \"${1:text to render}\", :layout => ${2:true}\n\
  759. snippet rts\n\
  760. render :text => \"${1:text to render}\", :status => ${2:401}\n\
  761. snippet ru\n\
  762. render :update do |${1:page}|\n\
  763. $1.${2}\n\
  764. end\n\
  765. snippet rxml\n\
  766. render :xml => ${1:text to render}\n\
  767. snippet sc\n\
  768. scope :${1:name}, :where(:@${2:field} => ${3:value})\n\
  769. snippet sl\n\
  770. scope :${1:name}, lambda do |${2:value}|\n\
  771. where(\"${3:field = ?}\", ${4:bind var})\n\
  772. end\n\
  773. snippet sha1\n\
  774. Digest::SHA1.hexdigest(${1:string})\n\
  775. snippet sweeper\n\
  776. class ${1:ModelClassName}Sweeper < ActionController::Caching::Sweeper\n\
  777. observe $1\n\
  778. \n\
  779. def after_save(${2:model_class_name})\n\
  780. expire_cache($2)\n\
  781. end\n\
  782. \n\
  783. def after_destroy($2)\n\
  784. expire_cache($2)\n\
  785. end\n\
  786. \n\
  787. def expire_cache($2)\n\
  788. expire_page\n\
  789. end\n\
  790. end\n\
  791. snippet tcb\n\
  792. t.boolean :${1:title}\n\
  793. ${2}\n\
  794. snippet tcbi\n\
  795. t.binary :${1:title}, :limit => ${2:2}.megabytes\n\
  796. ${3}\n\
  797. snippet tcd\n\
  798. t.decimal :${1:title}, :precision => ${2:10}, :scale => ${3:2}\n\
  799. ${4}\n\
  800. snippet tcda\n\
  801. t.date :${1:title}\n\
  802. ${2}\n\
  803. snippet tcdt\n\
  804. t.datetime :${1:title}\n\
  805. ${2}\n\
  806. snippet tcf\n\
  807. t.float :${1:title}\n\
  808. ${2}\n\
  809. snippet tch\n\
  810. t.change :${1:name}, :${2:string}, :${3:limit} => ${4:80}\n\
  811. ${5}\n\
  812. snippet tci\n\
  813. t.integer :${1:title}\n\
  814. ${2}\n\
  815. snippet tcl\n\
  816. t.integer :lock_version, :null => false, :default => 0\n\
  817. ${1}\n\
  818. snippet tcr\n\
  819. t.references :${1:taggable}, :polymorphic => { :default => '${2:Photo}' }\n\
  820. ${3}\n\
  821. snippet tcs\n\
  822. t.string :${1:title}\n\
  823. ${2}\n\
  824. snippet tct\n\
  825. t.text :${1:title}\n\
  826. ${2}\n\
  827. snippet tcti\n\
  828. t.time :${1:title}\n\
  829. ${2}\n\
  830. snippet tcts\n\
  831. t.timestamp :${1:title}\n\
  832. ${2}\n\
  833. snippet tctss\n\
  834. t.timestamps\n\
  835. ${1}\n\
  836. snippet va\n\
  837. validates_associated :${1:attribute}\n\
  838. snippet vao\n\
  839. validates_acceptance_of :${1:terms}\n\
  840. snippet vc\n\
  841. validates_confirmation_of :${1:attribute}\n\
  842. snippet ve\n\
  843. validates_exclusion_of :${1:attribute}, :in => ${2:%w( mov avi )}\n\
  844. snippet vf\n\
  845. validates_format_of :${1:attribute}, :with => /${2:regex}/\n\
  846. snippet vi\n\
  847. validates_inclusion_of :${1:attribute}, :in => %w(${2: mov avi })\n\
  848. snippet vl\n\
  849. validates_length_of :${1:attribute}, :within => ${2:3}..${3:20}\n\
  850. snippet vn\n\
  851. validates_numericality_of :${1:attribute}\n\
  852. snippet vpo\n\
  853. validates_presence_of :${1:attribute}\n\
  854. snippet vu\n\
  855. validates_uniqueness_of :${1:attribute}\n\
  856. snippet wants\n\
  857. wants.${1:js|xml|html} { ${2} }\n\
  858. snippet wc\n\
  859. where(${1:\"conditions\"}${2:, bind_var})\n\
  860. snippet wh\n\
  861. where(${1:field} => ${2:value})\n\
  862. snippet xdelete\n\
  863. xhr :delete, :${1:destroy}, :id => ${2:1}${3}\n\
  864. snippet xget\n\
  865. xhr :get, :${1:show}, :id => ${2:1}${3}\n\
  866. snippet xpost\n\
  867. xhr :post, :${1:create}, :${2:object} => { ${3} }\n\
  868. snippet xput\n\
  869. xhr :put, :${1:update}, :id => ${2:1}, :${3:object} => { ${4} }${5}\n\
  870. snippet test\n\
  871. test \"should ${1:do something}\" do\n\
  872. ${2}\n\
  873. end\n\
  874. #migrations\n\
  875. snippet mac\n\
  876. add_column :${1:table_name}, :${2:column_name}, :${3:data_type}\n\
  877. snippet mrc\n\
  878. remove_column :${1:table_name}, :${2:column_name}\n\
  879. snippet mrnc\n\
  880. rename_column :${1:table_name}, :${2:old_column_name}, :${3:new_column_name}\n\
  881. snippet mcc\n\
  882. change_column :${1:table}, :${2:column}, :${3:type}\n\
  883. snippet mccc\n\
  884. t.column :${1:title}, :${2:string}\n\
  885. snippet mct\n\
  886. create_table :${1:table_name} do |t|\n\
  887. t.column :${2:name}, :${3:type}\n\
  888. end\n\
  889. snippet migration\n\
  890. class ${1:class_name} < ActiveRecord::Migration\n\
  891. def self.up\n\
  892. ${2}\n\
  893. end\n\
  894. \n\
  895. def self.down\n\
  896. end\n\
  897. end\n\
  898. \n\
  899. snippet trc\n\
  900. t.remove :${1:column}\n\
  901. snippet tre\n\
  902. t.rename :${1:old_column_name}, :${2:new_column_name}\n\
  903. ${3}\n\
  904. snippet tref\n\
  905. t.references :${1:model}\n\
  906. \n\
  907. #rspec\n\
  908. snippet it\n\
  909. it \"${1:spec_name}\" do\n\
  910. ${2}\n\
  911. end\n\
  912. snippet itp\n\
  913. it \"${1:spec_name}\"\n\
  914. ${2}\n\
  915. snippet desc\n\
  916. describe ${1:class_name} do\n\
  917. ${2}\n\
  918. end\n\
  919. snippet cont\n\
  920. context \"${1:message}\" do\n\
  921. ${2}\n\
  922. end\n\
  923. snippet bef\n\
  924. before :${1:each} do\n\
  925. ${2}\n\
  926. end\n\
  927. snippet aft\n\
  928. after :${1:each} do\n\
  929. ${2}\n\
  930. end\n\
  931. ";
  932. exports.scope = "ruby";
  933. });