Commit bca7bddd authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Add ace editor to snippets

parent 273c0d2a
...@@ -89,6 +89,7 @@ $baseLineHeight: 18px !default; ...@@ -89,6 +89,7 @@ $baseLineHeight: 18px !default;
@import "sections/commits.scss"; @import "sections/commits.scss";
@import "sections/issues.scss"; @import "sections/issues.scss";
@import "sections/projects.scss"; @import "sections/projects.scss";
@import "sections/snippets.scss";
@import "sections/merge_requests.scss"; @import "sections/merge_requests.scss";
@import "sections/graph.scss"; @import "sections/graph.scss";
@import "sections/events.scss"; @import "sections/events.scss";
......
.snippet.file_holder {
.file_title {
.snippet-file-name {
position: relative;
top: -4px;
left: -4px;
}
}
}
%h3.page_title %h3.page_title
= @snippet.new_record? ? "New Snippet" : "Edit Snippet ##{@snippet.id}" = @snippet.new_record? ? "New Snippet" : "Edit Snippet ##{@snippet.id}"
%hr %hr
= form_for [@project, @snippet] do |f| .snippet-form-holder
-if @snippet.errors.any? = form_for [@project, @snippet] do |f|
.alert-message.block-message.error -if @snippet.errors.any?
%ul .alert-message.block-message.error
- @snippet.errors.full_messages.each do |msg| %ul
%li= msg - @snippet.errors.full_messages.each do |msg|
%li= msg
.clearfix .clearfix
= f.label :title = f.label :title
.input= f.text_field :title, placeholder: "Example Snippet" .input= f.text_field :title, placeholder: "Example Snippet", class: 'input-xlarge', required: true
.clearfix .clearfix
= f.label :file_name = f.label "Lifetime"
.input= f.text_field :file_name, placeholder: "example.rb" .input= f.select :expires_at, lifetime_select_options, {}, {class: 'chosen span2'}
.clearfix .clearfix
= f.label "Lifetime" .file-editor
.input= f.select :expires_at, lifetime_select_options, {}, {class: 'chosen span2'} = f.label :file_name, "File"
.clearfix .input
= f.label :content, "Code" .file_holder.snippet
.input= f.text_area :content, class: "span8" .file_title
= f.text_field :file_name, placeholder: "example.rb", class: 'snippet-file-name', required: true
.file_content.code
%pre#editor= @snippet.content
= f.hidden_field :content, class: 'snippet-file-content'
.form-actions
= f.submit 'Save', class: "save-btn btn"
= link_to "Cancel", project_snippets_path(@project), class: " btn"
- unless @snippet.new_record?
.right= link_to 'Destroy', [@project, @snippet], confirm: 'Are you sure?', method: :delete, class: "btn right danger delete-snippet", id: "destroy_snippet_#{@snippet.id}"
:javascript
var editor = ace.edit("editor");
$(".snippet-form-holder form").submit(function(){
$(".snippet-file-content").val(editor.getValue());
});
.form-actions
= f.submit 'Save', class: "primary btn"
= link_to "Cancel", project_snippets_path(@project), class: " btn"
- unless @snippet.new_record?
.right= link_to 'Destroy', [@project, @snippet], confirm: 'Are you sure?', method: :delete, class: "btn right danger delete-snippet", id: "destroy_snippet_#{@snippet.id}"
= render "projects/project_head" = render "projects/project_head"
%h3 %h3.page_title
= @snippet.title = @snippet.title
%small= @snippet.file_name %small= @snippet.file_name
- if can?(current_user, :admin_snippet, @project) || @snippet.author == current_user - if can?(current_user, :admin_snippet, @project) || @snippet.author == current_user
......
...@@ -48,11 +48,11 @@ describe "Snippets" do ...@@ -48,11 +48,11 @@ describe "Snippets" do
page.current_path.should == new_project_snippet_path(project) page.current_path.should == new_project_snippet_path(project)
end end
describe "fill in" do describe "fill in", js: true do
before do before do
fill_in "snippet_title", with: "login function" fill_in "snippet_title", with: "login function"
fill_in "snippet_file_name", with: "test.rb" fill_in "snippet_file_name", with: "test.rb"
fill_in "snippet_content", with: "def login; end" page.execute_script("editor.insert('def login; end');")
end end
it { expect { click_button "Save" }.to change {Snippet.count}.by(1) } it { expect { click_button "Save" }.to change {Snippet.count}.by(1) }
...@@ -83,7 +83,6 @@ describe "Snippets" do ...@@ -83,7 +83,6 @@ describe "Snippets" do
before do before do
fill_in "snippet_title", with: "login function" fill_in "snippet_title", with: "login function"
fill_in "snippet_file_name", with: "test.rb" fill_in "snippet_file_name", with: "test.rb"
fill_in "snippet_content", with: "def login; end"
end end
it { expect { click_button "Save" }.to_not change {Snippet.count} } it { expect { click_button "Save" }.to_not change {Snippet.count} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment