Giter Site home page Giter Site logo

cocos-creator / gulp-fontello-import-deprecated Goto Github PK

View Code? Open in Web Editor NEW
11.0 9.0 6.0 17 KB

Import svg files to fontello icon font project, use svg filename as glyph name. Also provide task for auto download exported css and font files into desinated folder.

License: MIT License

JavaScript 100.00%

gulp-fontello-import-deprecated's Introduction

gulp-fontello-import

Import svg files to fontello icon font project, use svg filename as glyph name. Also provide task for auto download exported css and font files into desinated folder.

This plugin currently is not utilizing streams for gulp, and used a lot of sync operation. This will be improved later with a pure gulp stream solution.

Recommended Structure

---project folder
   |--css (location can be specified in task options, output icon font css)
   |--fonts (location can be specified in task options, output icon fonts)
   |--svg-src (location can be specified in task options, source svg files)
   |--gulpfile.js (write your task here, can take the example gulpfile as reference)
   |--config.json (fontello config file, this path can be specified in task options)

Install

Add this in your pacakge.json:

"devDependencies": {
    "gulp": "^3.8.10",
    "gulp-fontello-import": "fireball-x/gulp-fontello-import"
}

And run:

npm install

Usage

You should create a config.json file somewhere in your project, with the following content:

{
    "name": "font-name",
    "css_prefix_text": "icon-",
    "css_use_suffix": false,
    "hinting": true,
    "units_per_em": 1000,
    "ascent": 850,
    "glyphs": []
}

Customization on name, prefix and units are available, just edit the file. You can also copy the config.json file included in this plugin as a starting point.

Next, you should have a folder with all your source svg files. You should manage this folder so that your svg icons are identified by their filename. We will use svg file name as the base of css classname of generated icon font.

You can add, replace svg files in that folder. Just make sure the naming of svg files are consistent. NOTE: if you remove a svg icon from the source folder, you have to remove the corresponding entry manually in your config.json file. The importer does not handle icon removal automatically.

Add Fontello Icons

There are icon font sets on http://fontello.com website you can add to your project. To do this, just open fontello website and drag your config.json file to the webpage. And follow instructions on fontello website.

Your imported Svg files will appears in Custom Icons section of the webpage.

You can also edit css class and code for all icon font glyphs in your project.

Update source SVG to config.json

Add the following code to your gulpfile.js:

var gulp = require('gulp');
var importer = require('gulp-fontello-import');

gulp.task('import-svg', function(cb) {
    importer.importSvg({
        config : 'config.json',
        svgsrc : 'svg-src'
    }, cb);
});

The importer api accept an option object that specified path to config.json and svg source folder. Run this task will update the config.json file you specified in the option.

Download generated icon font

Add the following code to your gulpfile.js:

gulp.task('get-icon-font', ['import-svg'], function(cb) {
    importer.getFont({
        host           : 'http://fontello.com',
        config         : 'config.json',
        css : 'css',
        font : 'fonts'
    },cb);
});

gulp.task('get-example', ['import-svg'], function(cb) {
    importer.getFont({
        host : 'http://fontello.com',
        config: 'config.json'
    }, cb);
});

There are two kind of options you can pass into importer.getFont task. The one with css and font will output generated icon font file and css to the path you specified.

The one without those will download the whole fontello project to "icon-example" folder in your project. A demo html file is included in the fontello project so you can check if all icons work correctly before you put them in use in your project.

gulp-fontello-import-deprecated's People

Contributors

idanb11 avatar jareguo avatar nantas avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

gulp-fontello-import-deprecated's Issues

Wrong code for custom icon

I run task to import and i have repeat the code 59392 twice for awesome icon(camera) and custom svg icon.
Of course, in the final file, instead of the icon fontawesome, I received the second my svg icon.

I watched the source files and how you get or calculated the number 59392?

Adding new icon breaks the font

When I add new svg file to svg-src and run get-icon-font task the font is broken. It happens because "code" property added for the new glyph in config json is not unique.

Any way to customize the CSS?

I'd like a slightly different CSS output in *-icons.css (specifically change text-decoration: inherit to text-decoration: none). What would be the easiest way to accomplish this?

For now I've settled with simply overriding it with my own CSS, but I'd like to change one more thing and that is to add the ability to place an icon after an element's contents by giving it a class of "icon--after" and changing the generated CSS from:

.icon-search:before { content: '\e800'; }

To:

.icon-search:before { content: '\e800'; }
.icon-search.icon--after:before { content: normal; }
.icon-search.icon--after:after { content: '\e800'; }

And that would require actually modifying the generated CSS rather than overriding (which would be very tedious every time a new icon is added)

Edit: Now that I think about it I guess all you do is actually download the CSS generated by Fontello? In which case it can't be changed within the Gulp plugin... Perhaps I can write my own Gulp plugin on top of it instead.

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.