Download the PHP package timkelty/craftcms-classmate without Composer

On this page you can find all versions of the php package timkelty/craftcms-classmate. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package craftcms-classmate

Classmate for Craft CMS 3

Donate

Test Status

Classmate is here to help with HTML class composition and is especially useful when paired with a utility-first css framework, such as Tailwind CSS.

Before Classmate:

template.twig

After Classmate:

template.twig

classmate.json

Why?

My opinons about Extracting component classes with @apply are pretty well summed up by this tweet:

Flowchart:

In short, I tend to avoid @apply when possible.

Classmate was created specifically for single element components (e.g. button, link, heading), where extracting to a template partial may be cumbersome and you still want to avoid @apply.

How is this better than @apply? Aren't we just moving problem elsewhere?

Yes and no. It is true that the practice of extracting components with @apply is similar to defining classes in classmate JSON file. However, Classmate abstracts the definition on the backend (PHP), while @apply abstracts it as part of the front-end build. Advantages to this are:

Configuration

Copy ./src/config.php to <yourProject>/config/classmate.php.

filePath

The location of your Classmate file. Aliases and environment variables are supported. Defaults to @config/classmate.json, but I suggest you put it alongside your pre-compiled frontend assets, e.g. ./src/css/classmate.json

If using Tailwind or PurgeCSS directly, you will also want to include this path. E.g.

tailwind.config.js

Classmate File

Your Classmate file is a JSON file with a single object. The values can be space separated strings or arrays, or a combination of both.

Since this is just a JSON file, it is easily consumable by Javascript, too!

Usage

tag function

tag tag

Craft 3.6+ only

attr function

attr filter

Class string

API

classmate is a chainable API, available as a global in your Twig templates.

get(string ...$keys): Classmate

Retrive classes of given $keys from your classmate file. Multiple keys will be merged right to left.

asClasses(): array

Retrive an array of classes. Duplicates and empty values are removed.

asAttributes(iterable $attributes = []): array

Retreive an attr-compatible iterable, with class set, merged into any passed $attributes.

add(string ...$classes): Classmate

Add classes to the current ClassList.

remove(string ...$classes): Classmate

Remove classes to the current ClassList.

matching(string $pattern): Classmate

Filter the current ClassList, keeping those that match $pattern.

notMatching(string $pattern): Classmate

Filter the current ClassList, removing those that match $pattern.

replace(string $search, string $replace, bool $partial = false): Classmate

Replace $search with $replace. Set $partial to true to match partial strings, otherwise only complete matches will be replaced.

prepend(string $string): Classmate

Prepend $string to each item in the ClassList.

append(string $string): Classmate

Append $string to each item in the ClassList.

Cache

Retrival of the JSON file is cached, and invalidated by modifications to the file, so you really shouldn't have to worry much about invalidation. However, you can selectively clear the cache via the CP or with the CLI command:

Requirements

Installation

Roadmap

How do I use Classmate classes in css?

You can't! …yet. @markhuot alluded to this here: https://twitter.com/markhuot/status/1351605237736419329

A Tailwind/Postcss plugin might allow something like:

E.g. you write

…to grab classes the same what that classmate.get('foo', 'bar') would.

Arrow Functions

I'd love to allow the use of arrow functions, but Twig currently doesn't allow it. For example, instead of our matches and prepend methods, I'd rather have:

While this works for Twig's map, filter, and reduce filters, it doesn't work here. See https://github.com/twigphp/Twig/issues/3402

CP settings

I don't really have a desire for this, but happy to accept a PR if someone wants to add this.


All versions of craftcms-classmate with dependencies

PHP Build Version
Package Version
Requires craftcms/cms Version ^3.2.0
illuminate/collections Version ^8.22
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package timkelty/craftcms-classmate contains the following files

Loading the files please wait ....