Skip to content

Commit 78d0c8e

Browse files
authored
Merge pull request #1 from ThinkR-open/refonte
Refonte
2 parents 03bfea6 + 14a6e48 commit 78d0c8e

File tree

14 files changed

+842
-214
lines changed

14 files changed

+842
-214
lines changed

.Rbuildignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,5 @@ $run_dev.*
1414
^app\.R$
1515
^rsconnect$
1616
^\.rscignore$
17+
^CLAUDE\.md$
18+
^manifest\.json$

CLAUDE.md

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
# CLAUDE.md
2+
3+
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
4+
5+
## What this project is
6+
7+
`{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.
8+
9+
The package is built with the [{golem}](https://thinkr-open.github.io/golem/) framework, which structures Shiny apps as R packages.
10+
11+
## Common commands
12+
13+
All commands are run from an R console inside the project.
14+
15+
**Develop interactively (runs the Shiny app in dev mode):**
16+
```r
17+
source("dev/run_dev.R")
18+
```
19+
20+
**Run all tests:**
21+
```r
22+
devtools::test()
23+
```
24+
25+
**Run a single test file:**
26+
```r
27+
devtools::test(filter = "css2r")
28+
```
29+
30+
**Document and reload the package:**
31+
```r
32+
golem::document_and_reload()
33+
```
34+
35+
**Check the package (equivalent of R CMD check):**
36+
```r
37+
devtools::check()
38+
```
39+
40+
**Update DESCRIPTION dependencies from parsed imports:**
41+
```r
42+
attachment::att_amend_desc()
43+
```
44+
45+
**Rebuild README.md from README.Rmd:**
46+
```r
47+
devtools::build_readme()
48+
```
49+
50+
## Architecture
51+
52+
### Core R6 class: `R/css2r.R`
53+
54+
The `css2r` R6 class is the main logic unit. It performs a sequential pipeline on initialization:
55+
56+
1. `check_internet()` — verifies connectivity via `{curl}`
57+
2. `download_html()` — fetches the page with `{rvest}`
58+
3. `extract_css_links()` — parses `<link rel="stylesheet">` tags
59+
4. `filter_css_links()` — keeps only links from the same domain
60+
5. `download_css_files()` — fetches CSS content via `{httr}`
61+
6. `extract_colors()` — regex-extracts 6-digit hex colors, counts frequency
62+
7. `analyze_colors()` — splits white/black from top-4 brand colors
63+
8. `detect_google_fonts()` — identifies Google Fonts from CSS link params
64+
9. `generate_shiny_code()` — assembles `bslib::bs_theme()` call and stores it in `$shiny_code` and `$shiny_theme`
65+
66+
Each step can also be called manually by passing `on_initialize = FALSE`.
67+
68+
### Shiny app (golem structure)
69+
70+
- `R/app_ui.R` — UI definition using `bslib::page()` with Bootstrap 5; a URL input + task button, and `uiOutput` placeholders for results
71+
- `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", ...)`
72+
- `R/run_app.R` — exported `run_app()` function (golem entry point)
73+
- `R/app_config.R` — golem configuration helpers (`app_sys()`, `get_golem_options()`)
74+
- `inst/app/www/` — static assets: `custom.css`, `handler.js` (handles the `apply_gradient` JS message), `favicon.ico`
75+
- `app.R` — thin launcher for deployment (`pkgload::load_all()` + `run_app()`)
76+
77+
### Testing
78+
79+
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`.

DESCRIPTION

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Package: css2r
22
Title: An Amazing Shiny App
3-
Version: 0.0.1
3+
Version: 0.1.0
44
Authors@R:
55
person("Arthur", "Bréant", , "arthur@thinkr.fr", role = c("aut", "cre"))
66
Description: What the package does (one paragraph).
@@ -12,7 +12,6 @@ Imports:
1212
curl,
1313
golem,
1414
httr,
15-
pkgload,
1615
purrr,
1716
R6,
1817
rvest,
@@ -25,4 +24,4 @@ Config/testthat/edition: 3
2524
Encoding: UTF-8
2625
Language: en-US
2726
LazyData: true
28-
RoxygenNote: 7.3.2
27+
RoxygenNote: 7.3.3

NEWS.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# css2r 0.1.0
2+
3+
* Update UI with new features
4+
15
# css2r 0.0.1
26

37
* Initiate the project

0 commit comments

Comments
 (0)