FileTree: Allow output as hash, convert to JSON separately
This commit is contained in:

committed by
Sebastian Serth

parent
ad8743a7d0
commit
fb9672c7a4
@ -35,7 +35,7 @@
|
||||
.card-header.d-flex.justify-content-between.align-items-center.px-0.py-2
|
||||
.px-2 = I18n.t('exercises.editor_file_tree.file_root')
|
||||
.card-body.pt-0.pe-0.ps-1.pb-1
|
||||
#files data-entries=FileTree.new(@files).to_js_tree
|
||||
#files data-entries=FileTree.new(@files).to_js_tree_in_json
|
||||
div class=(@community_solution.exercise.hide_file_tree ? 'col-sm-12' : 'col-sm-9')
|
||||
div.editor-col.col.p-0 id='frames'
|
||||
- @files.each do |file|
|
||||
@ -52,7 +52,7 @@
|
||||
.card-header.d-flex.justify-content-between.align-items-center.px-0.py-2
|
||||
.px-2 = I18n.t('exercises.editor_file_tree.file_root')
|
||||
.card-body.pt-0.pe-0.ps-1.pb-1
|
||||
#own-files data-entries=FileTree.new(@own_files).to_js_tree
|
||||
#own-files data-entries=FileTree.new(@own_files).to_js_tree_in_json
|
||||
div class=(@community_solution.exercise.hide_file_tree ? 'col-sm-12' : 'col-sm-9')
|
||||
div.editor-col.col.p-0 id='own-frames'
|
||||
- @own_files.each do |file|
|
||||
|
@ -25,7 +25,7 @@ div.d-grid.enforce-bottom-margin id='sidebar-uncollapsed' class=(@exercise.hide_
|
||||
|
||||
.card-body.pt-0.pe-0.ps-1.pb-1
|
||||
|
||||
#files data-entries=FileTree.new(files).to_js_tree
|
||||
#files data-entries=FileTree.new(files).to_js_tree_in_json
|
||||
|
||||
hr
|
||||
|
||||
|
@ -22,7 +22,7 @@ h1
|
||||
#stats-editor.row
|
||||
- index = 0
|
||||
- all_files.each do |files|
|
||||
.files class=(@exercise.hide_file_tree ? 'd-none col-sm-3' : 'col-sm-3') data-index=index data-entries=FileTree.new(files).to_js_tree
|
||||
.files class=(@exercise.hide_file_tree ? 'd-none col-sm-3' : 'col-sm-3') data-index=index data-entries=FileTree.new(files).to_js_tree_in_json
|
||||
- index += 1
|
||||
div class=(@exercise.hide_file_tree ? 'col-sm-12' : 'col-sm-9')
|
||||
#current-file.editor
|
||||
|
@ -77,6 +77,10 @@ class FileTree
|
||||
core: {
|
||||
data: @root.children.map {|child| map_to_js_tree(child) },
|
||||
},
|
||||
}.to_json
|
||||
}
|
||||
end
|
||||
|
||||
def to_js_tree_in_json
|
||||
to_js_tree.to_json
|
||||
end
|
||||
end
|
||||
|
@ -180,8 +180,8 @@ describe FileTree do
|
||||
end
|
||||
end
|
||||
|
||||
describe '#to_js_tree' do
|
||||
let(:js_tree) { file_tree.to_js_tree }
|
||||
describe '#to_js_tree_in_json' do
|
||||
let(:js_tree) { file_tree.to_js_tree_in_json }
|
||||
|
||||
it 'returns a String' do
|
||||
expect(js_tree).to be_a(String)
|
||||
@ -196,7 +196,7 @@ describe FileTree do
|
||||
context 'with files' do
|
||||
let(:files) { build_list(:file, 10, context: nil, path: 'foo/bar/baz') }
|
||||
let(:file_tree) { described_class.new(files) }
|
||||
let(:js_tree) { file_tree.to_js_tree }
|
||||
let(:js_tree) { file_tree.to_js_tree_in_json }
|
||||
|
||||
it 'produces the required JSON format with a file' do
|
||||
# We ignore the root node and only use the children here
|
||||
|
Reference in New Issue
Block a user