GithubHelp home page GithubHelp logo

troopers / asseticinjectorbundle Goto Github PK

View Code? Open in Web Editor NEW
20.0 20.0 10.0 26 KB

The AsseticInjectorBundle allow you to automaticly include javascripts and stylesheets anywhere in your project

License: MIT License

PHP 100.00%

asseticinjectorbundle's People

Contributors

bitdeli-chef avatar delormejonathan avatar lenybernard avatar paulandrieux avatar sanpii avatar webberig avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

asseticinjectorbundle's Issues

Prepend assets

Hello,

I have this situation :

template.html.twig :

{% javascripts injector="foot"
    '@AcmeBundle/Resources/public/js/arandomjqueryplugin.js'
%}
    <script type="text/javascript" src="{{ asset_url }}"></script>
{% endjavascripts %}

assetic_injector.json:

{
    "require_all":
    {
        "javascripts":
        {
            "foot": 
            [
                "@ThemeBundle/Resources/public/js/jquery.min.js",
            ]
        }
    }
}

The jQuery file is injected after the plugin and triggers an error.
Is it already possible to change this order ?

If not, can we use a static keyword like "pre-" or "post-" in injector tags to manually indicate the order we want ?

Inject by group

Injection with tag like head or foot is great but do not fit every needs.
I think we should be able to inject assets by a more semantical name.
For example, if we want to include the "redactor" library, only in admin layout for example, we should be able to simply add the "redactor" string in the list of tags (by directly adding like the "normal" way but with the tag name (redactor)).

So technically, I think we have to authorize infinite depth in assetic injector configuration file to be able to include small libraries like redactor to huge library like bootstrap.

Example of use for bootstrap :

assetic_injector.json :

{
    "require_all":
    {
        "stylesheets":
        {
            "bootstrap" : 
            {
                "popover": "@MopaBootstrapBundle/Resources/public/bootstrap/less/bootstrap-popover.min.js",
                "collapse": "@MopaBootstrapBundle/Resources/public/bootstrap/js/bootrstap-collapse.min.js"
            }
        },
        "javascripts":
        {
            "bootstrap" : 
            {
                "popover":
                [
                    "@MopaBootstrapBundle/Resources/public/bootstrap/js/bootstrap-tooltip.min.js",
                    "@MopaBootstrapBundle/Resources/public/bootstrap/js/bootstrap-popover.min.js",
                ]
                "collapse": "@MopaBootstrapBundle/Resources/public/bootstrap/js/bootstrap-collapse.min.js"
            }
        }
    }
}

layout.html.twig :

{% stylesheets injector='bootstrap/popover, bootstrap/collapse' %}
    <link rel="stylesheet" href="{{ asset_url }}">
{% endstylesheets %}

{% javascripts injector='bootstrap/popover, bootstrap/collapse' %}
    <script type="text/javascript" src="{{ asset_url }}"></script>
{% endjavascripts %}

That don't have to change for 1 depth library inclusions :

Example of use for redactor :

assetic_injector.json :

{
    "require_all":
    {
        "stylesheets":
        {
            "redactor": "@AvAwesomeShorcutsBundle/Resources/public/libs/redactor/redactor.css"
        },
        "javascripts":
        {
            "redactor": 
            [
                "@AvAwesomeShorcutsBundle/Resources/public/libs/redactor/redactor.min.js",
                "@AvAwesomeShorcutsBundle/Resources/public/libs/redactor/redactor.fr.js"
            ]
        }
    }
}

layout.html.twig :

{% stylesheets injector='redactor' %}
    <link rel="stylesheet" href="{{ asset_url }}">
{% endstylesheets %}

{% javascripts injector='redactor' %}
    <script type="text/javascript" src="{{ asset_url }}"></script>
{% endjavascripts %}

The next step will to add directly the name near line as I said before :

doing the stuff like this in layout.html.twig :

{% stylesheets injector='redactor' %}
    <link rel="stylesheet" href="{{ asset_url }}">
{% endstylesheets %}

{% javascripts 
    '@bootrstrap/popover'
    '@bootrstrap/collapse'
%}
    <script type="text/javascript" src="{{ asset_url }}"></script>
{% endjavascripts %}

To be continued

If injector is not set, it load all other resources defined in a config file

If you don't specify the injector tag, it seems that it will load the "rest" of the resources that page don't load and is however defined in config file.

For now I resolved my issue by setting an injector="" attribute :

{% stylesheets filter='less, cssrewrite' injector=""
    '@AppBundle/Resources/public/less/style.less'
%}
<link href="{{ asset_url }}" type="text/css" rel="stylesheet" media="screen" />
{% endstylesheets %}

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.