0
0
Fork 0
mirror of https://github.com/discourse/discourse.git synced 2026-08-09 21:45:25 +08:00
discourse/plugins/styleguide
Sérgio Saquetim a8b1606ff8
DEV: Derive styleguide code samples from the rendered example (#42100)
DEV: Keep styleguide samples synchronized with source

Styleguide code samples were hand-written strings that could silently drift
from the markup they described. This caused the char counter sample to
advertise a nonexistent `CharCounter` module while rendering
`DCharCounter`.

Add a `discourse-source-imports` bundler plugin that imports another module's
untranspiled source as a string. `?source=file` returns the complete file,
while `?source=template` extracts the contents of the module's single
`<template>` block. Imports use normal module resolution and pass the result
to `StyleguideExample` through its `@code` argument.

Move the spinner and char counter examples into `components/examples/` and
source their displayed code through the new plugin.

Register the plugin with both the core Rolldown build and the asset processor.
Each pipeline injects its own `readSource(id)` implementation: the asset
processor reads from its in-memory module map, while core reads from disk and
rejects paths outside the project root.

---------

Co-authored-by: David Taylor <david@taylorhq.com>
2026-07-29 13:48:35 -03:00
..
app/controllers/styleguide DEV: Minor fixes to everyone-based permissions for granular_anonymous_and_logged_in_groups_permissions (#41459) 2026-07-07 09:38:56 +10:00
assets DEV: Derive styleguide code samples from the rendered example (#42100) 2026-07-29 13:48:35 -03:00
config I18N: Update translations (#42016) 2026-07-28 16:55:49 +02:00
db/migrate
lib/styleguide DEV: Clean up scope resolution operators in plugins (#34979) 2025-09-30 14:36:34 +02:00
public/images
spec UX: Move the styleguide navigation into the main sidebar (#42058) 2026-07-27 18:32:34 -03:00
package.json DEV: Add a script for generating external types in discourse-types (#37095) 2026-03-09 20:37:43 +01:00
plugin.rb DEV: Clean up scope resolution operators in plugins (#34979) 2025-09-30 14:36:34 +02:00
README.md DEV: Derive styleguide code samples from the rendered example (#42100) 2026-07-29 13:48:35 -03:00
screenshot.png
tsconfig.json DEV: Add a script for generating external types in discourse-types (#37095) 2026-03-09 20:37:43 +01:00

styleguide

Adds a URL of /styleguide to discourse that renders widgets in various configurations to aid in styling.

Screenshot

Automatic code examples

Discourse's build pipeline allows adding ?source=file or ?source=template to a module import. This provides a string of the raw source code for the entire file, or just for the <template>. Put the example in its own module under examples/, import it twice, and pass the string to @code:

import StyleguideExample from "discourse/plugins/styleguide/discourse/components/styleguide-example";
import CharCounterExample from "../../examples/char-counter";
import charCounterSource from "../../examples/char-counter.gjs?source=file";

export default <template>
  <StyleguideExample @title="<DCharCounter>" @code={{charCounterSource}}>
    <CharCounterExample @dummy={{@dummy}} />
  </StyleguideExample>
</template>

The import must resolve within the same plugin or theme bundle, and ?source=template requires the module to contain exactly one <template>.

Keep using an explicit @code string for curated samples that intentionally differ from the rendered implementation.