Created
February 25, 2010 05:20
-
-
Save syntaxritual/314263 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def partial(template, locals={}) | |
haml("_#{template}".to_sym, :locals => locals, :layout => false) | |
end | |
def errors_on(object, field) | |
return "" unless errors = object.errors.on(field) | |
errors.map {|e| e.gsub(/#{field} /i, "") }.join(", ") | |
end | |
def error_class(object, field) | |
object.errors.on(field).nil? ? "" : "with_errors" | |
end | |
def checkbox(name, condition, extras={}) | |
attrs = {:name => name, :type => "checkbox", :value => "1"} | |
attrs[:checked] = !!condition | |
attrs.update(extras) | |
end | |
def dropdown(name, id, options, selected="") | |
haml_tag(:select, :id => id, :name => name) { | |
options.each { |opt| | |
haml_tag :option, opt, :value => opt, :selected => (opt == selected) | |
} | |
} | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
%form{ :method => "post", :action => (@project.new? ? root_path : project_path(@project)) } | |
- unless @project.new? | |
.hidden | |
%input{ :name => "_method", :type => "hidden", :value => "put" } | |
%p.required{ :class => error_class(@project, :name) } | |
%label{ :for => "project_name" }< | |
&== Name #{errors_on @project, :name} | |
%input.text#project_name{ :name => "project_data[name]", :type => "text", :value => h(@project.name) } | |
%p.required{ :class => error_class(@project, :uri) } | |
%label{ :for => "project_repository" }< | |
&== Repository URI#{errors_on @project, :uri} | |
%input.text#project_repository{ :name => "project_data[uri]", :type => "text", :value => h(@project.uri) } | |
%p.normal{ :class => error_class(@project, :branch) } | |
%label{ :for => "project_branch" }< | |
&== Branch to track #{errors_on @project, :branch} | |
%input.text#project_branch{ :name => "project_data[branch]", :type => "text", :value => h(@project.branch) } | |
%p.normal{ :class => error_class(@project, :command) } | |
%label{ :for => "project_build_script" } | |
&== Build script #{errors_on @project, :command} | |
%textarea#project_build_script{ :name => "project_data[command]", :cols => 40, :rows => 2 } | |
&== #{@project.command.to_s} | |
%p.normal.checkbox | |
%label{ :for => "project_public" } Public project | |
%input.hidden{ :name => "project_data[public]", :value => "0", :type => "hidden" } | |
%input.checkbox#project_public{ checkbox("project_data[public]", @project.public?) } | |
- notifier_form | |
%p.submit | |
%button.positive{ :type => "submit" }= @project.new? ? "Create Project" : "Update Project" | |
- unless @project.new? | |
%form{ :method => "post", :action => project_path(@project) } | |
.hidden | |
%input{ :name => "_method", :type => "hidden", :value => "delete" } | |
%h2 Delete this project | |
%p.submit.destroy | |
This will delete the project and all the builds in the system | |
%button.negative{ :type => "submit" } Yes, I'm sure, nuke it |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment