Skip to content
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

Introduce a new injection script for new DartPad frontend #205

Merged
merged 1 commit into from
Jan 16, 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
63 changes: 56 additions & 7 deletions .github/workflows/dart.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Created with package:mono_repo v6.6.0
# Created with package:mono_repo v6.6.1
name: Dart CI
on:
push:
Expand Down Expand Up @@ -35,7 +35,7 @@ jobs:
name: Checkout repository
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11
- name: mono_repo self validate
run: dart pub global activate mono_repo 6.6.0
run: dart pub global activate mono_repo 6.6.1
- name: mono_repo self validate
run: dart pub global run mono_repo generate --validate
job_002:
Expand Down Expand Up @@ -86,16 +86,50 @@ jobs:
if: "always() && steps.packages_code_excerpter_pub_upgrade.conclusion == 'success'"
working-directory: packages/code_excerpter
job_003:
name: "analyzer_and_format; Dart dev; PKGS: packages/code_excerpt_updater, packages/code_excerpter; `dart format --output=none --set-exit-if-changed .`, `dart analyze --fatal-infos .`"
name: "analyzer_and_format; Dart 3.2.0; PKG: packages/inject_dartpad; `dart format --output=none --set-exit-if-changed .`, `dart analyze --fatal-infos .`"
runs-on: ubuntu-latest
steps:
- name: Cache Pub hosted dependencies
uses: actions/cache@704facf57e6136b1bc63b828d79edcd491f0ee84
with:
path: "~/.pub-cache/hosted"
key: "os:ubuntu-latest;pub-cache-hosted;sdk:dev;packages:packages/code_excerpt_updater-packages/code_excerpter;commands:format-analyze"
key: "os:ubuntu-latest;pub-cache-hosted;sdk:3.2.0;packages:packages/inject_dartpad;commands:format-analyze"
restore-keys: |
os:ubuntu-latest;pub-cache-hosted;sdk:dev;packages:packages/code_excerpt_updater-packages/code_excerpter
os:ubuntu-latest;pub-cache-hosted;sdk:3.2.0;packages:packages/inject_dartpad
os:ubuntu-latest;pub-cache-hosted;sdk:3.2.0
os:ubuntu-latest;pub-cache-hosted
os:ubuntu-latest
- name: Setup Dart SDK
uses: dart-lang/setup-dart@b64355ae6ca0b5d484f0106a033dd1388965d06d
with:
sdk: "3.2.0"
- id: checkout
name: Checkout repository
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11
- id: packages_inject_dartpad_pub_upgrade
name: packages/inject_dartpad; dart pub upgrade
run: dart pub upgrade
if: "always() && steps.checkout.conclusion == 'success'"
working-directory: packages/inject_dartpad
- name: "packages/inject_dartpad; dart format --output=none --set-exit-if-changed ."
run: "dart format --output=none --set-exit-if-changed ."
if: "always() && steps.packages_inject_dartpad_pub_upgrade.conclusion == 'success'"
working-directory: packages/inject_dartpad
- name: "packages/inject_dartpad; dart analyze --fatal-infos ."
run: dart analyze --fatal-infos .
if: "always() && steps.packages_inject_dartpad_pub_upgrade.conclusion == 'success'"
working-directory: packages/inject_dartpad
job_004:
name: "analyzer_and_format; Dart dev; PKGS: packages/code_excerpt_updater, packages/code_excerpter, packages/inject_dartpad; `dart format --output=none --set-exit-if-changed .`, `dart analyze --fatal-infos .`"
runs-on: ubuntu-latest
steps:
- name: Cache Pub hosted dependencies
uses: actions/cache@704facf57e6136b1bc63b828d79edcd491f0ee84
with:
path: "~/.pub-cache/hosted"
key: "os:ubuntu-latest;pub-cache-hosted;sdk:dev;packages:packages/code_excerpt_updater-packages/code_excerpter-packages/inject_dartpad;commands:format-analyze"
restore-keys: |
os:ubuntu-latest;pub-cache-hosted;sdk:dev;packages:packages/code_excerpt_updater-packages/code_excerpter-packages/inject_dartpad
os:ubuntu-latest;pub-cache-hosted;sdk:dev
os:ubuntu-latest;pub-cache-hosted
os:ubuntu-latest
Expand Down Expand Up @@ -132,7 +166,20 @@ jobs:
run: dart analyze --fatal-infos .
if: "always() && steps.packages_code_excerpter_pub_upgrade.conclusion == 'success'"
working-directory: packages/code_excerpter
job_004:
- id: packages_inject_dartpad_pub_upgrade
name: packages/inject_dartpad; dart pub upgrade
run: dart pub upgrade
if: "always() && steps.checkout.conclusion == 'success'"
working-directory: packages/inject_dartpad
- name: "packages/inject_dartpad; dart format --output=none --set-exit-if-changed ."
run: "dart format --output=none --set-exit-if-changed ."
if: "always() && steps.packages_inject_dartpad_pub_upgrade.conclusion == 'success'"
working-directory: packages/inject_dartpad
- name: "packages/inject_dartpad; dart analyze --fatal-infos ."
run: dart analyze --fatal-infos .
if: "always() && steps.packages_inject_dartpad_pub_upgrade.conclusion == 'success'"
working-directory: packages/inject_dartpad
job_005:
name: "unit_test; Dart 3.1.0; PKGS: packages/code_excerpt_updater, packages/code_excerpter; `dart test`"
runs-on: ubuntu-latest
steps:
Expand Down Expand Up @@ -175,7 +222,8 @@ jobs:
- job_001
- job_002
- job_003
job_005:
- job_004
job_006:
name: "unit_test; Dart dev; PKGS: packages/code_excerpt_updater, packages/code_excerpter; `dart test`"
runs-on: ubuntu-latest
steps:
Expand Down Expand Up @@ -218,3 +266,4 @@ jobs:
- job_001
- job_002
- job_003
- job_004
11 changes: 11 additions & 0 deletions packages/inject_dartpad/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Dart-related files
.dart_tool
pubspec.lock

# IDE-related files
*.iml
.idea/
.vscode/

# Platform-related files
.DS_Store
51 changes: 51 additions & 0 deletions packages/inject_dartpad/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
## DartPad injection
parlough marked this conversation as resolved.
Show resolved Hide resolved

To embed a DartPad with arbitrary Dart in to your web page, add the
JS file found at `lib/inject_dartpad.js` with a `<script>` tag,
set up to run after the DOM is ready.

This might look something like the following, depending on where
your version of the JS file is stored.

```html
<script defer src="inject_dartpad.js"></script>
```

### Declare code to inject

The script looks for each inline `<code>` element on the page
that is the only child of a `<pre>` element and
has the `data-dartpad="true"` property.

```html
<pre>
<code class="language-dart" data-dartpad="true">
...Code here...
</code>
</pre>
```

If the code is correctly formatted, the script will replace
both elements with a DartPad iframe containing your specified code.

The DartPad defaults to the embed style and dark theme. To configure
this and other behavior, add one or more of the following options:

- `data-embed="false"`
To use the standalone UI version of DartPad.
- `data-theme="light"`
To use the light theme in the embed.
- `data-run="true"`
To run the included code once loaded.
- `data-width="<CSS width>"`
To specify the initial width of the injected iframe element.
- `data-height="<CSS height>"`
To specify the initial height of the injected iframe element.

### Developing script

To work on the script itself, modify the code within `/web/inject_dartpad.dart`.
To compile the code to JavaScript, use the latest Dart SDK,
verify you have the latest dependencies (`dart pub upgrade`), and then
run `dart run tool/compile.dart`.
The updated file will be written to `/lib/inject_dartpad.js`.
1 change: 1 addition & 0 deletions packages/inject_dartpad/analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include: package:analysis_defaults/analysis.yaml
12 changes: 12 additions & 0 deletions packages/inject_dartpad/build.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
targets:
$default:
builders:
build_web_compilers|entrypoint:
generate_for:
- web/**.dart
options:
dart2js_args:
- --no-frequency-based-minification
- --no-source-maps
- --show-package-warnings
- -O4
Loading