Commit bca7bddd3d0c6327e7ce0ce86874d72d1c76788f
1 parent
273c0d2a
Exists in
master
and in
4 other branches
Add ace editor to snippets
Showing
5 changed files
with
49 additions
and
27 deletions
Show diff stats
app/assets/stylesheets/main.scss
| ... | ... | @@ -89,6 +89,7 @@ $baseLineHeight: 18px !default; |
| 89 | 89 | @import "sections/commits.scss"; |
| 90 | 90 | @import "sections/issues.scss"; |
| 91 | 91 | @import "sections/projects.scss"; |
| 92 | +@import "sections/snippets.scss"; | |
| 92 | 93 | @import "sections/merge_requests.scss"; |
| 93 | 94 | @import "sections/graph.scss"; |
| 94 | 95 | @import "sections/events.scss"; | ... | ... |
app/views/snippets/_form.html.haml
| 1 | 1 | %h3.page_title |
| 2 | 2 | = @snippet.new_record? ? "New Snippet" : "Edit Snippet ##{@snippet.id}" |
| 3 | 3 | %hr |
| 4 | -= form_for [@project, @snippet] do |f| | |
| 5 | - -if @snippet.errors.any? | |
| 6 | - .alert-message.block-message.error | |
| 7 | - %ul | |
| 8 | - - @snippet.errors.full_messages.each do |msg| | |
| 9 | - %li= msg | |
| 4 | +.snippet-form-holder | |
| 5 | + = form_for [@project, @snippet] do |f| | |
| 6 | + -if @snippet.errors.any? | |
| 7 | + .alert-message.block-message.error | |
| 8 | + %ul | |
| 9 | + - @snippet.errors.full_messages.each do |msg| | |
| 10 | + %li= msg | |
| 10 | 11 | |
| 11 | - .clearfix | |
| 12 | - = f.label :title | |
| 13 | - .input= f.text_field :title, placeholder: "Example Snippet" | |
| 14 | - .clearfix | |
| 15 | - = f.label :file_name | |
| 16 | - .input= f.text_field :file_name, placeholder: "example.rb" | |
| 17 | - .clearfix | |
| 18 | - = f.label "Lifetime" | |
| 19 | - .input= f.select :expires_at, lifetime_select_options, {}, {class: 'chosen span2'} | |
| 20 | - .clearfix | |
| 21 | - = f.label :content, "Code" | |
| 22 | - .input= f.text_area :content, class: "span8" | |
| 12 | + .clearfix | |
| 13 | + = f.label :title | |
| 14 | + .input= f.text_field :title, placeholder: "Example Snippet", class: 'input-xlarge', required: true | |
| 15 | + .clearfix | |
| 16 | + = f.label "Lifetime" | |
| 17 | + .input= f.select :expires_at, lifetime_select_options, {}, {class: 'chosen span2'} | |
| 18 | + .clearfix | |
| 19 | + .file-editor | |
| 20 | + = f.label :file_name, "File" | |
| 21 | + .input | |
| 22 | + .file_holder.snippet | |
| 23 | + .file_title | |
| 24 | + = f.text_field :file_name, placeholder: "example.rb", class: 'snippet-file-name', required: true | |
| 25 | + .file_content.code | |
| 26 | + %pre#editor= @snippet.content | |
| 27 | + = f.hidden_field :content, class: 'snippet-file-content' | |
| 28 | + | |
| 29 | + .form-actions | |
| 30 | + = f.submit 'Save', class: "save-btn btn" | |
| 31 | + = link_to "Cancel", project_snippets_path(@project), class: " btn" | |
| 32 | + - unless @snippet.new_record? | |
| 33 | + .right= link_to 'Destroy', [@project, @snippet], confirm: 'Are you sure?', method: :delete, class: "btn right danger delete-snippet", id: "destroy_snippet_#{@snippet.id}" | |
| 34 | + | |
| 35 | + | |
| 36 | +:javascript | |
| 37 | + var editor = ace.edit("editor"); | |
| 38 | + $(".snippet-form-holder form").submit(function(){ | |
| 39 | + $(".snippet-file-content").val(editor.getValue()); | |
| 40 | + }); | |
| 23 | 41 | |
| 24 | - .form-actions | |
| 25 | - = f.submit 'Save', class: "primary btn" | |
| 26 | - = link_to "Cancel", project_snippets_path(@project), class: " btn" | |
| 27 | - - unless @snippet.new_record? | |
| 28 | - .right= link_to 'Destroy', [@project, @snippet], confirm: 'Are you sure?', method: :delete, class: "btn right danger delete-snippet", id: "destroy_snippet_#{@snippet.id}" | ... | ... |
app/views/snippets/show.html.haml
spec/requests/snippets_spec.rb
| ... | ... | @@ -48,11 +48,11 @@ describe "Snippets" do |
| 48 | 48 | page.current_path.should == new_project_snippet_path(project) |
| 49 | 49 | end |
| 50 | 50 | |
| 51 | - describe "fill in" do | |
| 51 | + describe "fill in", js: true do | |
| 52 | 52 | before do |
| 53 | 53 | fill_in "snippet_title", with: "login function" |
| 54 | 54 | fill_in "snippet_file_name", with: "test.rb" |
| 55 | - fill_in "snippet_content", with: "def login; end" | |
| 55 | + page.execute_script("editor.insert('def login; end');") | |
| 56 | 56 | end |
| 57 | 57 | |
| 58 | 58 | it { expect { click_button "Save" }.to change {Snippet.count}.by(1) } |
| ... | ... | @@ -83,7 +83,6 @@ describe "Snippets" do |
| 83 | 83 | before do |
| 84 | 84 | fill_in "snippet_title", with: "login function" |
| 85 | 85 | fill_in "snippet_file_name", with: "test.rb" |
| 86 | - fill_in "snippet_content", with: "def login; end" | |
| 87 | 86 | end |
| 88 | 87 | |
| 89 | 88 | it { expect { click_button "Save" }.to_not change {Snippet.count} } | ... | ... |