Skip to content

Commit ddddc8e

Browse files
committed
Read-only embedded
1 parent 14199f4 commit ddddc8e

File tree

6 files changed

+33
-25
lines changed

6 files changed

+33
-25
lines changed

Diff for: app.js

+3
Original file line numberDiff line numberDiff line change
@@ -517,6 +517,9 @@ findCompilers()
517517
})
518518
.get('/e', embeddedHandler)
519519
.get('/embed.html', embeddedHandler) // legacy. not a 301 to prevent any redirect loops between old e links and embed.html
520+
.get('/embed-ro', function (req, res) {
521+
res.render('embed', renderConfig({embedded: true, readOnly: true}));
522+
})
520523
.use(sFavicon(staticDir + '/favicon.ico'))
521524
.use('/v', express.static(staticDir + '/v', {maxAge: Infinity, index: false}))
522525
.use(express.static(staticDir, {maxAge: staticMaxAgeSecs * 1000}));

Diff for: static/editor.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ define(function (require) {
3333
var Sharing = require('sharing');
3434
var Components = require('components');
3535
var monaco = require('monaco');
36+
var options = require('options');
3637
require('./d-mode');
3738
require('./rust-mode');
3839

@@ -73,10 +74,12 @@ define(function (require) {
7374
}
7475

7576
var root = this.domRoot.find(".monaco-placeholder");
77+
var legacyReadOnly = !!state.options.readOnly;
7678
this.editor = monaco.editor.create(root[0], {
7779
value: state.source || defaultSrc || "",
7880
scrollBeyondLastLine: false,
79-
language: cmMode
81+
language: cmMode,
82+
readOnly: !!options.readOnly || legacyReadOnly
8083
});
8184

8285
this.editor.addAction({

Diff for: static/main.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -118,9 +118,9 @@ define(function (require) {
118118
showMaximiseIcon: false,
119119
showCloseIcon: false,
120120
hasHeaders: false
121-
},
122-
content: sharing.contentFromEmbedded(window.location.hash.substr(1))
123-
});
121+
}
122+
},
123+
sharing.configFromEmbedded(window.location.hash.substr(1)));
124124
}
125125

126126
var root = $("#root");

Diff for: static/sharing.js

+19-18
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ define(function (require) {
3232
var Components = require('components');
3333
var url = require('url');
3434

35-
function contentFromEmbedded(embeddedUrl) {
35+
function configFromEmbedded(embeddedUrl) {
3636
// Old-style link?
3737
var params;
3838
try {
@@ -46,19 +46,19 @@ define(function (require) {
4646
})
4747
.object()
4848
.value();
49-
return [
50-
{
51-
type: 'row',
52-
content: [
53-
Components.getEditorWith(1, params.source, filters),
54-
Components.getCompilerWith(1, filters, params.options, params.compiler)
55-
]
56-
}
57-
];
49+
return {
50+
content: [
51+
{
52+
type: 'row',
53+
content: [
54+
Components.getEditorWith(1, params.source, filters),
55+
Components.getCompilerWith(1, filters, params.options, params.compiler)
56+
]
57+
}
58+
]
59+
};
5860
} else {
59-
var config = url.deserialiseState(embeddedUrl);
60-
console.log(config);
61-
return config.content; // TODO not this? better to return whole config ?
61+
return url.deserialiseState(embeddedUrl);
6262
}
6363
}
6464

@@ -68,11 +68,11 @@ define(function (require) {
6868
});
6969
}
7070

71-
function getEmbeddedUrl(layout) {
72-
// TODO: readOnly?
71+
function getEmbeddedUrl(layout, readOnly) {
7372
var location = window.location.origin + window.location.pathname;
7473
if (location[location.length - 1] !== '/') location += '/';
75-
return location + 'e#' + url.serialiseState(layout.toConfig());
74+
var path = readOnly ? 'embed-ro#' : 'e#';
75+
return location + path + url.serialiseState(layout.toConfig());
7676
}
7777

7878
function initShareButton(getLink, layout) {
@@ -134,7 +134,8 @@ define(function (require) {
134134
function getLinks(layout, done) {
135135
var result = {
136136
Full: permalink(layout),
137-
Embed: '<iframe width="800px" height="200px" src="' + getEmbeddedUrl(layout) + '"></iframe>'
137+
Embed: '<iframe width="800px" height="200px" src="' + getEmbeddedUrl(layout, false) + '"></iframe>',
138+
'Embed (RO)': '<iframe width="800px" height="200px" src="' + getEmbeddedUrl(layout, true) + '"></iframe>'
138139
};
139140
if (!options.gapiKey) {
140141
done(result);
@@ -148,6 +149,6 @@ define(function (require) {
148149

149150
return {
150151
initShareButton: initShareButton,
151-
contentFromEmbedded: contentFromEmbedded
152+
configFromEmbedded: configFromEmbedded
152153
};
153154
});

Diff for: test/embedding.html

+3-3
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
Test; here's some inline Compiler Explorer stuff:
1111
</div>
1212
<iframe width="800px" height="200px"
13-
src="http://lud-ldnmg01:10240/e#source:'int+main()%7B%7D',compiler:g44,options:'-O2',filters:'colouriseAsm,intel,commentOnly,directives,labels,compileOnChange'"></iframe>
13+
src="http://localhost:10240/e#source:'int+main()%7B%7D',compiler:g44,options:'-O2',filters:'colouriseAsm,intel,commentOnly,directives,labels,compileOnChange'"></iframe>
1414
</body>
1515
<div>And here's some text after</div>
16-
<iframe width="800px" height="200px" src="http://lud-mgodbolt01:10240/e#compiler:/usr/bin/g%2B%2B,filters:'colouriseAsm,readOnly,labels,directives,commentOnly,intel',options:'-O2',source:'//+Type+your+code+here,+or+load+an+example.%0Aint+square(int+num)+%7B%0A++++return+num+*+num%3B%0A%7D%0A'"></iframe>
17-
</html>
16+
<iframe width="800px" height="200px" src="http://localhost:10240/e#compiler:/usr/bin/g%2B%2B,filters:'colouriseAsm,readOnly,labels,directives,commentOnly,intel',options:'-O2',source:'//+Type+your+code+here,+or+load+an+example.%0Aint+square(int+num)+%7B%0A++++return+num+*+num%3B%0A%7D%0A'"></iframe>
17+
</html>

Diff for: views/index.pug

+1
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ html(lang="en")
7979
li: a(href="#" data-bind="Short") Short
8080
li: a(href="#" data-bind="Full") Full
8181
li: a(href="#" data-bind="Embed") Embed
82+
li: a(href="#" data-bind="Embed (RO)") Embed (read only)
8283
input.form-control.input-sm.permalink(
8384
type="text" placeholder="Loading" readonly size="1024")
8485
span.input-group-btn

0 commit comments

Comments
 (0)