### Clone Discourse and Start Development Container Source: https://github.com/discourse/discourse-developer-docs/blob/main/docs/02-development-environments/03-docker-setup.md Clones the Discourse repository and starts the development container. The `--init` flag ensures dependencies are installed, the database is migrated, and an admin user is created. ```shell git clone https://github.com/discourse/discourse.git ``` ```shell cd discourse ``` ```shell d/boot_dev --init ``` -------------------------------- ### Start Discourse with Custom Hostname and Listener Source: https://github.com/discourse/discourse-developer-docs/blob/main/docs/02-development-environments/05-ubuntu-debian-setup.md Starts the Discourse development server, allowing for custom hostname and listener port configurations. This is useful when the default settings cause conflicts or when working on a remote server. ```shell DISCOURSE_HOSTNAME=localhost UNICORN_LISTENER=localhost:3000 bin/ember-cli -u ``` -------------------------------- ### Bootstrap Discourse Application Source: https://github.com/discourse/discourse-developer-docs/blob/main/docs/02-development-environments/05-ubuntu-debian-setup.md Installs Ruby gems and JavaScript dependencies for Discourse, and then creates and migrates the development and test databases. Finally, it starts the Rails and Ember servers. ```shell cd ~/discourse source ~/.bashrc bundle install pnpm install bin/rails db:create bin/rails db:migrate RAILS_ENV=test bin/rails db:create db:migrate bin/ember-cli -u ``` -------------------------------- ### Start Discourse Development Servers Source: https://github.com/discourse/discourse-developer-docs/blob/main/docs/02-development-environments/04-macos-setup.md Starts the Rails and Ember CLI servers for local development. Two options are provided: running them in separate terminal tabs or using a single command to run the Unicorn server in the background. ```shell # Option 1: Separate terminals bundle exec rails server bin/ember-cli # Option 2: Single terminal bin/ember-cli -u ``` -------------------------------- ### Setup PostgreSQL Role for Discourse Source: https://github.com/discourse/discourse-developer-docs/blob/main/docs/02-development-environments/05-ubuntu-debian-setup.md Creates a PostgreSQL role with the same name as the current Linux system username. This is required for Discourse to access the database. ```shell cd /tmp && sudo -u postgres createuser -s "$USER" ``` -------------------------------- ### Start development server with host forwarding Source: https://github.com/discourse/discourse-developer-docs/blob/main/docs/02-development-environments/09-multisite-setup.md Launch the ember-cli development server with the --forward-host option to allow the browser to resolve multisite hostnames. ```bash bin/ember-cli -u --forward-host ``` -------------------------------- ### Install Docker on MacOS Source: https://github.com/discourse/discourse-developer-docs/blob/main/docs/02-development-environments/03-docker-setup.md Provides options for installing Docker on MacOS. Users can download a packaged .dmg from the Docker store or use the Homebrew package manager to install Docker. ```shell # Option 1: Download a packaged .dmg from the [Docker store](https://store.docker.com/editions/community/docker-ce-desktop-mac) ``` ```shell # Option 2: brew install docker ``` -------------------------------- ### Create New Admin User for Discourse Source: https://github.com/discourse/discourse-developer-docs/blob/main/docs/02-development-environments/05-ubuntu-debian-setup.md Creates a new administrator account for the Discourse installation by running a Rails generator. This command prompts the user for necessary information to set up the admin. ```shell bin/rails admin:create ``` -------------------------------- ### Ember Component Test Setup Method Source: https://github.com/discourse/discourse-developer-docs/blob/main/docs/03-code-internals/03-acceptance-tests.md This JavaScript code demonstrates the 'setup' method within an Ember component test. It's used to define and set up the data context for the component being tested. Here, it initializes 'testSnack' with sample data, which is then passed to the component via the template. ```javascript setup() { this.set('testSnack', { name: 'Potato Chips', description: 'Now with extra trans fat!' }); } ``` -------------------------------- ### Install Missing Gems Source: https://github.com/discourse/discourse-developer-docs/blob/main/docs/02-development-environments/03-docker-setup.md Installs any missing Ruby gems required by Discourse. This command is useful if you encounter errors related to missing gem dependencies. ```shell d/bundle install ``` -------------------------------- ### Run MailHog for Email Testing Source: https://github.com/discourse/discourse-developer-docs/blob/main/docs/02-development-environments/05-ubuntu-debian-setup.md Starts the MailHog service, which is a local SMTP server used for testing email functionality in development environments. It captures outgoing emails without actually sending them. ```shell mailhog ``` -------------------------------- ### Install Docker on Ubuntu (alternative) Source: https://github.com/discourse/discourse-developer-docs/blob/main/docs/02-development-environments/03-docker-setup.md Installs the docker.io package and adds the current user to the docker group on Ubuntu systems. This allows running Docker commands without sudo and requires a system reboot to take effect. ```shell sudo apt-get install docker.io ``` ```shell sudo usermod -a -G docker $USER ``` ```shell sudo reboot ``` -------------------------------- ### Install Docker CE on Ubuntu Source: https://github.com/discourse/discourse-developer-docs/blob/main/docs/02-development-environments/03-docker-setup.md Installs Docker Community Edition on Ubuntu systems. This process involves adding the Docker repository, updating package lists, and installing the docker-ce package. It ensures Docker is available for running containers. ```shell curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add - ``` ```shell sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" ``` ```shell sudo apt-get update ``` ```shell sudo apt-get install -y docker-ce ``` -------------------------------- ### Initialize Discourse Markdown extension Source: https://github.com/discourse/discourse-developer-docs/blob/main/docs/03-code-internals/09-markdown-extensions.md Defines the required setup function for a Discourse Markdown extension. This function is automatically called by the engine during initialization if the module is located in the correct directory. ```javascript export function setup(helper) { // ... your code goes here } ``` -------------------------------- ### Run Discourse Development Servers Source: https://github.com/discourse/discourse-developer-docs/blob/main/docs/02-development-environments/03-docker-setup.md Starts the Rails server and the Ember CLI development server for Discourse. These commands should be run in separate terminals from the Discourse source root. ```shell # In one terminal: d/rails s ``` ```shell # And in a separate terminal d/ember-cli ``` -------------------------------- ### Initialize Git Repository for Discourse Plugin Source: https://github.com/discourse/discourse-developer-docs/blob/main/docs/04-plugins/04-git-setup.md Commands to create a local directory, initialize a new Git repository, add a README, and push the initial commit to a remote GitHub repository. ```sh mkdir -p ~/code/discourse-plugin-test cd ~/code/discourse-plugin-test echo "# discourse-plugin-test" >> README.md git init git add README.md git commit -m "first commit" git remote add origin git@github.com:eviltrout/discourse-plugin-test.git git push -u origin master ``` -------------------------------- ### Access Themeable Site Settings Source: https://github.com/discourse/discourse-developer-docs/blob/main/docs/05-themes-components/02-quick-reference.md Configure site-wide settings in about.json and access them via the siteSettings service in JavaScript or templates. ```json "theme_site_settings": { "enable_welcome_banner": false } ``` ```javascript @service siteSettings; this.siteSettings.enable_welcome_banner; ``` ```handlebars ``` -------------------------------- ### Install and initialize Lefthook for Git hooks Source: https://github.com/discourse/discourse-developer-docs/blob/main/docs/03-code-internals/02-lint-and-format.md This command installs the necessary project dependencies and initializes Lefthook to manage pre-commit hooks. It ensures that code linting and formatting checks are executed automatically before any commit is finalized. ```sh pnpm install pnpm run lefthook install ``` -------------------------------- ### Manage PostgreSQL and Redis Services Source: https://github.com/discourse/discourse-developer-docs/blob/main/docs/02-development-environments/06-windows-10-setup.md Commands to start PostgreSQL and Redis services to resolve connection errors. These commands ensure the backend services are active and listening on their respective ports. ```sh sudo service postgresql start redis-server --daemonize yes --port 6379 ``` -------------------------------- ### Clone Discourse Repository Source: https://github.com/discourse/discourse-developer-docs/blob/main/docs/02-development-environments/05-ubuntu-debian-setup.md Clones the Discourse source code repository into the user's home directory. This is the first step in setting up a local development environment. ```shell git clone https://github.com/discourse/discourse.git ~/discourse ``` -------------------------------- ### Manage Theme Settings Source: https://github.com/discourse/discourse-developer-docs/blob/main/docs/05-themes-components/02-quick-reference.md Define custom settings in settings.yml and access them across JavaScript, GJS templates, and SCSS files. ```yaml fruit: default: apples|oranges type: list description: en: English Description fr: Description Française ``` ```javascript console.log(settings.fruit); ``` ```handlebars ``` ```scss html { font-size: #{$global-font-size}px; background: $site-background; } ``` -------------------------------- ### Readable Message Format Example (Good) Source: https://github.com/discourse/discourse-developer-docs/blob/main/docs/05-themes-components/27-message-format.md Presents a well-formatted and readable example of Message Format strings in English, demonstrating proper indentation and structure for plural forms. This improves maintainability and understanding. ```messageformat There { currentTopics, plural, one {is # topic} other {are # topics} }. Visitors need more to read and reply to – we recommend at least { requiredTopics, plural, one {# topic} other {# topics} }. Only staff can see this message. ``` -------------------------------- ### Discourse Theme CLI Commands Source: https://context7.com/discourse/discourse-developer-docs/llms.txt Provides essential commands for the Discourse Theme CLI, facilitating local theme development and synchronization with a Discourse instance. Includes installation, creation, downloading, and live-watching functionalities. Requires Ruby and gem installation. ```bash # Install the theme CLI gem install discourse_theme # Create a new theme discourse_theme new my-awesome-theme # Download existing theme from Discourse discourse_theme download existing-theme # Watch for changes and sync to Discourse (live reload) discourse_theme watch my-awesome-theme # Theme directory structure after creation: # my-awesome-theme/ # # about.json # # settings.yml # # common/ # #  common.scss # #  head_tag.html # # desktop/ # #  desktop.scss # # mobile/ # #  mobile.scss # # javascript/ # #  discourse/ # #  api-initializers/ # #  init-theme.gjs ``` -------------------------------- ### Bootstrap Discourse Database and Migrations Source: https://github.com/discourse/discourse-developer-docs/blob/main/docs/02-development-environments/04-macos-setup.md Creates and migrates the local Discourse database for both development and testing environments. This prepares the database schema for the application. ```shell bundle exec rake db:create bundle exec rake db:migrate RAILS_ENV=test bundle exec rake db:create db:migrate ``` -------------------------------- ### Implement Theme Translations Source: https://github.com/discourse/discourse-developer-docs/blob/main/docs/05-themes-components/02-quick-reference.md Define localizable strings in locale YAML files and retrieve them using the i18n helper with the themePrefix scope. ```yaml en: my_translation_key: "I love themes" ``` ```javascript import { i18n } from "discourse-i18n"; i18n(themePrefix("my_translation_key")); ``` ```handlebars import { i18n } from "discourse-i18n"; ``` -------------------------------- ### Implement a full Markdown-it extension Source: https://github.com/discourse/discourse-developer-docs/blob/main/docs/03-code-internals/09-markdown-extensions.md Demonstrates a complete implementation of a Markdown-it extension in Discourse. It includes configuring options, allowlisting HTML tags, and registering a custom inline rule. ```javascript function amazingMarkdownItInline(state, silent) { // standard markdown it inline extension goes here. return false; } export function setup(helper) { if(!helper.markdownIt) { return; } helper.registerOptions((opts,siteSettings)=>{ opts.features.['my_extension'] = !!siteSettings.my_extension_enabled; }); helper.allowList(['span.amazing', 'div.amazing']); helper.registerPlugin(md=>{ md.inline.push('amazing', amazingMarkdownItInline); }); } ``` -------------------------------- ### Run Database Migrations Source: https://github.com/discourse/discourse-developer-docs/blob/main/docs/02-development-environments/03-docker-setup.md Applies pending database migrations for the development environment. This command ensures the database schema is up-to-date with the current Discourse code. ```shell d/rake db:migrate RAILS_ENV=development ``` -------------------------------- ### Define Discourse Plugin Metadata Source: https://github.com/discourse/discourse-developer-docs/blob/main/docs/04-plugins/04-git-setup.md A basic plugin.rb file structure required for Discourse to recognize and load the plugin, including name, description, version, and author metadata. ```ruby # name: discourse-plugin-test # about: Shows how to set up Git # version: 0.0.1 # authors: Robin Ward ``` -------------------------------- ### Integrating Discourse core components Source: https://github.com/discourse/discourse-developer-docs/blob/main/docs/07-theme-developer-tutorial/05-components.md Shows how to import and use the DButton component from Discourse core. It also illustrates using the @tracked decorator for state management and the @action decorator to bind component methods to template events. ```gjs import Component from "@glimmer/component"; import { tracked } from "@glimmer/tracking"; import { action } from "@ember/object"; import DButton from "discourse/components/d-button"; export default class CustomWelcomeBanner extends Component { @tracked counter = 0; @action incrementCounter() { this.counter++; } } ``` -------------------------------- ### Upload Theme or Component for System Tests Source: https://github.com/discourse/discourse-developer-docs/blob/main/docs/05-themes-components/15-e2e-testing.md Before running your system tests, you must upload the theme or theme component using the provided helper methods. `upload_theme` is used for themes, and `upload_theme_component` is for theme components. These should be called within a `let!` block to ensure they are executed before tests. ```ruby RSpec.describe "Testing A Theme or Theme Component", system: true do let!(:theme) do upload_theme end # or `upload_theme_component` if your theme is a component # # let!(:theme_component) do # upload_theme_component # end it "displays the component" do # Test logic here end end ``` -------------------------------- ### Create Hello World Banner with HTML and CSS Source: https://github.com/discourse/discourse-developer-docs/blob/main/docs/07-theme-developer-tutorial/01-introduction.md A basic example demonstrating how to inject a custom banner into a Discourse theme. The HTML defines the banner structure, while the SCSS provides styling to center the text and apply a background color. ```html

Hello World!

``` ```scss .hello-world-banner { height: 300px; width: 100%; background: red; display: flex; align-items: center; justify-content: center; margin-bottom: 1em; } .hello-world { font-size: 8em; color: white; } ``` -------------------------------- ### Sign In Users for System Tests Source: https://github.com/discourse/discourse-developer-docs/blob/main/docs/05-themes-components/15-e2e-testing.md The `sign_in` helper method allows you to test your theme's appearance and behavior under different user roles. You can easily switch between regular users, staff, or other fabricated user types to ensure consistent functionality across your site. ```ruby RSpec.describe "Testing A Theme", system: true do let!(:theme) do upload_theme end it "does not display the theme for a regular user" do user = Fabricate(:user) sign_in(user) # Test logic for regular user end it "displays the theme for a staff user" do admin = Fabricate(:admin) sign_in(admin) # Test logic for staff user end end ``` -------------------------------- ### Reset Discourse Development Database Source: https://github.com/discourse/discourse-developer-docs/blob/main/docs/02-development-environments/03-docker-setup.md Resets the Discourse development database by removing the persisted data. This command is useful for starting with a clean database state. ```shell sudo rm -fr data ``` -------------------------------- ### Render components into Discourse outlets Source: https://github.com/discourse/discourse-developer-docs/blob/main/docs/07-theme-developer-tutorial/04-outlets.md Demonstrates the basic usage of the renderInOutlet API to inject components into specific UI locations. It shows both standard component registration and inline template rendering. ```js api.renderInOutlet(outletName, component); ``` ```gjs const MyComponent = ; api.renderInOutlet("some-outlet", MyComponent); // Or on one line api.renderInOutlet("some-outlet", ); ``` -------------------------------- ### Run MailHog for Email Testing Source: https://github.com/discourse/discourse-developer-docs/blob/main/docs/02-development-environments/03-docker-setup.md Starts MailHog, a tool for testing emails sent by Discourse during development. This command allows developers to inspect outgoing emails without actually sending them. ```shell d/mailhog ``` -------------------------------- ### Initialize Discourse theme repository Source: https://github.com/discourse/discourse-developer-docs/blob/main/docs/05-themes-components/23-font-component.md Commands to create a new directory, initialize a git repository, and prepare the project structure for a Discourse theme component. ```shell mkdir discourse-roboto-theme cd discourse-roboto-theme git init . vim about.json ``` -------------------------------- ### Setup Discourse Development Environment with Dev Containers Source: https://context7.com/discourse/discourse-developer-docs/llms.txt Instructions for setting up a Discourse development environment using Dev Containers. This method ensures a consistent workspace by containerizing dependencies. It involves cloning the Discourse repository, opening it in VSCode with the Dev Containers extension, building the container, and accessing the development instance. ```bash # Clone Discourse repository git clone https://github.com/discourse/discourse # Open in VSCode with Dev Containers extension installed # Use: File -> Open Folder -> select discourse directory # Then: Cmd/Ctrl + Shift + P -> "Open folder in container..." # Run default build task (Ctrl/Cmd + Shift + B) # Wait for "Build successful" message # Access development instance at http://localhost:4200 ``` -------------------------------- ### Accessing contextual data in outlets Source: https://github.com/discourse/discourse-developer-docs/blob/main/docs/07-theme-developer-tutorial/04-outlets.md Shows how to use Handlebars syntax within