Giter VIP home page Giter VIP logo

iconfont's Introduction

IconFont

CLI to convert CSS StyleSheets for Icon Fonts like FontAwesome to a CommonJS module or Alloy TSS file that exports all unicodes by name.

I use them in native iOS & Android apps build with Titanium.

Example

Install the CLI npm

Install the CLI via NPM like this:

$ [sudo] npm install -g iconfont

CommonJS

Generate it

Just point the CLI to the CSS file:

$ iconfont font-awesome.css

This would create a file named font-awesome.js in the same directory as the CSS file. If you want to write to a different path, simply pass it as the second argument:

$ iconfont font-awesome.css ~/fa.js

Use it

In Titanium, I'd use the module like this:

var icons = require('font-awesome');

var button = Ti.UI.createButton({
	font: {
		fontFamily: 'FontAwesome'
	},
	title: icons.flag
});

In Alloy you can do:

alloy.js

Alloy.Globals.icons = require('font-awesome');

index.tss

"Button": {
	title: Alloy.Globals.icons.flag
}

Alloy TSS

Credits: Jong Eun Lee.

Generate it

Add the -t or --tss flag:

$ iconfont font-awesome.css -t

Or when using the second output-argument, make sure its extension is .tss:

$ iconfont font-awesome.css ~/fa.tss

Use it

Since you cannot import TSS files at the moment, you'd probably copy-paste the contents of the generated file to your app/styles/app.tss file.

index.xml

Use the classes just like in HTML:

<Label class="fa-thumbs-up otherClassName"></Label>

index.tss

And overwrite any property using additional class names:

".otherClassName": {
	font: {
		fontSize: 40
	}
}

Notes

  • For JS:
    • Icon names are camel-cased (arrow-up becomes arrowUp).
    • If all icon names share the same prefix this will be stripped out (icon-flag becomes flag).
  • The CLI expects selectors ending with :before.
  • The CLI expects declerations with a content property and a valid (unicode) string as value.

Changelog

  • 0.3.0: Adds support for generating TSS files
  • 0.2.0:
    • Adds support for non-unicode content
    • Fixes camelCase for some-1 (#3)
  • 0.1.0: Initial release

Issues

Please report issues and features requests in the repo's issue tracker.

License

Distributed under MIT License.

iconfont's People

Contributors

fokkezb avatar hazemkhaled avatar m1ga avatar yomybaby avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  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

iconfont's Issues

[Improvement] Allow add icon + string in tss

Like..

 "#login":{
     top:'5dp',
     width:'95%',
     height:'30dp',
     backgroundColor: '#01b7bb',
     title:Alloy.Globals.icons.signIn + ' Sign in' ,
     color:'white',
     font: {fontFamily:'FontAwesome', fontSize: '14sp'},
  }

This is possible?
Tks!

Issues with css files generated with http://fontello.com/

This is a great resource: http://fontello.com/ Unfortunately, the CSS it generates fails in IconFont.

/usr/local/lib/node_modules/iconfont/bin.js:117
var name = matches2[1];
^
TypeError: Cannot read property '1' of null
at /usr/local/lib/node_modules/iconfont/bin.js:117:26
at Function..each..forEach (/usr/local/lib/node_modules/iconfont/node_modules/underscore/underscore.js:103:9)
at /usr/local/lib/node_modules/iconfont/bin.js:109:7
at Function..each..forEach (/usr/local/lib/node_modules/iconfont/node_modules/underscore/underscore.js:103:9)
at /usr/local/lib/node_modules/iconfont/bin.js:80:5
at fs.js:271:14
at Object.oncomplete (fs.js:107:15)

Transform - to _

Hello,

In CSS icon fonts we can use - separated names, but in JS it's not well interpreted.
Maybe a transform rule can be added to modify the - in _, for compatibility ?

For example, I have in my customised css font the following :

.icon-home-1:before {
  content: "\e0ad";
}
.icon-home-2:before {
  content: "\e220";
}

which is converted to

... {
home-1: "\ue0ad",
home-2: "\e220",
... }

to which the Alloy compiler fail.

PS : thanks for your great works, I use them in my projects and it saved me lot of headache ;)

Doesn't work anymore?

iconfont ./vendor/fontawesome/css/all.css ./app/lib/fontawesome.js

produces

fs.js:36
} = primordials;
    ^

ReferenceError: primordials is not defined
    at fs.js:36:5
    at req_ (/usr/local/lib/node_modules/iconfont/node_modules/natives/index.js:143:24)
    at Object.req [as require] (/usr/local/lib/node_modules/iconfont/node_modules/natives/index.js:55:10)
    at Object.<anonymous> (/usr/local/lib/node_modules/iconfont/node_modules/graceful-fs/fs.js:1:37)
    at Module._compile (internal/modules/cjs/loader.js:999:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10)
    at Module.load (internal/modules/cjs/loader.js:863:32)
    at Function.Module._load (internal/modules/cjs/loader.js:708:14)
    at Module.require (internal/modules/cjs/loader.js:887:19)
    at require (internal/modules/cjs/helpers.js:74:18)```

I'm using node v12.21.0

Alloy compatible?

Can the icons be used in Alloy XML or TSS files? Or are they only available in the controllers?

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.