Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

add more rails snippets

  • Loading branch information...
commit 1ebd6e74183b0b37dec009acb03ef40bf424f06c 1 parent 2f39291
@kaichen authored
View
59 eruby-rails_view.snippets
@@ -0,0 +1,59 @@
+# Rails View
+
+snippet h
+ <%= h ${1} %>
+snippet contf
+ <% content_for :${1:yield_label_in_layout} do -%>
+ ${2}
+ <% end -%>
+
+# form
+snippet ff
+ <% form_for @${1:model} do |f| -%>
+ <%= f.error_messages %>
+ <%= f.submit "${2:button}" %>
+ <% end -%>
+snippet ffff
+ <%= f.file_field :${1:attribute} %>
+snippet ffhf
+ <%= f.hidden_field :${1:attribute} %>
+snippet ffl
+ <%= f.label :${1:attribute}, '${2:label}' %>
+snippet ffpf
+ <%= f.password_field :${1:attribute} %>
+snippet ffrb
+ <%= f.radio_button :${1:attribute}, :${2:tag_value} %>
+snippet ffs
+ <%= f.submit "${1:Submit}" %>
+snippet ffta
+ <%= f.text_area :${1:attribute} %>
+snippet fftf
+ <%= f.text_field :${1:attribute} %>
+snippet fieldsf
+ <% fields_for :${1:model}, @${2:model} do |f| -%>
+ ${3}
+ <% end -%>
+snippet formt
+ <% form_tag(:action => "${1:action}") do -%>
+ ${2}
+ <% end -%>
+
+snippet =jsit
+ <%= javascript_include_tag('${1:javascript_filename}') %>
+snippet =sslt
+ <%= stylesheet_link_tag "${1:stylesheet_filename}" %>
+
+snippet it
+ <%= image_tag "${1:image_path}" %>
+snippet lt
+ <%= link_to '${1:caption}', ${2:path} %>
+snippet ltp
+ <%= link_to '${1:caption}', ${2:model}_path(@${3:instance}) %>
+snippet ltpp
+ <%= link_to '${1:caption}', ${2:model}s_path %>
+
+snippet renderp
+ <%= render :partial => '${1:partial}' %>
+snippet rendert
+ <%= render :template => "${1:file}" %>
+
View
48 eruby.snippets
@@ -1,43 +1,33 @@
# Eruby
snippet each
- <% ${1:collection}.each do |${2:member}| %>
+ <% ${1:collection}.each do |${2:member}| -%>
${3}
- <% end %>
-snippet h
- <%=h ${1} %>
+ <% end -%>
snippet =
<%= ${1} %>
snippet -
- <% ${1} %>
-snippet rendp
- <%= render :partial => '${1}' %>
-snippet rendc
- <%= render :partial => @${1} %>
-snippet lt
- <%= link_to '${1:caption}>', ${2}> %>
-
+ <% ${1} -%>
snippet if
- <% if ${1:cond} %>
+ <% if ${1:cond} -%>
${2}
- <% end %>
-
+ <% end -%>
snippet unless
- <% unless ${1:cond} %>
+ <% unless ${1:cond} -%>
${2}
- <% end %>
-
+ <% end -%>
+snippet ife
+ <% if ${1:cond} -%>
+ ${2}
+ <% else -%>
+ ${3}
+ <% end -%>
+snippet unlesse
+ <% unless ${1:cond} -%>
+ ${2}
+ <% else -%>
+ ${3}
+ <% end -%>
snippet yield
<%= yield :${1:partial} %>
-snippet ff
- <% form_for(@${1:model}) do |f| %>
- <%= f.error_messages %>
- <%= f.submit "${2:button}" %>
- <% end %>
-
-snippet =jsit
- <%= javascript_include_tag('${1:javascript_filename}') %>
-
-snippet =sslt
- <%= stylesheet_link_tag "${1:stylesheet_filename}" %>
View
50 ruby-rails.snippets
@@ -1,42 +1,12 @@
# Rails
-# active record associations
-snippet bt
- belongs_to :${1}
-snippet ho
- has_one :${1}
-snippet hm
- has_many :${1}
-snippet habtm
- has_and_belongs_to_many :${1}
-snippet hmt
- has_many :${1:association}, :through => ${2}
-
-# active record validations
-snippet vpo
- validates_presence_of :${1:attribute}
-snippet vpos
- validates_presence_of :${1:attribute}, :scope => ${2:scope}
-snippet vuniq
- validates_uniqueness_of :${1:attribute}
-snippet vuniqs
- validates_uniqueness_of :${1:attribute}, :scope => ${2:scope}
-snippet vacc
- validates_acceptance_of :${1:attribute}
-snippet vass
- validates_associated :${1:association}
-snippet vconfirm
- validates_confirmation_of :${1:attribute}
-snippet vexclus
- validates_exclusion_of :${1:attribute}, :in => ${2:range}
-snippet vformat
- validates_format_of :${1:attribute}, :with => /${2:regex}/i
-snippet vinclus
- validates_inclusion_of :${1:attribute}, :in => ${2:range}
-snippet vlength
- validates_length_of :${1:attribute}, ${2}
-snippet vnumeric
- validates_numericality_of :${1:attribute}
-
-# actionpack controller
-
+snippet logi
+ logger.info { "${1:message}" }${2}
+snippet logd
+ logger.debug { "${1:message}" }${2}
+snippet logw
+ logger.warn { "${1:message}" }${2}
+snippet logd
+ logger.error { "${1:message}" }${2}
+snippet logf
+ logger.fatal { "${1:message}" }${2}
View
10 ruby-rails_controller.snippets
@@ -0,0 +1,10 @@
+# Actionpack controller
+
+snippet respond_to
+ respond_to do |wants|
+ wants.${1:html}${2}
+ end
+snippet wants
+ wants.${1:js|json|xml|html}${2}
+snippet flash
+ flash[:${1:notice}] = "${2}"
View
0  ruby-rails_migration.snippets
No changes.
View
39 ruby-rails_model.snippets
@@ -0,0 +1,39 @@
+# ActiveRecord
+
+# associations
+snippet bt
+ belongs_to :${1}
+snippet ho
+ has_one :${1}
+snippet hm
+ has_many :${1}
+snippet habtm
+ has_and_belongs_to_many :${1}
+snippet hmt
+ has_many :${1:association}, :through => ${2}
+
+# validations
+snippet vpo
+ validates_presence_of :${1:attribute}
+snippet vpos
+ validates_presence_of :${1:attribute}, :scope => ${2:scope}
+snippet vuniq
+ validates_uniqueness_of :${1:attribute}
+snippet vuniqs
+ validates_uniqueness_of :${1:attribute}, :scope => ${2:scope}
+snippet vacc
+ validates_acceptance_of :${1:attribute}
+snippet vass
+ validates_associated :${1:association}
+snippet vconfirm
+ validates_confirmation_of :${1:attribute}
+snippet vexclus
+ validates_exclusion_of :${1:attribute}, :in => ${2:range}
+snippet vformat
+ validates_format_of :${1:attribute}, :with => /${2:regex}/i
+snippet vinclus
+ validates_inclusion_of :${1:attribute}, :in => ${2:range}
+snippet vlength
+ validates_length_of :${1:attribute}, ${2}
+snippet vnumeric
+ validates_numericality_of :${1:attribute}
View
28 ruby-rspec.snippets
@@ -1,31 +1,39 @@
# rspec
snippet spechelper
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')${1}
-snippet desc
+snippet des
describe ${1:description}" do
${2}
end
-snippet descd
- describe ${1:class}, "${2:description}" do
+snippet desc
+ describe ${1:class} do
before do
- ${3}
+ ${2}
end
end
-snippet descc
- describe ${1:class} do
+snippet descd
+ describe ${1:class}, "${2:description}" do
before do
- ${2}
+ ${3}
end
end
-snippet descb
+snippet desd
describe "${1:description}" do
before do
${2}
end
end
+snippet before
+ before(:${1:each}) do
+ ${2}
+ end
+snippet after
+ after(:${1:each}) do
+ ${2}
+ end
snippet it
it "should ${1:description}" do
${2}
@@ -49,7 +57,9 @@ snippet atshbe
# matchers
snippet sheq
- should == ${1}
+ ${1:targe}.should == ${2}
+snippet shbe
+ ${1:target}.should be_${2:result}
# rspec-rails
snippet itres
View
2  ruby-shoulda.snippets
@@ -79,7 +79,7 @@ snippet shroute
should_route :${1:method}, "${2:path}", :action => :${3}
# Shoulda view macros
-snippet shreaform
+snippet shrenderaform
should_render_a_form
snippet shrender_page_with_metadata
should_render_page_with_metadata :${1:meta} => ${2:content}
Please sign in to comment.
Something went wrong with that request. Please try again.