8000 Add ES6 download button by Flamenco · Pull Request #509 · peggyjs/peggy · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Add ES6 download button #509

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Unreleased
### Breaking changes

### New features
- [#509](https://github.com/peggyjs/peggy/pull/509) Add and implement ES6 export button

### Bug fixes
- [#507](https://github.com/peggyjs/peggy/pull/507) Remove stray semicolon in CSS
Expand Down
9 changes: 6 additions & 3 deletions docs/css/content.css
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@
#content #settings label { padding-right: 1em; }
#content #parser-var { width: 15em; }
#content #options { padding-top: 1em; }
#content #parser-download {
#content .download-button {
float: right;
width: 10em;
margin-top: 2em;
Expand All @@ -151,8 +151,11 @@
text-align: center; text-decoration: none;
color: #e0ffe0; background-color: #499149;
}
#content #parser-download:hover { background-color: #006000; }
#content #parser-download.disabled { color: #e0e0e0; background-color: gray; }
#content .download-button:not(:first-of-type) {
margin-right: .5rem;
}
#content .download-button:hover { background-color: #006000; }
#content .download-button.disabled { color: #e0e0e0; background-color: gray; }


#output {
Expand Down
19 changes: 19 additions & 0 deletions docs/js/online.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ $(document).ready(function() {
$("#parser-var").attr("disabled", "disabled");
$("#option-cache").attr("disabled", "disabled");
$("#parser-download").attr("disabled", "disabled");
$("#parser-download-es6").attr("disabled", "disabled");

try {
var timeBefore = (new Date).getTime();
Expand Down Expand Up @@ -134,6 +135,7 @@ $(document).ready(function() {
$("#parser-var").removeAttr("disabled");
$("#option-cache").removeAttr("disabled");
$("#parser-download").removeAttr("disabled");
$("#parser-download-es6").removeAttr("disabled");

var result = true;
} catch (e) {
Expand Down Expand Up @@ -230,6 +232,23 @@ $(document).ready(function() {

});

$( "#parser-download-es6" )
.click(function(){
try { // If this button was enabled, the source was already validated by 'rebuildGrammar'
const esSource = peggy.generate(editor.getValue(), {
cache: $("#option-cache").is(":checked"),
output: "source",
format: 'es'
})

var blob = new Blob([esSource], {type: "application/javascript"});
window.saveAs(blob, "parser.mjs");
} catch (e) {
console.error('Unable to save parser', e);
}

});

doLayout();
$(window).resize(doLayout);

Expand Down
7 changes: 4 additions & 3 deletions docs/online.html
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,11 @@ <h2 class="suggestion">
</tr>
<tr>
<td class="content-height">
<input type="submit" id="parser-download" value="Download parser" disabled>
<input type="submit" id="parser-download-es6" class="download-button" value="Download ES6 parser" disabled>
<input type="submit" id="parser-download" class="download-button" value="Download CJS parser" disabled>
<div id="settings">
<label for="parser-var">Parser variable:</label>
<input type="text" id="parser-var" value="module.exports" disabled>
<label for="parser-var">Parser variable <span style="font-size: .7rem">For CommonJS</span>:</label>
<input type="text" id="parser-var" value="module.exports" placeholder="module.exports" disabled>
<div id="options">
<input type="checkbox" id="option-cache" disabled>
<label for="option-cache">Use results cache</label>
Expand Down
0