Skip to content

Latest commit

 

History

History
79 lines (57 loc) · 2.91 KB

File metadata and controls

79 lines (57 loc) · 2.91 KB

CLAUDE.md

This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.

What this project is

{css2r} is an R package that extracts CSS styles from a website and generates a bslib-compatible Shiny theme. It ships both as a reusable R6 class (css2r) and as a Shiny app (named "Shiny Copy") that wraps it.

The package is built with the {golem} framework, which structures Shiny apps as R packages.

Common commands

All commands are run from an R console inside the project.

Develop interactively (runs the Shiny app in dev mode):

source("dev/run_dev.R")

Run all tests:

devtools::test()

Run a single test file:

devtools::test(filter = "css2r")

Document and reload the package:

golem::document_and_reload()

Check the package (equivalent of R CMD check):

devtools::check()

Update DESCRIPTION dependencies from parsed imports:

attachment::att_amend_desc()

Rebuild README.md from README.Rmd:

devtools::build_readme()

Architecture

Core R6 class: R/css2r.R

The css2r R6 class is the main logic unit. It performs a sequential pipeline on initialization:

  1. check_internet() — verifies connectivity via {curl}
  2. download_html() — fetches the page with {rvest}
  3. extract_css_links() — parses <link rel="stylesheet"> tags
  4. filter_css_links() — keeps only links from the same domain
  5. download_css_files() — fetches CSS content via {httr}
  6. extract_colors() — regex-extracts 6-digit hex colors, counts frequency
  7. analyze_colors() — splits white/black from top-4 brand colors
  8. detect_google_fonts() — identifies Google Fonts from CSS link params
  9. generate_shiny_code() — assembles bslib::bs_theme() call and stores it in $shiny_code and $shiny_theme

Each step can also be called manually by passing on_initialize = FALSE.

Shiny app (golem structure)

  • R/app_ui.R — UI definition using bslib::page() with Bootstrap 5; a URL input + task button, and uiOutput placeholders for results
  • R/app_server.R — server logic: calls css2r$new(), applies the extracted theme live via session$setCurrentTheme(), and sends top colors to JS via session$sendCustomMessage(type = "apply_gradient", ...)
  • R/run_app.R — exported run_app() function (golem entry point)
  • R/app_config.R — golem configuration helpers (app_sys(), get_golem_options())
  • inst/app/www/ — static assets: custom.css, handler.js (handles the apply_gradient JS message), favicon.ico
  • app.R — thin launcher for deployment (pkgload::load_all() + run_app())

Testing

Tests live in tests/testthat/. The main test (test-css2r.R) hits the live thinkr.fr website and is wrapped in skip_if_offline(). CI runs R CMD check across macOS, Windows, and Ubuntu via .github/workflows/R-CMD-check.yaml.