Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
renderjs
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Labels
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
nexedi
renderjs
Commits
7bf5f1fc
Commit
7bf5f1fc
authored
Jan 29, 2020
by
Romain Courteaud
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
wip
parent
02175fb3
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
104 additions
and
15 deletions
+104
-15
renderjs.js
renderjs.js
+8
-8
test/renderjs_test.js
test/renderjs_test.js
+96
-7
No files found.
renderjs.js
View file @
7bf5f1fc
...
...
@@ -1376,7 +1376,6 @@
RenderJSGadget
.
onLoop
;
tmp_constructor
.
prototype
=
new
RenderJSGadget
();
tmp_constructor
.
prototype
.
constructor
=
tmp_constructor
;
tmp_constructor
.
prototype
.
__path
=
url
;
tmp_constructor
.
prototype
.
__acquired_method_dict
=
{};
// https://developer.mozilla.org/en-US/docs/HTML_in_XMLHttpRequest
// https://developer.mozilla.org/en-US/docs/Web/API/DOMParser
...
...
@@ -1496,7 +1495,7 @@
interface_list
:
[],
required_css_list
:
[],
required_js_list
:
[],
base_url
:
url
path
:
url
},
i
,
element
,
...
...
@@ -1518,25 +1517,26 @@
if
(
element
.
rel
===
"
stylesheet
"
)
{
settings
.
required_css_list
.
push
(
renderJS
.
getAbsoluteURL
(
element
.
getAttribute
(
"
href
"
),
settings
.
base_url
)
settings
.
path
)
);
}
else
if
(
element
.
nodeName
===
"
SCRIPT
"
&&
(
element
.
type
===
"
text/javascript
"
||
!
element
.
type
))
{
settings
.
required_js_list
.
push
(
renderJS
.
getAbsoluteURL
(
element
.
getAttribute
(
"
src
"
),
settings
.
base_url
)
settings
.
path
)
);
}
else
if
(
element
.
rel
===
"
http://www.renderjs.org/rel/interface
"
)
{
settings
.
interface_list
.
push
(
renderJS
.
getAbsoluteURL
(
element
.
getAttribute
(
"
href
"
),
settings
.
base_url
)
settings
.
path
)
);
}
else
if
((
element
.
nodeName
===
"
BASE
"
)
&&
!
base_found
)
{
settings
.
base_url
=
renderJS
.
getAbsoluteURL
(
}
else
if
((
element
.
nodeName
===
"
BASE
"
)
&&
!
base_found
&&
element
.
getAttribute
(
"
href
"
))
{
settings
.
path
=
renderJS
.
getAbsoluteURL
(
element
.
getAttribute
(
"
href
"
),
settings
.
base_url
settings
.
path
);
// Only use the first base element found
// https://developer.mozilla.org/en-US/docs/Web/HTML/Element/base#Usage_notes
...
...
test/renderjs_test.js
View file @
7bf5f1fc
...
...
@@ -86,7 +86,7 @@
// Check that parseGadgetHTMLDocument returns the default value
// if the string is not a valid xml
deepEqual
(
parseGadgetHTML
(
""
,
"
http://example.org
"
),
{
base_url
:
"
http://example.org
"
,
path
:
"
http://example.org
"
,
title
:
""
,
interface_list
:
[],
required_css_list
:
[],
...
...
@@ -119,7 +119,7 @@
document
.
implementation
.
createHTMLDocument
(
""
),
"
http://example.org
"
),
{
base_url
:
"
http://example.org
"
,
path
:
"
http://example.org
"
,
title
:
""
,
interface_list
:
[],
required_css_list
:
[],
...
...
@@ -173,7 +173,7 @@
"
</head></html>
"
;
settings
=
parseGadgetHTML
(
html
,
"
http://example.org
"
);
equal
(
settings
.
base_url
,
'
http://example.org/bar/bar2/
'
,
'
Base extracted
'
);
equal
(
settings
.
path
,
'
http://example.org/bar/bar2/
'
,
'
Base extracted
'
);
});
test
(
'
Extract only one base url
'
,
function
()
{
...
...
@@ -186,7 +186,7 @@
"
</head></html>
"
;
settings
=
parseGadgetHTML
(
html
,
"
http://example.org
"
);
equal
(
settings
.
base_url
,
'
http://example.org/bar/bar2/
'
,
'
Base extracted
'
);
equal
(
settings
.
path
,
'
http://example.org/bar/bar2/
'
,
'
Base extracted
'
);
});
// XXX innerHTML is not extracted anymore
...
...
@@ -468,7 +468,7 @@
'
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
'
+
'
</head><body><p>Non valid XML</p></body></html>
'
,
'
http://example.org/foo/
'
),
{
base_url
:
"
http://example.org/foo/
"
,
path
:
"
http://example.org/foo/
"
,
title
:
"
Test non valid XML
"
,
interface_list
:
[],
required_css_list
:
[],
...
...
@@ -672,12 +672,11 @@
);
stop
();
expect
(
8
);
expect
(
7
);
renderJS
.
declareGadgetKlass
(
url
)
.
then
(
function
(
Klass
)
{
var
instance
;
equal
(
Klass
.
prototype
.
__path
,
url
);
deepEqual
(
Klass
.
prototype
.
__acquired_method_dict
,
{});
equal
(
Klass
.
prototype
.
__foo
,
'
bar
'
);
equal
(
Klass
.
__template_element
.
nodeType
,
9
);
...
...
@@ -4970,6 +4969,96 @@
});
});
test
(
'
can declareGadget relativeurl in HTML
'
,
function
()
{
var
gadget
=
new
RenderJSGadget
(),
html_url
=
'
https://example.org/files/qunittest/test12345.html
'
,
html_relative_url2
=
'
test12346.html
'
,
html_url2
=
'
https://example.org/files/qunittest/test12346.html
'
,
spy
;
gadget
.
__sub_gadget_dict
=
{};
this
.
server
.
respondWith
(
"
GET
"
,
html_url
,
[
200
,
{
"
Content-Type
"
:
"
text/html
"
},
"
<html><body><div data-foo='bar'
"
+
"
data-gadget-scope='bar' data-gadget-url='
"
+
html_relative_url2
+
"
'></div></body></html>
"
]);
this
.
server
.
respondWith
(
"
GET
"
,
html_url2
,
[
200
,
{
"
Content-Type
"
:
"
text/html
"
},
"
raw html
"
]);
spy
=
sinon
.
spy
(
renderJS
,
"
parseGadgetHTMLDocument
"
);
stop
();
expect
(
6
);
gadget
.
declareGadget
(
html_url
)
.
then
(
function
(
g
)
{
equal
(
spy
.
callCount
,
2
);
equal
(
spy
.
firstCall
.
args
[
1
],
html_url
);
equal
(
spy
.
secondCall
.
args
[
1
],
html_url2
);
// Second gadget is a child
return
g
.
getDeclaredGadget
(
"
bar
"
);
})
.
then
(
function
(
g2
)
{
equal
(
g2
.
__path
,
html_url2
);
// The gadget element is the one defined in HTML
equal
(
g2
.
element
.
getAttribute
(
"
data-foo
"
),
"
bar
"
);
// The gadget is public by default
equal
(
g2
.
element
.
innerHTML
,
"
raw html
"
);
})
.
fail
(
function
(
e
)
{
ok
(
false
,
e
);
})
.
always
(
function
()
{
start
();
spy
.
restore
();
});
});
test
(
'
can declareGadget relativeurl in HTML with base tag
'
,
function
()
{
var
gadget
=
new
RenderJSGadget
(),
html_url
=
'
https://example.org/files/qunittest/test12345.html
'
,
html_relative_url2
=
'
test12346.html
'
,
html_url2
=
'
https://example.org/files/qunittest/foo/test12346.html
'
,
spy
;
gadget
.
__sub_gadget_dict
=
{};
this
.
server
.
respondWith
(
"
GET
"
,
html_url
,
[
200
,
{
"
Content-Type
"
:
"
text/html
"
},
"
<html><head><base href='./foo/'></head><body><div data-foo='bar'
"
+
"
data-gadget-scope='bar' data-gadget-url='
"
+
html_relative_url2
+
"
'></div></body></html>
"
]);
this
.
server
.
respondWith
(
"
GET
"
,
html_url2
,
[
200
,
{
"
Content-Type
"
:
"
text/html
"
},
"
raw html
"
]);
spy
=
sinon
.
spy
(
renderJS
,
"
parseGadgetHTMLDocument
"
);
stop
();
expect
(
6
);
gadget
.
declareGadget
(
html_url
)
.
then
(
function
(
g
)
{
equal
(
spy
.
callCount
,
2
);
equal
(
spy
.
firstCall
.
args
[
1
],
html_url
);
equal
(
spy
.
secondCall
.
args
[
1
],
html_url2
);
// Second gadget is a child
return
g
.
getDeclaredGadget
(
"
bar
"
);
})
.
then
(
function
(
g2
)
{
equal
(
g2
.
__path
,
html_url2
);
// The gadget element is the one defined in HTML
equal
(
g2
.
element
.
getAttribute
(
"
data-foo
"
),
"
bar
"
);
// The gadget is public by default
equal
(
g2
.
element
.
innerHTML
,
"
raw html
"
);
})
.
fail
(
function
(
e
)
{
ok
(
false
,
e
);
})
.
always
(
function
()
{
start
();
spy
.
restore
();
});
});
test
(
'
can declareGadget a sandboxed gadget in HTML directly
'
,
function
()
{
var
gadget
=
new
RenderJSGadget
(),
html_url
=
'
https://example.org/files/qunittest/test123456.html
'
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment