Skip to content

sass

dev_tool.commands.sass

log = logging.getLogger(__name__) module-attribute

SassCommandGroup

Bases: CommandGroup

A command group for Sass/SCSS operations.

This class provides commands for compiling SCSS stylesheets to CSS and watching source stylesheets during development.

The constructor for the SassCommandGroup class.

Parameters:

  • sass (SassService) –

    The Sass service for SCSS operations.

Source code in dev_tool/commands/sass.py
def __init__(self, sass: SassService) -> None:
    """
    The constructor for the SassCommandGroup class.

    :param sass: The Sass service for SCSS operations.
    """

    super().__init__()

    self.sass = sass

sass = sass instance-attribute

__str__

The string representation of the command group.

Returns:

  • str

    The category name as a string.

Source code in dev_tool/commands/sass.py
def __str__(self) -> str:
    """
    The string representation of the command group.

    :return: The category name as a string.
    """

    return 'Styles'

compile_styles

A command that compiles SCSS stylesheets to CSS.

Source code in dev_tool/commands/sass.py
@ordered_command(label='Compile SCSS to CSS')
def compile_styles(self) -> None:
    """A command that compiles SCSS stylesheets to CSS."""

    try:
        self.sass.compile_styles(production=False)
    except Exception as e:
        self.emit_error(f'Failed to compile SCSS: {e}')

compile_styles_production

A command that compiles SCSS stylesheets to CSS for production.

Source code in dev_tool/commands/sass.py
@ordered_command(label='Compile SCSS to CSS (production)')
def compile_styles_production(self) -> None:
    """A command that compiles SCSS stylesheets to CSS for production."""

    try:
        self.sass.compile_styles(production=True)
    except Exception as e:
        self.emit_error(f'Failed to compile SCSS for production: {e}')

watch_styles

A command that watches SCSS source files and recompiles on change.

Source code in dev_tool/commands/sass.py
@ordered_command(label='Watch SCSS for changes')
def watch_styles(self) -> None:
    """A command that watches SCSS source files and recompiles on change."""

    runner = self.sass.create_runner()

    if runner is None:
        self.emit_error('No SCSS source directories found to watch')
        return

    try:
        runner.run_and_wait()
    except Exception as e:
        self.emit_error(f'Failed to watch SCSS: {e}')