-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Interactive code block] Add "theme mode" in the code editor (#353)
<!-- Thanks for contributing to WordPress Playground Tools! --> ## What? <!-- In a few words, what is the PR actually doing? Include screenshots or screencasts if applicable --> This PR attempts to add theme support to the code editor mode, so that users can set up a plugin or theme in the code editor mode. ## Why? <!-- Why is this PR necessary? What problem is it solving? Reference any existing previous issue(s) or PR(s), but please add a short summary here, too --> I would like to be able to set up practical activities for learners on Learn.WordPress.org around both plugin and theme development, using the WordPress Playground block ## How? <!-- How is your PR addressing the issue at hand? What are the implementation details? --> ## Testing Instructions <!-- Please include step by step instructions on how to test this PR. --> <!-- 1. Check out the branch. --> <!-- 2. Run a command. --> <!-- 3. etc. --> 1. Check out the [jonathanbossenger:351-code-editor-theme-support](https://github.com/jonathanbossenger/playground-tools/tree/351-code-editor-theme-support) branch 2. Load and instance of the playground in the Site Editor 3. Change the Code Editor Mode to "Theme" 4. Create a style.css and templates/index.html block theme files 5. Run the playground preview 6. The two theme files should activate as the active theme in the preview Fixes #351
- Loading branch information
1 parent
c183062
commit 2423859
Showing
4 changed files
with
105 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
packages/wordpress-playground-block/src/components/playground-preview/write-theme-files.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import type { EditorFile } from '../../index'; | ||
import { | ||
PlaygroundClient, | ||
activateTheme, | ||
// @ts-ignore | ||
} from 'https://playground.wordpress.net/client/index.js'; | ||
|
||
export const writeThemeFiles = async ( | ||
client: PlaygroundClient, | ||
files: EditorFile[] | ||
) => { | ||
const docroot = await client.documentRoot; | ||
const themeFolderName = 'demo-theme'; | ||
const themePath = docroot + '/wp-content/themes/' + themeFolderName; | ||
if (await client.fileExists(themePath)) { | ||
await client.rmdir(themePath, { | ||
recursive: true, | ||
}); | ||
} | ||
await client.mkdir(themePath); | ||
|
||
for (const file of files) { | ||
const filePath = `${themePath}/${file.name}`; | ||
const parentDir = filePath.split('/').slice(0, -1).join('/'); | ||
await client.mkdir(parentDir); | ||
await client.writeFile(filePath, file.contents); | ||
} | ||
|
||
try { | ||
await activateTheme(client, { | ||
themeFolderName, | ||
}); | ||
} catch (e) { | ||
console.error(e); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters