Hatena::Groupsubtech

subpop

2007-09-07

rails.elで使えるスニペット

22:00 | rails.elで使えるスニペット - subpop を含むブックマーク はてなブックマーク - rails.elで使えるスニペット - subpop rails.elで使えるスニペット - subpop のブックマークコメント

rails-snippets-feature.el(0.5.99.5)から抜き出し。適当。

loops

略語展開結果説明
whilewhile $${condition}\n$>$.\nend$>while ... end
whenwhen $${condition}\n$>$.when ...
wattr_writer :$${attr_names}attr_writer ...
uptupto($${0}) { |$${n}|$. }upto(1.0/0.0) { |n| ... }
untiluntil $${condition}\n$>$.\nend$>until ... end
timtimes { |$${n}|$. }times { |n| ... }
stestep($${2}) { |$${n}|$. }step(2) { |e| ... }
forinfor $${element} in $${collection}\n$>$${element}.$.\nend$>for ... in ... end
dowdownto($${0}) { |$${n}|$. }downto(0) { |n| ... }

general

略語展開結果説明
ha{ $>:$. }{ :key => 'value' }
::$${key} => '$${value}':key => 'value'
ylFile.open($${yaml}) { |$${file}| YAML.load($${file}) }YAML.load(file)
ydFile.open($${yaml}, "w") { |$${file}| YAML.dump($${obj}, $${file}) }YAML.dump(..., file)
y :yields: $${arguments}:yields:
verrenverify :only => [:$${1}], :method => :post, :render => {:status => 500, :text => "use HTTP-POST"}\nverify -- render
verredverify :only => [:$${1}], :session => :user, :params => :id, :redirect_to => {:action => '$${index}'}\nverify -- redirect
tratransaction$${1} { $. }transaction( ... ) { ... }
subsub(/$${pattern}/) { |$${match}|$. }sub(/.../) { |match| ... }
scascan(/$${pattern}/) { |$${match}| $. }scan(/.../) { |match| ... }
represults.report("$${name}:") { TESTS.times { $. } }results.report(...) { ... }
rb#!/usr/bin/env ruby -w\n\n#!/usr/local/bin/ruby -w
rattr_reader :$${attr_names}attr_reader ...
pnPStore.new($${file_name})PStore.new( ... )
patfhFile.join(File.dirname(__FILE__), *%w[$${here}])path_from_here( ... )
opeopen($${pipe}) { |$${io}| $. }open("path/or/url", "w") { |io| ... }
mlFile.open($${dump}) { |$${file}| Marshal.load($${file}) }Marshal.load(obj)
minmin { |a, b| $. }min { |a, b| ... }
maxmax { |a, b| $. }max { |a, b| ... }
mdFile.open($${dump}, "w") { |$${file}| Marshal.dump($${obj}, $${file}) }Marshal.dump(..., file)
lamlambda { |$${args}|$. }lambda { |args| ... }
gsugsub(/$${pattern}/) { |$${match}|$. }gsub(/.../) { |match| ... }
gregrep($${pattern}) { |$${match}| $. }grep(/pattern/) { |match| ... }
flflunk('$${message}')flunk(...)
fileFile.foreach($${file}) { |$${line}| $. }File.foreach ("...") { |line| ... }
dirDir.glob($${glob}) { |$${file}| $. }Dir.glob("...") { |file| ... }
b=begin rdoc\n$>$.\n=endNew Block
beginbegin\n$>$${paste}\nrescue $${Exception} => $${e}\n$>$.\nend$>\nbegin ... rescue ... end
bmTESTS = $${10_000}\nBenchmark.bmbm($${10}) do |results|\n $.\nend$>Benchmark.bmbm(...) do ... end
amalias_method :$${new_name}, :$${old_name}alias_method ...
amcalias_method_chain :$${first_method}, :$${second_method}alias_method_chain ...

definitions

略語展開結果説明
tsrequire "test/unit"\n\nrequire "tc_$${test_case_file}"\nrequire "tc_$${test_case_file}"\nrequire "tc_..." ...
tcrequire "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
sinclass << self; self endsingleton_class()
rwattr_accessor :$${attr_names}attr_accessor ...
reqrequire "$."require "..."
modfmodule $${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
modsmodule $${ModuleName}\n$>$.\nend$>module ... end
modumodule $${ModuleName}\n$>module_function\n$>\n$>$.\nend$>module ... module_function ... end
mmdef method_missing(meth, *args, &block)\n$>$.\nend$>def method_missing ... end
hashHash.new { |$${hash}, $${key}| $${hash}[$${key}] = $. }Hash.new { |hash, key| hash[key] = ... }
forwextend Forwardableextend Forwardable
enuminclude Enumerable\n\ndef each(&block)\n$>$.\nend$>include Enumerable ...
elsifelsif $${condition}\n$>$.elsif ...
doodo |$${object}|\n$>$.\nend$>Insert do |object| ... end
dodo\n$>$.\nend$>do ... end
defddef_delegator :$${del_obj}, :$${del_meth}, :$${new_name}def_delegator ...
defdsdef_delegators :$${del_obj}, :$${del_methods}def_delegators ...
defsdef self.$${class_method_name}\n$>$.\nend$>def self ... end
deftdef test_$${case_name}\n$>$.\nend$>def test_ ... end
deeMarshal.load(Marshal.dump($${obj_to_copy}))deep_copy(...)
compinclude Comparable\n\ndef <=>(other)\n$>$.\nend$>include Comparable ...
cladlclass $${ClassName} < DelegateClass($${ParentClass})\n$>def initialize$${1}\n$>$>super($${del_obj})\n$>$>\n$>$>$.\nend$>\n$>\n$>\nend$>class ... < DelegateClass ... initialize ... end
claprclass $${ClassName} < $${ParentClass}\n$>def initialize$${1}\n$>$>$.\nend$>\n$>\n$>\nend$>class ... < ParentClass ... initialize ... end
clastclass $${ClassName} < Struct.new(:$${attr_names})\n$>def initialize(*args)\n$>$>super\n$>$>\n$>$>$.\nend$>\n$>\n$>\nend$>class ... < Struct ... initialize ... end
classclass $${ClassName}\n$>$.\nend$>class ... end
classiclass $${ClassName}\n$>def initialize$${1}\n$>$>$.\nend$>\n$>\n$>\nend$>class ... initialize ... end
clasfclass << $${self}\n$>$.\nend$>class << self ... end

collections

略語展開結果説明
zipzip($${enums}) { |$${row}| $. }zip(enums) { |row| ... }
sorbsort_by { |$${e}| $. }sort_by { |e| ... }
sorsort { |a, b| $. }sort { |a, b| ... }
selectselect { |$${element}| $${element}.$${2} }$.select element
selselect { |$${e}| $. }select { |e| ... }
revereverse_each { |$${e}| $. }reverse_each { |e| ... }
rejectreject { |$${element}| $${element}.$. }reject element
rejreject { |$${e}| $. }reject { |e| ... }
ransort_by { rand }randomize()
mapwienum_with_index.map { |$${e}, $${i}| $. }map_with_index { |e, i| ... }
mapmap { |$${e}| $. }map { |e| ... }
injectinject($${object}) { |$${injection}, $${element}| $${4} }$.inject object
injinject($${init}) { |$${mem}, $${var}| $. }inject(init) { |mem, var| ... }
flaoinject(Array.new) { |$${arr}, $${a}| $${arr}.push(*$${a}) }flatten_once()
finafind_all { |$${e}| $. }find_all { |e| ... }
finfind { |$${e}| $. }find { |e| ... }
filfill($${range}) { |$${i}|$. }fill(range) { |i| ... }
fetfetch($${name}) { |$${key}|$. }fetch(name) { |key| ... }
eawieach_with_index { |$${e}, $${i}| $. }each_with_index { |e, i| ... }
eaieach_index { |$${i}| $. }each_index { |i| ... }
eakeach_key { |$${key}| $. }each_key { |key| ... }
ealeach_line$${1} { |$${line}| $. }each_line { |line| ... }
eapeach_pair { |$${name}, $${val}| $. }each_pair { |name, val| ... }
easeach_slice($${2}) { |$${group}| $. }each_slice(...) { |group| ... }
eaveach_value { |$${val}| $. }each_value { |val| ... }
eacheach { |$${element}| $${element}.$. }each element
eaceach_cons($${2}) { |$${group}| $. }each_cons(...) { |group| ... }
eabeach_byte { |$${byte}| $. }each_byte { |byte| ... }
eaeach { |$${e}| $. }each { |e| ... }
detdetect { |$${e}| $. }detect { |e| ... }
delidelete_if { |$${e}| $. }delete_if { |e| ... }
collectcollect { |$${element}| $${element}.$. }collect element
colcollect { |$${e}| $. }collect { |e| ... }
clclassify { |$${e}| $. }classify { |e| ... }
arrayArray.new($${10}) { |$${i}|$. }Array.new(10) { |i| ... }
anyany? { |$${e}| $. }any? { |e| ... }
allall? { |$${e}| $. }all? { |e| ... }

erb

略語展開結果説明
title<title>$${title}</title>title
textarea<textarea name="$${Name}" rows="$${8}" cols="$${40}">$.</textarea>textarea
table<table border="$${0}" $${cellpadding}>\n$><tr><th>$${Header}</th></tr>\n$><tr><td>$${Data}</td></tr>\n</table>table
style<style type="text/css" media="screen">\n$>$.\n</style>style
scriptsrc<script src="$${1}" type="text/javascript" charset="$${utf}"></script>script with source
script<script type="text/javascript" charset="utf-8">\n$>$.\n</script>script
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
meta<meta name="$${name}" content="$${content}"/>meta
mailto<a href="mailto:$${example}?subject=$${feedback}">$${email}</a>mailto
link<link rel="$${stylesheet}" href="$${master}" type="text/css" media="$${screen}" title="$${title}" charset="$${utf}"/>link
licai<%= link_to "$${text}", :controller => "$${items}", :action => "$${edit}", :id => $${item} %>link_to (controller, action, id)
lica<%= link_to "$${text}", :controller => "$${items}", :action => "$${index}" %>link_to (controller, action)
lica<%= link_to "$${text}", :controller => "$${items}", :action => "$${index}" %>link_to (controller, action)
liai<%= link_to "$${text}", :action => "$${edit}", :id => $${item} %>link_to (action, id)
lic<%= link_to "$${text}", :controller => "$${items}" %>link_to (controller)
lia<%= link_to "$${text}", :action => "$${index}" %>link_to (action)
input<input type="$${button}" name="$${some_name}" value="$${3}"$${id}>input
head<head>\n$><meta http-equiv="Content-type" content="text/html; charset=utf-8"/>\n$><title>$${title}</title>\n$>$.\n</head>head
h<h1 id="$${alpha}">$${paste}</h1>heading
ft<%= form_tag :action => "$${update}" %>\n$.\n<%= end_form_tag %>form_tag
ff<%= form_for :$${item}, :action => "$${update}" %>\n$.\n<% end %>form_for
form<form action="$${action}" method="$${post}" accept-charset="utf-8">\n$>$.\n\n$><p><input type="submit" value="Continue →"/></p>\n</form>form
dtht<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"\n$>"http://www.w3.org/TR/html4/strict.dtd">\nHTML -- 4.01 Strict
dchttr<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"\n$>"http://www.w3.org/TR/html4/loose.dtd">\nHTML -- 4.01 Transitional
dcxmlf<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN"\n$>"http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">\nXHTML -- 1.0 Frameset
dcxmls<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"\n$>"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">\nXHTML -- 1.0 Strict
dcxmlt<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"\n$>"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">\nXHTML -- 1.0 Transitional
dcxml1<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"\n$>"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">\nXHTML -- 1.1
body<body id="$${id}" $${onload}>\n$>$.\n</body>body
div<div>\n$>$${paste}\n</div>div
%h<%=h $${@item} %><% h ... %>
%if<% if $${cond} -%>\n$.\n<% end -%><% if/end %>
%ifel<% if $${cond} -%>\n$.\n<% else -%>\n<% end -%><% if/else/end %>
%unless<% unless $${cond} -%>\n$.\n<% end -%><% unless/end %>
%for<% for $${elem} in @$${list} %>\n$>$.\n<% end %>$><% for/end %>
%<% $. -%><% ... %>
%%<%= $. %><%= ... %>

controller

略語展開結果説明
rurender :update do |page|\n$>$.\nend$>render :update ...
bfbefore_filter :$${filter}refore_filter
afafter_filter :$${filter}after_filter
arfaround_filter :$${filter}around_filter

RESTful

略語展開結果説明
restrespond_to do |format|\n$>format.html$>$.\nend$>respond_to ...
rindex$${,rails-snippets-feature:rest-index}models_url
rshow$${,rails-snippets-feature:rest-show}model_url(@model)
rnew$${,rails-snippets-feature:rest-new}new_model_url
redit$${,rails-snippets-feature:rest-edit}edit_model_url(@model)
rcreate$${,rails-snippets-feature:rest-create}models_url
rupdate$${,rails-snippets-feature:rest-update}model_url(@model)
rdestroy$${,rails-snippets-feature:rest-destroy}model_url(@model)

render

略語展開結果説明
rpsrender :partial => '$${item}', :status => $${500}render (partial, status)
rtrender :text => '$${render}'render (text)
rtlrender :text => '$${render}', :layout => '$${layoutname}'render (text, layout)
rtltrender :text => '$${render}', :layout => $${true}render (text, layout => true)
rtsrender :text => '$${render}', :status => $${401}render (text, status)
rfrender :file => '$${filepath}'render (file)
rfurender :file => '$${filepath}', :use_full_path => $${false}render (file, use_full_path)
rirender :inline => '$${hello}'render (inline)
rilrender :inline => '$${hello}', :locals => { $${name} => '$${value}'$${4} }render (inline, locals)
ritrender :inline => '$${hello}', :type => $${rxml}render (inline, type)
rlrender :layout => '$${layoutname}'render (layout)
rnrender :nothing => $${true}render (nothing)
rnsrender :nothing => $${true}, :status => $${401}render (nothing, status)
rprender :partial => '$${item}'render (partial)
rpcrender :partial => '$${item}', :collection => $${items}render (partial, collection)
rplrender :partial => '$${item}', :locals => { :$${name} => '$${value}'$${4} }render (partial, locals)
rporender :partial => '$${item}', :object => $${object}render (partial, object)
rcearender_component :action => '$${index}'render_component (action)
rcecrender_component :controller => '$${items}'render_component (controller)
rcecarender_component :controller => '$${items}', :action => '$${index}'render_component (controller, action)
rarender :action => '$${index}'render (action)
ralrender :action => '$${index}', :layout => '{default}'render (action, layout)

redirect_to

略語展開結果説明
rearedirect_to :action => '$${index}'redirect_to (action)
reairedirect_to :action => '$${show}', :id => $${item}redirect_to (action, id)
recredirect_to :controller => '$${items}'redirect_to (controller)
recaredirect_to :controller => '$${items}', :action => '$${list}'redirect_to (controller, action)
recairedirect_to :controller => '$${items}', :action => '$${show}', :id => $${item}redirect_to (controller, action, id)

rails

略語展開結果説明
rdlRAILS_DEFAULT_LOGGER.debug '$${message}'$.RAILS_DEFAULT_LOGGER.debug
nr@$${item}.new_record?item.new_record?

model

略語展開結果説明
vavalidates_associated :$${attribute}validates_associated
vcvalidates_confirmation_of :$${attribute}validates_confirmation_of
vevalidates_exclusion_of :$${attribute}validates_exclusion_of
vuvalidates_uniqueness_of :$${attribute}validates_uniqueness_of
vpifvalidates_presence_of :$${attribute}, :if => proc { |obj| $${condition} }validates_presence_of if
vpvalidates_presence_of :$${attribute}validates_presence_of
vlvalidates_length_of :$${attribute}, :within => $${20}validates_length_of
btbelongs_to :$${model}belongs_to
hmhas_many :$${objects}has_many
hmthas_many :$${objects}, :through => :$${,rails-snippets-feature:prev-has-many-table-name}has_many :through
hohas_one :$${object}has_one
habtmhas_and_belongs_to_many :$${object}has_and_belongs_to_many

migrations

略語展開結果説明
tclst.column :$${title}, :$${string}\n$>tcls$.create several columns
tclt.column :$${title}, :$${string}$.create column
tclnt.column :$${title}, :$${string}, :null => false$.create column :null => false
acladd_column :$${,rails-snippets-feature:migration-table-name}, :$${column}, :$${string}add column
aiadd_index :$${,rails-snippets-feature:migration-table-name}, $${column}add index
aiuadd_index :$${,rails-snippets-feature:migration-table-name}, $${column}, :unique => trueadd unique index
rmclremove_column :$${,rails-snippets-feature:migration-table-name}, :$${column}remove column
reclrename_column :$${column}, :$${new_column}rename column
dtdrop_table :$${,rails-snippets-feature:migration-table-name}$.drop table
ctcreate_table :$${,rails-snippets-feature:migration-table-name} do |t|\n$>tcls$.\nend$>create_table
retrename_table :$${,rails-snippets-feature:migration-table-name}, :$${new_name}$.rename table

environment

略語展開結果説明
logdlogger.debug '$${message}'$.logger.debug
logelogger.error '$${message}'$.logger.error
logflogger.fatal '$${message}'$.logger.fatal
logilogger.info '$${message}'$.logger.info
logwlogger.warn '$${message}'$.logger.warn
parparams[:$${id}]params[...]
sessionsession[:$${User}]session[...]
flashflash[:$${notice}] = '$${Successfully}'$.flash[...]

tests

略語展開結果説明
fix$${,rails-snippets-feature:fixture}(:$${one})$.|models(:name)|);functional tests

assertions

略語展開結果説明
artassert_redirected_to :action => '$${index}'assert_redirected_to
asassert $${test}assert(...)
asaassert assigns(:$${,rails-snippets-feature:model-name})assert assigns(...)
aseassert_equal $${expected}, $${actual}assert_equal(...)
asidassert_in_delta $${expected_float}, $${actual_float}, $${20}assert_in_delta(...)
asioassert_instance_of $${ExpectedClass}, $${actual_instance}assert_instance_of(...)
askoassert_kind_of $${ExpectedKind}, $${actual_instance}assert_kind_of(...)
asmassert_match(/$${expected_pattern}/, $${actual_string})assert_match(...)
asnassert_nil $${instance}assert_nil(...)
asneassert_not_equal $${unexpected}, $${actual}assert_not_equal(...)
asnmassert_no_match(/$${unexpected_pattern}/, $${actual_string})assert_no_match(...)
asnnassert_not_nil $${instance}assert_not_nil(...)
asnrassert_nothing_raised $${Exception} { $. }assert_nothing_raised(...) { ... }
asnsassert_not_same $${unexpected}, $${actual}assert_not_same(...)
asntassert_nothing_thrown { $. }assert_nothing_thrown { ... }
asoassert_operator $${left}, :$${operator}, $${right}assert_operator(...)
asrassert_raise $${Exception} { $. }assert_raise(...) { ... }
asreassert_response :$${success}assert_response
asrtassert_respond_to $${object}, :$${method}assert_respond_to(...)
assassert_same $${expected}, $${actual}assert_same(...)
assdassert_send [$${object}, :$${message}, $${args}]assert_send(...)
astassert_throws :$${expected} { $. }assert_throws(...) { ... }
astmassert_template '$${index}'assert_template