2017 © Pedro Peláez
 

symfony-bundle includelibrary-bundle

Bundle to include easily main libraries jQuery, Bootstrap, etc. to your html header

image

c975l/includelibrary-bundle

Bundle to include easily main libraries jQuery, Bootstrap, etc. to your html header

  • Saturday, July 21, 2018
  • by Laurent3170
  • Repository
  • 2 Watchers
  • 2 Stars
  • 244 Installations
  • PHP
  • 12 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 27 Versions
  • 26 % Grown

The README.md

IncludeLibraryBundle

Fed up of having to look to latest, or specifc, version of jQuery, Bootstrap, etc. IncludeLibraryBundle is made for you ;-), (*1)

Want to replace this, (*2)

    <link
        rel="stylesheet"
        type="text/css"
        href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"
        integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u"
        crossorigin="anonymous">

    <script
        type="text/javascript"
        src="//maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"
        integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa"
        crossorigin="anonymous">
    </script>

by this?, (*3)

    {{ inc_lib('bootstrap', 'css', '3.3.7') }}
    {{ inc_lib('bootstrap', 'js', '3.3.7') }}

IncludeLibraryBundle will let you specify which library and version to include, version can use wildcard "*". It will do a lot more, see "How to use" below., (*4)

Subresource Integrity are provided, even for the libraries that don't provide them, based on https://www.srihash.org/, (*5)

You can also include Google Font, see below., (*6)

IncludeLibraryBundle dedicated web page., (*7)

IncludeLibraryBundle API documentation., (*8)

 Bundle installation

 Step 1: Download the Bundle

Use Composer to install the library, (*9)

    composer require c975l/includelibrary-bundle

 How to use

IncludeLibraryBundle provide the following Twig extension functions inc_lib(), inc_link(), inc_content() and inc_font(), (*10)

 Include Library - inc_lib()

Simply add {{ inc_lib('library', 'type', 'version', 'params') }} to your header and that's it!, (*11)

  • library is the name of the library (see below Supported libraries). It is case unsensitive and can have "-" or "_", if you want to use 'BoOsTrap', it will work ;-).
  • type is css or js or local, also case insensitive.
  • version is the version wanted, it can use wildcard or be omitted to get the latest one.
  • params is the parameters you want to add when calling a javascript.

 Examples

{{ inc_lib('bootstrap', 'css') }}: Latest version, (*12)

{{ inc_lib('bootstrap', 'css', '3.3.7') }}: Specific version, (*13)

{{ inc_lib('bootstrap', 'css', '3.*') }}: Wildcard MAJOR version, (*14)

{{ inc_lib('bootstrap', 'css', '3.3.*') }}: Wildcard MINOR version, (*15)

{{ inc_lib('bootstrap', 'css', '3.3.3.*') }}: Wildcard PATCH version, (*16)

{{ inc_lib(absolute_url(asset('css/styles.min.css')), 'local') }}: local file, (*17)

 Local file

To include a local file, you need to provide an absolute url. Important the type is determined by the extension provided in the url, so it has to be '.css' or '.js'. While it's not really useful for inc_lib(), it is for inc_content() (see below) as it will allow to include the content of the called library in the html, which can be useful when creating PDF files with wkhtmltopdf for example., (*18)

 Javascript parameters

For javascript, if you need to add some url query parameters, you can do so by calling the fourth argument params of inc_lib(). Works also for local file., (*19)

For example, Tinymce needs an apiKey, so call it like this: {{ inc_lib('tinymce', 'js', 'stable', '?apiKey=YOUR_API_KEY') }}, you simply need to provide the full query parameters, including "?" and "&" as it will be added to the srcipt call., (*20)

You can also use inc_link in the same way {{ inc_link('bootstrap', 'css', '3.*') }} to get only the href (css) or src (js) part (url). Does not work for a local file as it will return the same url as provided., (*21)

For example, Tinymce needs to get the css used on the website to display using those styles, so we need to provide it the url, inc_link will do so :, (*22)

<script type="text/javascript">
    tinymce.init({
        content_css : [
            '{{ inc_link('bootstrap', 'css', '3.*') }}',
        ],
    //...
    });
</script>

 Get content - inc_content()

If you need to get the content to include, i.e. for wkhtmltopdf, you can use the function inc_content in the same way {{ inc_content('bootstrap', 'css', '3.*') }}. Works also for local file. Content will be wrapped within <style type="text/css"></style> for css and <script type="text/javascript"></script> for js., (*23)

 Include Google font - inc_font()

All you have to do is to worry about its name! Find your Google Font, pick its name and call it with {{ inc_font('FONT_NAME') }}. That's it! Now you can refer, using the same names in your css files!, (*24)

 Supported libraries

Use following names and versions (+ wildcard if wanted, as indicated above) in the functions inc_lib, inc_link or inc_content: To find supported versions check the sub-folders of src/integrities, (*25)

How to add libraries and/or versions

  • Go into the folder Libraries,
  • Open the library class (or add it if not present),
  • Locate the corresponding method getCss() or getJavascript(),
  • If you add new Library, add method getVersion(),
  • Add versions and wildcards to the methods getVersion(), keeping the latest above,
  • Add the needed data (take example on existing ones).

Feel free to make PR's to add other libraries/versions :-), (*26)

If this project help you to reduce time to develop, you can sponsor me via the "Sponsor" button at the top :), (*27)

The Versions

21/07 2018

dev-master

9999999-dev https://github.com/975L/IncludeLibraryBundle

Bundle to include easily main libraries jQuery, Bootstrap, etc. to your html header

  Sources   Download

MIT

The Requires

  • php >=5.5.9

 

library bundle symfony

21/07 2018

v1.8

1.8.0.0 https://github.com/975L/IncludeLibraryBundle

Bundle to include easily main libraries jQuery, Bootstrap, etc. to your html header

  Sources   Download

MIT

The Requires

  • php >=5.5.9

 

library bundle symfony

23/06 2018

v1.7.8

1.7.8.0 https://github.com/975L/IncludeLibraryBundle

Bundle to include easily main libraries jQuery, Bootstrap, etc. to your html header

  Sources   Download

MIT

The Requires

  • php >=5.5.9

 

library bundle symfony

24/05 2018

v1.7.7

1.7.7.0 https://github.com/975L/IncludeLibraryBundle

Bundle to include easily main libraries jQuery, Bootstrap, etc. to your html header

  Sources   Download

MIT

The Requires

  • php >=5.5.9

 

library bundle symfony

22/05 2018

v1.7.6.1

1.7.6.1 https://github.com/975L/IncludeLibraryBundle

Bundle to include easily main libraries jQuery, Bootstrap, etc. to your html header

  Sources   Download

MIT

The Requires

  • php >=5.5.9

 

library bundle symfony

12/05 2018

v1.7.6

1.7.6.0 https://github.com/975L/IncludeLibraryBundle

Bundle to include easily main libraries jQuery, Bootstrap, etc. to your html header

  Sources   Download

MIT

The Requires

 

library bundle symfony

29/04 2018

v1.7.5.1

1.7.5.1 https://github.com/975L/IncludeLibraryBundle

Bundle to include easily main libraries jQuery, Bootstrap, etc. to your html header

  Sources   Download

MIT

The Requires

 

library bundle symfony

29/04 2018

v1.7.5

1.7.5.0 https://github.com/975L/IncludeLibraryBundle

Bundle to include easily main libraries jQuery, Bootstrap, etc. to your html header

  Sources   Download

MIT

The Requires

 

library bundle symfony

10/04 2018

v1.7.4

1.7.4.0 https://github.com/975L/IncludeLibraryBundle

Bundle to include easily main libraries jQuery, Bootstrap, etc. to your html header

  Sources   Download

MIT

The Requires

 

library bundle symfony

21/03 2018

v1.7.3

1.7.3.0 https://github.com/975L/IncludeLibraryBundle

Bundle to include easily main libraries jQuery, Bootstrap, etc. to your html header

  Sources   Download

MIT

The Requires

 

library bundle symfony

19/03 2018

v1.7.2

1.7.2.0 https://github.com/975L/IncludeLibraryBundle

Bundle to include easily main libraries jQuery, Bootstrap, etc. to your html header

  Sources   Download

MIT

The Requires

 

library bundle symfony

09/03 2018

v1.7.1

1.7.1.0 https://github.com/975L/IncludeLibraryBundle

Bundle to include easily main libraries jQuery, Bootstrap, etc. to your html header

  Sources   Download

MIT

The Requires

 

library bundle symfony

08/03 2018

v1.7

1.7.0.0 https://github.com/975L/IncludeLibraryBundle

Bundle to include easily main libraries jQuery, Bootstrap, etc. to your html header

  Sources   Download

MIT

The Requires

 

library bundle symfony

07/03 2018

v1.6.1.1

1.6.1.1 https://github.com/975L/IncludeLibraryBundle

Bundle to include easily main libraries jQuery, Bootstrap, etc. to your html header

  Sources   Download

MIT

The Requires

 

library bundle symfony

06/03 2018

v1.6.1

1.6.1.0 https://github.com/975L/IncludeLibraryBundle

Bundle to include easily main libraries jQuery, Bootstrap, etc. to your html header

  Sources   Download

MIT

The Requires

 

library bundle symfony

06/03 2018

v1.6

1.6.0.0 https://github.com/975L/IncludeLibraryBundle

Bundle to include easily main libraries jQuery, Bootstrap, etc. to your html header

  Sources   Download

MIT

The Requires

 

library bundle symfony

01/03 2018

v1.5.1

1.5.1.0 https://github.com/975L/IncludeLibraryBundle

Bundle to include easily main libraries jQuery, Bootstrap, etc. to your html header

  Sources   Download

MIT

The Requires

 

library bundle symfony

01/03 2018

v1.5

1.5.0.0 https://github.com/975L/IncludeLibraryBundle

Bundle to include easily main libraries jQuery, Bootstrap, etc. to your html header

  Sources   Download

MIT

The Requires

 

library bundle symfony

27/02 2018

v1.4.1

1.4.1.0 https://github.com/975L/IncludeLibraryBundle

Bundle to include easily main libraries jQuery, Bootstrap, etc. to your html header

  Sources   Download

MIT

The Requires

 

library bundle symfony

27/02 2018

v1.4

1.4.0.0 https://github.com/975L/IncludeLibraryBundle

Bundle to include easily main libraries jQuery, Bootstrap, etc. to your html header

  Sources   Download

MIT

The Requires

 

library bundle symfony

26/02 2018

v1.3.2.1

1.3.2.1 https://github.com/975L/IncludeLibraryBundle

Bundle to include easily main libraries jQuery, Bootstrap, etc. to your html header

  Sources   Download

MIT

The Requires

 

library bundle symfony

26/02 2018

v1.3.2

1.3.2.0 https://github.com/975L/IncludeLibraryBundle

Bundle to include easily main libraries jQuery, Bootstrap, etc. to your html header

  Sources   Download

MIT

The Requires

 

library bundle symfony

24/02 2018

v1.3.1

1.3.1.0 https://github.com/975L/IncludeLibraryBundle

Bundle to include easily main libraries jQuery, Bootstrap, etc. to your html header

  Sources   Download

MIT

The Requires

 

library bundle symfony

24/02 2018

v1.3

1.3.0.0 https://github.com/975L/IncludeLibraryBundle

Bundle to include easily main libraries jQuery, Bootstrap, etc. to your html header

  Sources   Download

MIT

The Requires

 

library bundle symfony

23/02 2018

v1.2

1.2.0.0 https://github.com/975L/IncludeLibraryBundle

Bundle to include easily main libraries jQuery, Bootstrap, etc. to your html header

  Sources   Download

MIT

The Requires

 

library bundle symfony

23/02 2018

v1.1

1.1.0.0 https://github.com/975L/IncludeLibraryBundle

Bundle to include easily main libraries jQuery, Bootstrap, etc. to your html header

  Sources   Download

MIT

The Requires

 

library bundle symfony

23/02 2018

v1.0

1.0.0.0 https://github.com/975L/IncludeLibraryBundle

Bundle to include easily main libraries jQuery, Bootstrap, etc. to your html header

  Sources   Download

MIT

The Requires

 

library bundle symfony