├── .browserslistrc
├── .editorconfig
├── .eslintignore
├── .eslintrc
├── .github
├── ISSUE_TEMPLATE
│ ├── bug.md
│ ├── epic.md
│ └── task.md
├── PULL_REQUEST_TEMPLATE.md
├── bin
│ └── determine-modified-files-count.js
├── dependabot.yml
├── release.yml
└── workflows
│ ├── auto-merge.yml
│ └── test-measure.yml
├── .gitignore
├── .lintstagedrc.js
├── .npmrc
├── .nvmrc
├── .stylelintignore
├── .stylelintrc.json
├── .vipgoci_phpcs_skip_folders
├── .wp-env.json
├── LICENSE
├── README.md
├── assets
└── src
│ ├── css
│ ├── core-navigation.scss
│ └── styles.scss
│ └── js
│ ├── core-navigation.js
│ └── modules
│ └── media-text.js
├── babel.config.js
├── bin
├── init.js
└── phpcbf.js
├── composer.json
├── composer.lock
├── docs
└── asset-building-process.md
├── functions.php
├── inc
├── classes
│ ├── block-extension
│ │ └── class-media-text-interactive.php
│ ├── class-assets.php
│ └── class-elementary-theme.php
├── helpers
│ └── custom-functions.php
└── traits
│ └── trait-singleton.php
├── languages
└── elementary-theme.pot
├── package-lock.json
├── package.json
├── parts
├── footer.html
└── header.html
├── patterns
├── footer.php
├── hidden-404.php
├── media-text-interactive.php
└── page-creation-pattern.php
├── phpcs.xml.dist
├── phpunit.xml.dist
├── screenshot.png
├── style.css
├── styles
└── light.json
├── templates
├── 404.html
├── archive.html
├── home.html
├── index.html
├── no-title.html
├── page.html
├── search.html
└── single.html
├── tests
├── bootstrap.php
├── js
│ ├── jest.config.js
│ └── setup-globals.js
└── php
│ ├── TestCase.php
│ └── inc
│ └── classes
│ └── test-class-elementary-theme.php
├── theme.json
└── webpack.config.js
/.browserslistrc:
--------------------------------------------------------------------------------
1 | extends @wordpress/browserslist-config
2 |
--------------------------------------------------------------------------------
/.editorconfig:
--------------------------------------------------------------------------------
1 | # This file is for unifying the coding style for different editors and IDEs
2 | # editorconfig.org
3 |
4 | # WordPress Coding Standards
5 | # https://make.wordpress.org/core/handbook/coding-standards/
6 |
7 | root = true
8 |
9 | [*]
10 | charset = utf-8
11 | end_of_line = lf
12 | insert_final_newline = true
13 | trim_trailing_whitespace = true
14 | indent_style = tab
15 |
16 | [*.yml]
17 | indent_style = space
18 | indent_size = 2
19 |
20 | [*.md]
21 | trim_trailing_whitespace = false
22 |
--------------------------------------------------------------------------------
/.eslintignore:
--------------------------------------------------------------------------------
1 | **/*.min.js
2 | **/node_modules/**
3 | **/vendor/**
4 | build/*
5 |
--------------------------------------------------------------------------------
/.eslintrc:
--------------------------------------------------------------------------------
1 | {
2 | "root": true,
3 | "extends": [
4 | "plugin:@wordpress/eslint-plugin/recommended-with-formatting",
5 | "plugin:import/recommended",
6 | "plugin:eslint-comments/recommended"
7 | ],
8 | "env": {
9 | "browser": true
10 | },
11 | "rules": {
12 | "jsdoc/check-indentation": "error",
13 | "@wordpress/dependency-group": "error"
14 | },
15 | "overrides": [{
16 | "files": [
17 | "**/__tests__/**/*.js",
18 | "**/test/*.js",
19 | "**/?(*.)test.js",
20 | "tests/js/**/*.js"
21 | ],
22 | "extends": [
23 | "plugin:jest/all"
24 | ],
25 | "rules": {
26 | // Add Rules for Jest here
27 | }
28 | }]
29 | }
30 |
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE/bug.md:
--------------------------------------------------------------------------------
1 | ---
2 | name: Bug Report
3 | about: There is a bug in functionality that needs to be fixed.
4 | title: ''
5 | labels: ''
6 | assignees: ''
7 |
8 | ---
9 |
10 | ## Description
11 |
12 |
13 |
14 | ## Steps to Reproduce
15 |
16 |
17 |
18 | ## Screenshots
19 |
20 |
21 |
22 | ## Additional Information
23 |
24 |
25 |
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE/epic.md:
--------------------------------------------------------------------------------
1 | ---
2 | name: Epic
3 | about: An Epic for tracking multiple tasks related to a theme of work.
4 | title: ''
5 | labels: ''
6 | assignees: ''
7 | ---
8 |
9 | ## Summary
10 |
11 |
12 |
13 | ## References
14 |
15 |
16 |
17 | ## Tasks
18 |
19 |
25 |
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE/task.md:
--------------------------------------------------------------------------------
1 | ---
2 | name: Task
3 | about: A descriptive task to be done.
4 | title: ''
5 | labels: ''
6 | assignees: ''
7 | ---
8 |
9 | ## Summary
10 |
11 |
12 |
13 | ## References
14 |
15 |
16 |
17 | ## Acceptance Criteria
18 |
19 |
25 |
--------------------------------------------------------------------------------
/.github/PULL_REQUEST_TEMPLATE.md:
--------------------------------------------------------------------------------
1 | ## Description
2 |
3 |
4 |
5 | ## Technical Details
6 |
7 |
8 |
9 | ## Checklist
10 |
11 |
18 |
19 | ## Screenshots
20 |
21 |
22 |
23 | ## To-do
24 |
25 |
26 |
27 | ## Fixes/Covers issue
28 |
29 |
30 | Fixes #
31 |
32 |
33 |
--------------------------------------------------------------------------------
/.github/bin/determine-modified-files-count.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Determine the modified files count.
3 | *
4 | * Usage:
5 | * node determine-modified-files-count.js [path/to/dir]
6 | *
7 | * Example:
8 | * node determine-modified-files-count.js "foo\/bar|bar*" "foo/bar/baz\nquux" "foo/bar"
9 | *
10 | * Output: 1
11 | */
12 | const args = process.argv.slice(2);
13 | const pattern = args[0];
14 | const modifiedFiles = args[1].split('\n');
15 | const dirInclude = args[2];
16 |
17 | let count;
18 |
19 | if ( 'all' === dirInclude ) {
20 | count = modifiedFiles.reduce((count, file) => {
21 | if (pattern.split('|').some(pattern => file.match(pattern))) {
22 | return count;
23 | }
24 |
25 | return count + 1;
26 | }, 0);
27 | } else {
28 | count = modifiedFiles.filter( ( file ) => {
29 | return file.match( pattern );
30 | } ).length;
31 | }
32 |
33 | console.log( count );
34 |
--------------------------------------------------------------------------------
/.github/dependabot.yml:
--------------------------------------------------------------------------------
1 | version: 2
2 | updates:
3 | - package-ecosystem: github-actions
4 | directory: '/'
5 | schedule:
6 | interval: monthly
7 | time: '00:00'
8 | timezone: 'Asia/Calcutta'
9 | open-pull-requests-limit: 10
10 | labels:
11 | - GHA
12 | - Dependencies
13 |
14 | - package-ecosystem: npm
15 | directory: '/'
16 | schedule:
17 | interval: monthly
18 | time: '00:00'
19 | timezone: 'Asia/Calcutta'
20 | open-pull-requests-limit: 10
21 | labels:
22 | - NPM
23 | - Dependencies
24 | groups:
25 | wordpress-packages:
26 | patterns:
27 | - "@wordpress/*"
28 |
29 | - package-ecosystem: composer
30 | directory: '/'
31 | schedule:
32 | interval: monthly
33 | time: '00:00'
34 | timezone: 'Asia/Calcutta'
35 | open-pull-requests-limit: 10
36 | labels:
37 | - Composer
38 | - Dependencies
39 |
--------------------------------------------------------------------------------
/.github/release.yml:
--------------------------------------------------------------------------------
1 | changelog:
2 | exclude:
3 | authors:
4 | - dependabot
5 | - dependabot-preview
6 |
--------------------------------------------------------------------------------
/.github/workflows/auto-merge.yml:
--------------------------------------------------------------------------------
1 | name: Pull Requests auto-merge
2 |
3 | on:
4 | workflow_run:
5 | workflows: ["Test and Measure"]
6 | types:
7 | - completed
8 |
9 | permissions:
10 | pull-requests: write
11 | contents: write
12 |
13 | # Cancel previous workflow run groups that have not completed.
14 | concurrency:
15 | # Group workflow runs by workflow name and branch name of pull request.
16 | group: ${{ github.workflow }}-${{ github.head_ref }}
17 | cancel-in-progress: true
18 |
19 | jobs:
20 | dependabot:
21 | name: Dependabot PR auto-merge
22 | runs-on: ubuntu-latest
23 | if: ${{ github.actor == 'dependabot[bot]' }}
24 | steps:
25 | - name: Checkout
26 | uses: actions/checkout@v4
27 |
28 | - name: Approve and merge the PR
29 | if: |
30 | contains( github.event.workflow_run.head_commit.message, 'version-update:semver-minor' ) ||
31 | contains( github.event.workflow_run.head_commit.message, 'version-update:semver-patch' )
32 | run: gh pr merge "$PR_NUMBER" --auto --merge --delete-branch
33 | env:
34 | PR_NUMBER: ${{github.event.workflow_run.pull_requests[0].number}}
35 | GITHUB_TOKEN: ${{secrets.GH_BOT_TOKEN}}
36 |
37 | gutenberg-packages:
38 | name: Gutenberg packages update PR auto-merge
39 | runs-on: ubuntu-latest
40 | if: ${{ github.actor == 'rtBot' }}
41 | steps:
42 | - name: Checkout
43 | uses: actions/checkout@v4
44 |
45 | - name: Approve and merge the PR
46 | if: |
47 | startsWith(github.event.workflow_run.head_commit.message, 'Update WordPress NPM packages based on Gutenberg release') &&
48 | endsWith(github.event.workflow_run.head_commit.message, format('{0} {1}', 'rtBot', '<43742164+rtBot@users.noreply.github.com>')) &&
49 | github.event.workflow_run.head_commit.author.name == 'rtBot' &&
50 | github.event.workflow_run.head_commit.author.email == '43742164+rtBot@users.noreply.github.com'
51 | run: gh pr merge "$PR_NUMBER" --auto --merge --delete-branch
52 | env:
53 | PR_NUMBER: ${{github.event.workflow_run.pull_requests[0].number}}
54 | GITHUB_TOKEN: ${{secrets.GH_BOT_TOKEN}}
55 |
--------------------------------------------------------------------------------
/.github/workflows/test-measure.yml:
--------------------------------------------------------------------------------
1 | name: Test and Measure
2 |
3 | on:
4 | push:
5 | branches:
6 | - main
7 | pull_request:
8 | types:
9 | - opened
10 | - synchronize
11 | - ready_for_review
12 |
13 | concurrency:
14 | group: ${{ github.workflow }}-${{ github.event_name == 'pull_request' && github.head_ref || github.ref }}
15 | cancel-in-progress: true
16 |
17 | jobs:
18 | pre-run:
19 | name: 'Pre run'
20 | runs-on: ubuntu-latest
21 | outputs:
22 | changed-file-count: ${{ steps.determine-file-counts.outputs.count }}
23 | changed-css-count: ${{ steps.determine-file-counts.outputs.css-count }}
24 | changed-js-count: ${{ steps.determine-file-counts.outputs.js-count }}
25 | changed-php-count: ${{ steps.determine-file-counts.outputs.php-count }}
26 | changed-gha-workflow-count: ${{ steps.determine-file-counts.outputs.gha-workflow-count }}
27 |
28 | steps:
29 | - name: Checkout including last 2 commits
30 | # Fetch last 2 commits if it's not a PR, so that we can determine the list of modified files.
31 | if: ${{ github.base_ref == null }}
32 | uses: actions/checkout@v4
33 | with:
34 | fetch-depth: 2
35 |
36 | - name: Checkout
37 | # Do usual checkout if it's a PR.
38 | if: ${{ github.base_ref != null }}
39 | uses: actions/checkout@v4
40 |
41 | - name: Fetch base branch
42 | # Only fetch base ref if it's a PR.
43 | if: ${{ github.base_ref != null }}
44 | run: git fetch --depth=1 --no-tags origin ${{ github.base_ref }}
45 |
46 | - name: Determine modified files for PR
47 | if: ${{ github.base_ref != null }}
48 | run: echo "MODIFIED_FILES=$(git diff --name-only FETCH_HEAD HEAD | base64 -w 0)" >> $GITHUB_ENV
49 |
50 | - name: Determine modified files for commit
51 | if: ${{ github.base_ref == null }}
52 | run: echo "MODIFIED_FILES=$(git diff --name-only HEAD~1 HEAD | base64 -w 0)" >> $GITHUB_ENV
53 |
54 | - id: determine-file-counts
55 | name: Determine if modified files should make the workflow run continue
56 | run: |
57 | MODIFIED_FILES=$(echo "$MODIFIED_FILES" | base64 -d)
58 | echo -e "Modified files:\n$MODIFIED_FILES\n"
59 |
60 | MODIFIED_FILES_DATA=$(node .github/bin/determine-modified-files-count.js "$IGNORE_PATH_REGEX" "$MODIFIED_FILES" "all")
61 | CSS_FILE_COUNT=$(node .github/bin/determine-modified-files-count.js ".+\.s?css|package\.json|package-lock\.json" "$MODIFIED_FILES")
62 | JS_FILE_COUNT=$(node .github/bin/determine-modified-files-count.js ".+\.(js|snap)|package\.json|package-lock\.json" "$MODIFIED_FILES")
63 | PHP_FILE_COUNT=$(node .github/bin/determine-modified-files-count.js ".+\.php|composer\.(json|lock)|phpstan\.neon\.dist" "$MODIFIED_FILES")
64 | GHA_WORKFLOW_COUNT=$(node .github/bin/determine-modified-files-count.js "(\.github\/workflows\/.+\.yml)" "$MODIFIED_FILES")
65 |
66 | echo "Changed file count: $MODIFIED_FILES_DATA"
67 | echo "Changed CK theme CSS file count: $CSS_FILE_COUNT"
68 | echo "Changed CK theme JS file count: $JS_FILE_COUNT"
69 | echo "Changed CK theme PHP file count: $PHP_FILE_COUNT"
70 | echo "Changed GHA workflow count: $GHA_WORKFLOW_COUNT"
71 |
72 | echo "::set-output name=count::$MODIFIED_FILES_DATA"
73 | echo "::set-output name=css-count::$CSS_FILE_COUNT"
74 | echo "::set-output name=js-count::$JS_FILE_COUNT"
75 | echo "::set-output name=php-count::$PHP_FILE_COUNT"
76 | echo "::set-output name=gha-workflow-count::$GHA_WORKFLOW_COUNT"
77 | env:
78 | # Ignore Paths:
79 | # - .github/
80 | # - !.github/workflows
81 | # - .wordpress-org/
82 | # - docs/
83 | IGNORE_PATH_REGEX: \.github\/(?!workflows)|\.wordpress-org\/|docs\/
84 |
85 | lint-css:
86 | needs: pre-run
87 | if: needs.pre-run.outputs.changed-css-count > 0 || needs.pre-run.outputs.changed-gha-workflow-count > 0
88 | name: 'Lint CSS'
89 | runs-on: ubuntu-latest
90 | steps:
91 | - name: Checkout
92 | uses: actions/checkout@v4
93 |
94 | - name: Setup Node
95 | uses: actions/setup-node@v4.1.0
96 | with:
97 | node-version-file: '.nvmrc'
98 | cache: npm
99 |
100 | - name: Install Node dependencies
101 | run: npm ci --ignore-scripts
102 | env:
103 | CI: true
104 |
105 | - name: Detect coding standard violations (stylelint)
106 | run: npm run lint:css
107 |
108 | lint-js:
109 | needs: pre-run
110 | if: needs.pre-run.outputs.changed-js-count > 0 || needs.pre-run.outputs.changed-gha-workflow-count > 0
111 | name: 'Lint JS'
112 | runs-on: ubuntu-latest
113 | steps:
114 | - name: Checkout
115 | uses: actions/checkout@v4
116 |
117 | - name: Setup Node
118 | uses: actions/setup-node@v4.1.0
119 | with:
120 | node-version-file: '.nvmrc'
121 | cache: npm
122 |
123 | - name: Install Node dependencies
124 | run: npm ci --ignore-scripts
125 | env:
126 | CI: true
127 |
128 | - name: Detect coding standard violations (eslint)
129 | run: npm run lint:js
130 |
131 | unit-tests-js:
132 | needs: pre-run
133 | if: needs.pre-run.outputs.changed-js-count > 0 || needs.pre-run.outputs.changed-gha-workflow-count > 0
134 | name: 'Run JS unit tests'
135 | runs-on: ubuntu-latest
136 | steps:
137 | - name: Checkout
138 | uses: actions/checkout@v4
139 |
140 | - name: Setup Node
141 | uses: actions/setup-node@v4.1.0
142 | with:
143 | node-version-file: '.nvmrc'
144 | cache: npm
145 |
146 | - name: Install Node dependencies
147 | run: npm ci --ignore-scripts
148 | env:
149 | CI: true
150 |
151 | - name: Run unit tests
152 | run: npm run test:js
153 | env:
154 | CI: true
155 |
156 | lint-php:
157 | needs: pre-run
158 | if: needs.pre-run.outputs.changed-php-count > 0 || needs.pre-run.outputs.changed-gha-workflow-count > 0
159 | name: 'Lint PHP'
160 | runs-on: ubuntu-latest
161 | steps:
162 | - name: Checkout
163 | uses: actions/checkout@v4
164 |
165 | - name: Setup PHP
166 | uses: shivammathur/setup-php@v2
167 | with:
168 | php-version: '8.2'
169 | coverage: none
170 | tools: cs2pr
171 |
172 | - name: Get Composer Cache Directory
173 | id: composer-cache
174 | run: echo "::set-output name=dir::$(composer config cache-files-dir)"
175 |
176 | - name: Configure Composer cache
177 | uses: actions/cache@v4.2.0
178 | with:
179 | path: ${{ steps.composer-cache.outputs.dir }}
180 | key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
181 | restore-keys: |
182 | ${{ runner.os }}-composer-
183 | - name: Install Composer dependencies
184 | run: composer install --prefer-dist --optimize-autoloader --no-progress --no-interaction --no-scripts
185 |
186 | - name: Validate composer.json
187 | run: composer --no-interaction validate --no-check-all
188 |
189 | - name: Detect coding standard violations (PHPCS)
190 | run: vendor/bin/phpcs -q --report=checkstyle --runtime-set ignore_errors_on_exit 1 --runtime-set ignore_warnings_on_exit 1 | cs2pr --graceful-warnings
191 |
192 | unit-test-php:
193 | name: "PHP Unit test"
194 | runs-on: ubuntu-latest
195 | needs: pre-run
196 | steps:
197 | # Note: The repeated `needs.pre-run.outputs.changed-php-count > 0` checks would be avoided if a step could short-
198 | # circuit per . The reason why the if statement can't be put on the
199 | # job as a whole is because the name is variable based on the matrix, and if the condition is not met then the
200 | # name won't be interpolated in order to match the required jobs set up in branch protection.
201 | - name: Notice
202 | if: needs.pre-run.outputs.changed-php-count > 0
203 | run: echo "No PHP files were changed in CK theme so no PHP unit tests will run"
204 |
205 | - name: Checkout
206 | if: needs.pre-run.outputs.changed-php-count > 0
207 | uses: actions/checkout@v4
208 |
209 | - name: Setup Node
210 | if: needs.pre-run.outputs.changed-php-count > 0
211 | uses: actions/setup-node@v4.1.0
212 | with:
213 | node-version-file: '.nvmrc'
214 | cache: npm
215 |
216 | - name: Install Node dependencies
217 | if: needs.pre-run.outputs.changed-php-count > 0
218 | run: npm ci --ignore-scripts
219 | env:
220 | CI: true
221 |
222 | - name: Start WP environment
223 | if: needs.pre-run.outputs.changed-php-count > 0
224 | run: npm run wp-env start
225 |
226 | - name: Run tests
227 | if: ${{ needs.pre-run.outputs.changed-php-count > 0 }}
228 | run: npm run test:php
229 |
230 | build-prod:
231 | needs: pre-run
232 | if: needs.pre-run.outputs.changed-js-count > 0 || needs.pre-run.outputs.changed-gha-workflow-count > 0 || needs.pre-run.outputs.changed-css-count > 0
233 | name: 'Build production'
234 | runs-on: ubuntu-latest
235 | steps:
236 | - name: Checkout
237 | uses: actions/checkout@v4
238 |
239 | - name: Setup Node
240 | uses: actions/setup-node@v4.1.0
241 | with:
242 | node-version-file: '.nvmrc'
243 | cache: npm
244 |
245 | - name: Install Node dependencies
246 | run: npm ci --ignore-scripts
247 | env:
248 | CI: true
249 |
250 | - name: Build production
251 | id: build
252 | run: npm run build:prod
253 | env:
254 | CI: true
255 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | ### WordPress ###
2 |
3 | # Core
4 | /wordpress/
5 |
6 | # macOS/IDE
7 | .DS_Store
8 | .idea
9 |
10 | # Log files
11 | *.log
12 | /tests/logs
13 |
14 | # Packages
15 | /vendor/
16 | /node_modules/
17 |
18 | # Enviroment
19 | .env
20 | .wp-env.override.json
21 |
22 | # Build
23 | assets/build/
24 |
25 | # PHPCS
26 | phpcs.xml
27 |
28 | # Cache
29 | .phpunit.result.cache
30 |
--------------------------------------------------------------------------------
/.lintstagedrc.js:
--------------------------------------------------------------------------------
1 | module.exports = {
2 | "**/*.php": [
3 | "npm run lint:php"
4 | ],
5 | "**/*.js": [
6 | "npm run lint:js"
7 | ],
8 | "**/*.{css,scss}": [
9 | "npm run lint:css"
10 | ],
11 | "package.json": [
12 | "npm run lint:package-json"
13 | ],
14 | };
15 |
--------------------------------------------------------------------------------
/.npmrc:
--------------------------------------------------------------------------------
1 | save-exact = true
2 |
--------------------------------------------------------------------------------
/.nvmrc:
--------------------------------------------------------------------------------
1 | v20
2 |
--------------------------------------------------------------------------------
/.stylelintignore:
--------------------------------------------------------------------------------
1 | /assets/build/*.css
2 | /tests
3 | /vendor
4 |
--------------------------------------------------------------------------------
/.stylelintrc.json:
--------------------------------------------------------------------------------
1 | {
2 | "extends": "@wordpress/stylelint-config/scss",
3 | "ignoreFiles": [
4 | "**/*.js"
5 | ],
6 | "rules": {}
7 | }
8 |
--------------------------------------------------------------------------------
/.vipgoci_phpcs_skip_folders:
--------------------------------------------------------------------------------
1 | .github
2 | tests
3 | vendor
4 | node_modules
5 |
6 |
--------------------------------------------------------------------------------
/.wp-env.json:
--------------------------------------------------------------------------------
1 | {
2 | "core": null,
3 | "phpVersion": "8.2",
4 | "themes": [ "." ],
5 | "port": 5890,
6 | "env": {
7 | "tests": {
8 | "port": 5891
9 | }
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | GNU GENERAL PUBLIC LICENSE
2 | Version 2, June 1991
3 |
4 | Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
5 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
6 | Everyone is permitted to copy and distribute verbatim copies
7 | of this license document, but changing it is not allowed.
8 |
9 | Preamble
10 |
11 | The licenses for most software are designed to take away your
12 | freedom to share and change it. By contrast, the GNU General Public
13 | License is intended to guarantee your freedom to share and change free
14 | software--to make sure the software is free for all its users. This
15 | General Public License applies to most of the Free Software
16 | Foundation's software and to any other program whose authors commit to
17 | using it. (Some other Free Software Foundation software is covered by
18 | the GNU Lesser General Public License instead.) You can apply it to
19 | your programs, too.
20 |
21 | When we speak of free software, we are referring to freedom, not
22 | price. Our General Public Licenses are designed to make sure that you
23 | have the freedom to distribute copies of free software (and charge for
24 | this service if you wish), that you receive source code or can get it
25 | if you want it, that you can change the software or use pieces of it
26 | in new free programs; and that you know you can do these things.
27 |
28 | To protect your rights, we need to make restrictions that forbid
29 | anyone to deny you these rights or to ask you to surrender the rights.
30 | These restrictions translate to certain responsibilities for you if you
31 | distribute copies of the software, or if you modify it.
32 |
33 | For example, if you distribute copies of such a program, whether
34 | gratis or for a fee, you must give the recipients all the rights that
35 | you have. You must make sure that they, too, receive or can get the
36 | source code. And you must show them these terms so they know their
37 | rights.
38 |
39 | We protect your rights with two steps: (1) copyright the software, and
40 | (2) offer you this license which gives you legal permission to copy,
41 | distribute and/or modify the software.
42 |
43 | Also, for each author's protection and ours, we want to make certain
44 | that everyone understands that there is no warranty for this free
45 | software. If the software is modified by someone else and passed on, we
46 | want its recipients to know that what they have is not the original, so
47 | that any problems introduced by others will not reflect on the original
48 | authors' reputations.
49 |
50 | Finally, any free program is threatened constantly by software
51 | patents. We wish to avoid the danger that redistributors of a free
52 | program will individually obtain patent licenses, in effect making the
53 | program proprietary. To prevent this, we have made it clear that any
54 | patent must be licensed for everyone's free use or not licensed at all.
55 |
56 | The precise terms and conditions for copying, distribution and
57 | modification follow.
58 |
59 | GNU GENERAL PUBLIC LICENSE
60 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
61 |
62 | 0. This License applies to any program or other work which contains
63 | a notice placed by the copyright holder saying it may be distributed
64 | under the terms of this General Public License. The "Program", below,
65 | refers to any such program or work, and a "work based on the Program"
66 | means either the Program or any derivative work under copyright law:
67 | that is to say, a work containing the Program or a portion of it,
68 | either verbatim or with modifications and/or translated into another
69 | language. (Hereinafter, translation is included without limitation in
70 | the term "modification".) Each licensee is addressed as "you".
71 |
72 | Activities other than copying, distribution and modification are not
73 | covered by this License; they are outside its scope. The act of
74 | running the Program is not restricted, and the output from the Program
75 | is covered only if its contents constitute a work based on the
76 | Program (independent of having been made by running the Program).
77 | Whether that is true depends on what the Program does.
78 |
79 | 1. You may copy and distribute verbatim copies of the Program's
80 | source code as you receive it, in any medium, provided that you
81 | conspicuously and appropriately publish on each copy an appropriate
82 | copyright notice and disclaimer of warranty; keep intact all the
83 | notices that refer to this License and to the absence of any warranty;
84 | and give any other recipients of the Program a copy of this License
85 | along with the Program.
86 |
87 | You may charge a fee for the physical act of transferring a copy, and
88 | you may at your option offer warranty protection in exchange for a fee.
89 |
90 | 2. You may modify your copy or copies of the Program or any portion
91 | of it, thus forming a work based on the Program, and copy and
92 | distribute such modifications or work under the terms of Section 1
93 | above, provided that you also meet all of these conditions:
94 |
95 | a) You must cause the modified files to carry prominent notices
96 | stating that you changed the files and the date of any change.
97 |
98 | b) You must cause any work that you distribute or publish, that in
99 | whole or in part contains or is derived from the Program or any
100 | part thereof, to be licensed as a whole at no charge to all third
101 | parties under the terms of this License.
102 |
103 | c) If the modified program normally reads commands interactively
104 | when run, you must cause it, when started running for such
105 | interactive use in the most ordinary way, to print or display an
106 | announcement including an appropriate copyright notice and a
107 | notice that there is no warranty (or else, saying that you provide
108 | a warranty) and that users may redistribute the program under
109 | these conditions, and telling the user how to view a copy of this
110 | License. (Exception: if the Program itself is interactive but
111 | does not normally print such an announcement, your work based on
112 | the Program is not required to print an announcement.)
113 |
114 | These requirements apply to the modified work as a whole. If
115 | identifiable sections of that work are not derived from the Program,
116 | and can be reasonably considered independent and separate works in
117 | themselves, then this License, and its terms, do not apply to those
118 | sections when you distribute them as separate works. But when you
119 | distribute the same sections as part of a whole which is a work based
120 | on the Program, the distribution of the whole must be on the terms of
121 | this License, whose permissions for other licensees extend to the
122 | entire whole, and thus to each and every part regardless of who wrote it.
123 |
124 | Thus, it is not the intent of this section to claim rights or contest
125 | your rights to work written entirely by you; rather, the intent is to
126 | exercise the right to control the distribution of derivative or
127 | collective works based on the Program.
128 |
129 | In addition, mere aggregation of another work not based on the Program
130 | with the Program (or with a work based on the Program) on a volume of
131 | a storage or distribution medium does not bring the other work under
132 | the scope of this License.
133 |
134 | 3. You may copy and distribute the Program (or a work based on it,
135 | under Section 2) in object code or executable form under the terms of
136 | Sections 1 and 2 above provided that you also do one of the following:
137 |
138 | a) Accompany it with the complete corresponding machine-readable
139 | source code, which must be distributed under the terms of Sections
140 | 1 and 2 above on a medium customarily used for software interchange; or,
141 |
142 | b) Accompany it with a written offer, valid for at least three
143 | years, to give any third party, for a charge no more than your
144 | cost of physically performing source distribution, a complete
145 | machine-readable copy of the corresponding source code, to be
146 | distributed under the terms of Sections 1 and 2 above on a medium
147 | customarily used for software interchange; or,
148 |
149 | c) Accompany it with the information you received as to the offer
150 | to distribute corresponding source code. (This alternative is
151 | allowed only for noncommercial distribution and only if you
152 | received the program in object code or executable form with such
153 | an offer, in accord with Subsection b above.)
154 |
155 | The source code for a work means the preferred form of the work for
156 | making modifications to it. For an executable work, complete source
157 | code means all the source code for all modules it contains, plus any
158 | associated interface definition files, plus the scripts used to
159 | control compilation and installation of the executable. However, as a
160 | special exception, the source code distributed need not include
161 | anything that is normally distributed (in either source or binary
162 | form) with the major components (compiler, kernel, and so on) of the
163 | operating system on which the executable runs, unless that component
164 | itself accompanies the executable.
165 |
166 | If distribution of executable or object code is made by offering
167 | access to copy from a designated place, then offering equivalent
168 | access to copy the source code from the same place counts as
169 | distribution of the source code, even though third parties are not
170 | compelled to copy the source along with the object code.
171 |
172 | 4. You may not copy, modify, sublicense, or distribute the Program
173 | except as expressly provided under this License. Any attempt
174 | otherwise to copy, modify, sublicense or distribute the Program is
175 | void, and will automatically terminate your rights under this License.
176 | However, parties who have received copies, or rights, from you under
177 | this License will not have their licenses terminated so long as such
178 | parties remain in full compliance.
179 |
180 | 5. You are not required to accept this License, since you have not
181 | signed it. However, nothing else grants you permission to modify or
182 | distribute the Program or its derivative works. These actions are
183 | prohibited by law if you do not accept this License. Therefore, by
184 | modifying or distributing the Program (or any work based on the
185 | Program), you indicate your acceptance of this License to do so, and
186 | all its terms and conditions for copying, distributing or modifying
187 | the Program or works based on it.
188 |
189 | 6. Each time you redistribute the Program (or any work based on the
190 | Program), the recipient automatically receives a license from the
191 | original licensor to copy, distribute or modify the Program subject to
192 | these terms and conditions. You may not impose any further
193 | restrictions on the recipients' exercise of the rights granted herein.
194 | You are not responsible for enforcing compliance by third parties to
195 | this License.
196 |
197 | 7. If, as a consequence of a court judgment or allegation of patent
198 | infringement or for any other reason (not limited to patent issues),
199 | conditions are imposed on you (whether by court order, agreement or
200 | otherwise) that contradict the conditions of this License, they do not
201 | excuse you from the conditions of this License. If you cannot
202 | distribute so as to satisfy simultaneously your obligations under this
203 | License and any other pertinent obligations, then as a consequence you
204 | may not distribute the Program at all. For example, if a patent
205 | license would not permit royalty-free redistribution of the Program by
206 | all those who receive copies directly or indirectly through you, then
207 | the only way you could satisfy both it and this License would be to
208 | refrain entirely from distribution of the Program.
209 |
210 | If any portion of this section is held invalid or unenforceable under
211 | any particular circumstance, the balance of the section is intended to
212 | apply and the section as a whole is intended to apply in other
213 | circumstances.
214 |
215 | It is not the purpose of this section to induce you to infringe any
216 | patents or other property right claims or to contest validity of any
217 | such claims; this section has the sole purpose of protecting the
218 | integrity of the free software distribution system, which is
219 | implemented by public license practices. Many people have made
220 | generous contributions to the wide range of software distributed
221 | through that system in reliance on consistent application of that
222 | system; it is up to the author/donor to decide if he or she is willing
223 | to distribute software through any other system and a licensee cannot
224 | impose that choice.
225 |
226 | This section is intended to make thoroughly clear what is believed to
227 | be a consequence of the rest of this License.
228 |
229 | 8. If the distribution and/or use of the Program is restricted in
230 | certain countries either by patents or by copyrighted interfaces, the
231 | original copyright holder who places the Program under this License
232 | may add an explicit geographical distribution limitation excluding
233 | those countries, so that distribution is permitted only in or among
234 | countries not thus excluded. In such case, this License incorporates
235 | the limitation as if written in the body of this License.
236 |
237 | 9. The Free Software Foundation may publish revised and/or new versions
238 | of the General Public License from time to time. Such new versions will
239 | be similar in spirit to the present version, but may differ in detail to
240 | address new problems or concerns.
241 |
242 | Each version is given a distinguishing version number. If the Program
243 | specifies a version number of this License which applies to it and "any
244 | later version", you have the option of following the terms and conditions
245 | either of that version or of any later version published by the Free
246 | Software Foundation. If the Program does not specify a version number of
247 | this License, you may choose any version ever published by the Free Software
248 | Foundation.
249 |
250 | 10. If you wish to incorporate parts of the Program into other free
251 | programs whose distribution conditions are different, write to the author
252 | to ask for permission. For software which is copyrighted by the Free
253 | Software Foundation, write to the Free Software Foundation; we sometimes
254 | make exceptions for this. Our decision will be guided by the two goals
255 | of preserving the free status of all derivatives of our free software and
256 | of promoting the sharing and reuse of software generally.
257 |
258 | NO WARRANTY
259 |
260 | 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
261 | FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
262 | OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
263 | PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
264 | OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
265 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
266 | TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
267 | PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
268 | REPAIR OR CORRECTION.
269 |
270 | 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
271 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
272 | REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
273 | INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
274 | OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
275 | TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
276 | YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
277 | PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
278 | POSSIBILITY OF SUCH DAMAGES.
279 |
280 | END OF TERMS AND CONDITIONS
281 |
282 | How to Apply These Terms to Your New Programs
283 |
284 | If you develop a new program, and you want it to be of the greatest
285 | possible use to the public, the best way to achieve this is to make it
286 | free software which everyone can redistribute and change under these terms.
287 |
288 | To do so, attach the following notices to the program. It is safest
289 | to attach them to the start of each source file to most effectively
290 | convey the exclusion of warranty; and each file should have at least
291 | the "copyright" line and a pointer to where the full notice is found.
292 |
293 | {description}
294 | Copyright (C) {year} {fullname}
295 |
296 | This program is free software; you can redistribute it and/or modify
297 | it under the terms of the GNU General Public License as published by
298 | the Free Software Foundation; either version 2 of the License, or
299 | (at your option) any later version.
300 |
301 | This program is distributed in the hope that it will be useful,
302 | but WITHOUT ANY WARRANTY; without even the implied warranty of
303 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
304 | GNU General Public License for more details.
305 |
306 | You should have received a copy of the GNU General Public License along
307 | with this program; if not, write to the Free Software Foundation, Inc.,
308 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
309 |
310 | Also add information on how to contact you by electronic and paper mail.
311 |
312 | If the program is interactive, make it output a short notice like this
313 | when it starts in an interactive mode:
314 |
315 | Gnomovision version 69, Copyright (C) year name of author
316 | Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
317 | This is free software, and you are welcome to redistribute it
318 | under certain conditions; type `show c' for details.
319 |
320 | The hypothetical commands `show w' and `show c' should show the appropriate
321 | parts of the General Public License. Of course, the commands you use may
322 | be called something other than `show w' and `show c'; they could even be
323 | mouse-clicks or menu items--whatever suits your program.
324 |
325 | You should also get your employer (if you work as a programmer) or your
326 | school, if any, to sign a "copyright disclaimer" for the program, if
327 | necessary. Here is a sample; alter the names:
328 |
329 | Yoyodyne, Inc., hereby disclaims all copyright interest in the program
330 | `Gnomovision' (which makes passes at compilers) written by James Hacker.
331 |
332 | {signature of Ty Coon}, 1 April 1989
333 | Ty Coon, President of Vice
334 |
335 | This General Public License does not permit incorporating your program into
336 | proprietary programs. If your program is a subroutine library, you may
337 | consider it more useful to permit linking proprietary applications with the
338 | library. If this is what you want to do, use the GNU Lesser General
339 | Public License instead of this License.
340 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Theme Elementary
2 |
3 | 
4 |
5 | A starter theme that facilitates a quick head start for developing new [block-based themes](https://developer.wordpress.org/block-editor/how-to-guides/themes/block-theme-overview/) along with a bunch of developer-friendly features.
6 |
7 | - [Understand the Folder Structure](https://github.com/rtCamp/theme-elementary#understand-the-folder-structure-open_file_folder)
8 | - [Get Started](https://github.com/rtCamp/theme-elementary#get-started-rocket)
9 | - [Development](https://github.com/rtCamp/theme-elementary#development-computer)
10 |
11 | ## Understand the Folder Structure :open_file_folder:
12 | ```
13 | .
14 | ├── assets (Holds theme's assets)
15 | │ └── src
16 | │ └── js
17 | │ └── css
18 | ├── bin (Holds scripts)
19 | ├── functions.php (PHP entry point)
20 | ├── inc
21 | │ ├── classes (Holds all classes)
22 | │ │ └── class-elementary-theme.php (Instantiates all of the classes)
23 | │ ├── helpers (PHP Helpers)
24 | │ │ └── custom-functions.php
25 | │ └── traits (PHP Traits)
26 | │ └── trait-singleton.php
27 | ├── index.php
28 | ├── parts (Block Template Parts)
29 | ├── patterns (Block Patterns)
30 | │ ├── *.html
31 | ├── style.css
32 | ├── templates (Block Templates)
33 | │ ├── *.html
34 | ├── tests (Holds JS & PHP tests)
35 | │ ├── bootstrap.php
36 | │ ├── js
37 | │ └── php
38 | └── theme.json
39 |
40 | ```
41 |
42 | ## Get Started :rocket:
43 |
44 | ### Method 1 (Recommended)
45 | ```
46 | composer create-project rtcamp/elementary [folder_name]
47 | ```
48 | This command is equivalent to cloning the repository and running `composer install && npm install`
49 |
50 | ### Method 2
51 | Manually clone this repository using
52 | ```
53 | git clone [URL to Git repo]
54 | ```
55 | Having cloned this repository, install node packages and PHP dependencies using
56 | ```
57 | composer install
58 | ```
59 |
60 | In both the methods, you will be prompted with a theme setup wizard which will help you with the search-replace. That was all! You're good to go with building your block theme. :sparkles:
61 |
62 | **Note**: Refer to the `.nvmrc` file to check the supported Node.js version for running this project. If your current Node.js version does not run the project successfully on localhost, please use [Node Version Manager](https://github.com/nvm-sh/nvm) on your terminal to configure the right Node.js version.
63 |
64 | ## Development :computer:
65 |
66 |
67 | **Production**
68 |
69 | ```bash
70 | npm run build:prod
71 | ```
72 |
73 | **Watch changes**
74 |
75 | ```bash
76 | npm start
77 | ```
78 |
79 | **Linting & Formatting**
80 |
81 | Lint JS, CSS & PHP.
82 | ```bash
83 | npm run lint:js
84 | npm run lint:css
85 | npm run lint:php #phpcs
86 | ```
87 |
88 | Auto fix fixable linting errors for JS, CSS & PHP.
89 |
90 | ```bash
91 | npm run lint:js:fix
92 | npm run lint:css:fix
93 | npm run lint:php:fix #phpcbf
94 | ```
95 |
96 | **Testing**
97 |
98 | Run all tests.
99 |
100 | ```bash
101 | npm run test
102 | ```
103 |
104 | Run JS tests.
105 |
106 | ```bash
107 | npm run test:js
108 | ```
109 |
110 | Watch JS tests.
111 |
112 | ```bash
113 | npm run test:js:watch
114 | ```
115 |
116 | Run PHP tests.
117 |
118 | ```bash
119 | npm run test:php
120 | ```
121 |
122 | ## Does this interest you?
123 |
124 |
--------------------------------------------------------------------------------
/assets/src/css/core-navigation.scss:
--------------------------------------------------------------------------------
1 | /**
2 | * Custom styles required for the core Navigatino block.
3 | */
4 |
--------------------------------------------------------------------------------
/assets/src/css/styles.scss:
--------------------------------------------------------------------------------
1 | // The global styles for the theme.
2 | pre {
3 | overflow-x: auto;
4 | }
5 |
--------------------------------------------------------------------------------
/assets/src/js/core-navigation.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Custom script required for the core Navigation block.
3 | */
4 |
5 | /**
6 | * Internal dependencies
7 | */
8 | import '../css/core-navigation.scss';
9 |
--------------------------------------------------------------------------------
/assets/src/js/modules/media-text.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Custom module script required for the media text interactive pattern.
3 | */
4 |
5 | /**
6 | * WordPress dependencies
7 | */
8 | import { store, getContext, getElement } from '@wordpress/interactivity';
9 |
10 | store( 'elementary/media-text', {
11 | actions: {
12 | /**
13 | * Update the video play state.
14 | *
15 | * @return {void}
16 | */
17 | play() {
18 | const context = getContext();
19 | context.isPlaying = true;
20 | },
21 | },
22 | callbacks: {
23 | /**
24 | * Play the video.
25 | *
26 | * @return {void}
27 | */
28 | playVideo() {
29 | const context = getContext();
30 | const { ref } = getElement();
31 | if ( context.isPlaying ) {
32 | ref.querySelector( 'video' )?.play();
33 | context.isPlaying = false;
34 | }
35 | },
36 | },
37 | } );
38 |
--------------------------------------------------------------------------------
/babel.config.js:
--------------------------------------------------------------------------------
1 | /**
2 | * WordPress dependencies
3 | */
4 | const defaultConfig = require( '@wordpress/babel-preset-default' );
5 |
6 | module.exports = function( api ) {
7 | const config = defaultConfig( api );
8 |
9 | return {
10 | ...config,
11 | plugins: [
12 | ...config.plugins,
13 | // Add your own plugins here
14 | ],
15 | sourceMaps: true,
16 | env: {
17 | production: {
18 | plugins: [
19 | ...config.plugins,
20 | // Add your own plugins here
21 | ],
22 | },
23 | },
24 | };
25 | };
26 |
--------------------------------------------------------------------------------
/bin/init.js:
--------------------------------------------------------------------------------
1 | #! /usr/bin/env node
2 |
3 | /* eslint no-console: 0 */
4 |
5 | /**
6 | * External dependencies
7 | */
8 | const fs = require( 'fs' );
9 | const path = require( 'path' );
10 | const readline = require( 'readline' );
11 | const { promisify } = require( 'util' );
12 | const { execSync } = require( 'child_process' );
13 |
14 | /**
15 | * Define Constants
16 | */
17 | const rl = readline.createInterface( {
18 | input: process.stdin,
19 | output: process.stdout,
20 | } );
21 |
22 | const info = {
23 | error: ( message ) => {
24 | return `\x1b[31m${ message }\x1b[0m`;
25 | },
26 | success: ( message ) => {
27 | return `\x1b[32m${ message }\x1b[0m`;
28 | },
29 | warning: ( message ) => {
30 | return `\x1b[33m${ message }\x1b[0m`;
31 | },
32 | message: ( message ) => {
33 | return `\x1b[34m${ message }\x1b[0m`;
34 | },
35 | };
36 |
37 | /**
38 | * Return root directory
39 | *
40 | * @return {string} root directory
41 | */
42 | const getRoot = () => {
43 | return path.resolve( __dirname, '../' );
44 | }
45 |
46 | let fileContentUpdated = false;
47 | let fileNameUpdated = false;
48 | let themeCleanup = false;
49 | let isGitInitialized = false;
50 |
51 | const args = process.argv.slice( 2 );
52 |
53 | if ( 0 === args.length ) {
54 | rl.question( 'Would you like to setup the theme? (y/n) ', ( answer ) => {
55 |
56 | if ( 'n' === answer.toLowerCase() ) {
57 | console.log( info.warning( '\nTheme Setup Cancelled.\n' ) );
58 | rl.close();
59 | }
60 |
61 | rl.question( 'Enter theme name (shown in WordPress admin)*: ', ( themeName ) => {
62 |
63 | const themeInfo = renderThemeDetails( themeName );
64 |
65 | rl.question( 'Confirm the Theme Details (y/n) ', ( confirm ) => {
66 |
67 | if ( 'n' === confirm.toLowerCase() ) {
68 | console.log( info.warning( '\nTheme Setup Cancelled.\n' ) );
69 | rl.close();
70 | }
71 |
72 | initTheme( themeInfo );
73 |
74 | rl.question( 'Would you like to initialize git (Note: It will delete any `.git` folder already in current directory)? (y/n) ', async ( initialize ) => {
75 | if ( 'n' === initialize.toLowerCase() ) {
76 | console.log( info.warning( '\nExiting without initializing GitHub.\n' ) );
77 | await askQuestionForHuskyInstallation();
78 | } else {
79 | await initializeGit()
80 | }
81 | themeCleanupQuestion();
82 | } );
83 | } );
84 | } );
85 | } );
86 | } else if ( ( args.includes( '--clean' ) || args.includes( '-c' ) ) && 1 === args.length ) {
87 | themeCleanupQuestion();
88 | } else {
89 | console.log( info.error( '\nInvalid arguments.\n' ) );
90 | rl.close();
91 | }
92 | rl.on( 'close', () => {
93 | process.exit( 0 );
94 | } );
95 |
96 | /**
97 | * Update composer.json file.
98 | *
99 | * @return {void}
100 | */
101 | const updateComposerJson = () => {
102 | console.log( info.message( '\nRemoving post-install-cmd script from the composer.json...' ) );
103 | const composerJsonPath = path.resolve( getRoot(), 'composer.json' );
104 |
105 | try {
106 | if ( ! fs.existsSync( composerJsonPath ) ) {
107 | return;
108 | }
109 |
110 | const composerJson = JSON.parse( fs.readFileSync( composerJsonPath ) );
111 |
112 | // Remove scripts.
113 | delete composerJson.scripts['post-install-cmd'];
114 |
115 | // Commit the changes to file.
116 | fs.writeFileSync( composerJsonPath, JSON.stringify( composerJson, null, 2 ) );
117 | console.log( info.success( '\ncomposer.json updated successfully!' ), '✨' );
118 | } catch ( error ) {
119 | console.log( info.error( `Error while updating composer.json: ${ error.message }` ) );
120 | console.log( info.message( 'Please remove post-install-cmd script from the composer.json file manually.' ) );
121 | }
122 | }
123 |
124 | /**
125 | * Update package.json file.
126 | *
127 | * @return {void}
128 | */
129 | const updatePackageJson = () => {
130 | console.log( info.message( '\nRemoving init script from the package.json...' ) );
131 | const packageJsonPath = path.resolve( getRoot(), 'package.json' );
132 |
133 | try {
134 | if ( ! fs.existsSync( packageJsonPath ) ) {
135 | return;
136 | }
137 |
138 | const packageJson = JSON.parse( fs.readFileSync( packageJsonPath ) );
139 |
140 | delete packageJson.scripts['init'];
141 |
142 | if ( ! packageJson.scripts['prepare'] ) {
143 | return;
144 | }
145 |
146 | const prepareScript = packageJson.scripts['prepare'];
147 |
148 | // Check if 'npm run init' is part of the prepare script.
149 | if ( ! prepareScript.includes( 'npm run init' ) ) {
150 | return;
151 | }
152 |
153 | // Split the prepare script into an array of individual scripts.
154 | const prepareScriptArray = prepareScript.split( '&&' ).map( ( script ) => script.trim() );
155 |
156 | // Find the index of 'npm run init' in the array.
157 | const initScriptIndex = prepareScriptArray.indexOf( 'npm run init' );
158 |
159 | // Remove 'npm run init' from the array if it exists.
160 | if ( -1 !== initScriptIndex ) {
161 | prepareScriptArray.splice( initScriptIndex, 1 );
162 | }
163 | // Join the array back into a string and update the 'prepare' script in packageJson.
164 | packageJson.scripts['prepare'] = prepareScriptArray.join( ' && ' );
165 |
166 | // Commit the changes to file.
167 | fs.writeFileSync( packageJsonPath, JSON.stringify( packageJson, null, 2 ) );
168 | console.log( info.success( '\npackage.json updated successfully!' ), '✨' );
169 | } catch ( error ) {
170 | console.log( info.error( `Error while updating package.json: ${ error.message }` ) );
171 | console.log( info.message( 'Please remove init script and remove npm run init command from the prepare script from the package.json file manually.' ) );
172 | }
173 | }
174 |
175 | /**
176 | * Ask theme claenup question.
177 | *
178 | * @return {void}
179 | */
180 | function themeCleanupQuestion() {
181 | rl.question( 'Would you like to run the theme cleanup? (y/n) ', ( cleanup ) => {
182 | if ( 'n' === cleanup.toLowerCase() ) {
183 | console.log( info.warning( '\nExiting without running theme cleanup.\n' ) );
184 | } else {
185 | updateComposerJson();
186 | updatePackageJson();
187 | runThemeCleanup();
188 | }
189 | rl.close();
190 | } );
191 | }
192 |
193 | /**
194 | * Initialize Git.
195 | *
196 | * @return {void}
197 | */
198 | const initializeGit = async () => {
199 | // Initialize git.
200 | console.log( info.success( '\nInitializing git...' ) );
201 |
202 | // Check if .git file exists.
203 | const gitDir = path.resolve( getRoot(), '.git' );
204 | try {
205 | if ( fs.existsSync( gitDir ) ) {
206 | // Remove .git directory.
207 | fs.rmSync( gitDir, {
208 | recursive: true,
209 | } );
210 | }
211 | } catch ( error ) {
212 |
213 | }
214 |
215 | const pathToRoot = path.resolve( getRoot() );
216 | const gitInitCommand = `git init '${ pathToRoot }'`;
217 | const pathToAllFiles = path.resolve( getRoot(), '.' );
218 | const gitAddCommand = `git add '${ pathToAllFiles }'`;
219 | // Apply --no-verify flag to skip husky pre-commit hook.
220 | const gitCommit = `git commit -m 'Initialize project using https://github.com/rtCamp/theme-elementary' --no-verify`;
221 |
222 | try {
223 | // Execute git init command in the root directory.
224 | execSync( gitInitCommand );
225 | console.log( info.success( '\nGit initialized successfully!' ), '✨' );
226 | isGitInitialized = true;
227 |
228 | await askQuestionForHuskyInstallation();
229 |
230 | // Execute git add command in the root directory.
231 | execSync( gitAddCommand );
232 |
233 | // Execute git commit command in the root directory.
234 | execSync( gitCommit );
235 | } catch ( error ) {
236 | console.log( info.error( 'Error while installing Git. Please check above for the logs.' ) );
237 | }
238 | };
239 |
240 | /**
241 | * Ask Question for Husky Installation.
242 | *
243 | * @return {void}
244 | */
245 | const askQuestionForHuskyInstallation = async () => {
246 |
247 | // Promisify the question function for this instance only as this question is in between another question so code after this was getting executed before this is completed.
248 | // There is readlinePromises Interface introduced in v17.0.0 and is in Experimental phase so we are using promisify for now.
249 | // In future we can use readlinePromises Interface.
250 | const question = promisify( rl.question ).bind( rl );
251 | const install = await question( 'Would you like to install Husky? (y/n) ' );
252 | if ( 'n' === install.toLowerCase() ) {
253 | console.log(info.warning('\nExiting without installing Husky.\n'));
254 | return;
255 | }
256 | installHusky();
257 | }
258 |
259 | /**
260 | * Install Husky.
261 | *
262 | * @return {void}
263 | */
264 | const installHusky = () => {
265 |
266 | // Search if .git directory exists.
267 | const gitDir = path.resolve( getRoot(), '.git' );
268 | if ( ! fs.existsSync( gitDir ) ) {
269 | console.log( info.warning( '\nGit is not initialized. Please initialize git first.\n' ) );
270 | return;
271 | }
272 |
273 | // Install Husky.
274 | console.log( info.success( '\nInstalling Husky...' ) );
275 |
276 | const pathToRoot = path.resolve( getRoot() );
277 | const huskyInstallCommand = `npm install husky@9.0.1 --save-dev --prefix '${ pathToRoot }'`;
278 |
279 | try {
280 | // Execute Husky install command in the root directory.
281 | execSync( huskyInstallCommand );
282 |
283 | const pathToPackageJson = path.resolve( getRoot(), 'package.json' );
284 |
285 | let prepareScript = '';
286 |
287 | // Extracting the prepare script from package.json before husky installation ovrwrites it.
288 | if ( fs.existsSync( pathToPackageJson ) ) {
289 | const packageJson = JSON.parse( fs.readFileSync( pathToPackageJson ) );
290 |
291 | if ( packageJson.scripts && packageJson.scripts.prepare ) {
292 | prepareScript = packageJson.scripts.prepare;
293 | }
294 | }
295 |
296 | execSync( 'npx husky init' );
297 | execSync( 'echo "npm run lint:staged" > .husky/pre-commit' );
298 |
299 | if ( '' === prepareScript ) {
300 | return;
301 | }
302 |
303 | // Update the prepare script with the old prepare script after husky installation overwrites it.
304 | if ( fs.existsSync( pathToPackageJson ) ) {
305 | const packageJson = JSON.parse( fs.readFileSync( pathToPackageJson ) );
306 |
307 | if ( packageJson.scripts && packageJson.scripts.prepare ) {
308 | packageJson.scripts.prepare += ` && ${ prepareScript }`;
309 |
310 | fs.writeFileSync( pathToPackageJson, JSON.stringify( packageJson, null, 2 ) );
311 | }
312 | }
313 |
314 | console.log( info.success( '\nHusky installed successfully!' ), '✨' );
315 | } catch ( error ) {
316 | console.log( error );
317 | console.log( info.error( 'Error while installing husky. Please check above for the logs.' ) );
318 | }
319 | }
320 |
321 | /**
322 | * Renders the theme setup modal with all necessary information related to the search-replace.
323 | *
324 | * @param {string} themeName
325 | *
326 | * @return {Object} themeInfo
327 | */
328 | const renderThemeDetails = ( themeName ) => {
329 | console.log( info.success( '\nFiring up the theme setup...' ) );
330 |
331 | // Ask theme name.
332 | if ( ! themeName ) {
333 | console.log( info.error( '\nTheme name is required.\n' ) );
334 | process.exit( 0 );
335 | }
336 |
337 | // Generate theme info.
338 | const themeInfo = generateThemeInfo( themeName );
339 |
340 | const themeDetails = {
341 | 'Theme Name: ': `${ themeInfo.themeName }`,
342 | 'Theme Version: ': '1.0.0',
343 | 'Text Domain: ': themeInfo.kebabCase,
344 | 'Package: ': themeInfo.trainCase,
345 | 'Namespace: ': themeInfo.pascalSnakeCase,
346 | 'Function Prefix: ': themeInfo.snakeCaseWithUnderscoreSuffix,
347 | 'CSS Class Prefix: ': themeInfo.kebabCaseWithHyphenSuffix,
348 | 'PHP Variable Prefix: ': themeInfo.snakeCaseWithUnderscoreSuffix,
349 | 'Version Constant: ': `${ themeInfo.macroCase }_VERSION`,
350 | 'Theme Directory Constant: ': `${ themeInfo.macroCase }_TEMP_DIR`,
351 | 'Theme Build Directory Constant: ': `${ themeInfo.macroCase }_BUILD_DIR`,
352 | 'Theme Build Directory URI Constant: ': `${ themeInfo.macroCase }_BUILD_URI`,
353 | };
354 |
355 | const biggestStringLength = themeDetails[ 'Theme Build Directory URI Constant: ' ].length + 'Theme Build Directory URI Constant: '.length;
356 |
357 | console.log( info.success( '\nTheme Details:' ) );
358 | console.log(
359 | info.warning( '┌' + '─'.repeat( biggestStringLength + 2 ) + '┐' ),
360 | );
361 | Object.keys( themeDetails ).forEach( ( key ) => {
362 | console.log(
363 | info.warning( '│' + ' ' + info.success( key ) + info.message( themeDetails[ key ] ) + ' ' + ' '.repeat( biggestStringLength - ( themeDetails[ key ].length + key.length ) ) + info.warning( '│' ) ),
364 | );
365 | } );
366 | console.log(
367 | info.warning( '└' + '─'.repeat( biggestStringLength + 2 ) + '┘' ),
368 | );
369 |
370 | return themeInfo;
371 | };
372 |
373 | /**
374 | * Initialize new theme
375 | *
376 | * @param {Object} themeInfo
377 | */
378 | const initTheme = ( themeInfo ) => {
379 | const chunksToReplace = {
380 | 'rtcamp/elementary': themeInfo.packageName, // Specifically targets composer.json file.
381 | 'elementary theme': themeInfo.themeNameLowerCase,
382 | 'Elementary Theme': themeInfo.themeName,
383 | 'ELEMENTARY THEME': themeInfo.themeNameCobolCase,
384 | 'elementary-theme': themeInfo.kebabCase,
385 | 'Elementary-Theme': themeInfo.trainCase,
386 | 'ELEMENTARY-THEME': themeInfo.cobolCase,
387 | elementary_theme: themeInfo.snakeCase,
388 | Elementary_Theme: themeInfo.pascalSnakeCase,
389 | ELEMENTARY_THEME: themeInfo.macroCase,
390 | 'elementary-theme-': themeInfo.kebabCaseWithHyphenSuffix,
391 | 'Elementary-Theme-': themeInfo.trainCaseWithHyphenSuffix,
392 | 'ELEMENTARY-THEME-': themeInfo.cobolCaseWithHyphenSuffix,
393 | elementary_theme_: themeInfo.snakeCaseWithUnderscoreSuffix,
394 | Elementary_Theme_: themeInfo.pascalSnakeCaseWithUnderscoreSuffix,
395 | ELEMENTARY_THEME_: themeInfo.macroCaseWithUnderscoreSuffix,
396 | };
397 |
398 | const files = getAllFiles( getRoot() );
399 |
400 | // File name to replace in.
401 | const fileNameToReplace = {};
402 | files.forEach( ( file ) => {
403 | const fileName = path.basename( file );
404 | Object.keys( chunksToReplace ).forEach( ( key ) => {
405 | if ( fileName.includes( key ) ) {
406 | fileNameToReplace[ fileName ] = fileName.replace( key, chunksToReplace[ key ] );
407 | }
408 | } );
409 | } );
410 |
411 | // Replace files contents.
412 | console.log( info.success( '\nUpdating theme details in file(s)...' ) );
413 | Object.keys( chunksToReplace ).forEach( ( key ) => {
414 | replaceFileContent( files, key, chunksToReplace[ key ] );
415 | } );
416 |
417 | if ( ! fileContentUpdated ) {
418 | console.log( info.error( 'No file content updated.\n' ) );
419 | }
420 |
421 | // Replace file names
422 | console.log( info.success( '\nUpdating theme file(s) name...' ) );
423 | Object.keys( fileNameToReplace ).forEach( ( key ) => {
424 | replaceFileName( files, key, fileNameToReplace[ key ] );
425 | } );
426 | if ( ! fileNameUpdated ) {
427 | console.log( info.error( 'No file name updated.\n' ) );
428 | }
429 |
430 | if ( fileContentUpdated || fileNameUpdated ) {
431 | console.log( info.success( '\nYour new theme is ready to go!' ), '✨' );
432 | // Docs link
433 | console.log( info.success( '\nFor more information on how to use this theme, please visit the following link: ' + info.warning( 'https://github.com/rtCamp/theme-elementary/blob/main/README.md\n' ) ) );
434 | } else {
435 | console.log( info.warning( '\nNo changes were made to your theme.\n' ) );
436 | }
437 |
438 | try {
439 | const result = execSync( 'composer dump-autoload' );
440 | console.log( info.success( result ) );
441 | } catch ( error ) {
442 | console.log( info.error( `Error while executing composer dump-autoload: ${error}` ) );
443 | }
444 | };
445 |
446 | /**
447 | * Get all files in a directory
448 | *
449 | * @param {Array} dir - Directory to search
450 | */
451 | const getAllFiles = ( dir ) => {
452 | const dirOrFilesIgnore = [
453 | '.git',
454 | '.github',
455 | 'node_modules',
456 | 'vendor',
457 | ];
458 |
459 | try {
460 | let files = fs.readdirSync( dir );
461 | files = files.filter( ( fileOrDir ) => ! dirOrFilesIgnore.includes( fileOrDir ) );
462 |
463 | const allFiles = [];
464 | files.forEach( ( file ) => {
465 | const filePath = path.join( dir, file );
466 | const stat = fs.statSync( filePath );
467 | if ( stat.isDirectory() ) {
468 | allFiles.push( ...getAllFiles( filePath ) );
469 | } else {
470 | allFiles.push( filePath );
471 | }
472 | } );
473 | return allFiles;
474 | } catch ( err ) {
475 | console.log( info.error( err ) );
476 | }
477 | };
478 |
479 | /**
480 | * Replace content in file
481 | *
482 | * @param {Array} files Files to search
483 | * @param {string} chunksToReplace String to replace
484 | * @param {string} newChunk New string to replace with
485 | */
486 | const replaceFileContent = ( files, chunksToReplace, newChunk ) => {
487 | files.forEach( ( file ) => {
488 | const filePath = path.resolve( getRoot(), file );
489 |
490 | try {
491 | let content = fs.readFileSync( filePath, 'utf8' );
492 | const regex = new RegExp( chunksToReplace, 'g' );
493 | content = content.replace( regex, newChunk );
494 | if ( content !== fs.readFileSync( filePath, 'utf8' ) ) {
495 | fs.writeFileSync( filePath, content, 'utf8' );
496 | console.log( info.success( `Updated [${ info.message( chunksToReplace ) }] ${ info.success( 'to' ) } [${ info.message( newChunk ) }] ${ info.success( 'in file' ) } [${ info.message( path.basename( file ) ) }]` ) );
497 | fileContentUpdated = true;
498 | }
499 | } catch ( err ) {
500 | console.log( info.error( `\nError: ${ err }` ) );
501 | }
502 | } );
503 | };
504 |
505 | /**
506 | * Change File Name
507 | *
508 | * @param {Array} files Files to search
509 | * @param {string} oldFileName Old file name
510 | * @param {string} newFileName New file name
511 | */
512 | const replaceFileName = ( files, oldFileName, newFileName ) => {
513 | files.forEach( ( file ) => {
514 | if ( oldFileName !== path.basename( file ) ) {
515 | return;
516 | }
517 | const filePath = path.resolve( getRoot(), file );
518 | const newFilePath = path.resolve( getRoot(), file.replace( oldFileName, newFileName ) );
519 | try {
520 | fs.renameSync( filePath, newFilePath );
521 | console.log( info.success( `Updated file [${ info.message( path.basename( filePath ) ) }] ${ info.success( 'to' ) } [${ info.message( path.basename( newFilePath ) ) }]` ) );
522 | fileNameUpdated = true;
523 | } catch ( err ) {
524 | console.log( info.error( `\nError: ${ err }` ) );
525 | }
526 | } );
527 | };
528 |
529 | /**
530 | * Generate Theme Info from Theme Name
531 | *
532 | * @param {string} themeName
533 | */
534 | const generateThemeInfo = ( themeName ) => {
535 | const themeNameLowerCase = themeName.toLowerCase();
536 |
537 | const kebabCase = themeName.replace( /\s+/g, '-' ).toLowerCase();
538 | const packageName = `rtcamp/${ kebabCase }`;
539 | const snakeCase = kebabCase.replace( /\-/g, '_' );
540 | const kebabCaseWithHyphenSuffix = kebabCase + '-';
541 | const snakeCaseWithUnderscoreSuffix = snakeCase + '_';
542 |
543 | const trainCase = kebabCase.replace( /\b\w/g, ( l ) => {
544 | return l.toUpperCase();
545 | } );
546 | const themeNameTrainCase = trainCase.replace( /\-/g, ' ' );
547 | const pascalSnakeCase = trainCase.replace( /\-/g, '_' );
548 | const trainCaseWithHyphenSuffix = trainCase + '-';
549 | const pascalSnakeCaseWithUnderscoreSuffix = pascalSnakeCase + '_';
550 |
551 | const cobolCase = kebabCase.toUpperCase();
552 | const themeNameCobolCase = themeNameTrainCase.toUpperCase();
553 | const macroCase = snakeCase.toUpperCase();
554 | const cobolCaseWithHyphenSuffix = cobolCase + '-';
555 | const macroCaseWithUnderscoreSuffix = macroCase + '_';
556 |
557 | return {
558 | themeName,
559 | packageName,
560 | themeNameLowerCase,
561 | kebabCase,
562 | snakeCase,
563 | kebabCaseWithHyphenSuffix,
564 | snakeCaseWithUnderscoreSuffix,
565 | trainCase,
566 | themeNameTrainCase,
567 | pascalSnakeCase,
568 | trainCaseWithHyphenSuffix,
569 | pascalSnakeCaseWithUnderscoreSuffix,
570 | cobolCase,
571 | themeNameCobolCase,
572 | macroCase,
573 | cobolCaseWithHyphenSuffix,
574 | macroCaseWithUnderscoreSuffix,
575 | };
576 | };
577 |
578 | /**
579 | * Run theme cleanup to delete files and directories
580 | *
581 | * It will remove following directories and files:
582 | * 1. .git
583 | * 2. .github
584 | * 3. bin
585 | * 4. languages
586 | */
587 | const runThemeCleanup = () => {
588 | const deleteDirs = [
589 | '.github',
590 | 'bin/init.js',
591 | 'languages',
592 | ];
593 |
594 | if ( ! isGitInitialized ) {
595 | deleteDirs.push( '.git' );
596 | }
597 |
598 | deleteDirs.forEach( ( dir ) => {
599 | const dirPath = path.resolve( getRoot(), dir );
600 | try {
601 | if ( fs.existsSync( dirPath ) ) {
602 | let isDirectory = false;
603 |
604 | if ( true === fs.lstatSync( dirPath ).isDirectory() ) {
605 | isDirectory = true;
606 | }
607 |
608 | // rmSync function introduced in Node v14.14.0. It can delete files and directories recursively.
609 | fs.rmSync( dirPath, {
610 | recursive: true,
611 | } );
612 |
613 | if ( isDirectory ) {
614 | console.log( info.success( `Removed directory [${ info.message( dir ) }]` ) );
615 | } else {
616 | console.log( info.success( `Removed file [${ info.message( dir ) }]` ) );
617 | }
618 | themeCleanup = true;
619 | }
620 | } catch ( err ) {
621 | console.log( info.error( `\nError: ${ err }` ) );
622 | }
623 | } );
624 |
625 | if ( themeCleanup ) {
626 | console.log( info.success( '\nTheme cleanup completed!' ), '✨' );
627 | } else {
628 | console.log( info.warning( '\nNo theme cleanup required!\n' ) );
629 | }
630 | };
631 |
--------------------------------------------------------------------------------
/bin/phpcbf.js:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env node
2 |
3 | /**
4 | * External dependencies
5 | */
6 | const { join } = require( 'node:path' );
7 | const { argv } = require( 'node:process' );
8 | const { spawn } = require( 'node:child_process' );
9 | const { accessSync, constants } = require( 'node:fs' );
10 |
11 | const args = argv.slice( 2 );
12 | const scriptPath = join( __dirname, '..', 'vendor', 'bin', 'phpcbf' );
13 |
14 | try {
15 | accessSync( scriptPath, constants.F_OK );
16 | } catch (e) {
17 | // eslint-disable-next-line no-console
18 | console.error(
19 | '\x1b[31m%s\x1b[0m',
20 | 'Error: vendor/bin/phpcbf is not found or not executable. Please run `composer install` first.'
21 | );
22 | process.exit( 1 );
23 | }
24 |
25 | const phpcbfProcess = spawn( scriptPath, args );
26 |
27 | phpcbfProcess.stdout.on( 'data', ( data ) => {
28 | process.stdout.write( data );
29 | });
30 |
31 | phpcbfProcess.stderr.on( 'data', ( data ) => {
32 | process.stderr.write( data );
33 | });
34 |
35 | process.on( 'SIGINT', () => {
36 | phpcbfProcess.kill();
37 | });
38 |
39 | process.on( 'SIGTERM', () => {
40 | phpcbfProcess.kill();
41 | });
42 |
43 | phpcbfProcess.on( 'exit', ( code ) => {
44 | process.exit( 1 === code ? 0 : code );
45 | });
46 |
--------------------------------------------------------------------------------
/composer.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "rtcamp/elementary",
3 | "description": "A starter theme that facilitates a quick head start for developing new block-based themes along with a bunch of developer-friendly features.",
4 | "type": "wordpress-theme",
5 | "homepage": "https://rtcamp.com/",
6 | "license": "GPL-2.0-or-later",
7 | "require": {
8 | "php": ">=8.2"
9 | },
10 | "require-dev": {
11 | "wp-coding-standards/wpcs": "^2.3",
12 | "phpcompatibility/phpcompatibility-wp": "^2.1",
13 | "automattic/vipwpcs": "^2.3",
14 | "dealerdirect/phpcodesniffer-composer-installer": "1.0.0",
15 | "sirbrillig/phpcs-variable-analysis": "^2.11.3",
16 | "phpunit/phpunit": "^9.5",
17 | "wp-phpunit/wp-phpunit": "^6.0",
18 | "yoast/phpunit-polyfills": "^3.0",
19 | "wp-cli/i18n-command": "^2.4"
20 | },
21 | "minimum-stability": "dev",
22 | "prefer-stable": true,
23 | "config": {
24 | "allow-plugins": {
25 | "dealerdirect/phpcodesniffer-composer-installer": true
26 | }
27 | },
28 | "autoload": {
29 | "classmap": [
30 | "inc/"
31 | ],
32 | "files": [
33 | "inc/helpers/custom-functions.php"
34 | ]
35 | },
36 | "autoload-dev": {
37 | "psr-4": {
38 | "Elementary_Theme\\Tests\\": "tests/php/"
39 | }
40 | },
41 | "scripts": {
42 | "phpcs": "@php ./vendor/bin/phpcs",
43 | "phpcs:fix": "@php ./vendor/bin/phpcbf",
44 | "post-install-cmd": [
45 | "npm i"
46 | ],
47 | "pot": "wp i18n make-pot . ./languages/elementary-theme.pot --domain=elementary-theme --include=\"inc,patterns,assets/build/js\""
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/docs/asset-building-process.md:
--------------------------------------------------------------------------------
1 | # Asset Building Process
2 |
3 | This document outlines the process of building and managing assets (CSS, JS, and modules) within the theme. It also explains how to add new scripts or modules into the build process.
4 |
5 | ## Overview
6 |
7 | Our asset pipeline is managed by **Webpack**, using the configuration provided by WordPress and some additional optimizations. The build process involves the following steps:
8 |
9 | 1. **JS and CSS Files** are processed, concatenated, and minified for production.
10 | 2. **Modules** are handled separately to ensure they're loaded correctly.
11 | 3. **CSS/SCSS files** are extracted and moved to a dedicated `css` directory.
12 |
13 | ### Key Configuration Files
14 |
15 | - **webpack.config.js**: This is the main configuration file for building assets.
16 | - **package.json**: Contains the scripts and dependencies necessary for the build process.
17 |
18 | ### Directory Structure
19 |
20 | - **assets/src/js**: Contains JavaScript files.
21 | - **assets/src/css**: Contains CSS/SCSS files.
22 | - **assets/src/js/modules**: Contains modular JavaScript files that are handled separately.
23 | - **assets/build/js**: Where built JavaScript files are output.
24 | - **assets/build/css**: Where built CSS files are output.
25 |
26 | ---
27 |
28 | ## How the Asset Building Works
29 |
30 | ### JS and CSS Build Process
31 |
32 | 1. **CSS Files**: All `.css` or `.scss` files in the `assets/src/css` directory are collected into the build process. They are extracted into a separate CSS file in the `assets/build/css` folder.
33 |
34 | - The main `webpack.config.js` file uses the `MiniCssExtractPlugin` to extract the CSS.
35 | - The extracted CSS files are minified using `CssMinimizerPlugin` in production builds.
36 |
37 | 2. **JS Files**: The JavaScript files are bundled into a single file or multiple files (for split chunks). The `assets/src/js` folder contains files like `core-navigation.js`, which are part of the main entry point.
38 |
39 | - JavaScript files are processed using Babel to ensure compatibility with different browsers.
40 | - We use `webpack-remove-empty-scripts` to remove any empty JavaScript files that do not have content.
41 |
42 | 3. **Modules**: Files located in `assets/src/js/modules` are treated as separate entry points. These are compiled into separate files and stored in the `assets/build/js/modules` directory.
43 |
44 | - The configuration for modules is handled through the `moduleScripts` entry in the `webpack.config.js`.
45 |
46 | ---
47 |
48 | ## Adding New Scripts or Modules
49 |
50 | To add a new script or module to the build process, follow these steps:
51 |
52 | ### Adding a New Script
53 |
54 | 1. Place your JavaScript file in the `assets/src/js` directory or a subdirectory.
55 |
56 | Example: `assets/src/js/my-script.js`
57 |
58 | 2. Edit the `webpack.config.js` file and add your script to the `scripts` entry object.
59 |
60 | Example:
61 | ```js
62 | entry: {
63 | 'my-new-script': path.resolve( process.cwd(), 'assets', 'src', 'js', 'my-script.js' ),
64 | },
65 | ```
66 |
67 | 3. If necessary, add any required dependencies or libraries to `assets/src/js` and import them in your new script.
68 |
69 | 4. Run the build script:
70 |
71 | ```bash
72 | npm run build:dev # For development
73 | npm run build:prod # For production
74 | ```
75 |
76 | ---
77 |
78 | ### Adding a New Module
79 |
80 | 1. Place your module JavaScript file in the `assets/src/js/modules` directory.
81 |
82 | Example: `assets/src/js/modules/my-module.js`
83 |
84 | 2. The modules will automatically be included in the Webpack build process, but if you want to make sure it is included in the final output, ensure it’s referenced correctly in the entry object for modules:
85 |
86 | ```js
87 | entry: () => readAllFileEntries( './assets/src/js/modules' ),
88 | ```
89 |
90 | 3. Add any necessary logic in your module’s JavaScript code to ensure it functions correctly within the theme. Modules are usually self-contained and independent, so make sure to export and import dependencies as needed.
91 |
92 | 4. Run the build script:
93 |
94 | ```bash
95 | npm run build:dev # For development
96 | npm run build:prod # For production
97 | ```
98 |
99 | ## Avoid Bundling Specific Files
100 |
101 | For example, if you have a file like `_my-excluded-script.js` or `_my-excluded-styles.css`, Webpack will **ignore** it when bundling and it won't be included in the final output.
102 |
103 | ### How to Exclude Files
104 |
105 | - **CSS/SCSS**: If you want to add a CSS file without bundling it, name it starting with an underscore.
106 |
107 | Example: `_my-excluded-styles.scss`
108 |
109 | - **JavaScript**: Similarly, prefix JS files with an underscore to prevent bundling.
110 |
111 | Example: `_my-excluded-script.js`
112 |
113 | By naming files with the underscore, we make sure they are excluded from the Webpack build process but can still be used elsewhere in the project.
114 |
--------------------------------------------------------------------------------
/functions.php:
--------------------------------------------------------------------------------
1 | get( 'Version' ) );
12 | endif;
13 |
14 | if ( ! defined( 'ELEMENTARY_THEME_TEMP_DIR' ) ) :
15 | define( 'ELEMENTARY_THEME_TEMP_DIR', untrailingslashit( get_template_directory() ) );
16 | endif;
17 |
18 | if ( ! defined( 'ELEMENTARY_THEME_BUILD_URI' ) ) :
19 | define( 'ELEMENTARY_THEME_BUILD_URI', untrailingslashit( get_template_directory_uri() ) . '/assets/build' );
20 | endif;
21 |
22 | if ( ! defined( 'ELEMENTARY_THEME_BUILD_DIR' ) ) :
23 | define( 'ELEMENTARY_THEME_BUILD_DIR', untrailingslashit( get_template_directory() ) . '/assets/build' );
24 | endif;
25 |
26 | require_once ELEMENTARY_THEME_TEMP_DIR . '/vendor/autoload.php';
27 |
28 | /**
29 | * Theme bootstrap instance.
30 | *
31 | * @since 1.0.0
32 | *
33 | * @return object Theme bootstrap instance.
34 | */
35 | function elementary_theme_instance() {
36 | return Elementary_Theme\Elementary_Theme::get_instance();
37 | }
38 |
39 | // Instantiate theme.
40 | elementary_theme_instance();
41 |
--------------------------------------------------------------------------------
/inc/classes/block-extension/class-media-text-interactive.php:
--------------------------------------------------------------------------------
1 | setup_hooks();
25 | }
26 |
27 | /**
28 | * Setup hooks.
29 | *
30 | * @return void
31 | */
32 | public function setup_hooks() {
33 |
34 | add_filter( 'render_block_core/button', array( $this, 'render_block_core_button' ), 10, 2 );
35 | add_filter( 'render_block_core/columns', array( $this, 'render_block_core_columns' ), 10, 2 );
36 | add_filter( 'render_block_core/video', array( $this, 'render_block_core_video' ), 10, 2 );
37 |
38 | }
39 |
40 | /**
41 | * Render block core/button.
42 | *
43 | * @param string $block_content Block content.
44 | * @param array $block Block.
45 | * @return string
46 | */
47 | public function render_block_core_button( $block_content, $block ) {
48 | if ( ! isset( $block['attrs']['className'] ) || ! str_contains( $block['attrs']['className'], 'elementary-media-text-interactive' ) ) {
49 | return $block_content;
50 | }
51 |
52 | $p = new WP_HTML_Tag_Processor( $block_content );
53 |
54 | $p->next_tag();
55 | $p->set_attribute( 'data-wp-on--click', 'actions.play' );
56 |
57 | return $p->get_updated_html();
58 | }
59 |
60 | /**
61 | * Render block core/columns.
62 | *
63 | * @param string $block_content Block content.
64 | * @param array $block Block.
65 | * @return string
66 | */
67 | public function render_block_core_columns( $block_content, $block ) {
68 | if ( ! isset( $block['attrs']['className'] ) || ! str_contains( $block['attrs']['className'], 'elementary-media-text-interactive' ) ) {
69 | return $block_content;
70 | }
71 |
72 | /**
73 | * Enqueue the module script, The prefix `@` is used to indicate that the script is a module.
74 | * This handle with the prefix `@` will be used in other scripts to import this module.
75 | */
76 | wp_enqueue_script_module(
77 | '@elementary/media-text',
78 | sprintf( '%s/js/modules/media-text.js', ELEMENTARY_THEME_BUILD_URI ),
79 | [
80 | '@wordpress/interactivity',
81 | ]
82 | );
83 |
84 | $p = new WP_HTML_Tag_Processor( $block_content );
85 |
86 | $p->next_tag();
87 | $p->set_attribute( 'data-wp-interactive', '{ "namespace": "elementary/media-text" }' );
88 | $p->set_attribute( 'data-wp-context', '{ "isPlaying": false }' );
89 |
90 | return $p->get_updated_html();
91 | }
92 |
93 | /**
94 | * Render block core/video.
95 | *
96 | * @param string $block_content Block content.
97 | * @param array $block Block.
98 | * @return string
99 | */
100 | public function render_block_core_video( $block_content, $block ) {
101 | if ( ! isset( $block['attrs']['className'] ) || ! str_contains( $block['attrs']['className'], 'elementary-media-text-interactive' ) ) {
102 | return $block_content;
103 | }
104 | $p = new WP_HTML_Tag_Processor( $block_content );
105 |
106 | $p->next_tag();
107 | $p->set_attribute( 'data-wp-watch', 'callbacks.playVideo' );
108 |
109 | return $p->get_updated_html();
110 | }
111 | }
112 |
--------------------------------------------------------------------------------
/inc/classes/class-assets.php:
--------------------------------------------------------------------------------
1 | setup_hooks();
27 | }
28 |
29 | /**
30 | * Setup hooks.
31 | *
32 | * @since 1.0.0
33 | */
34 | public function setup_hooks() {
35 | add_action( 'wp_enqueue_scripts', [ $this, 'register_assets' ] );
36 | add_action( 'wp_enqueue_scripts', [ $this, 'enqueue_assets' ] );
37 | add_filter( 'render_block', [ $this, 'enqueue_block_specific_assets' ], 10, 2 );
38 | }
39 |
40 | /**
41 | * Register assets.
42 | *
43 | * @since 1.0.0
44 | *
45 | * @action wp_enqueue_scripts
46 | */
47 | public function register_assets() {
48 |
49 | $this->register_script( 'core-navigation', 'js/core-navigation.js' );
50 | $this->register_style( 'core-navigation', 'css/core-navigation.css' );
51 | $this->register_style( 'elementary-theme-styles', 'css/styles.css' );
52 | }
53 |
54 | /**
55 | * Enqueue block specific assets.
56 | *
57 | * @param string $markup Markup of the block.
58 | * @param array $block Array with block information.
59 | *
60 | * @since 1.0.0
61 | */
62 | public function enqueue_block_specific_assets( $markup, $block ) {
63 | if ( is_array( $block ) && ! empty( $block['blockName'] ) && 'core/navigation' === $block['blockName'] ) {
64 | wp_enqueue_script( 'core-navigation' );
65 | wp_enqueue_style( 'core-navigation' );
66 | }
67 |
68 | return $markup;
69 | }
70 |
71 | /**
72 | * Get asset dependencies and version info from {handle}.asset.php if exists.
73 | *
74 | * @param string $file File name.
75 | * @param array $deps Script dependencies to merge with.
76 | * @param string $ver Asset version string.
77 | *
78 | * @return array
79 | */
80 | public function get_asset_meta( $file, $deps = [], $ver = false ) {
81 | $asset_meta_file = sprintf( '%s/js/%s.asset.php', untrailingslashit( ELEMENTARY_THEME_BUILD_DIR ), basename( $file, '.' . pathinfo( $file )['extension'] ) );
82 | $asset_meta = is_readable( $asset_meta_file )
83 | ? require $asset_meta_file
84 | : [
85 | 'dependencies' => [],
86 | 'version' => $this->get_file_version( $file, $ver ),
87 | ];
88 |
89 | $asset_meta['dependencies'] = array_merge( $deps, $asset_meta['dependencies'] );
90 |
91 | return $asset_meta;
92 | }
93 |
94 | /**
95 | * Register a new script.
96 | *
97 | * @param string $handle Name of the script. Should be unique.
98 | * @param string|bool $file script file, path of the script relative to the assets/build/ directory.
99 | * @param array $deps Optional. An array of registered script handles this script depends on. Default empty array.
100 | * @param string|bool|null $ver Optional. String specifying script version number, if not set, filetime will be used as version number.
101 | * @param bool $in_footer Optional. Whether to enqueue the script before
instead of in the
.
102 | * Default 'false'.
103 | * @return bool Whether the script has been registered. True on success, false on failure.
104 | */
105 | public function register_script( $handle, $file, $deps = [], $ver = false, $in_footer = true ) {
106 |
107 | $file_path = sprintf( '%s/%s', ELEMENTARY_THEME_BUILD_DIR, $file );
108 |
109 | if ( ! \file_exists( $file_path ) ) {
110 | return false;
111 | }
112 |
113 | $src = sprintf( ELEMENTARY_THEME_BUILD_URI . '/%s', $file );
114 | $asset_meta = $this->get_asset_meta( $file, $deps );
115 |
116 | return wp_register_script( $handle, $src, $asset_meta['dependencies'], $asset_meta['version'], $in_footer );
117 | }
118 |
119 | /**
120 | * Register a CSS stylesheet.
121 | *
122 | * @param string $handle Name of the stylesheet. Should be unique.
123 | * @param string|bool $file style file, path of the script relative to the assets/build/ directory.
124 | * @param array $deps Optional. An array of registered stylesheet handles this stylesheet depends on. Default empty array.
125 | * @param string|bool|null $ver Optional. String specifying script version number, if not set, filetime will be used as version number.
126 | * @param string $media Optional. The media for which this stylesheet has been defined.
127 | * Default 'all'. Accepts media types like 'all', 'print' and 'screen', or media queries like
128 | * '(orientation: portrait)' and '(max-width: 640px)'.
129 | *
130 | * @return bool Whether the style has been registered. True on success, false on failure.
131 | */
132 | public function register_style( $handle, $file, $deps = [], $ver = false, $media = 'all' ) {
133 |
134 | $file_path = sprintf( '%s/%s', ELEMENTARY_THEME_BUILD_DIR, $file );
135 |
136 | if ( ! \file_exists( $file_path ) ) {
137 | return false;
138 | }
139 |
140 | $src = sprintf( ELEMENTARY_THEME_BUILD_URI . '/%s', $file );
141 | $asset_meta = $this->get_asset_meta( $file, $deps );
142 |
143 | return wp_register_style( $handle, $src, $asset_meta['dependencies'], $asset_meta['version'], $media );
144 | }
145 |
146 | /**
147 | * Get file version.
148 | *
149 | * @param string $file File path.
150 | * @param int|string|boolean $ver File version.
151 | *
152 | * @return bool|false|int
153 | */
154 | public function get_file_version( $file, $ver = false ) {
155 | if ( ! empty( $ver ) ) {
156 | return $ver;
157 | }
158 |
159 | $file_path = sprintf( '%s/%s', ELEMENTARY_THEME_BUILD_DIR, $file );
160 |
161 | return file_exists( $file_path ) ? filemtime( $file_path ) : false;
162 | }
163 |
164 | /**
165 | * Enqueue JS and CSS in frontend.
166 | *
167 | * @return void
168 | */
169 | public function enqueue_assets() {
170 | wp_enqueue_style( 'elementary-theme-styles' );
171 | }
172 | }
173 |
--------------------------------------------------------------------------------
/inc/classes/class-elementary-theme.php:
--------------------------------------------------------------------------------
1 | setup_hooks();
32 | $this->block_extensions();
33 | }
34 |
35 | /**
36 | * Setup hooks.
37 | *
38 | * @since 1.0.0
39 | */
40 | public function setup_hooks() {
41 | add_action( 'after_setup_theme', [ $this, 'elementary_theme_support' ] );
42 | }
43 |
44 | /**
45 | * Add required theme support.
46 | *
47 | * @since 1.0.0
48 | */
49 | public function elementary_theme_support() {
50 | // Add support for core block styles.
51 | add_theme_support( 'wp-block-styles' );
52 | }
53 |
54 | /**
55 | * Block extensions
56 | *
57 | * @since 1.0.0
58 | */
59 | public function block_extensions() {
60 | Media_Text_Interactive::get_instance();
61 | }
62 | }
63 |
--------------------------------------------------------------------------------
/inc/helpers/custom-functions.php:
--------------------------------------------------------------------------------
1 | value pair for each `classname => instance` in self::$_instance
70 | * for each sub-class.
71 | */
72 | $called_class = get_called_class();
73 |
74 | if ( ! isset( $instance[ $called_class ] ) ) {
75 |
76 | $instance[ $called_class ] = new $called_class();
77 |
78 | /**
79 | * Dependent items can use the `elementary_theme_singleton_init_{$called_class}` hook to execute code
80 | */
81 | do_action( sprintf( 'elementary_theme_singleton_init_%s', $called_class ) ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores, WordPress.NamingConventions.PrefixAllGlobals.DynamicHooknameFound
82 |
83 | }
84 |
85 | return $instance[ $called_class ];
86 | }
87 | }
88 |
--------------------------------------------------------------------------------
/languages/elementary-theme.pot:
--------------------------------------------------------------------------------
1 | # Copyright (C) 2023 rtCamp
2 | # This file is distributed under the GNU General Public License v2 or later.
3 | msgid ""
4 | msgstr ""
5 | "Project-Id-Version: Elementary Theme 1.0.0\n"
6 | "Report-Msgid-Bugs-To: https://wordpress.org/support/theme/enhance-use-wp-cli-for-pot-file-generation\n"
7 | "Last-Translator: FULL NAME \n"
8 | "Language-Team: LANGUAGE \n"
9 | "MIME-Version: 1.0\n"
10 | "Content-Type: text/plain; charset=UTF-8\n"
11 | "Content-Transfer-Encoding: 8bit\n"
12 | "POT-Creation-Date: 2023-12-12T14:37:44+05:45\n"
13 | "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
14 | "X-Generator: WP-CLI 2.9.0\n"
15 | "X-Domain: elementary-theme\n"
16 |
17 | #. Theme Name of the theme
18 | msgid "Elementary Theme"
19 | msgstr ""
20 |
21 | #. Theme URI of the theme
22 | #. Author URI of the theme
23 | msgid "https://rtcamp.com/"
24 | msgstr ""
25 |
26 | #. Description of the theme
27 | msgid "Elementary is a FSE based theme,"
28 | msgstr ""
29 |
30 | #. Author of the theme
31 | msgid "rtCamp"
32 | msgstr ""
33 |
34 | #: patterns/footer.php
35 | msgctxt "Pattern title"
36 | msgid "Footer"
37 | msgstr ""
38 |
39 | #: patterns/footer.php
40 | msgctxt "Pattern description"
41 | msgid "Footer pattern."
42 | msgstr ""
43 |
44 | #. Translators: WordPress link.
45 | #: patterns/footer.php:25
46 | msgid "Proudly powered by %s"
47 | msgstr ""
48 |
49 | #: patterns/footer.php:26
50 | msgid "https://wordpress.org/"
51 | msgstr ""
52 |
53 | #: patterns/hidden-404.php
54 | msgctxt "Pattern title"
55 | msgid "404 content"
56 | msgstr ""
57 |
58 | #: patterns/hidden-404.php
59 | msgctxt "Pattern description"
60 | msgid "404 pattern content."
61 | msgstr ""
62 |
63 | #: patterns/hidden-404.php:17
64 | msgctxt "Error code for a webpage that is not found."
65 | msgid "404"
66 | msgstr ""
67 |
68 | #: patterns/hidden-404.php:23
69 | msgid "This page could not be found. Maybe try a search?"
70 | msgstr ""
71 |
72 | #: patterns/hidden-404.php:31
73 | msgid "Search"
74 | msgstr ""
75 |
76 | #: patterns/page-creation-pattern.php
77 | msgctxt "Pattern title"
78 | msgid "Page Creation Pattern"
79 | msgstr ""
80 |
81 | #: patterns/page-creation-pattern.php
82 | msgctxt "Pattern description"
83 | msgid "A page creation pattern"
84 | msgstr ""
85 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "elementary-theme",
3 | "version": "1.0.0",
4 | "description": "A starter theme that facilitates a quick head start for developing new block-based themes along with a bunch of developer-friendly features.",
5 | "private": true,
6 | "author": "rtCamp",
7 | "license": "GPL-2.0-or-later",
8 | "keywords": [
9 | "rtcamp",
10 | "wp-theme",
11 | "block-theme"
12 | ],
13 | "homepage": "https://github.com/rtCamp/theme-elementary#readme",
14 | "repository": {
15 | "type": "git",
16 | "url": "https://github.com/rtCamp/theme-elementary.git"
17 | },
18 | "bugs": {
19 | "url": "https://github.com/rtCamp/theme-elementary/issues"
20 | },
21 | "dependencies": {
22 | "@wordpress/interactivity": "^5.4.0"
23 | },
24 | "devDependencies": {
25 | "@babel/core": "7.25.2",
26 | "@wordpress/babel-preset-default": "8.15.1",
27 | "@wordpress/browserslist-config": "6.15.0",
28 | "@wordpress/env": "10.15.0",
29 | "@wordpress/eslint-plugin": "22.1.1",
30 | "@wordpress/jest-preset-default": "12.15.1",
31 | "@wordpress/scripts": "30.8.1",
32 | "browserslist": "4.24.3",
33 | "cross-env": "7.0.3",
34 | "css-minimizer-webpack-plugin": "7.0.0",
35 | "eslint": "8.56.0",
36 | "eslint-plugin-eslint-comments": "3.2.0",
37 | "eslint-plugin-import": "2.31.0",
38 | "eslint-plugin-jest": "28.6.0",
39 | "jest-silent-reporter": "0.6.0",
40 | "lint-staged": "15.3.0",
41 | "npm-run-all": "4.1.5",
42 | "webpack-remove-empty-scripts": "1.0.4"
43 | },
44 | "scripts": {
45 | "build:dev": "cross-env NODE_ENV=development npm-run-all 'build:!(dev|prod)'",
46 | "build:prod": "cross-env NODE_ENV=production npm-run-all 'build:!(dev|prod)'",
47 | "build:js": "wp-scripts build --experimental-modules",
48 | "init": "./bin/init.js",
49 | "lint:all": "npm-run-all --parallel lint:*",
50 | "lint:css": "wp-scripts lint-style ./assets/src",
51 | "lint:css:fix": "npm run lint:css -- --fix ./assets/src",
52 | "lint:js": "wp-scripts lint-js ./assets/src",
53 | "lint:js:fix": "npm run lint:js -- --fix ./assets/src",
54 | "lint:js:report": "npm run lint:js -- --output-file lint-js-report.json --format json .",
55 | "lint:php": "php vendor/bin/phpcs",
56 | "lint:php:fix": "node ./bin/phpcbf.js",
57 | "lint:package-json": "wp-scripts lint-pkg-json --ignorePath .gitignore",
58 | "lint:staged": "lint-staged",
59 | "prepare": "npm run init",
60 | "start": "wp-scripts start --experimental-modules",
61 | "test": "npm-run-all --parallel test:*",
62 | "test:js": "wp-scripts test-unit-js --config=tests/js/jest.config.js --passWithNoTests",
63 | "test:js:watch": "npm run test:js -- --watch",
64 | "pretest:php": "wp-env run cli --env-cwd=/var/www/html/wp-content/themes/$(basename $(pwd)) composer install --no-interaction --no-scripts",
65 | "test:php": "wp-env run cli --env-cwd=/var/www/html/wp-content/themes/$(basename $(pwd)) composer exec 'phpunit --do-not-cache-result --verbose'",
66 | "wp-env": "wp-env",
67 | "pot": "composer run pot"
68 | }
69 | }
70 |
--------------------------------------------------------------------------------
/parts/footer.html:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/parts/header.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/patterns/footer.php:
--------------------------------------------------------------------------------
1 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 | WordPress'
27 | );
28 | ?>
29 |
30 |
31 |
32 |
33 |
--------------------------------------------------------------------------------
/patterns/hidden-404.php:
--------------------------------------------------------------------------------
1 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
--------------------------------------------------------------------------------
/patterns/media-text-interactive.php:
--------------------------------------------------------------------------------
1 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
--------------------------------------------------------------------------------
/patterns/page-creation-pattern.php:
--------------------------------------------------------------------------------
1 |
14 |
15 | Page creation patterns are some starter patterns when creating a page. Learn more about Page creation patterns.
16 |
17 |
18 |
--------------------------------------------------------------------------------
/phpcs.xml.dist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 | A custom set of code standard rules to check for WordPress themes.
10 |
11 |
12 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 | .
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
51 |
52 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
86 |
87 |
88 |
89 |
90 | tests/bootstrap.php
91 |
92 |
93 |
94 |
95 | tests/php/TestCase.php
96 |
97 |
98 |
99 | tests/*
100 |
101 |
102 |
103 | tests/*
104 |
105 |
106 |
107 | tests/*
108 |
109 |
110 |
111 | tests/*
112 |
113 |
114 |
119 |
120 |
121 |
122 |
123 |
124 |
125 |
126 |
127 | *patterns/*
128 |
129 |
130 | */build/*
131 | */data/*
132 | packages/e2e-tests/src/plugins/*
133 | */node_modules/*
134 | */third-party/*
135 | */vendor/*
136 | assets/js/*.asset.php
137 | assets/js/*.chunks.php
138 | includes/polyfills/mbstring.php
139 | tests/phpstan/*
140 | tests/phpunit/includes/MarkupComparison.php
141 |
142 |
143 |
--------------------------------------------------------------------------------
/phpunit.xml.dist:
--------------------------------------------------------------------------------
1 |
2 |
10 |
11 |
12 | ./tests/php/
13 |
14 |
15 |
16 |
--------------------------------------------------------------------------------
/screenshot.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rtCamp/theme-elementary/361872dc15209baf6e2fa27f03ff99caa9fcc32b/screenshot.png
--------------------------------------------------------------------------------
/style.css:
--------------------------------------------------------------------------------
1 | /*
2 | Theme Name: Elementary Theme
3 | Theme URI: https://rtcamp.com/
4 | Author: rtCamp
5 | Author URI: https://rtcamp.com/
6 | Description: Elementary is a FSE based theme,
7 | Version: 1.0.0
8 | License: GNU General Public License v2 or later
9 | License URI: http://www.gnu.org/licenses/gpl-2.0.html
10 | Text Domain: elementary-theme
11 | Domain Path: /languages
12 | Tags: fse
13 | This theme, like WordPress, is licensed under the GPL.
14 | Use it to make something cool, have fun, and share what
15 | you've learned with others.
16 | */
17 |
--------------------------------------------------------------------------------
/styles/light.json:
--------------------------------------------------------------------------------
1 | {
2 | "version": 2,
3 | "settings": {
4 | "color": {
5 | "palette": [
6 | {
7 | "slug": "background",
8 | "color": "#ffffff",
9 | "name": "Background"
10 | },
11 | {
12 | "slug": "foreground",
13 | "color": "#1d2327",
14 | "name": "Foreground"
15 | },
16 | {
17 | "slug": "primary",
18 | "color": "#153956",
19 | "name": "Primary"
20 | },
21 | {
22 | "slug": "secondary",
23 | "color": "#eee",
24 | "name": "Secondary"
25 | },
26 | {
27 | "slug": "transparent",
28 | "color": "transparent",
29 | "name": "Transparent"
30 | }
31 | ]
32 | },
33 | "custom": {
34 | "text-shadow": "0 2px 5px rgba(0, 0, 0, 0.2);"
35 | }
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/templates/404.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/templates/archive.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
--------------------------------------------------------------------------------
/templates/home.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
--------------------------------------------------------------------------------
/templates/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
--------------------------------------------------------------------------------
/templates/no-title.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/templates/page.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/templates/search.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
--------------------------------------------------------------------------------
/templates/single.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
Categories:
47 |
48 |
49 |
50 |
51 |
52 |
· Tagged:
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
--------------------------------------------------------------------------------
/tests/bootstrap.php:
--------------------------------------------------------------------------------
1 | /node_modules/@wordpress/scripts/config/babel-transform',
6 | },
7 | setupFiles: [
8 | '/tests/js/setup-globals',
9 | ],
10 | preset: '@wordpress/jest-preset-default',
11 | testPathIgnorePatterns: [
12 | '/.git',
13 | '/node_modules',
14 | '/assets/build',
15 | '/vendor',
16 | // Add more specific patterns here if needed.
17 | ],
18 | coveragePathIgnorePatterns: [
19 | '/node_modules',
20 | '/assets/build/',
21 | // Add more specific patterns here if needed.
22 | ],
23 | modulePathIgnorePatterns: [
24 | // Add more specific patterns here if needed.
25 | ],
26 | coverageReporters: [ 'lcov' ],
27 | coverageDirectory: '/tests/logs',
28 | reporters: [
29 | [ 'jest-silent-reporter', { useDots: true } ],
30 | '/node_modules/@wordpress/scripts/config/jest-github-actions-reporter',
31 | ],
32 | };
33 |
--------------------------------------------------------------------------------
/tests/js/setup-globals.js:
--------------------------------------------------------------------------------
1 | // Define globals for the test
2 | // global.CSS = {};
3 |
--------------------------------------------------------------------------------
/tests/php/TestCase.php:
--------------------------------------------------------------------------------
1 | assertTrue( class_exists( 'Elementary_Theme\Elementary_Theme' ) );
23 | }
24 |
25 | /**
26 | * Test if class Elementary_Theme is a singleton.
27 | *
28 | * @since 1.0.0
29 | */
30 | public function test_class_is_singleton() {
31 | $this->assertTrue( Elementary_Theme::get_instance() instanceof Elementary_Theme );
32 | }
33 |
34 | /**
35 | * Test if class Elementary_Theme has a method 'setup_hooks'.
36 | *
37 | * @since 1.0.0
38 | */
39 | public function test_class_has_method_setup_hooks() {
40 | $this->assertTrue( method_exists( 'Elementary_Theme\Elementary_Theme', 'setup_hooks' ) );
41 | }
42 |
43 | /**
44 | * Test if class Elementary_Theme has a method 'elementary_theme_support'.
45 | *
46 | * @since 1.0.0
47 | */
48 | public function test_class_has_method_elementary_theme_support() {
49 | $this->assertTrue( method_exists( 'Elementary_Theme\Elementary_Theme', 'elementary_theme_support' ) );
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/theme.json:
--------------------------------------------------------------------------------
1 | {
2 | "$schema": "https://schemas.wp.org/trunk/theme.json",
3 | "version": 2,
4 | "customTemplates": [
5 | {
6 | "name": "no-title",
7 | "title": "No Title Template",
8 | "postTypes": [
9 | "page",
10 | "post"
11 | ]
12 | }
13 | ],
14 | "settings": {
15 | "appearanceTools": true,
16 | "color": {
17 | "palette": [
18 | {
19 | "slug": "foreground",
20 | "color": "#242321",
21 | "name": "Foreground"
22 | },
23 | {
24 | "slug": "background",
25 | "color": "#FCFBF8",
26 | "name": "Background"
27 | },
28 | {
29 | "slug": "primary",
30 | "color": "#242321",
31 | "name": "Primary"
32 | },
33 | {
34 | "slug": "secondary",
35 | "color": "#666666",
36 | "name": "Secondary"
37 | },
38 | {
39 | "slug": "tertiary",
40 | "color": "#CFCFCF",
41 | "name": "Tertiary"
42 | }
43 | ]
44 | },
45 | "custom": {
46 | "spacing": {
47 | "small": "clamp(20px, 4vw, 40px)",
48 | "medium": "clamp(48px, 8vw, 100px)",
49 | "large": "clamp(100px, 12vw, 460px)",
50 | "outer": "min(4vw, 90px)"
51 | }
52 | },
53 | "typography": {
54 | "dropCap": false,
55 | "fluid": true,
56 | "fontFamilies": [
57 | {
58 | "fontFamily": "-apple-system,BlinkMacSystemFont,\"Segoe UI\",Roboto,Oxygen-Sans,Ubuntu,Cantarell,\"Helvetica Neue\",sans-serif",
59 | "name": "System Font",
60 | "slug": "system-font"
61 | },
62 | {
63 | "fontFamily": "\"Source Serif Pro\", serif",
64 | "name": "Source Serif Pro",
65 | "slug": "source-serif-pro"
66 | }
67 | ],
68 | "fontSizes": [
69 | {
70 | "fluid": {
71 | "min": "0.875rem",
72 | "max": "1rem"
73 | },
74 | "size": "1rem",
75 | "slug": "small"
76 | },
77 | {
78 | "fluid": {
79 | "min": "1rem",
80 | "max": "1.125rem"
81 | },
82 | "size": "1.125rem",
83 | "slug": "medium"
84 | },
85 | {
86 | "fluid": {
87 | "min": "1.125rem",
88 | "max": "1.75rem"
89 | },
90 | "size": "1.75rem",
91 | "slug": "large"
92 | },
93 | {
94 | "fluid": {
95 | "min": "1.75rem",
96 | "max": "2.25rem"
97 | },
98 | "size": "2.25rem",
99 | "slug": "x-large"
100 | },
101 | {
102 | "fluid": {
103 | "min": "3rem",
104 | "max": "4.5rem"
105 | },
106 | "size": "4.5rem",
107 | "slug": "xx-large"
108 | }
109 | ]
110 | },
111 | "layout": {
112 | "contentSize": "620px",
113 | "wideSize": "1260px"
114 | },
115 | "spacing": {
116 | "units": [
117 | "%",
118 | "px",
119 | "em",
120 | "rem",
121 | "vh",
122 | "vw"
123 | ]
124 | },
125 | "useRootPaddingAwareAlignments": true
126 | },
127 | "styles": {
128 | "blocks": {
129 | "core/heading": {
130 | "typography": {
131 | "fontWeight": "100",
132 | "lineHeight": "1.1"
133 | }
134 | },
135 | "core/navigation": {
136 | "typography": {
137 | "fontSize": "var(--wp--preset--font-size--small)"
138 | }
139 | },
140 | "core/post-comments": {
141 | "elements": {
142 | "h3": {
143 | "typography": {
144 | "textTransform": "uppercase"
145 | }
146 | }
147 | },
148 | "typography": {
149 | "fontSize": "var(--wp--preset--font-size--small)"
150 | },
151 | "spacing": {
152 | "padding": {
153 | "top": "var(--wp--custom--spacing--small)"
154 | }
155 | }
156 | },
157 | "core/post-navigation-link": {
158 | "typography": {
159 | "fontSize": "var(--wp--preset--font-size--medium)",
160 | "fontWeight": "100",
161 | "textTransform": "uppercase"
162 | }
163 | },
164 | "core/query-pagination": {
165 | "typography": {
166 | "fontSize": "var(--wp--preset--font-size--small)"
167 | }
168 | },
169 | "core/pullquote": {
170 | "border": {
171 | "width": "0"
172 | },
173 | "spacing": {
174 | "padding": {
175 | "top": "var(--wp--custom--spacing--medium)",
176 | "bottom": "var(--wp--custom--spacing--medium)"
177 | }
178 | },
179 | "typography": {
180 | "fontWeight": "100",
181 | "lineHeight": "1.2"
182 | }
183 | },
184 | "core/quote": {
185 | "border": {
186 | "width": "1px"
187 | }
188 | },
189 | "core/separator": {
190 | "color": {
191 | "background": "var(--wp--preset--color--foreground)"
192 | }
193 | },
194 | "core/site-title": {
195 | "typography": {
196 | "fontSize": "var(--wp--preset--font-size--normal)",
197 | "fontWeight": "400",
198 | "textTransform": "uppercase"
199 | }
200 | }
201 | },
202 | "color": {
203 | "background": "var(--wp--preset--color--background)",
204 | "text": "var(--wp--preset--color--foreground)"
205 | },
206 | "elements": {
207 | "h1": {
208 | "typography": {
209 | "fontSize": "var(--wp--preset--font-size--xx-large)"
210 | }
211 | },
212 | "h2": {
213 | "typography": {
214 | "fontSize": "var(--wp--preset--font-size--x-large)"
215 | }
216 | },
217 | "h3": {
218 | "typography": {
219 | "fontSize": "var(--wp--preset--font-size--large)"
220 | }
221 | },
222 | "h4": {
223 | "typography": {
224 | "fontSize": "var(--wp--preset--font-size--medium)"
225 | }
226 | },
227 | "h5": {
228 | "typography": {
229 | "fontSize": "var(--wp--preset--font-size--normal)"
230 | }
231 | },
232 | "h6": {
233 | "typography": {
234 | "fontSize": "var(--wp--preset--font-size--small)"
235 | }
236 | },
237 | "button": {
238 | "border": {
239 | "radius": "0"
240 | },
241 | "color": {
242 | "background": "var(--wp--preset--color--primary)",
243 | "text": "var(--wp--preset--color--background)"
244 | },
245 | "typography": {
246 | "fontSize": "var(--wp--preset--typography--font-size--normal)",
247 | "textTransform": "uppercase"
248 | },
249 | ":hover": {
250 | "color": {
251 | "background": "var(--wp--preset--color--secondary)",
252 | "text": "var(--wp--preset--color--background)"
253 | }
254 | },
255 | ":focus": {
256 | "color": {
257 | "background": "var(--wp--preset--color--secondary)",
258 | "text": "var(--wp--preset--color--background)"
259 | }
260 | },
261 | ":active": {
262 | "color": {
263 | "background": "var(--wp--preset--color--primary)",
264 | "text": "var(--wp--preset--color--background)"
265 | }
266 | },
267 | ":visited": {
268 | "color": {
269 | "text": "var(--wp--preset--color--background)"
270 | }
271 | }
272 | }
273 | },
274 | "spacing": {
275 | "blockGap": "1.25rem",
276 | "padding": {
277 | "top": "var(--wp--custom--spacing--small)",
278 | "right": "var(--wp--custom--spacing--small)",
279 | "bottom": "var(--wp--custom--spacing--small)",
280 | "left": "var(--wp--custom--spacing--small)"
281 | }
282 | },
283 | "typography": {
284 | "fontFamily": "var(--wp--preset--font-family--system-font)",
285 | "fontSize": "var(--wp--preset--font-size--normal)",
286 | "fontWeight": "400",
287 | "lineHeight": "1.6"
288 | }
289 | },
290 | "templateParts": [
291 | {
292 | "name": "header",
293 | "title": "Header",
294 | "area": "header"
295 | },
296 | {
297 | "name": "footer",
298 | "title": "Footer",
299 | "area": "footer"
300 | }
301 | ]
302 | }
303 |
--------------------------------------------------------------------------------
/webpack.config.js:
--------------------------------------------------------------------------------
1 | /**
2 | * External dependencies
3 | */
4 | const fs = require( 'fs' );
5 | const path = require( 'path' );
6 | const CssMinimizerPlugin = require( 'css-minimizer-webpack-plugin' );
7 | const RemoveEmptyScriptsPlugin = require( 'webpack-remove-empty-scripts' );
8 |
9 | /**
10 | * WordPress dependencies
11 | */
12 | const [ scriptConfig, moduleConfig ] = require( '@wordpress/scripts/config/webpack.config' );
13 |
14 | /**
15 | * Read all file entries in a directory.
16 | * @param {string} dir Directory to read.
17 | * @return {Object} Object with file entries.
18 | */
19 | const readAllFileEntries = ( dir ) => {
20 | const entries = {};
21 |
22 | if ( ! fs.existsSync( dir ) ) {
23 | return entries;
24 | }
25 |
26 | if ( fs.readdirSync( dir ).length === 0 ) {
27 | return entries;
28 | }
29 |
30 | fs.readdirSync( dir ).forEach( ( fileName ) => {
31 | const fullPath = `${ dir }/${ fileName }`;
32 | if ( ! fs.lstatSync( fullPath ).isDirectory() && ! fileName.startsWith( '_' ) ) {
33 | entries[ fileName.replace( /\.[^/.]+$/, '' ) ] = fullPath;
34 | }
35 | } );
36 |
37 | return entries;
38 | };
39 |
40 | // Extend the default config.
41 | const sharedConfig = {
42 | ...scriptConfig,
43 | output: {
44 | path: path.resolve( process.cwd(), 'assets', 'build', 'js' ),
45 | filename: '[name].js',
46 | chunkFilename: '[name].js',
47 | },
48 | plugins: [
49 | ...scriptConfig.plugins
50 | .map(
51 | ( plugin ) => {
52 | if ( plugin.constructor.name === 'MiniCssExtractPlugin' ) {
53 | plugin.options.filename = '../css/[name].css';
54 | }
55 | return plugin;
56 | },
57 | ),
58 | new RemoveEmptyScriptsPlugin(),
59 | ],
60 | optimization: {
61 | ...scriptConfig.optimization,
62 | splitChunks: {
63 | ...scriptConfig.optimization.splitChunks,
64 | },
65 | minimizer: scriptConfig.optimization.minimizer.concat( [ new CssMinimizerPlugin() ] ),
66 | },
67 | };
68 |
69 | // Generate a webpack config which includes setup for CSS extraction.
70 | // Look for css/scss files and extract them into a build/css directory.
71 | const styles = {
72 | ...sharedConfig,
73 | entry: () => readAllFileEntries( './assets/src/css' ),
74 | module: {
75 | ...sharedConfig.module,
76 | },
77 | plugins: [
78 | ...sharedConfig.plugins.filter(
79 | ( plugin ) => plugin.constructor.name !== 'DependencyExtractionWebpackPlugin',
80 | ),
81 | ],
82 |
83 | };
84 |
85 | const scripts = {
86 | ...sharedConfig,
87 | entry: {
88 | 'core-navigation': path.resolve( process.cwd(), 'assets', 'src', 'js', 'core-navigation.js' ),
89 | },
90 | };
91 |
92 | const moduleScripts = {
93 | ...moduleConfig,
94 | entry: () => readAllFileEntries( './assets/src/js/modules' ),
95 | output: {
96 | ...moduleConfig.output,
97 | path: path.resolve( process.cwd(), 'assets', 'build', 'js', 'modules' ),
98 | filename: '[name].js',
99 | chunkFilename: '[name].js',
100 | },
101 | };
102 |
103 | module.exports = [ scripts, styles, moduleScripts ];
104 |
--------------------------------------------------------------------------------