├── app └── app_delegate.rb ├── Gemfile ├── .gitignore ├── .travis.yml ├── lib ├── moticons.rb └── moticons │ └── icon.rb ├── Rakefile ├── vendor └── Podfile.lock ├── moticons.gemspec ├── LICENSE.txt ├── spec └── icon_spec.rb └── README.md /app/app_delegate.rb: -------------------------------------------------------------------------------- 1 | class AppDelegate 2 | def application(application, didFinishLaunchingWithOptions:launchOptions) 3 | true 4 | end 5 | end 6 | -------------------------------------------------------------------------------- /Gemfile: -------------------------------------------------------------------------------- 1 | source 'https://rubygems.org' 2 | 3 | gem "motion-cocoapods" 4 | gem "motion-facon" 5 | 6 | # Gem dependencies are specified in moticons.gemspec 7 | gemspec 8 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /.bundle/ 2 | /.yardoc 3 | /Gemfile.lock 4 | /_yardoc/ 5 | /coverage/ 6 | /doc/ 7 | /pkg/ 8 | /spec/reports/ 9 | /tmp/ 10 | 11 | build 12 | vendor/Pods 13 | .repl_history 14 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: objective-c 2 | before_install: 3 | - (ruby --version) 4 | - sudo chown -R travis ~/Library/RubyMotion 5 | - sudo mkdir -p ~/Library/RubyMotion/build 6 | - sudo motion update 7 | gemfile: 8 | - Gemfile 9 | script: 10 | - bundle exec rake clean 11 | - bundle install 12 | - bundle exec rake pod:install > /dev/null 13 | - bundle exec rake spec 14 | -------------------------------------------------------------------------------- /lib/moticons.rb: -------------------------------------------------------------------------------- 1 | unless defined?(Motion::Project::Config) 2 | raise "This gem is intended to be used in a RubyMotion project." 3 | end 4 | 5 | require "motion-cocoapods" 6 | 7 | Motion::Project::App.setup do |app| 8 | app.files += Dir.glob(File.join(File.dirname(__FILE__), "moticons", "**", "*.rb")) 9 | app.pods do 10 | pod "FontAwesomeKit", "~> 2.2.1" 11 | end 12 | end 13 | -------------------------------------------------------------------------------- /Rakefile: -------------------------------------------------------------------------------- 1 | $:.unshift("/Library/RubyMotion/lib") 2 | $:.unshift("~/.rubymotion/rubymotion-templates") 3 | 4 | # case ENV.fetch('platform', 'ios') # allow setting from the command line, default to iOS 5 | # when 'ios' then require 'motion/project/template/ios' 6 | # when 'osx' then require 'motion/project/template/osx' 7 | # when 'android' then require 'motion/project/template/android' 8 | # else raise "Unsupported platform #{ENV['platform']}" 9 | # end 10 | 11 | require 'motion/project/template/ios' 12 | require 'motion/project/template/gem/gem_tasks' 13 | require 'bundler' 14 | Bundler.require 15 | 16 | Motion::Project::App.setup do |app| 17 | app.name = 'moticons' 18 | end 19 | -------------------------------------------------------------------------------- /vendor/Podfile.lock: -------------------------------------------------------------------------------- 1 | PODS: 2 | - FontAwesomeKit (2.2.0): 3 | - FontAwesomeKit/Core (= 2.2.0) 4 | - FontAwesomeKit/FontAwesome (= 2.2.0) 5 | - FontAwesomeKit/FoundationIcons (= 2.2.0) 6 | - FontAwesomeKit/IonIcons (= 2.2.0) 7 | - FontAwesomeKit/Zocial (= 2.2.0) 8 | - FontAwesomeKit/Core (2.2.0) 9 | - FontAwesomeKit/FontAwesome (2.2.0): 10 | - FontAwesomeKit/Core 11 | - FontAwesomeKit/FoundationIcons (2.2.0): 12 | - FontAwesomeKit/Core 13 | - FontAwesomeKit/IonIcons (2.2.0): 14 | - FontAwesomeKit/Core 15 | - FontAwesomeKit/Zocial (2.2.0): 16 | - FontAwesomeKit/Core 17 | 18 | DEPENDENCIES: 19 | - FontAwesomeKit (~> 2.2) 20 | 21 | SPEC CHECKSUMS: 22 | FontAwesomeKit: 025fd4dd1017fe4e3f8d47b03e024deedbb33cd4 23 | 24 | COCOAPODS: 0.37.2 25 | -------------------------------------------------------------------------------- /moticons.gemspec: -------------------------------------------------------------------------------- 1 | # coding: utf-8 2 | lib = File.expand_path('../lib', __FILE__) 3 | $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) 4 | 5 | Gem::Specification.new do |spec| 6 | spec.name = "moticons" 7 | spec.version = "1.1.0" 8 | spec.authors = ["Andrew Havens"] 9 | spec.email = ["email@andrewhavens.com"] 10 | 11 | spec.summary = %q{The easiest way to add icons to your RubyMotion app.} 12 | spec.description = %q{The easiest way to add icons to your RubyMotion app.} 13 | spec.homepage = "https://github.com/andrewhavens/moticons" 14 | spec.license = "MIT" 15 | 16 | spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) } 17 | spec.bindir = "exe" 18 | spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) } 19 | spec.require_paths = ["lib"] 20 | 21 | spec.add_runtime_dependency "motion-cocoapods" 22 | 23 | spec.add_development_dependency "bundler", "~> 1.10" 24 | spec.add_development_dependency "rake", "~> 10.0" 25 | spec.add_development_dependency "rspec" 26 | end 27 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Andrew Havens 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /lib/moticons/icon.rb: -------------------------------------------------------------------------------- 1 | module Moticons 2 | class Icon 3 | COLLECTION_CLASSES = { 4 | awesome: :FAKFontAwesome, 5 | foundation: :FAKFoundationIcons, 6 | ion: :FAKIonIcons, 7 | zocial: :FAKZocial, 8 | octicon: :FAKOcticons, 9 | material: :FAKMaterialIcons 10 | } 11 | 12 | attr_reader :collection, :name, :size, :color 13 | 14 | def initialize(collection, name = nil, options = {}) 15 | if name.is_a?(Hash) 16 | options = name; name = nil 17 | end 18 | if name.nil? 19 | collection, name = collection.split('_', 2) 20 | end 21 | @collection = collection.to_sym 22 | @name = camelize(name).to_sym 23 | @size = options.fetch(:size, 42) 24 | @color = options.fetch(:color, UIColor.blackColor) 25 | 26 | create_instance 27 | end 28 | 29 | def to_image 30 | @instance.imageWithSize(CGSizeMake(size, size)) 31 | end 32 | 33 | def to_string 34 | @instance.attributedString 35 | end 36 | 37 | private 38 | 39 | def create_instance 40 | raise "Unknown icon collection name: #{collection}" unless COLLECTION_CLASSES.has_key? collection 41 | 42 | collection_class = Kernel.const_get(COLLECTION_CLASSES[collection]) 43 | 44 | if collection_class.respond_to?("#{name}IconWithSize") 45 | @instance = collection_class.send("#{name}IconWithSize", size) 46 | @instance.addAttribute(NSForegroundColorAttributeName, value: color) 47 | else 48 | raise "#{name} is an invalid icon name for the #{collection} collection" 49 | end 50 | end 51 | 52 | def camelize(string) 53 | string.split('_').inject([]){ |buffer,e| buffer.push(buffer.empty? ? e : e.capitalize) }.join 54 | end 55 | end 56 | end 57 | 58 | def icon_string(collection, name = nil, options = {}) 59 | Moticons::Icon.new(collection, name, options).to_string 60 | end 61 | 62 | def icon_image(collection, name = nil, options = {}) 63 | Moticons::Icon.new(collection, name, options).to_image 64 | end 65 | -------------------------------------------------------------------------------- /spec/icon_spec.rb: -------------------------------------------------------------------------------- 1 | describe Moticons::Icon do 2 | 3 | before do 4 | @icon = Moticons::Icon.new(:ion, :star) 5 | end 6 | 7 | describe '.new' do 8 | it 'creates an instance with the correct attributes' do 9 | @icon.should.be.an.instance_of(Moticons::Icon) 10 | @icon.collection.should == :ion 11 | @icon.name.should == :star 12 | # defaults 13 | @icon.size.should == 42 14 | @icon.color.should == UIColor.blackColor 15 | end 16 | 17 | it 'allows collection name and icon name to be combined' do 18 | @icon = Moticons::Icon.new(:ion_ios_heart_outline) 19 | @icon.collection.should == :ion 20 | @icon.name.should == :iosHeartOutline # converts to camelcase too 21 | end 22 | 23 | it 'allows you to specify a size' do 24 | @icon = Moticons::Icon.new(:ion_ios_heart_outline, size: 123) 25 | @icon.size.should == 123 26 | end 27 | 28 | it 'allows you to specify a color' do 29 | @icon = Moticons::Icon.new(:ion_ios_heart_outline, color: UIColor.redColor) 30 | @icon.color.should == UIColor.redColor 31 | end 32 | end 33 | 34 | describe '#to_string' do 35 | it 'converts the instance to an NSAttributedString' do 36 | string = @icon.to_string 37 | string.should.be.a.kind_of(NSAttributedString) 38 | end 39 | end 40 | 41 | describe '#to_image' do 42 | it 'converts the instance to a UIImage' do 43 | string = @icon.to_image 44 | string.should.be.a.kind_of(UIImage) 45 | end 46 | end 47 | 48 | describe 'icon_string' do 49 | it 'provides a shorthand way of doing the same thing' do 50 | @icon.to_string.should == icon_string(:ion, :star) 51 | end 52 | end 53 | 54 | describe 'icon_image' do 55 | it 'provides a shorthand way of doing the same thing' do 56 | image1 = UIImagePNGRepresentation @icon.to_image 57 | image2 = UIImagePNGRepresentation icon_image(:ion, :star) 58 | image1.should.be.isEqual image2 59 | end 60 | end 61 | end 62 | 63 | # Due to a RubyMotion limitation, we need to define the 64 | # Objective-C methods that will be called dynamically. 65 | class FAKIonIcons 66 | class << self 67 | alias :original_starIconWithSize :starIconWithSize 68 | def starIconWithSize(size) 69 | original_starIconWithSize(size) 70 | end 71 | 72 | alias :original_iosHeartOutlineIconWithSize :iosHeartOutlineIconWithSize 73 | def iosHeartOutlineIconWithSize(size) 74 | original_iosHeartOutlineIconWithSize(size) 75 | end 76 | end 77 | end 78 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # RubyMotion Icons (a.k.a. Moticons) 2 | 3 | Moticons is the easiest way to add icons to your RubyMotion project. It provides a simple interface for creating text-based or image-based icons. 4 | 5 | Moticons is a wrapper around the [FontAwesomeKit CocoaPod](https://github.com/PrideChung/FontAwesomeKit). 6 | 7 | Currently Moticons supports **6** different icon fonts. 8 | 9 | - [FontAwesome 4.7](http://fontawesome.io) Our old friend, contains **675** icons 10 | - [Foundation icons](http://zurb.com/playground/foundation-icon-fonts-3) Contains **283** icons. 11 | - [Zocial](http://zocial.smcllns.com/) Contains **99** social icons. 12 | - [ionicons 2.0.0](http://ionicons.com/) Contains **733** icons, lots of iOS 7 style outlined icons. 13 | - [Octicons 2.4.1](https://octicons.github.com/) Contains **206** icons, built with love by Github. 14 | - [Material 2.0.0](https://google.github.io/material-design-icons/) Contains **743** icons, built by Google for Material design. 15 | 16 | 17 | ## Installation 18 | 19 | Add this line to your application's Gemfile: 20 | 21 | ```ruby 22 | gem 'moticons' 23 | ``` 24 | 25 | And then execute: 26 | 27 | $ bundle && rake pod:install 28 | 29 | ## Usage 30 | 31 | Moticons provides two global helper methods for creating icons: `icon_string` and `icon_image`. 32 | 33 | Both methods require you to specify the name of the icon collection and the name of the font. 34 | 35 | The collection names are: 36 | 37 | * Font Awesome - `:awesome` 38 | * Foundation - `:foundation` 39 | * Zocial - `:zocial` 40 | * Ionicons - `:ion` 41 | * Octicons - `:octicon` 42 | * Material - `:material` 43 | 44 | The icon names are the typical, Ruby snake-cased version of the original name. For example, you would refer to the Font Awesome `cart-arrow-down` icon as `cart_arrow_down`. 45 | 46 | You may specify collection and icon names as separate arguments: 47 | 48 | icon_image(:ion, :star) 49 | 50 | Or you can combine them as a single argument: 51 | 52 | icon_image(:ion_star) 53 | 54 | ### Creating an icon as an `NSAttributedString` 55 | 56 | icon_string(:ion, :star, size: 40, color: UIColor.redColor) 57 | 58 | Specifying size and color are optional. 59 | 60 | ### Creating an icon as a `UIImage` 61 | 62 | icon_image(:ion, :star, size: 40, color: UIColor.redColor) 63 | 64 | Specifying size and color are optional. 65 | 66 | 67 | ## License 68 | 69 | This gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT). Refer to each icon library for their license. 70 | 71 | --------------------------------------------------------------------------------