FontAwesome is now up to 4.3.0, and I have to agree with a comment in #2312935: [fontawesome] 7.x-2.x -- there has to be an easier way to get available classes into the module than having to add them in by hand.

While the packaged distributions do not include a list, the master repo (sourced by this module's makefile) does - it's in src/icons.yml. That's got to be worth something?

For people who aren't using drush and instead have added the library in manually, there is a version number in both the minified and un-minified css files. So, not only could the module use the icons.yml to list only the icons for whatever version the user has, it can also display a status message when a more recent version comes out.

Full disclosure: I don't currently use this module, and instead have a custom module of my own that loads the library. Looking to reduce duplication of effort, but I'm happy to try my hand at getting this auto-detection up and running if there's interest from the maintainers?

Comments

n20’s picture

StatusFileSize
new55.58 KB

I made a patch to download always the latest master branch instead of the hard coded version during installation with drush. I also changed some stuff to get all the icons from the icons.yaml file instead of the hard coded class names.

In case you have an old library of font awesome you could replace it with latest master branch or simply delete the fa library folder and run drush fadl.

With the dynamic loading of icon classes it would be nice to have some sort of drush faup to update the library.

Only thing not so elegant is that i had to include Spyc class to be able to parse the yaml file. In an Drupal 8 port the symfony yaml parser could be used and the Spyc class be removed.

n20’s picture

Improved code:

/**
 * Implements hook_icon_bundles().
 *
 * @todo Extract icons from CSS or JSON file (currently not possible).
 */
function fontawesome_icon_bundles() {
  $bundles[FONTAWESOME_LIBRARY] = array(
    'title' => FONTAWESOME_NAME,
    'provider' => FONTAWESOME_LIBRARY,
    'render' => 'sprite',
    'settings' => array(
      'tag' => 'i',
    ),
    'icons' => _fontawesome_get_icons()
  );
  return $bundles;
}

/**
 * Helper function to get icon ID's.
 */
function _fontawesome_get_icons() {
  if (file_exists(FONTAWESOME_LIBRARY_PATH . '/src/icons.yml')) {
    require_once FONTAWESOME_MODULE_PATH . '/includes/spyc.php';
    $icon_list = Spyc::YAMLLoad(FONTAWESOME_LIBRARY_PATH . '/src/icons.yml');
    $icons = array_map(function ($icons) {return $icons['id'];}, $icon_list['icons']);
    $icons = array_combine($icons, $icons);
  }
}

I don't have the time to create a patch right now but will do in the coming days.

markhalliwell’s picture

Status: Active » Needs work
  1. +++ b/fontawesome.module
    @@ -6,10 +6,12 @@
    -define('FONTAWESOME_DOWNLOAD_URL', 'https://github.com/FortAwesome/Font-Awesome/archive/v4.2.0.zip');
    +define('FONTAWESOME_DOWNLOAD_URL', 'https://github.com/FortAwesome/Font-Awesome/archive/master.zip');
    

    No stable release should ever use the master or dev branch releases. It should always be a specific version release.

  2. It is generally not acceptable to include 3rd-party libraries that are not specific to a project. It can be supported as a separate library or libraries that is loaded or better yet perhaps even backporting D8's implementation: Drupal\Component\Serialization\Yaml.
n20’s picture

agree, if I find the time I will have another look. thanks for the feedback

cmonnow’s picture

StatusFileSize
new17.05 KB

I haven't used this module yet either but for anyone interested here's a text file with the icon array for 4.3.0 (until a yml-parsing method is/will be finalised). There are 41 new additions (and 'gittip' has been updated to 'gratipay').

n20’s picture

Is this text file made by you or did you found it in the fontawesome library?

cmonnow’s picture

Sorry N20. I parsed the YML file with Spyc. It would be nice if they included a JSON file (and YAML for readability) within each official release and not just the src.

For my own projects, I've been testing out Fontello for custom icons or free ones found on-line and it works well to convert SVG after some routine inkscape tweaks (80% work first time). Fontawesome becomes somewhat redundant for my needs.

ovi.indrei’s picture

Title: Another Fontawesome update... » Extract icons automatically
Status: Needs work » Needs review
StatusFileSize
new20.14 KB

Why not parse the CSS file directly? I think this makes more sense, since the CSS file would be always available.

Here's a patch that does exactly this. And it also works with the CDN URL.

ovi.indrei’s picture

The patch I submitted in #8 is slightly malformed (it uses paths relative to the project directory and not to the module folder) and will fail to apply. New patch attached.

chaseontheweb’s picture

Updated #9 to fix a PHP 5.3 incompatibility.

Otherwise, it's working for me using FontAwesome 4.5.x locally.

kyletaylored’s picture

Status: Needs review » Reviewed & tested by the community

#10 works for me! Tested against dev. Would love to see this get checked in.

  • ChaseOnTheWeb authored c0714b2 on 7.x-2.x
    Issue #2427005 by ovi.indrei, N20, ChaseOnTheWeb, cmonnow: Extract icons...
oriol_e9g’s picture

Version: 7.x-2.x-dev » 8.x-1.x-dev

This should be ported to Drupal 8.

oriol_e9g’s picture

Status: Reviewed & tested by the community » Needs review
StatusFileSize
new20.53 KB

  • oriol_e9g authored da66d40 on 8.x-1.x
    Issue #2427005 by ovi.indrei, N20, inders, oriol_e9g: Extract icons...
inders’s picture

Status: Needs review » Fixed
inders’s picture

Status: Fixed » Closed (fixed)