Revised the Rails snippets according to Ruby code styles.
This commit is contained in:
parent
8bb5faebbc
commit
e311671659
@ -1,5 +1,5 @@
|
|||||||
snippet art
|
snippet art
|
||||||
assert_redirected_to ${1::action => "${2:index}"}
|
assert_redirected_to ${1:action}: '${2:index}'
|
||||||
snippet artnp
|
snippet artnp
|
||||||
assert_redirected_to ${1:parent}_${2:child}_path(${3:@$1}, ${0:@$2})
|
assert_redirected_to ${1:parent}_${2:child}_path(${3:@$1}, ${0:@$2})
|
||||||
snippet artnpp
|
snippet artnpp
|
||||||
@ -9,19 +9,21 @@ snippet artp
|
|||||||
snippet artpp
|
snippet artpp
|
||||||
assert_redirected_to ${0:model}s_path
|
assert_redirected_to ${0:model}s_path
|
||||||
snippet asd
|
snippet asd
|
||||||
assert_difference "${1:Model}.${2:count}", ${3:1} do
|
assert_difference '${1:Model}.${2:count}', ${3:1} do
|
||||||
${0}
|
${0}
|
||||||
end
|
end
|
||||||
snippet asnd
|
snippet asnd
|
||||||
assert_no_difference "${1:Model}.${2:count}" do
|
assert_no_difference '${1:Model}.${2:count}' do
|
||||||
${0}
|
${0}
|
||||||
end
|
end
|
||||||
snippet asre
|
snippet asre
|
||||||
assert_response :${1:success}, @response.body
|
assert_response :${1:success}, @response.body
|
||||||
snippet asrj
|
snippet asrj
|
||||||
assert_rjs :${1:replace}, "${0:dom id}"
|
assert_rjs :${1:replace}, '${0:dom id}'
|
||||||
snippet ass assert_select(..)
|
snippet ass assert_select(..)
|
||||||
assert_select '${1:path}', :${2:text} => '${3:inner_html' ${4:do}
|
assert_select '${1:path}', ${2:text}: '${3:inner_html}' ${4:do}
|
||||||
|
${0}
|
||||||
|
end
|
||||||
snippet ba
|
snippet ba
|
||||||
before_action :${0:method}
|
before_action :${0:method}
|
||||||
snippet bf
|
snippet bf
|
||||||
@ -29,7 +31,7 @@ snippet bf
|
|||||||
snippet bt
|
snippet bt
|
||||||
belongs_to :${0:association}
|
belongs_to :${0:association}
|
||||||
snippet btp
|
snippet btp
|
||||||
belongs_to :${1:association}, :polymorphic => true
|
belongs_to :${1:association}, polymorphic: true
|
||||||
snippet crw
|
snippet crw
|
||||||
cattr_accessor :${0:attr_names}
|
cattr_accessor :${0:attr_names}
|
||||||
snippet defcreate
|
snippet defcreate
|
||||||
@ -40,10 +42,10 @@ snippet defcreate
|
|||||||
if @$1.save
|
if @$1.save
|
||||||
flash[:notice] = '$2 was successfully created.'
|
flash[:notice] = '$2 was successfully created.'
|
||||||
format.html { redirect_to(@$1) }
|
format.html { redirect_to(@$1) }
|
||||||
format.xml { render :xml => @$1, :status => :created, :location => @$1 }
|
format.xml { render xml: @$1, status: :created, location: @$1 }
|
||||||
else
|
else
|
||||||
format.html { render :action => "new" }
|
format.html { render action: 'new' }
|
||||||
format.xml { render :xml => @$1.errors, :status => :unprocessable_entity }
|
format.xml { render xml: @$1.errors, status: :unprocessable_entity }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -67,7 +69,7 @@ snippet defindex
|
|||||||
|
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
format.html # index.html.erb
|
format.html # index.html.erb
|
||||||
format.xml { render :xml => @$1s }
|
format.xml { render xml: @$1s }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
snippet defnew
|
snippet defnew
|
||||||
@ -76,7 +78,7 @@ snippet defnew
|
|||||||
|
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
format.html # new.html.erb
|
format.html # new.html.erb
|
||||||
format.xml { render :xml => @$1 }
|
format.xml { render xml: @$1 }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
snippet defshow
|
snippet defshow
|
||||||
@ -85,7 +87,7 @@ snippet defshow
|
|||||||
|
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
format.html # show.html.erb
|
format.html # show.html.erb
|
||||||
format.xml { render :xml => @$1 }
|
format.xml { render xml: @$1 }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
snippet defupdate
|
snippet defupdate
|
||||||
@ -98,25 +100,25 @@ snippet defupdate
|
|||||||
format.html { redirect_to(@$1) }
|
format.html { redirect_to(@$1) }
|
||||||
format.xml { head :ok }
|
format.xml { head :ok }
|
||||||
else
|
else
|
||||||
format.html { render :action => "edit" }
|
format.html { render action: 'edit' }
|
||||||
format.xml { render :xml => @$1.errors, :status => :unprocessable_entity }
|
format.xml { render xml: @$1.errors, status: :unprocessable_entity }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
snippet dele delegate .. to
|
snippet dele delegate .. to
|
||||||
delegate :${1:methods}, :to => :${0:object}
|
delegate :${1:methods}, to: :${0:object}
|
||||||
snippet dele delegate .. to .. prefix .. allow_nil
|
snippet dele delegate .. to .. prefix .. allow_nil
|
||||||
delegate :${1:methods}, :to => :${2:object}, :prefix => :${3:prefix}, :allow_nil => ${0:allow_nil}
|
delegate :${1:methods}, to: :${2:object}, prefix: :${3:prefix}, allow_nil: ${0:allow_nil}
|
||||||
snippet flash
|
snippet flash
|
||||||
flash[:${1:notice}] = "${0}"
|
flash[:${1:notice}] = '${0}'
|
||||||
snippet habtm
|
snippet habtm
|
||||||
has_and_belongs_to_many :${1:object}, :join_table => "${2:table_name}", :foreign_key => "${3}_id"
|
has_and_belongs_to_many :${1:object}, join_table: '${2:table_name}', foreign_key: '${3}_id'
|
||||||
snippet hm
|
snippet hm
|
||||||
has_many :${0:object}
|
has_many :${0:object}
|
||||||
snippet hmd
|
snippet hmd
|
||||||
has_many :${1:other}s, :class_name => "${2:$1}", :foreign_key => "${3:$1}_id", :dependent => :destroy
|
has_many :${1:other}s, class_name: '${2:$1}', foreign_key: '${3:$1}_id', dependent: :destroy
|
||||||
snippet hmt
|
snippet hmt
|
||||||
has_many :${1:object}, :through => :${0:object}
|
has_many :${1:object}, through: :${0:object}
|
||||||
snippet ho
|
snippet ho
|
||||||
has_one :${0:object}
|
has_one :${0:object}
|
||||||
snippet hod
|
snippet hod
|
||||||
@ -124,31 +126,31 @@ snippet hod
|
|||||||
snippet i18
|
snippet i18
|
||||||
I18n.t('${1:type.key}')
|
I18n.t('${1:type.key}')
|
||||||
snippet ist
|
snippet ist
|
||||||
<%= image_submit_tag("${1:agree.png}", :id => "${2:id}"${0} %>
|
<%= image_submit_tag('${1:agree.png}', id: '${2:id}'${0}) %>
|
||||||
snippet log
|
snippet log
|
||||||
Rails.logger.${1:debug} ${0}
|
Rails.logger.${1:debug} ${0}
|
||||||
snippet log2
|
snippet log2
|
||||||
RAILS_DEFAULT_LOGGER.${1:debug} ${0}
|
RAILS_DEFAULT_LOGGER.${1:debug} ${0}
|
||||||
snippet logd
|
snippet logd
|
||||||
logger.debug { "${1:message}" }
|
logger.debug { '${1:message}' }
|
||||||
snippet loge
|
snippet loge
|
||||||
logger.error { "${1:message}" }
|
logger.error { '${1:message}' }
|
||||||
snippet logf
|
snippet logf
|
||||||
logger.fatal { "${1:message}" }
|
logger.fatal { '${1:message}' }
|
||||||
snippet logi
|
snippet logi
|
||||||
logger.info { "${1:message}" }
|
logger.info { '${1:message}' }
|
||||||
snippet logw
|
snippet logw
|
||||||
logger.warn { "${1:message}" }
|
logger.warn { '${1:message}' }
|
||||||
snippet mapc
|
snippet mapc
|
||||||
${1:map}.${2:connect} '${0:controller/:action/:id}'
|
${1:map}.${2:connect} '${0:controller/:action/:id}'
|
||||||
snippet mapca
|
snippet mapca
|
||||||
${1:map}.catch_all "*${2:anything}", :controller => "${3:default}", :action => "${4:error}"
|
${1:map}.catch_all '*${2:anything}', controller: '${3:default}', action: '${4:error}'
|
||||||
snippet mapr
|
snippet mapr
|
||||||
${1:map}.resource :${0:resource}
|
${1:map}.resource :${0:resource}
|
||||||
snippet maprs
|
snippet maprs
|
||||||
${1:map}.resources :${0:resource}
|
${1:map}.resources :${0:resource}
|
||||||
snippet mapwo
|
snippet mapwo
|
||||||
${1:map}.with_options :${2:controller} => '${3:thing}' do |$3|
|
${1:map}.with_options ${2:controller}: '${3:thing}' do |$3|
|
||||||
${0}
|
${0}
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -203,66 +205,66 @@ snippet mp
|
|||||||
snippet mrw
|
snippet mrw
|
||||||
mattr_accessor :${0:attr_names}
|
mattr_accessor :${0:attr_names}
|
||||||
snippet oa
|
snippet oa
|
||||||
order("${0:field}")
|
order('${0:field}')
|
||||||
snippet od
|
snippet od
|
||||||
order("${0:field} DESC")
|
order('${0:field} DESC')
|
||||||
snippet pa
|
snippet pa
|
||||||
params[:${1:id}]
|
params[:${1:id}]
|
||||||
snippet ra
|
snippet ra
|
||||||
render :action => "${0:action}"
|
render action: '${0:action}'
|
||||||
snippet ral
|
snippet ral
|
||||||
render :action => "${1:action}", :layout => "${0:layoutname}"
|
render action: '${1:action}', layout: '${0:layoutname}'
|
||||||
snippet rest
|
snippet rest
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
format.${1:html} { ${0} }
|
format.${1:html} { ${0} }
|
||||||
end
|
end
|
||||||
snippet rf
|
snippet rf
|
||||||
render :file => "${0:filepath}"
|
render file: '${0:filepath}'
|
||||||
snippet rfu
|
snippet rfu
|
||||||
render :file => "${1:filepath}", :use_full_path => ${0:false}
|
render file: '${1:filepath}', use_full_path: ${0:false}
|
||||||
snippet ri
|
snippet ri
|
||||||
render :inline => "${0:<%= 'hello' %>}"
|
render inline: "${0:<%= 'hello' %>}"
|
||||||
snippet ril
|
snippet ril
|
||||||
render :inline => "${1:<%= 'hello' %>}", :locals => { ${2::name} => "${3:value}"${0} }
|
render inline: "${1:<%= 'hello' %>}", locals: { ${2:name}: '${3:value}'${0} }
|
||||||
snippet rit
|
snippet rit
|
||||||
render :inline => "${1:<%= 'hello' %>}", :type => ${0::rxml}
|
render inline: "${1:<%= 'hello' %>}", type: ${0::rxml}
|
||||||
snippet rjson
|
snippet rjson
|
||||||
render :json => ${0:text to render}
|
render json: '${0:text to render}'
|
||||||
snippet rl
|
snippet rl
|
||||||
render :layout => "${0:layoutname}"
|
render layout: '${0:layoutname}'
|
||||||
snippet rn
|
snippet rn
|
||||||
render :nothing => ${0:true}
|
render nothing: ${0:true}
|
||||||
snippet rns
|
snippet rns
|
||||||
render :nothing => ${1:true}, :status => ${0:401}
|
render nothing: ${1:true}, status: ${0:401}
|
||||||
snippet rp
|
snippet rp
|
||||||
render :partial => "${0:item}"
|
render partial: '${0:item}'
|
||||||
snippet rpc
|
snippet rpc
|
||||||
render :partial => "${1:item}", :collection => ${0:@$1s}
|
render partial: '${1:item}', collection: ${0:@$1s}
|
||||||
snippet rpl
|
snippet rpl
|
||||||
render :partial => "${1:item}", :locals => { :${2:$1} => ${0:@$1}
|
render partial: '${1:item}', locals: { ${2:$1}: ${0:@$1} }
|
||||||
snippet rpo
|
snippet rpo
|
||||||
render :partial => "${1:item}", :object => ${0:@$1}
|
render partial: '${1:item}', object: ${0:@$1}
|
||||||
snippet rps
|
snippet rps
|
||||||
render :partial => "${1:item}", :status => ${0:500}
|
render partial: '${1:item}', status: ${0:500}
|
||||||
snippet rt
|
snippet rt
|
||||||
render :text => "${0:text to render}"
|
render text: '${0:text to render}'
|
||||||
snippet rtl
|
snippet rtl
|
||||||
render :text => "${1:text to render}", :layout => "${0:layoutname}"
|
render text: '${1:text to render}', layout: '${0:layoutname}'
|
||||||
snippet rtlt
|
snippet rtlt
|
||||||
render :text => "${1:text to render}", :layout => ${0:true}
|
render text: '${1:text to render}', layout: ${0:true}
|
||||||
snippet rts
|
snippet rts
|
||||||
render :text => "${1:text to render}", :status => ${0:401}
|
render text: '${1:text to render}', status: ${0:401}
|
||||||
snippet ru
|
snippet ru
|
||||||
render :update do |${1:page}|
|
render :update do |${1:page}|
|
||||||
$1.${0}
|
$1.${0}
|
||||||
end
|
end
|
||||||
snippet rxml
|
snippet rxml
|
||||||
render :xml => ${0:text to render}
|
render xml: '${0:text to render}'
|
||||||
snippet sc
|
snippet sc
|
||||||
scope :${1:name}, -> { where(${2:field}: ${0:value}) }
|
scope :${1:name}, -> { where(${2:field}: ${0:value}) }
|
||||||
snippet sl
|
snippet sl
|
||||||
scope :${1:name}, lambda do |${2:value}|
|
scope :${1:name}, lambda do |${2:value}|
|
||||||
where("${3:field = ?}", ${0:bind var})
|
where('${3:field = ?}', ${0:value})
|
||||||
end
|
end
|
||||||
snippet sha1
|
snippet sha1
|
||||||
Digest::SHA1.hexdigest(${0:string})
|
Digest::SHA1.hexdigest(${0:string})
|
||||||
@ -284,40 +286,40 @@ snippet sweeper
|
|||||||
end
|
end
|
||||||
snippet va validates_associated
|
snippet va validates_associated
|
||||||
validates_associated :${0:attribute}
|
validates_associated :${0:attribute}
|
||||||
snippet va validates .., :acceptance => true
|
snippet va validates .., acceptance: true
|
||||||
validates :${0:terms}, :acceptance => true
|
validates :${0:terms}, acceptance: true
|
||||||
snippet vc
|
snippet vc
|
||||||
validates :${0:attribute}, :confirmation => true
|
validates :${0:attribute}, confirmation: true
|
||||||
snippet ve
|
snippet ve
|
||||||
validates :${1:attribute}, :exclusion => { :in => ${0:%w( mov avi )} }
|
validates :${1:attribute}, exclusion: { in: ${0:%w( mov avi )} }
|
||||||
snippet vf
|
snippet vf
|
||||||
validates :${1:attribute}, :format => { :with => /${0:regex}/ }
|
validates :${1:attribute}, format: { with: /${0:regex}/ }
|
||||||
snippet vi
|
snippet vi
|
||||||
validates :${1:attribute}, :inclusion => { :in => %w(${0: mov avi }) }
|
validates :${1:attribute}, inclusion: { in: %w(${0: mov avi }) }
|
||||||
snippet vl
|
snippet vl
|
||||||
validates :${1:attribute}, :length => { :in => ${2:3}..${0:20} }
|
validates :${1:attribute}, length: { in: ${2:3}..${0:20} }
|
||||||
snippet vn
|
snippet vn
|
||||||
validates :${0:attribute}, :numericality => true
|
validates :${0:attribute}, numericality: true
|
||||||
snippet vp
|
snippet vp
|
||||||
validates :${0:attribute}, :presence => true
|
validates :${0:attribute}, presence: true
|
||||||
snippet vu
|
snippet vu
|
||||||
validates :${0:attribute}, :uniqueness => true
|
validates :${0:attribute}, uniqueness: true
|
||||||
snippet format
|
snippet format
|
||||||
format.${1:js|xml|html} { ${0} }
|
format.${1:js|xml|html} { ${0} }
|
||||||
snippet wc
|
snippet wc
|
||||||
where(${1:"conditions"}${0:, bind_var})
|
where(${1:'conditions'}${0:, bind_var})
|
||||||
snippet wf
|
snippet wf
|
||||||
where(${1:field} => ${0:value})
|
where(${1:field}: ${0:value})
|
||||||
snippet xdelete
|
snippet xdelete
|
||||||
xhr :delete, :${1:destroy}, :id => ${2:1}
|
xhr :delete, :${1:destroy}, id: ${2:1}
|
||||||
snippet xget
|
snippet xget
|
||||||
xhr :get, :${1:show}, :id => ${2:1}
|
xhr :get, :${1:show}, id: ${2:1}
|
||||||
snippet xpost
|
snippet xpost
|
||||||
xhr :post, :${1:create}, :${2:object} => { ${0} }
|
xhr :post, :${1:create}, ${2:object}: ${3:object}
|
||||||
snippet xput
|
snippet xput
|
||||||
xhr :put, :${1:update}, :id => ${2:1}, :${3:object} => { ${4} }
|
xhr :put, :${1:update}, id: ${2:1}, ${3:object}: ${4:object}
|
||||||
snippet test
|
snippet test
|
||||||
test "should ${1:do something}" do
|
test 'should ${1:do something}' do
|
||||||
${0}
|
${0}
|
||||||
end
|
end
|
||||||
###########################
|
###########################
|
||||||
@ -365,10 +367,10 @@ snippet tcb
|
|||||||
t.boolean :${1:title}
|
t.boolean :${1:title}
|
||||||
${0}
|
${0}
|
||||||
snippet tcbi
|
snippet tcbi
|
||||||
t.binary :${1:title}, :limit => ${2:2}.megabytes
|
t.binary :${1:title}, limit: ${2:2}.megabytes
|
||||||
${0}
|
${0}
|
||||||
snippet tcd
|
snippet tcd
|
||||||
t.decimal :${1:title}, :precision => ${2:10}, :scale => ${3:2}
|
t.decimal :${1:title}, precision: ${2:10}, scale: ${3:2}
|
||||||
${0}
|
${0}
|
||||||
snippet tcda
|
snippet tcda
|
||||||
t.date :${1:title}
|
t.date :${1:title}
|
||||||
@ -380,16 +382,16 @@ snippet tcf
|
|||||||
t.float :${1:title}
|
t.float :${1:title}
|
||||||
${0}
|
${0}
|
||||||
snippet tch
|
snippet tch
|
||||||
t.change :${1:name}, :${2:string}, :${3:limit} => ${4:80}
|
t.change :${1:name}, :${2:string}, ${3:limit}: ${4:80}
|
||||||
${0}
|
${0}
|
||||||
snippet tci
|
snippet tci
|
||||||
t.integer :${1:title}
|
t.integer :${1:title}
|
||||||
${0}
|
${0}
|
||||||
snippet tcl
|
snippet tcl
|
||||||
t.integer :lock_version, :null => false, :default => 0
|
t.integer :lock_version, null: false, default: 0
|
||||||
${0}
|
${0}
|
||||||
snippet tcr
|
snippet tcr
|
||||||
t.references :${1:taggable}, :polymorphic => { :default => '${2:Photo}' }
|
t.references :${1:taggable}, polymorphic: { default: '${2:Photo}' }
|
||||||
${0}
|
${0}
|
||||||
snippet tcs
|
snippet tcs
|
||||||
t.string :${1:title}
|
t.string :${1:title}
|
||||||
@ -446,9 +448,9 @@ snippet expb
|
|||||||
snippet experr
|
snippet experr
|
||||||
expect { ${1:object} }.to raise_error ${2:StandardError}, /${0:message_regex}/
|
expect { ${1:object} }.to raise_error ${2:StandardError}, /${0:message_regex}/
|
||||||
snippet shared
|
snippet shared
|
||||||
shared_examples ${0:"shared examples name"}
|
shared_examples ${0:'shared examples name'}
|
||||||
snippet ibl
|
snippet ibl
|
||||||
it_behaves_like ${0:"shared examples name"}
|
it_behaves_like ${0:'shared examples name'}
|
||||||
snippet it
|
snippet it
|
||||||
it '${1:spec_name}' do
|
it '${1:spec_name}' do
|
||||||
${0}
|
${0}
|
||||||
|
Loading…
Reference in New Issue
Block a user