Giter Club home page Giter Club logo

tessa's Introduction

Installation

To install latest version of juniwalk/tessa use Composer.

composer require juniwalk/tessa

Usage

Check config.neon from tests for more details.

extensions:
	tessa: JuniWalk\Tessa\DI\TessaExtension

tessa:
	outputDir: %wwwDir%/static
	checkLastModified: true

	default:
		defer: true
		assets:
			- %moduleDir%/font-awesome/css/font-awesome.min.css
			- %moduleDir%/jquery/dist/jquery.min.js
			- %moduleDir%/bootstrap/dist/css/bootstrap.min.css
			- %moduleDir%/bootstrap/dist/js/bootstrap.min.js
			- %moduleDir%/nette-forms/src/assets/netteForms.min.js
			- %wwwDir%/assets/style.css
			- %wwwDir%/assets/index.js

	frontend:
		extend: default
		assets: []

	backend:
		extend: default
		assets:
			- %wwwDir%/assets/admin.js

	fullcalendar:
		defer: true
		assets:
			- %moduleDir%/fullcalendar/index.global.min.js

Include AssetManager trait to get access to Tessa component.

use JuniWalk\Tessa\Attributes\AssetBundle;
use JuniWalk\Tessa\Traits\AssetManager;

#[AssetBundle('frontend')]
class TessaPresenter extends Presenter
{
	use AssetManager;

	#[AssetBundle('calendar')]
	public function actionCalendar(): void {}
}

Then render styles and scripts in template from Presenter attributes.

<!DOCTYPE html>
<html>
<head>

	<title>Tessa example</title>
	{control tessa:css}
	{control tessa:js}

</head>
<body>

	<!-- your page content -->

</body>
</html>

Alternatively you can render specific part of bundle.

<!DOCTYPE html>
<html>
<head>

	<title>Render just fullcalendar scripts</title>
	{control tessa:js 'fullcalendar'}

</head>
<body>

	<!-- your page content -->

</body>
</html>

tessa's People

Contributors

juniwalk avatar

Watchers

 avatar  avatar  avatar

tessa's Issues

Config: Allow explicit type override in config.

There are types of assets that cannot be easily distinguished for types from file extension (url that don't have extension).

For ease of use and fast compiling, there should be an option to explicitly set asset type in the configuration.

Example:

default:
    joinFiles: false
    assets:
        - %wwwDir%/css/style.css --type=js	# as cli param?
        - %wwwDir%/css/style.css?type=js	# as url query?

        # Potential issues
        - https://example.com/script.js --type=js	# should work well
        - https://example.com/script.js?type=js		# could be interpreted as part of the url

And the result

$asset = new FileAsset($file, $type ?? null);

Leave room for future params extension if possible.

ScssAsset: Parse for @imports and check if hasBeenModified

/**
 * @param  string  $file
 * @param  bool  $checkLastModified
 * @return bool
 */
public function hasBeenModified(string $file, bool $checkLastModified): bool
{
	if (!file_exists($file)) {
		return true;
	}

	if (!$checkLastModified) {
		return false;
	}

	// TODO: Parse for @imports and check those files too

	return filemtime($this->file) > filemtime($file);
}

Bundle: Add option to include modified time in url

/**
 * @param  Asset  $asset
 * @return string
 */
public function createPublicPath(Asset $asset): string
{
	return str_replace($this->wwwDir, $this->basePath, $asset->getFile()).'?'.$asset->getLastModified();
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.