Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
李少辉-开发者
gitlab-foss
提交
47aeacd7
G
gitlab-foss
项目概览
李少辉-开发者
/
gitlab-foss
通知
15
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
G
gitlab-foss
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
47aeacd7
编写于
3月 28, 2017
作者:
J
Jacob Schatz
浏览文件
操作
浏览文件
下载
差异文件
Merge branch 'ipython-notebook-viewer' into 'master'
iPython notebook viewer See merge request !10017
上级
5f6c32e1
0f790dbc
变更
9
展开全部
隐藏空白更改
内联
并排
Showing
9 changed file
with
6146 addition
and
0 deletion
+6146
-0
app/assets/javascripts/blob/notebook/index.js
app/assets/javascripts/blob/notebook/index.js
+81
-0
app/assets/javascripts/blob/notebook_viewer.js
app/assets/javascripts/blob/notebook_viewer.js
+3
-0
app/models/blob.rb
app/models/blob.rb
+6
-0
app/views/projects/blob/_notebook.html.haml
app/views/projects/blob/_notebook.html.haml
+5
-0
config/webpack.config.js
config/webpack.config.js
+2
-0
spec/javascripts/blob/notebook/index_spec.js
spec/javascripts/blob/notebook/index_spec.js
+159
-0
spec/javascripts/fixtures/notebook_viewer.html.haml
spec/javascripts/fixtures/notebook_viewer.html.haml
+1
-0
spec/models/blob_spec.rb
spec/models/blob_spec.rb
+19
-0
vendor/assets/javascripts/notebooklab.js
vendor/assets/javascripts/notebooklab.js
+5870
-0
未找到文件。
app/assets/javascripts/blob/notebook/index.js
0 → 100644
浏览文件 @
47aeacd7
/* eslint-disable no-new */
import
Vue
from
'
vue
'
;
import
VueResource
from
'
vue-resource
'
;
import
NotebookLab
from
'
vendor/notebooklab
'
;
Vue
.
use
(
VueResource
);
Vue
.
use
(
NotebookLab
);
export
default
()
=>
{
const
el
=
document
.
getElementById
(
'
js-notebook-viewer
'
);
new
Vue
({
el
,
data
()
{
return
{
error
:
false
,
loadError
:
false
,
loading
:
true
,
json
:
{},
};
},
template
:
`
<div class="container-fluid md prepend-top-default append-bottom-default">
<div
class="text-center loading"
v-if="loading && !error">
<i
class="fa fa-spinner fa-spin"
aria-hidden="true"
aria-label="iPython notebook loading">
</i>
</div>
<notebook-lab
v-if="!loading && !error"
:notebook="json"
code-css-class="code white" />
<p
class="text-center"
v-if="error">
<span v-if="loadError">
An error occured whilst loading the file. Please try again later.
</span>
<span v-else>
An error occured whilst parsing the file.
</span>
</p>
</div>
`
,
methods
:
{
loadFile
()
{
this
.
$http
.
get
(
el
.
dataset
.
endpoint
)
.
then
((
res
)
=>
{
this
.
json
=
res
.
json
();
this
.
loading
=
false
;
})
.
catch
((
e
)
=>
{
if
(
e
.
status
)
{
this
.
loadError
=
true
;
}
this
.
error
=
true
;
});
},
},
mounted
()
{
$
(
'
<link>
'
,
{
rel
:
'
stylesheet
'
,
type
:
'
text/css
'
,
href
:
gon
.
katex_css_url
,
}).
appendTo
(
'
head
'
);
if
(
gon
.
katex_js_url
)
{
$
.
getScript
(
gon
.
katex_js_url
,
()
=>
{
this
.
loadFile
();
});
}
else
{
this
.
loadFile
();
}
},
});
};
app/assets/javascripts/blob/notebook_viewer.js
0 → 100644
浏览文件 @
47aeacd7
import
renderNotebook
from
'
./notebook
'
;
document
.
addEventListener
(
'
DOMContentLoaded
'
,
renderNotebook
);
app/models/blob.rb
浏览文件 @
47aeacd7
...
...
@@ -46,6 +46,10 @@ class Blob < SimpleDelegator
text?
&&
language
&&
language
.
name
==
'SVG'
end
def
ipython_notebook?
text?
&&
language
&&
language
.
name
==
'Jupyter Notebook'
end
def
size_within_svg_limits?
size
<=
MAXIMUM_SVG_SIZE
end
...
...
@@ -63,6 +67,8 @@ class Blob < SimpleDelegator
end
elsif
image?
||
svg?
'image'
elsif
ipython_notebook?
'notebook'
elsif
text?
'text'
else
...
...
app/views/projects/blob/_notebook.html.haml
0 → 100644
浏览文件 @
47aeacd7
-
content_for
:page_specific_javascripts
do
=
page_specific_javascript_bundle_tag
(
'common_vue'
)
=
page_specific_javascript_bundle_tag
(
'notebook_viewer'
)
.file-content
#js-notebook-viewer
{
data:
{
endpoint:
namespace_project_raw_path
(
@project
.
namespace
,
@project
,
@id
)
}
}
config/webpack.config.js
浏览文件 @
47aeacd7
...
...
@@ -37,6 +37,7 @@ var config = {
merge_request_widget
:
'
./merge_request_widget/ci_bundle.js
'
,
monitoring
:
'
./monitoring/monitoring_bundle.js
'
,
network
:
'
./network/network_bundle.js
'
,
notebook_viewer
:
'
./blob/notebook_viewer.js
'
,
profile
:
'
./profile/profile_bundle.js
'
,
protected_branches
:
'
./protected_branches/protected_branches_bundle.js
'
,
snippet
:
'
./snippet/snippet_bundle.js
'
,
...
...
@@ -105,6 +106,7 @@ var config = {
'
environments_folder
'
,
'
issuable
'
,
'
merge_conflicts
'
,
'
notebook_viewer
'
,
'
vue_pipelines
'
,
],
minChunks
:
function
(
module
,
count
)
{
...
...
spec/javascripts/blob/notebook/index_spec.js
0 → 100644
浏览文件 @
47aeacd7
import
Vue
from
'
vue
'
;
import
renderNotebook
from
'
~/blob/notebook
'
;
describe
(
'
iPython notebook renderer
'
,
()
=>
{
preloadFixtures
(
'
static/notebook_viewer.html.raw
'
);
beforeEach
(()
=>
{
loadFixtures
(
'
static/notebook_viewer.html.raw
'
);
});
it
(
'
shows loading icon
'
,
()
=>
{
renderNotebook
();
expect
(
document
.
querySelector
(
'
.loading
'
),
).
not
.
toBeNull
();
});
describe
(
'
successful response
'
,
()
=>
{
const
response
=
(
request
,
next
)
=>
{
next
(
request
.
respondWith
(
JSON
.
stringify
({
cells
:
[{
cell_type
:
'
markdown
'
,
source
:
[
'
# test
'
],
},
{
cell_type
:
'
code
'
,
execution_count
:
1
,
source
:
[
'
def test(str)
'
,
'
return str
'
,
],
outputs
:
[],
}],
}),
{
status
:
200
,
}));
};
beforeEach
((
done
)
=>
{
Vue
.
http
.
interceptors
.
push
(
response
);
renderNotebook
();
setTimeout
(()
=>
{
done
();
});
});
afterEach
(()
=>
{
Vue
.
http
.
interceptors
=
_
.
without
(
Vue
.
http
.
interceptors
,
response
,
);
});
it
(
'
does not show loading icon
'
,
()
=>
{
expect
(
document
.
querySelector
(
'
.loading
'
),
).
toBeNull
();
});
it
(
'
renders the notebook
'
,
()
=>
{
expect
(
document
.
querySelector
(
'
.md
'
),
).
not
.
toBeNull
();
});
it
(
'
renders the markdown cell
'
,
()
=>
{
expect
(
document
.
querySelector
(
'
h1
'
),
).
not
.
toBeNull
();
expect
(
document
.
querySelector
(
'
h1
'
).
textContent
.
trim
(),
).
toBe
(
'
test
'
);
});
it
(
'
highlights code
'
,
()
=>
{
expect
(
document
.
querySelector
(
'
.token
'
),
).
not
.
toBeNull
();
expect
(
document
.
querySelector
(
'
.language-python
'
),
).
not
.
toBeNull
();
});
});
describe
(
'
error in JSON response
'
,
()
=>
{
const
response
=
(
request
,
next
)
=>
{
next
(
request
.
respondWith
(
'
{ "cells": [{"cell_type": "markdown"} }
'
,
{
status
:
200
,
}));
};
beforeEach
((
done
)
=>
{
Vue
.
http
.
interceptors
.
push
(
response
);
renderNotebook
();
setTimeout
(()
=>
{
done
();
});
});
afterEach
(()
=>
{
Vue
.
http
.
interceptors
=
_
.
without
(
Vue
.
http
.
interceptors
,
response
,
);
});
it
(
'
does not show loading icon
'
,
()
=>
{
expect
(
document
.
querySelector
(
'
.loading
'
),
).
toBeNull
();
});
it
(
'
shows error message
'
,
()
=>
{
expect
(
document
.
querySelector
(
'
.md
'
).
textContent
.
trim
(),
).
toBe
(
'
An error occured whilst parsing the file.
'
);
});
});
describe
(
'
error getting file
'
,
()
=>
{
const
response
=
(
request
,
next
)
=>
{
next
(
request
.
respondWith
(
''
,
{
status
:
500
,
}));
};
beforeEach
((
done
)
=>
{
Vue
.
http
.
interceptors
.
push
(
response
);
renderNotebook
();
setTimeout
(()
=>
{
done
();
});
});
afterEach
(()
=>
{
Vue
.
http
.
interceptors
=
_
.
without
(
Vue
.
http
.
interceptors
,
response
,
);
});
it
(
'
does not show loading icon
'
,
()
=>
{
expect
(
document
.
querySelector
(
'
.loading
'
),
).
toBeNull
();
});
it
(
'
shows error message
'
,
()
=>
{
expect
(
document
.
querySelector
(
'
.md
'
).
textContent
.
trim
(),
).
toBe
(
'
An error occured whilst loading the file. Please try again later.
'
);
});
});
});
spec/javascripts/fixtures/notebook_viewer.html.haml
0 → 100644
浏览文件 @
47aeacd7
.file-content
#js-notebook-viewer
{
data:
{
endpoint:
'/test'
}
}
spec/models/blob_spec.rb
浏览文件 @
47aeacd7
...
...
@@ -53,6 +53,20 @@ describe Blob do
end
end
describe
'#ipython_notebook?'
do
it
'is falsey when language is not Jupyter Notebook'
do
git_blob
=
double
(
text?:
true
,
language:
double
(
name:
'JSON'
))
expect
(
described_class
.
decorate
(
git_blob
)).
not_to
be_ipython_notebook
end
it
'is truthy when language is Jupyter Notebook'
do
git_blob
=
double
(
text?:
true
,
language:
double
(
name:
'Jupyter Notebook'
))
expect
(
described_class
.
decorate
(
git_blob
)).
to
be_ipython_notebook
end
end
describe
'#video?'
do
it
'is falsey with image extension'
do
git_blob
=
Gitlab
::
Git
::
Blob
.
new
(
name:
'image.png'
)
...
...
@@ -116,6 +130,11 @@ describe Blob do
blob
=
stubbed_blob
expect
(
blob
.
to_partial_path
(
project
)).
to
eq
'download'
end
it
'handles iPython notebooks'
do
blob
=
stubbed_blob
(
text?:
true
,
ipython_notebook?:
true
)
expect
(
blob
.
to_partial_path
(
project
)).
to
eq
'notebook'
end
end
describe
'#size_within_svg_limits?'
do
...
...
vendor/assets/javascripts/notebooklab.js
0 → 100644
浏览文件 @
47aeacd7
此差异已折叠。
点击以展开。
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录