{"id":21651394,"url":"https://github.com/sgtpep/css-modules-html-demo","last_synced_at":"2025-04-11T20:23:45.839Z","repository":{"id":144845689,"uuid":"46924555","full_name":"sgtpep/css-modules-html-demo","owner":"sgtpep","description":"A demo of using CSS Modules within HTML files following the BEM-like approach and powered by Gulp and Lo-Dash/Underscore templates.","archived":false,"fork":false,"pushed_at":"2015-11-29T20:28:35.000Z","size":24,"stargazers_count":22,"open_issues_count":1,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-25T16:21:54.984Z","etag":null,"topics":["bem","css-modules","demo","gulp","html","underscore-templates"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sgtpep.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-11-26T12:05:34.000Z","updated_at":"2022-07-06T08:39:19.000Z","dependencies_parsed_at":"2023-05-19T15:31:30.606Z","dependency_job_id":null,"html_url":"https://github.com/sgtpep/css-modules-html-demo","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sgtpep%2Fcss-modules-html-demo","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sgtpep%2Fcss-modules-html-demo/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sgtpep%2Fcss-modules-html-demo/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sgtpep%2Fcss-modules-html-demo/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sgtpep","download_url":"https://codeload.github.com/sgtpep/css-modules-html-demo/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248473718,"owners_count":21109764,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bem","css-modules","demo","gulp","html","underscore-templates"],"created_at":"2024-11-25T07:47:47.316Z","updated_at":"2025-04-11T20:23:45.797Z","avatar_url":"https://github.com/sgtpep.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# CSS Modules HTML Demo\n\nA demo of using [CSS Modules](https://github.com/css-modules/css-modules) within HTML files following the [BEM](http://getbem.com/)-like approach and powered by [Gulp](https://github.com/gulpjs/gulp) and [Lo-Dash/Underscore templates](https://lodash.com/docs#template).\n\n## Usage example\n\nRequire css files from html templates and use them as CSS Modules. Source files:\n\n`index.html`\n\n```html\n\u003clink href=\"styles.css\" rel=\"stylesheet\"\u003e\n\n\u003c% var block1 = require(\"./styles/block1\") %\u003e\n\u003cdiv class=\"${block1.element}\"\u003eBlock 1 element\u003c/div\u003e\n\n\u003c% var block2 = require(\"./styles/block2\") %\u003e\n\u003cdiv class=\"${block2.element}\"\u003eBlock 2 element\u003c/div\u003e\n```\n\n`styles/block1.css`\n\n```css\n.element {\n  color: red;\n}\n```\n\n`styles/block2.css`\n\n```css\n.element {\n  color: green;\n}\n```\n\nCompiles to:\n\n`build/index.html`\n\n```html\n\u003clink href=\"styles.css\" rel=\"stylesheet\"\u003e\n\n\u003cdiv class=\"block1__element\"\u003eBlock 1 element\u003c/div\u003e\n\n\u003cdiv class=\"block2__element\"\u003eBlock 2 element\u003c/div\u003e\n```\n\n`build/styles.css`\n\n```css\n.block1__element {\n  color: red;\n}\n.block2__element {\n  color: green;\n}\n```\n\n## Template includes\n\nInclude one html template into another. Source files:\n\n`index.html`\n\n```html\n\u003cdiv\u003eindex.html\u003c/div\u003e\n\u003c%= require(\"./includes/include\") %\u003e\n```\n\n`includes/include.html`\n\n```html\n\u003cdiv\u003einclude.html\u003c/div\u003e\n```\n\nCompiles to:\n\n`build/index.html`\n\n```html\n\u003cdiv\u003eindex.html\u003c/div\u003e\n\u003cdiv\u003einclude.html\u003c/div\u003e\n```\n\n## Comparison with BEM\n\nClass naming convensions in BEM:\n\n```html\n\u003cdiv class=\"block\"\u003e\n  Block\n  \u003cdiv class=\"block__element\"\u003eElement\u003c/div\u003e\n\u003c/div\u003e\n\u003cdiv class=\"block block--modifier\"\u003e\n  Modified block\n  \u003cdiv class=\"block__element block__element--modifier\"\u003eModified element\u003c/div\u003e\n\u003c/div\u003e\n```\n\nAchieving the same with CSS Modules:\n\n`block.html`\n\n```html\n\u003c% var block = require(\"./styles/block\") %\u003e\n\u003cdiv class=\"${block.root}\"\u003e\n  Block\n  \u003cdiv class=\"${block.element}\"\u003eElement\u003c/div\u003e\n\u003c/div\u003e\n\u003cdiv class=\"${block.modifiedRoot}\"\u003e\n  Modified block\n  \u003cdiv class=\"${block.modifiedElement}\"\u003eModified element\u003c/div\u003e\n\u003c/div\u003e\n```\n\n`styles/block.css`\n\n```css\n.root {\n  color: red;\n}\n.modifiedRoot {\n  composes: root;\n  border: 1px solid;\n}\n.element {\n  color: green;\n}\n.modifiedElement {\n  composes: element;\n  border: 1px solid;\n}\n```\n\n## License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsgtpep%2Fcss-modules-html-demo","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsgtpep%2Fcss-modules-html-demo","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsgtpep%2Fcss-modules-html-demo/lists"}