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
= form_for [@project, @snippet] do |f|
-if @snippet.errors.any? -if @snippet.errors.any?
.alert-message.block-message.error .alert-message.block-message.error
%ul %ul
...@@ -10,19 +11,31 @@ ...@@ -10,19 +11,31 @@
.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
= f.label :file_name
.input= f.text_field :file_name, placeholder: "example.rb"
.clearfix .clearfix
= f.label "Lifetime" = f.label "Lifetime"
.input= f.select :expires_at, lifetime_select_options, {}, {class: 'chosen span2'} .input= f.select :expires_at, lifetime_select_options, {}, {class: 'chosen span2'}
.clearfix .clearfix
= f.label :content, "Code" .file-editor
.input= f.text_area :content, class: "span8" = f.label :file_name, "File"
.input
.file_holder.snippet
.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 .form-actions
= f.submit 'Save', class: "primary btn" = f.submit 'Save', class: "save-btn btn"
= link_to "Cancel", project_snippets_path(@project), class: " btn" = link_to "Cancel", project_snippets_path(@project), class: " btn"
- unless @snippet.new_record? - 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}" .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());
});
= 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