Modernizr just published a beta builder (all client-side), seeing this in a module would be awesome.
http://modernizr.github.com/Modernizr/2.0-beta/

BTW
Why not integrate Modernizr into the module?

Comments

tamasd’s picture

How could it be useful for the module? Do you have a use case?

I can't integrate it because of the Drupal.org's CVS repository policy (hosting 3rd party code is strictly prohibited).

LewisNyman’s picture

I think it would be a great idea to integrate the V2 download builder in to Drupal. Other modules could use this as an API to hook in support for HTML5 features.

We are allowed to host third party code in the d.o CVS. You could say that Drupal is build off third party code. The only requirement is that it is GPL licensed.
Moderizr is licenced under the MIT licence. This allows you to re-licence the work as anything we want. Including GPL.

LewisNyman’s picture

I have done some digging and I've found the Modular Build Script JS file here:

http://www.modernizr.com/i/js/builderapp.js

rupl’s picture

Title: Modernizr 2 beta builder » Modernizr 2 custom builder
Version: 7.x-2.x-dev » 7.x-3.x-dev

I can see how this would be useful, but it will take quite a bit of work to reproduce this functionality within Drupal's UI, especially because it's client-side and would download to the user's computer instead of the server where it's needed.

If anything, I think it would be more useful to integrate with the command-line builder and write a drush command that builds what a site currently needs, as defined by invoking hook_modernizr_info(). Right now the 7.x-3.x branch can ask a Drupal installation what Modernizr tests it needs to include in the build, and link the user to the exact build page. See #1288248-3: [Meta] Develop a Modernizr API for other Drupal modules for more info.

This would still be quite a task, because there's no web service that provides command-line builds, so someone would need to set that up. I'm not particularly interested in funding such a service, because the first person to set it up would inevitably be supporting the greater web community, not just Drupal. I asked the Modernizr team if/when they would set such a service up, and the bandwidth cost was essentially the only thing stopping them from doing it.

rupl’s picture

After some preliminary testing, it seems that the code in the Modernizr repo is working very well, albeit a bit out of date. Modernizr stable has been bumped to 2.5.3 but the CLI outputs 2.0.6 builds. I'm trying to figure out how much work it will be to get the builder back in sync with the master branch.

Now that I have this piece working, it won't be difficult to write a drush command that can integrate. Hooray!

There will not be an external service to compliment this feature of the module, but I will provide some instructions to assist with setup on dev environments. It will rely on node.js and npm.

LewisNyman’s picture

Here's an alternative approach, what if the module included all the Modernizr functions inside their own files? Then the builder function becomes as simple as drupal_add_js? Drupal handles the aggregation so it doesn't need to be all in one file.

rupl’s picture

That's a very interesting idea, Lewis!

For now I don't think I'll attempt to implement it until Modernizr has a modular builder included with the JS library. For now, I'd say it's much more efficient to rely on the tool that's already available, rather than re-engineering from scratch.

As far as drupal_add_js() goes, I would want to avoid aggregating Modernizr along with other Drupal JS. It's supposed to be small so that it downloads quickly and executes ASAP. Grouping it with other JS will slow it down considerably.

rupl’s picture

Boom! I checked in a first pass at the drush command to generate custom builds. There is much to improve upon, but it definitely works. Here are instructions as of June 4, 2012. Note: for this section, the words 'node' and 'module' are referring to node.js/npm terms, NOT Drupal terms.

Node.js and npm

First, install node.js and npm (it's not too bad).

Second, clone the Modernizr repository somewhere, checkout customizr branch, and go inside the customizr directory:

git clone --branch customizr https://github.com/Modernizr/Modernizr.git modernizr
cd modernizr/customizr

You have to do a little bit of work to get the npm module installed. Edit package.json and change the versions of commander, uglify, and node itself to have greater than or equals signs (>=) in front of the version numbers. Here's the package.json that allowed me to install the module:

{
    "name": "modernizr"
  , "version": "0.0.1"
  , "description": "Modernizr custom script builder"
  , "keywords": ["modernizr", "html5", "feature detection"]
  , "author": "Kevin Gorski <n.o.s.p.a.m@gmail.com>"
  , "dependencies": {
      "commander": ">=0.1.0"
    , "uglify-js": ">=1.0.7" }
  , "bin": { "modernizr": "./bin/modernizr" }
  , "engines": { "node": ">=0.4.x" }
}

Finally, install the node.js module:

[sudo] npm install . -g

Hooray! You now have a command line tool called 'modernizr' at your disposal.

Drush

The drush command will eventually execute the node.js builder from PHP, but for now it outputs a set of arguments for the modernizr command. Right now it can handle four arguments: extras, tests, groups, and not. Read docs on the command-line builder.

modernizr `drush mcb`

Todos

  1. Add 'type' to the module API, so that tests, extras, and other types of args can be separated to make the drush command more flexible. Update: code is checked in. See example above.
  2. Upgrade the npm module so that it outputs 2.5.3 like http://modernizr.com/download/

Known issues

  • Currently the command-line builder outputs Modernizr 2.0.6 builds, so the 'printshiv' extra within 7.x-3.x is unknown to the builder. Change printshiv to iepp in order to test.
klonos’s picture

Interesting stuff! ...perhaps it belongs to (or even deserves) its own submodule(?).

rupl’s picture

Ultimately this will be a simple drush command, so I'd be weary of splitting it out into its own submodule.

As I add more features I'll be mindful of the core module's size, and if some component grows too big I will consider splitting it into a submodule.

rupl’s picture

Status: Active » Postponed

After another failed attempt to update the CLI builder this feature is postponed until Modernizr 3 is released. I've spoken to the Modernizr team and v3 will be completely modular, making derivative tools like the CLI builder easier to keep current as they update the main lib. At that time, we'll have drush integration ready.

klonos’s picture

Thanx for the update ;)

rupl’s picture

Interesting development for Modernizr 2: https://github.com/doctyper/grunt-modernizr

It's a grunt tool that scrapes your files for Modernizr classes and assembles a custom build based on the findings. We can integrate with this in the exact same way as I posted in #1030822-8: Modernizr 2 custom builder (client-side for admin UI) because it takes the same basic set of flags. No new code on the Drupal side but I wanted to point out this new integration option.

rupl’s picture

Title: Modernizr 2 custom builder » Modernizr 2 custom builder (client-side for admin UI)
Issue summary: View changes
Status: Postponed » Closed (won't fix)

Closing this issue as I do not want to integrate the client-side builder, but will work toward providing grunt-modernizr integration in #2239291: Integrate with grunt-modernizr