motion-awesome 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/.gitignore +3 -0
- data/Gemfile +15 -0
- data/Gemfile.lock +62 -0
- data/README.md +126 -0
- data/Rakefile +29 -0
- data/app/app_delegate.rb +59 -0
- data/app/controllers/a.rb +12 -0
- data/app/controllers/b.rb +14 -0
- data/app/controllers/c.rb +14 -0
- data/app/controllers/d.rb +27 -0
- data/app/controllers/e.rb +27 -0
- data/app/controllers/z.rb +57 -0
- data/lib/assets/fontawesome-webfont.ttf +0 -0
- data/lib/assets/fontawesome.plist +504 -0
- data/lib/motion-awesome.rb +13 -0
- data/lib/motion-awesome/awesome.rb +70 -0
- data/lib/motion-awesome/core_ext/ui_label.rb +21 -0
- data/lib/motion-awesome/version.rb +3 -0
- data/lib/utils/generator.rb +30 -0
- data/motion-awesome.gemspec +21 -0
- data/resources/button-bg.png +0 -0
- data/resources/button-bg@2x.png +0 -0
- data/resources/vermin_vibes_out_of_ink.ttf +0 -0
- data/spec/motion-awesome/motion_awesome_spec.rb +93 -0
- metadata +124 -0
@@ -0,0 +1,13 @@
|
|
1
|
+
unless defined?(Motion::Project::Config)
|
2
|
+
raise "motion-awesome must be required within a RubyMotion project Rakefile."
|
3
|
+
end
|
4
|
+
|
5
|
+
LIB_DIR = File.dirname(__FILE__)
|
6
|
+
Motion::Project::App.setup do |app|
|
7
|
+
Dir.glob(File.join( LIB_DIR, %w(motion-awesome ** *.rb))).each do |file|
|
8
|
+
app.files.unshift(file)
|
9
|
+
end
|
10
|
+
FileUtils.cp( File.join( LIB_DIR, %w(assets fontawesome-webfont.ttf) ), './resources/' )
|
11
|
+
FileUtils.cp( File.join( LIB_DIR, %w(assets fontawesome.plist) ), './resources/' )
|
12
|
+
app.fonts << "fontawesome-webfont.ttf"
|
13
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
module MotionAwesome
|
2
|
+
module_function
|
3
|
+
|
4
|
+
class InvalidAwesomeIconError < RuntimeError; end
|
5
|
+
|
6
|
+
def button( icon, options={}, &block )
|
7
|
+
opts = parse_options( icon, options )
|
8
|
+
comp = UIButton.buttonWithType( map_types( opts.type? ? opts.type : nil ) )
|
9
|
+
comp.setAttributedTitle( attributed_text(opts), forState: UIControlStateNormal )
|
10
|
+
yield comp if block_given?
|
11
|
+
comp
|
12
|
+
end
|
13
|
+
|
14
|
+
def label( icon, options={}, &block )
|
15
|
+
opts = parse_options( icon, options )
|
16
|
+
comp = UILabel.alloc.initWithFrame( [[0,0],[opts[:size],opts[:size]]] )
|
17
|
+
comp.setAttributedText( attributed_text(opts) )
|
18
|
+
comp.awesome_color = opts.color if opts.color?
|
19
|
+
yield comp if block_given?
|
20
|
+
comp
|
21
|
+
end
|
22
|
+
|
23
|
+
def font( size )
|
24
|
+
UIFont.fontWithName( 'FontAwesome', size:size )
|
25
|
+
end
|
26
|
+
|
27
|
+
def parse_options( icon, opts )
|
28
|
+
options = MotionMap::Map[opts.merge( icon: xform_icon(icon) )]
|
29
|
+
options[:size] = UIFont.systemFontSize unless options[:size]
|
30
|
+
options
|
31
|
+
end
|
32
|
+
|
33
|
+
def xform_icon( icon )
|
34
|
+
icon.to_s.gsub( /_/, '-')
|
35
|
+
end
|
36
|
+
|
37
|
+
def attributed_text( opts )
|
38
|
+
awesome_attrs = MotionMap::Map[NSFontAttributeName, font(opts[:size])]
|
39
|
+
awesome_attrs[NSForegroundColorAttributeName] = opts.color if opts.color?
|
40
|
+
text = hex_for_icon( opts.icon )
|
41
|
+
text += " " + opts.text if opts.text?
|
42
|
+
range = opts.text? ? (0..1) : (0..0)
|
43
|
+
NSMutableAttributedString.alloc.initWithString( text, attributes: nil ).tap do |attrs|
|
44
|
+
attrs.setAttributes( awesome_attrs, range:range )
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def hex_for_icon( icon )
|
49
|
+
index = plist["icon-#{icon}"]
|
50
|
+
raise InvalidAwesomeIconError, "Unable to find icon representation for `#{icon.inspect}" unless index
|
51
|
+
index.hex.chr(Encoding::UTF_8)
|
52
|
+
end
|
53
|
+
|
54
|
+
def map_types( type )
|
55
|
+
button_types.get(type) {UIButtonTypeRoundedRect}
|
56
|
+
end
|
57
|
+
|
58
|
+
def plist
|
59
|
+
@plist ||= begin
|
60
|
+
NSMutableDictionary.dictionaryWithContentsOfFile(
|
61
|
+
NSBundle.mainBundle.resourcePath.stringByAppendingPathComponent( "fontawesome.plist" )
|
62
|
+
)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
def button_types
|
67
|
+
@button_types ||=
|
68
|
+
MotionMap::Map[custom: UIButtonTypeCustom, rounded: UIButtonTypeRoundedRect]
|
69
|
+
end
|
70
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
class UILabel
|
2
|
+
attr_accessor :awesome_color
|
3
|
+
|
4
|
+
def awesome?
|
5
|
+
(self.text =~ /\A\W/) != nil
|
6
|
+
end
|
7
|
+
|
8
|
+
def font=( font )
|
9
|
+
super
|
10
|
+
return unless awesome?
|
11
|
+
|
12
|
+
attr_text = self.attributedText
|
13
|
+
if attr_text.length > 1
|
14
|
+
attr_text.addAttribute( NSFontAttributeName, value: font, range:(2..attr_text.length-1) )
|
15
|
+
end
|
16
|
+
attr_text.addAttribute( NSFontAttributeName,
|
17
|
+
value:MotionAwesome.font(font.pointSize),
|
18
|
+
range:(0...1) )
|
19
|
+
attr_text.addAttribute( NSForegroundColorAttributeName, value:awesome_color, range:(0...1) ) if awesome_color
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'css_parser'
|
2
|
+
include CssParser
|
3
|
+
require 'plist'
|
4
|
+
|
5
|
+
module MotionAwesome
|
6
|
+
class Generator
|
7
|
+
def self.plist; File.join( File.dirname( __FILE__), %w(.. .. resources fontawesome.plist) ) end
|
8
|
+
|
9
|
+
def self.gen_plist( css )
|
10
|
+
parser = CssParser::Parser.new
|
11
|
+
parser.load_file!( css )
|
12
|
+
fonts = {}
|
13
|
+
parser.each_selector do |selector, declarations, specificity|
|
14
|
+
next if selector !~ /\A.icon/
|
15
|
+
name = selector[/\.(.*)\:before/,1]
|
16
|
+
next unless name and name != 'icon-large'
|
17
|
+
hex_val = "0x#{declarations[/(f.*)"/, 1]}"
|
18
|
+
puts "#{name} : #{hex_val.inspect}"
|
19
|
+
fonts[name] = hex_val
|
20
|
+
end
|
21
|
+
write( fonts )
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.write( fonts )
|
25
|
+
File.open( plist, 'w' ) do |f|
|
26
|
+
f << fonts.to_plist
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/motion-awesome/version.rb', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.name = 'motion-awesome'
|
6
|
+
gem.version = MotionAwesome::VERSION
|
7
|
+
gem.authors = ['Fernand Galiana']
|
8
|
+
gem.email = ['fernand.galiana@gmail.com']
|
9
|
+
gem.summary = %{Port of the most excellent FontAwesome lib to IOS}
|
10
|
+
gem.description = %{Blah Blah attributions}
|
11
|
+
gem.homepage = 'http://derailed.github.io/motion-awesome'
|
12
|
+
gem.files = `git ls-files`.split($\)
|
13
|
+
gem.test_files = gem.files.grep(%r{^spec/})
|
14
|
+
gem.require_paths = ['lib']
|
15
|
+
|
16
|
+
gem.add_development_dependency 'rspec'
|
17
|
+
gem.add_development_dependency 'plist'
|
18
|
+
gem.add_development_dependency 'css_parser'
|
19
|
+
|
20
|
+
gem.add_dependency 'motion-map'
|
21
|
+
end
|
Binary file
|
Binary file
|
Binary file
|
@@ -0,0 +1,93 @@
|
|
1
|
+
describe MotionAwesome do
|
2
|
+
|
3
|
+
describe "#label" do
|
4
|
+
it "builds a simple label correctly" do
|
5
|
+
comp = MotionAwesome.label( :flag ) do |label|
|
6
|
+
label.class.should == UILabel
|
7
|
+
end
|
8
|
+
comp.text.should == "\xEF\x80\xA4"
|
9
|
+
end
|
10
|
+
|
11
|
+
it "builds a text label correctly" do
|
12
|
+
comp = MotionAwesome.label( :flag, text:%q(Bozo!) ) do |label|
|
13
|
+
label.class.should == UILabel
|
14
|
+
end
|
15
|
+
comp.text.should == "\xEF\x80\xA4 Bozo!"
|
16
|
+
end
|
17
|
+
|
18
|
+
it "builds a text label with all the fixins correctly" do
|
19
|
+
comp = MotionAwesome.label( :flag, text:%q(Bozo!), color: UIColor.redColor ) do |label|
|
20
|
+
label.color = UIColor.greenColor
|
21
|
+
label.font = UIFont.fontWithName( 'copperplate', size:40 )
|
22
|
+
label.class.should == UILabel
|
23
|
+
end
|
24
|
+
comp.text.should == "\xEF\x80\xA4 Bozo!"
|
25
|
+
attrs = comp.attributedText
|
26
|
+
attrs.string.should == "\xEF\x80\xA4 Bozo!"
|
27
|
+
|
28
|
+
attrs.enumerateAttributesInRange( (0...1),
|
29
|
+
options:NSAttributedStringEnumerationReverse,
|
30
|
+
usingBlock:->(attrs, range, stop) {
|
31
|
+
attrs['NSColor'].should == UIColor.redColor
|
32
|
+
attrs['NSFont'].familyName.should == 'FontAwesome'
|
33
|
+
}
|
34
|
+
)
|
35
|
+
attrs.enumerateAttributesInRange( (2..attrs.string.size-1),
|
36
|
+
options:NSAttributedStringEnumerationReverse,
|
37
|
+
usingBlock:->(attrs, range, stop) {
|
38
|
+
attrs['NSColor'].should == UIColor.greenColor
|
39
|
+
attrs['NSFont'].familyName.should == 'Copperplate'
|
40
|
+
attrs['NSFont'].pointSize.should == 40
|
41
|
+
}
|
42
|
+
)
|
43
|
+
end
|
44
|
+
|
45
|
+
it 'raises an error if no icon is found' do
|
46
|
+
lambda {
|
47
|
+
MotionAwesome.label( :bozo )
|
48
|
+
}.should.raise(MotionAwesome::InvalidAwesomeIconError)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
describe '#button' do
|
53
|
+
it 'build a round button correctly' do
|
54
|
+
comp = MotionAwesome.button( :flag, text:%q(Hello World!) ) do |button|
|
55
|
+
button.class.should == UIRoundedRectButton
|
56
|
+
end
|
57
|
+
comp.attributedTitleForState(UIControlStateNormal).string.should == "\xEF\x80\xA4 Hello World!"
|
58
|
+
end
|
59
|
+
|
60
|
+
it 'build a cust button correctly' do
|
61
|
+
comp = MotionAwesome.button( :flag, type: :custom, text:%q(Bumblebee Tuna) ) do |button|
|
62
|
+
button.class.should == UIButton
|
63
|
+
end
|
64
|
+
comp.attributedTitleForState(UIControlStateNormal).string.should == "\xEF\x80\xA4 Bumblebee Tuna"
|
65
|
+
end
|
66
|
+
|
67
|
+
it "builds a button with all the fixins correctly" do
|
68
|
+
comp = MotionAwesome.button( :flag, text:%q(Bozo!), color: UIColor.redColor ) do |button|
|
69
|
+
button.titleLabel.textColor = UIColor.greenColor
|
70
|
+
button.titleLabel.font = UIFont.fontWithName( "Vermin Vibes Out Of Ink", size:55 )
|
71
|
+
end
|
72
|
+
|
73
|
+
attrs = comp.attributedTitleForState(UIControlStateNormal)
|
74
|
+
attrs.string.should == "\xEF\x80\xA4 Bozo!"
|
75
|
+
|
76
|
+
attrs.enumerateAttributesInRange( (0...1),
|
77
|
+
options:NSAttributedStringEnumerationReverse,
|
78
|
+
usingBlock:->(attrs, range, stop) {
|
79
|
+
attrs['NSColor'].should == UIColor.redColor
|
80
|
+
attrs['NSFont'].familyName.should == 'FontAwesome'
|
81
|
+
}
|
82
|
+
)
|
83
|
+
# attrs.enumerateAttributesInRange( (2..attrs.string.size-1),
|
84
|
+
# options:NSAttributedStringEnumerationReverse,
|
85
|
+
# usingBlock:->(attrs, range, stop) {
|
86
|
+
# # attrs['NSColor'].should == UIColor.greenColor
|
87
|
+
# # attrs['NSFont'].familyName.should == 'Copperplate'
|
88
|
+
# # attrs['NSFont'].pointSize.should == 40
|
89
|
+
# }
|
90
|
+
# )
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
metadata
ADDED
@@ -0,0 +1,124 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: motion-awesome
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.3
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Fernand Galiana
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-04-20 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
prerelease: false
|
15
|
+
version_requirements: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ! '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
name: rspec
|
21
|
+
requirement: !ruby/object:Gem::Requirement
|
22
|
+
requirements:
|
23
|
+
- - ! '>='
|
24
|
+
- !ruby/object:Gem::Version
|
25
|
+
version: '0'
|
26
|
+
type: :development
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
prerelease: false
|
29
|
+
version_requirements: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ! '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
name: plist
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - ! '>='
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '0'
|
40
|
+
type: :development
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
prerelease: false
|
43
|
+
version_requirements: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ! '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
name: css_parser
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :development
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
prerelease: false
|
57
|
+
version_requirements: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
name: motion-map
|
63
|
+
requirement: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - ! '>='
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '0'
|
68
|
+
type: :runtime
|
69
|
+
description: Blah Blah attributions
|
70
|
+
email:
|
71
|
+
- fernand.galiana@gmail.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- .gitignore
|
77
|
+
- Gemfile
|
78
|
+
- Gemfile.lock
|
79
|
+
- README.md
|
80
|
+
- Rakefile
|
81
|
+
- app/app_delegate.rb
|
82
|
+
- app/controllers/a.rb
|
83
|
+
- app/controllers/b.rb
|
84
|
+
- app/controllers/c.rb
|
85
|
+
- app/controllers/d.rb
|
86
|
+
- app/controllers/e.rb
|
87
|
+
- app/controllers/z.rb
|
88
|
+
- lib/assets/fontawesome-webfont.ttf
|
89
|
+
- lib/assets/fontawesome.plist
|
90
|
+
- lib/motion-awesome.rb
|
91
|
+
- lib/motion-awesome/awesome.rb
|
92
|
+
- lib/motion-awesome/core_ext/ui_label.rb
|
93
|
+
- lib/motion-awesome/version.rb
|
94
|
+
- lib/utils/generator.rb
|
95
|
+
- motion-awesome.gemspec
|
96
|
+
- resources/button-bg.png
|
97
|
+
- resources/button-bg@2x.png
|
98
|
+
- resources/vermin_vibes_out_of_ink.ttf
|
99
|
+
- spec/motion-awesome/motion_awesome_spec.rb
|
100
|
+
homepage: http://derailed.github.io/motion-awesome
|
101
|
+
licenses: []
|
102
|
+
metadata: {}
|
103
|
+
post_install_message:
|
104
|
+
rdoc_options: []
|
105
|
+
require_paths:
|
106
|
+
- lib
|
107
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
108
|
+
requirements:
|
109
|
+
- - ! '>='
|
110
|
+
- !ruby/object:Gem::Version
|
111
|
+
version: '0'
|
112
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
113
|
+
requirements:
|
114
|
+
- - ! '>='
|
115
|
+
- !ruby/object:Gem::Version
|
116
|
+
version: '0'
|
117
|
+
requirements: []
|
118
|
+
rubyforge_project:
|
119
|
+
rubygems_version: 2.0.3
|
120
|
+
signing_key:
|
121
|
+
specification_version: 4
|
122
|
+
summary: Port of the most excellent FontAwesome lib to IOS
|
123
|
+
test_files:
|
124
|
+
- spec/motion-awesome/motion_awesome_spec.rb
|