%h3.page-title
  = @snippet.new_record? ? "New Snippet" : "Edit Snippet ##{@snippet.id}"
%hr
.snippet-form-holder
  = form_for [@project, @snippet], as: :project_snippet, url: url, html: {class: "form-horizontal snippet-form"} do |f|
    -if @snippet.errors.any?
      .alert.alert-danger
        %ul
          - @snippet.errors.full_messages.each do |msg|
            %li= msg

    .form-group
      = f.label :title, class: 'control-label'
      .col-sm-10= f.text_field :title, placeholder: "Example Snippet", class: 'form-control', required: true
    .form-group
      .file-editor
        = f.label :file_name, "File", class: 'control-label'
        .col-sm-10
          .file-holder.snippet
            .file-title
              = f.text_field :file_name, placeholder: "example.rb", class: 'form-control snippet-file-name', required: true
            .file-content.code
              %pre#editor= @snippet.content
              = f.hidden_field :content, class: 'snippet-file-content'

    .form-actions
      - if @snippet.new_record?
        = f.submit 'Create snippet', class: "btn-create btn"
      - else
        = f.submit 'Save', class: "btn-save btn"

      - unless @snippet.new_record?
        .pull-right.prepend-left-20
          = link_to 'Remove snippet', project_snippet_path(@project, @snippet), data: { confirm: 'Are you sure?' }, method: :delete, class: "btn pull-right btn-remove delete-snippet prepend-left-10", id: "destroy_snippet_#{@snippet.id}"
      = link_to "Cancel", project_snippets_path(@project), class: "btn btn-cancel"

:javascript
  var editor = ace.edit("editor");
  $(".snippet-form-holder form").submit(function(){
    $(".snippet-file-content").val(editor.getValue());
  });