Skip to content

Commit 1e90795

Browse files
committed
Support for YouTube object blocks
1 parent 8979ee2 commit 1e90795

File tree

2 files changed

+94
-1
lines changed
  • src/main/webapp/static/com/atomgraph/linkeddatahub/xsl

2 files changed

+94
-1
lines changed
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE xsl:stylesheet [
3+
<!ENTITY def "https://w3id.org/atomgraph/linkeddatahub/default#">
4+
<!ENTITY ldh "https://w3id.org/atomgraph/linkeddatahub#">
5+
<!ENTITY ac "https://w3id.org/atomgraph/client#">
6+
<!ENTITY rdf "http://www.w3.org/1999/02/22-rdf-syntax-ns#">
7+
<!ENTITY rdfs "http://www.w3.org/2000/01/rdf-schema#">
8+
<!ENTITY xsd "http://www.w3.org/2001/XMLSchema#">
9+
<!ENTITY acl "http://www.w3.org/ns/auth/acl#">
10+
<!ENTITY ldt "https://www.w3.org/ns/ldt#">
11+
<!ENTITY sd "http://www.w3.org/ns/sparql-service-description#">
12+
<!ENTITY foaf "http://xmlns.com/foaf/0.1/">
13+
]>
14+
<xsl:stylesheet version="3.0"
15+
xmlns="http://www.w3.org/1999/xhtml"
16+
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
17+
xmlns:ixsl="http://saxonica.com/ns/interactiveXSLT"
18+
xmlns:prop="http://saxonica.com/ns/html-property"
19+
xmlns:xhtml="http://www.w3.org/1999/xhtml"
20+
xmlns:xs="http://www.w3.org/2001/XMLSchema"
21+
xmlns:map="http://www.w3.org/2005/xpath-functions/map"
22+
xmlns:json="http://www.w3.org/2005/xpath-functions"
23+
xmlns:array="http://www.w3.org/2005/xpath-functions/array"
24+
xmlns:ac="&ac;"
25+
xmlns:ldh="&ldh;"
26+
xmlns:rdf="&rdf;"
27+
xmlns:rdfs="&rdfs;"
28+
xmlns:acl="&acl;"
29+
xmlns:ldt="&ldt;"
30+
xmlns:sd="&sd;"
31+
xmlns:foaf="&foaf;"
32+
xmlns:bs2="http://graphity.org/xsl/bootstrap/2.3.2"
33+
extension-element-prefixes="ixsl"
34+
exclude-result-prefixes="#all"
35+
>
36+
37+
<!-- TEMPLATES -->
38+
39+
<!-- object block (RDF resource) -->
40+
41+
<xsl:template match="*[@typeof = '&ldh;Object'][descendant::*[@property = '&rdf;value'][starts-with(@resource, 'https://www.youtube.com/watch?v=') or starts-with(@resource, 'https://youtube.com/watch?v=')]]" mode="ldh:RenderRow" as="function(item()?) as map(*)" priority="3">
42+
<xsl:param name="container" select="." as="element()"/>
43+
<xsl:param name="resource-uri" select="descendant::*[@property = '&rdf;value']/@resource" as="xs:anyURI?"/>
44+
45+
<xsl:variable name="context" as="map(*)" select="map{
46+
'container': $container,
47+
'resource-uri': $resource-uri,
48+
'block': ancestor::div[contains-token(@class, 'block')][1]
49+
}"/>
50+
51+
<xsl:message>
52+
YouTube object: <xsl:value-of select="$resource-uri"/>
53+
</xsl:message>
54+
55+
<!-- Return the YouTube rendering function with partial application -->
56+
<xsl:sequence select="ldh:render-youtube#2($context, ?)"/>
57+
</xsl:template>
58+
59+
<xsl:function name="ldh:render-youtube" as="map(*)" ixsl:updating="yes">
60+
<xsl:param name="context" as="map(*)"/>
61+
<xsl:param name="ignored" as="item()?" />
62+
63+
<xsl:variable name="container" select="$context('container')" as="element()"/>
64+
<xsl:variable name="resource-uri" select="$context('resource-uri')" as="xs:anyURI"/>
65+
66+
<xsl:variable name="video-id" select="
67+
if (starts-with($resource-uri, 'https://www.youtube.com/watch?v='))
68+
then substring-after($resource-uri, 'https://www.youtube.com/watch?v=')
69+
else substring-after($resource-uri, 'https://youtube.com/watch?v=')" as="xs:string"/>
70+
71+
<xsl:for-each select="$container">
72+
<xsl:result-document href="?." method="ixsl:replace-content">
73+
<div class="offset2 span7">
74+
<div class="text-center">
75+
<iframe width="560" height="315"
76+
src="https://www.youtube.com/embed/{$video-id}"
77+
frameborder="0"
78+
allowfullscreen="allowfullscreen">
79+
</iframe>
80+
</div>
81+
</div>
82+
</xsl:result-document>
83+
</xsl:for-each>
84+
85+
<!-- Hide progress bar and remove striped class like the original code -->
86+
<xsl:sequence select="ldh:hide-block-progress-bar($context, ())[current-date() lt xs:date('2000-01-01')]"/>
87+
88+
<!-- Return resolved promise -->
89+
<xsl:sequence select="ixsl:resolve($context)"/>
90+
</xsl:function>
91+
92+
</xsl:stylesheet>

src/main/webapp/static/com/atomgraph/linkeddatahub/xsl/client.xsl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,8 @@ extension-element-prefixes="ixsl"
111111
<xsl:include href="bootstrap/2.3.2/client/block/view.xsl"/>
112112
<xsl:include href="bootstrap/2.3.2/client/block/chart.xsl"/>
113113
<xsl:include href="bootstrap/2.3.2/client/block/query.xsl"/>
114-
114+
<xsl:include href="bootstrap/2.3.2/client/block/object/youtube.xsl"/>
115+
115116
<xsl:param name="ac:contextUri" as="xs:anyURI"/>
116117
<xsl:param name="ldt:base" as="xs:anyURI"/>
117118
<xsl:param name="ldh:requestUri" select="xs:anyURI(ixsl:location())" as="xs:anyURI"/>

0 commit comments

Comments
 (0)