Skip to content

Commit

Permalink
Initial release
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremyfrank committed Sep 16, 2019
0 parents commit 8e16e5d
Show file tree
Hide file tree
Showing 13 changed files with 4,467 additions and 0 deletions.
1 change: 1 addition & 0 deletions .craftplugin
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"pluginName":"Classnames","pluginDescription":"Classnames plugin for Craft CMS","pluginVersion":"1.0.0","pluginAuthorName":"Jeremy Frank","pluginVendorName":"viget","pluginAuthorUrl":"https://www.viget.com/","pluginAuthorGithub":"vigetlabs","codeComments":"","pluginComponents":["twigextensions"],"consolecommandName":"","controllerName":"","cpsectionName":"","elementName":"","fieldName":"","modelName":"","purchasableName":"","recordName":"","serviceName":"","taskName":"","utilityName":"","widgetName":"","apiVersion":"api_version_3_0"}
32 changes: 32 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# CRAFT ENVIRONMENT
.env.php
.env.sh
.env

# COMPOSER
/vendor

# BUILD FILES
/bower_components/*
/node_modules/*
/build/*
/yarn-error.log

# MISC FILES
.cache
.DS_Store
.idea
.project
.settings
*.esproj
*.sublime-workspace
*.sublime-project
*.tmproj
*.tmproject
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json
config.codekit3
prepros-6.config
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Classnames Changelog

All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/).

## 1.0.0 - 2019-09-16
### Added
- Initial release
9 changes: 9 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
The MIT License (MIT)

Copyright (c) 2019 Viget Labs

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
65 changes: 65 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# Classnames plugin for Craft CMS 3.x

Classnames is a simple Twig function for conditionally joining css class names together in Twig templates, in a way that makes them much more readable. It's like Jed Watson's [Classnames](https://github.com/JedWatson/classnames) but for Twig in Craft.

## Requirements

This plugin requires Craft CMS 3.0.0-beta.23 or later.

## Installation

To install the plugin, follow these instructions.

1. Open your terminal and go to your Craft project:

cd /path/to/project

2. Then tell Composer to load the plugin:

composer require viget/craft-classnames

3. Install the plugin via `./craft install/plugin classnames` via the CLI, or in the Control Panel, go to Settings → Plugins and click the “Install” button for Classnames.

## Using Classnames

A real world example:

```twig
<button
class="{{ classNames({
'group relative z-0 hover:z-1': true,
'px-24 py-12': true,
'font-bold text-14 text-dark-gray': true,
'inline-flex items-center justify-between': props.arrow,
'inline-block': not props.arrow,
'w-full text-center': props.full
}) }}"
>
{{ props.text }}
</button>
```

Other examples:

```twig
{{ classNames('foo', 'bar') }} {# 'foo bar' #}
{{ classNames('foo', { 'bar': true }) }} {# 'foo bar' #}
{{ classNames({ 'foo-bar': true }) }} {# 'foo-bar' #}
{{ classNames({ 'foo-bar': false }) }} {# '' #}
{{ classNames({ 'foo': true }, { 'bar': true }) }} {# 'foo bar' #}
{{ classNames({ 'foo': true, 'bar': true }) }} {# 'foo bar' #}
```

There is even a shorthand `cx` version available:

```twig
{{ cx('foo', { 'bar': true }) }} {# 'foo bar' #}
```

***

<a href="http://code.viget.com">
<img src="http://code.viget.com/github-banner.png" alt="Code At Viget">
</a>

Visit [code.viget.com](http://code.viget.com) to see more projects from [Viget](https://viget.com).
41 changes: 41 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
"name": "viget/craft-classnames",
"description": "Classnames plugin for Craft CMS",
"type": "craft-plugin",
"version": "1.0.0",
"keywords": [
"craft",
"cms",
"craftcms",
"craft-plugin",
"classnames"
],
"support": {
"docs": "https://github.com/vigetlabs/craft-classnames/blob/master/README.md",
"issues": "https://github.com/vigetlabs/craft-classnames/issues"
},
"license": "MIT",
"authors": [
{
"name": "Jeremy Frank",
"homepage": "https://www.viget.com/"
}
],
"require": {
"craftcms/cms": "^3.0.0-RC1",
"newridetech/php-classnames": "^1.2"
},
"autoload": {
"psr-4": {
"viget\\classnames\\": "src/"
}
},
"extra": {
"name": "Classnames",
"handle": "classnames",
"hasCpSettings": false,
"hasCpSection": false,
"changelogUrl": "https://raw.githubusercontent.com/vigetlabs/craft-classnames/master/CHANGELOG.md",
"class": "viget\\classnames\\Classnames"
}
}
Loading

0 comments on commit 8e16e5d

Please sign in to comment.