motion-now 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ .DS_Store
2
+ build/
3
+ .repl_history
4
+ .dat*
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ source :rubygems
2
+
3
+ gem 'motion-now', :path => '.'
4
+
5
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,26 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ motion-now (0.0.1)
5
+ rake
6
+
7
+ GEM
8
+ remote: http://rubygems.org/
9
+ specs:
10
+ diff-lcs (1.1.3)
11
+ rake (0.9.2.2)
12
+ rspec (2.11.0)
13
+ rspec-core (~> 2.11.0)
14
+ rspec-expectations (~> 2.11.0)
15
+ rspec-mocks (~> 2.11.0)
16
+ rspec-core (2.11.1)
17
+ rspec-expectations (2.11.3)
18
+ diff-lcs (~> 1.1.3)
19
+ rspec-mocks (2.11.3)
20
+
21
+ PLATFORMS
22
+ ruby
23
+
24
+ DEPENDENCIES
25
+ motion-now!
26
+ rspec
data/README.md ADDED
@@ -0,0 +1,84 @@
1
+
2
+ # now
3
+
4
+ motion-now is a DSL for working with UIViews in your rubymotion application. Now borrows all of it's good ideas from jQuery.
5
+
6
+
7
+ ## Installation
8
+
9
+ to install now, run:
10
+
11
+ gem install motion-now
12
+
13
+ add the following line to your rubymotion Rakefile
14
+
15
+ require 'motion-now'
16
+
17
+
18
+ ## Examples
19
+
20
+
21
+ ### Creating views
22
+
23
+ Creating a button that says 'Hi!'
24
+
25
+
26
+ button = Now.button "Say Hi!" do |button|
27
+ button.width 100
28
+ button.height 50
29
+ end.click do
30
+ Now.alert "Hi!"
31
+ end
32
+
33
+ self.view.now.add button
34
+
35
+
36
+ ### Moving Views Around
37
+
38
+
39
+ circle = Now.view do |view|
40
+ view.size "10x10"
41
+ view.border_radius 10
42
+ view.background_color "#f4f4f4"
43
+ end
44
+
45
+ # To center a view in its parent view
46
+ circle.center
47
+
48
+ # To align in the top-right corner of parent view
49
+ # Same as circle.top(0).right(0)
50
+ circle.top.right
51
+
52
+
53
+ ### Sizing Views
54
+
55
+ square = Now.view
56
+
57
+ # make the height 10px
58
+ square.height 10
59
+
60
+ # every square is the same size on all sides
61
+ square.width 10
62
+
63
+ # there's an easier way
64
+ square.size "10x10"
65
+ # or ..
66
+ square.size [10, 10]
67
+
68
+ ### Properties
69
+
70
+ ball = Now.image "ball.png"
71
+
72
+ # to hide ball:
73
+ ball.hide
74
+
75
+ # let's bring it back
76
+ ball.show
77
+
78
+ # let's ghostify it
79
+ ball.alpha(10)
80
+ .shadow(1, 1, 10, "blue")
81
+ .add_animation(:giggle)
82
+
83
+
84
+
data/Rakefile ADDED
@@ -0,0 +1,11 @@
1
+ $:.unshift('/Library/RubyMotion/lib')
2
+ require 'motion/project'
3
+ require 'bundler'
4
+ Bundler.require
5
+
6
+
7
+ Motion::Project::App.setup do |app|
8
+ # Use `rake config' to see complete project settings.
9
+ app.name = 'now'
10
+ app.identifier = 'com.iosam.now'
11
+ end
@@ -0,0 +1,11 @@
1
+ class AppDelegate
2
+
3
+ def application(application, didFinishLaunchingWithOptions:launchOptions)
4
+ return true if RUBYMOTION_ENV == 'test'
5
+ @window = UIWindow.alloc.initWithFrame(UIScreen.mainScreen.bounds)
6
+ @window.rootViewController = SampleViewController.alloc.init
7
+ @window.makeKeyAndVisible
8
+ true
9
+ end
10
+
11
+ end
@@ -0,0 +1,28 @@
1
+ class SampleViewController < UIViewController
2
+
3
+ def viewWillAppear(animated)
4
+
5
+ self.view.backgroundColor = UIColor.whiteColor
6
+
7
+ button = Now.button("Test") do |button|
8
+ button.width 100
9
+ button.height 50
10
+ end.click do
11
+ Now.alert "Hi"
12
+ end
13
+
14
+ self.view.now.add button
15
+
16
+
17
+ @x = Now.drawing do
18
+ set_fill_color UIColor.redColor
19
+ fill_rect CGRectMake 0, 0, 10, 10
20
+ end
21
+
22
+ @x.size("10x10")
23
+
24
+ self.view.now.add @x
25
+
26
+ end
27
+
28
+ end
data/lib/motion-now.rb ADDED
@@ -0,0 +1,15 @@
1
+ unless defined?(Motion::Project::Config)
2
+ raise "This file must be required within a RubyMotion project Rakefile."
3
+ end
4
+
5
+ Motion::Project::App.setup do |app|
6
+
7
+ now_files = Dir.glob(File.join(File.dirname(__FILE__), 'motion-now/now.rb')) +
8
+ Dir.glob(File.join(File.dirname(__FILE__), 'motion-now/additions/*.rb')) +
9
+ Dir.glob(File.join(File.dirname(__FILE__), 'motion-now/class_methods/*.rb')) +
10
+ Dir.glob(File.join(File.dirname(__FILE__), 'motion-now/behaviors/*.rb'))
11
+
12
+ now_files.each do |file|
13
+ app.files.unshift(file)
14
+ end
15
+ end
@@ -0,0 +1,8 @@
1
+ class UIView
2
+
3
+ def now
4
+ @now ||= Now.new(self)
5
+ end
6
+
7
+
8
+ end
@@ -0,0 +1,16 @@
1
+ module MotionNow
2
+ module Now
3
+ module Controllable
4
+
5
+ def click(options = {}, &block)
6
+ @click_handlers ||= []
7
+ @click_handlers << block
8
+ @view.addTarget block, action: 'call', forControlEvents:UIControlEventTouchUpInside
9
+ self
10
+ end
11
+
12
+ end
13
+ end
14
+ end
15
+
16
+ Now.send "include", MotionNow::Now::Controllable
@@ -0,0 +1,48 @@
1
+ module MotionNow
2
+ module Now
3
+ module Positioning
4
+
5
+ def top(points = 0)
6
+ do_frame {|f| f.origin.y = points}
7
+ end
8
+
9
+ def left(points = 0)
10
+ do_frame {|f| f.origin.x = points}
11
+ end
12
+
13
+ def bottom(points = 0)
14
+ super_height = @view.superview.bounds.size.height
15
+ do_frame do |frame|
16
+ frame.origin.y = (super_height - frame.size.height) - points
17
+ end
18
+ end
19
+
20
+ def right(points = 0)
21
+ super_width = @view.superview.bounds.size.height
22
+ do_frame do |frame|
23
+ frame.origin.x = (super_width - frame.size.width) - points
24
+ end
25
+ end
26
+
27
+ def center_horizontal
28
+ do_frame do |frame|
29
+ frame.origin.x = (parent_frame.size.width - frame.size.width) / 2
30
+ end
31
+ end
32
+
33
+ def center_vertical
34
+ do_frame do |frame|
35
+ frame.origin.y = (parent_frame.size.height - frame.size.height) / 2
36
+ end
37
+ end
38
+
39
+ def center
40
+ center_horizontal
41
+ center_vertical
42
+ end
43
+
44
+ end
45
+ end
46
+ end
47
+
48
+ Now.send "include", MotionNow::Now::Positioning
@@ -0,0 +1,25 @@
1
+ module MotionNow
2
+ module Now
3
+ module Sizing
4
+
5
+
6
+ def height(points)
7
+ do_frame {|f| f.size.height = points}
8
+ end
9
+
10
+ def width(points)
11
+ do_frame {|f| f.size.width = points}
12
+ end
13
+
14
+ def size(arg)
15
+ if arg.is_a? String
16
+ arg = arg.split("x")
17
+ end
18
+ do_frame {|f| f.size = arg}
19
+ end
20
+
21
+ end
22
+ end
23
+ end
24
+
25
+ Now.send "include", MotionNow::Now::Sizing
@@ -0,0 +1,55 @@
1
+ module MotionNow
2
+ module Now
3
+ module ClassMethods
4
+ module ViewCreation
5
+
6
+ def label(title, &block)
7
+ uilabel = UILabel.alloc.init
8
+ uilabel.text = title
9
+ yield uilabel.now if block_given?
10
+ uilabel.now
11
+ end
12
+
13
+ def button(title, &block)
14
+ button = UIButton.buttonWithType UIButtonTypeRoundedRect
15
+ button.setTitle(title, forState:UIControlStateNormal)
16
+ yield button.now if block_given?
17
+ button.now
18
+ end
19
+
20
+ def image(image_name, &block)
21
+ image_view = UIImageView.alloc.initWithImage UIImage.imageNamed(image_name)
22
+ yield image_view.now if block_given?
23
+ image_view.now
24
+ end
25
+
26
+ def alert(title)
27
+ alert = UIAlertView.alloc.initWithTitle(title,
28
+ message: nil,
29
+ delegate: nil,
30
+ cancelButtonTitle: "Ok",
31
+ otherButtonTitles: nil,
32
+ )
33
+ alert.show
34
+ end
35
+
36
+
37
+ # Initialize a uiview subclass with a drawing
38
+ def drawing(&block)
39
+ view = UIView.alloc.init
40
+ view.instance_eval do
41
+ def drawRect(frame)
42
+ context_draw do
43
+ self.call frame
44
+ end
45
+ end
46
+ end
47
+ view.now
48
+ end
49
+
50
+ end
51
+ end
52
+ end
53
+ end
54
+
55
+ Now.send "extend", MotionNow::Now::ClassMethods::ViewCreation
@@ -0,0 +1,35 @@
1
+ class Now
2
+
3
+ attr_reader :view
4
+
5
+ def initialize(view)
6
+ @view = view
7
+ end
8
+
9
+ def do_frame(&block)
10
+ frame = @view.frame
11
+ yield frame
12
+ @view.frame = frame
13
+ self
14
+ end
15
+
16
+ def add(view_or_now)
17
+ view = view_or_now.is_a?(Now) ? view_or_now.view : view_or_now
18
+ @view.addSubview(view)
19
+ end
20
+
21
+ def parent_frame
22
+ @view.superview.frame
23
+ end
24
+
25
+ def hide
26
+ @view.visible = false
27
+ self
28
+ end
29
+
30
+ def show
31
+ @view.visible = true
32
+ self
33
+ end
34
+
35
+ end
@@ -0,0 +1,82 @@
1
+ class UIView
2
+
3
+ def context_draw(&block)
4
+ CoreGraphicsDrawing.new(&block)
5
+ end
6
+
7
+ end
8
+
9
+
10
+
11
+ class CoreGraphicsDrawing
12
+
13
+ def initialize(&block)
14
+ @ctx = UIGraphicsGetCurrentContext()
15
+ yield self
16
+ end
17
+
18
+ def context
19
+ @ctx
20
+ end
21
+
22
+ def add_arc(x, y, radius, start_angle, end_angle, clockwise = 1)
23
+ CGContextAddArc(@ctx, x, y, radius, start_angle, end_angle, clockwise)
24
+ end
25
+
26
+ def set_fill_color(uicolor)
27
+ CGContextSetFillColorWithColor(@ctx, uicolor.CGColor);
28
+ end
29
+
30
+ def set_stroke_color(uicolor)
31
+ CGContextSetStrokeColorWithColor(@ctx, uicolor.CGColor);
32
+ end
33
+
34
+ def move_to_point(x, y)
35
+ CGContextMoveToPoint(@ctx, x.to_f, y.to_f)
36
+ end
37
+
38
+ def add_line_to_point(x, y)
39
+ CGContextAddLineToPoint(@ctx, x.to_f, y.to_f)
40
+ end
41
+
42
+ def add_elipse_in_rect(rect)
43
+ CGContextAddEllipseInRect(@ctx, rect)
44
+ end
45
+
46
+ def begin_path
47
+ CGContextBeginPath(@ctx)
48
+ end
49
+
50
+ def fill_path
51
+ CGContextFillPath(@ctx)
52
+ end
53
+
54
+ def stroke_path
55
+ CGContextStrokePath(@ctx)
56
+ end
57
+
58
+ def set_line_width(width)
59
+ CGContextSetLineWidth(@ctx, width.to_f)
60
+ end
61
+
62
+ def set_alpha(alpha = 0.0)
63
+ CGContextSetAlpha(@ctx, alpha.to_f)
64
+ end
65
+
66
+ def stroke_rect(rect)
67
+ CGContextStrokeRect(@ctx, rect)
68
+ end
69
+
70
+ def fill_rect(rect)
71
+ CGContextFillRect(@ctx, rect)
72
+ end
73
+
74
+ def clear_rect(rect)
75
+ CGContextClearRect(@ctx, rect)
76
+ end
77
+
78
+ def add_rect(rect)
79
+ CGContextAddRect(@ctx, rect)
80
+ end
81
+
82
+ end
@@ -0,0 +1,3 @@
1
+ module MotionNow
2
+ VERSION = '0.0.1'
3
+ end
@@ -0,0 +1,25 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/motion-now/version.rb', __FILE__)
3
+
4
+
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = 'motion-now'
8
+ gem.version = MotionNow::VERSION
9
+
10
+ gem.authors = ['Sam Murphy']
11
+
12
+ gem.description = %Q(
13
+
14
+ ).gsub("\t", '')
15
+
16
+ gem.summary = 'A DSL for UIViews'
17
+
18
+ gem.files = `git ls-files`.split($\)
19
+ gem.require_paths = ['lib']
20
+ gem.test_files = gem.files.grep(%r{^spec/})
21
+
22
+ gem.add_dependency 'rake'
23
+ gem.add_development_dependency 'rspec'
24
+
25
+ end
data/spec/now_spec.rb ADDED
@@ -0,0 +1,9 @@
1
+ describe "Application 'now'" do
2
+
3
+ before do
4
+ end
5
+
6
+ it "should" do
7
+ end
8
+
9
+ end
metadata ADDED
@@ -0,0 +1,95 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: motion-now
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Sam Murphy
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-12-23 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rake
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: rspec
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ description: ! "\n \n "
47
+ email:
48
+ executables: []
49
+ extensions: []
50
+ extra_rdoc_files: []
51
+ files:
52
+ - .gitignore
53
+ - Gemfile
54
+ - Gemfile.lock
55
+ - README.md
56
+ - Rakefile
57
+ - app/app_delegate.rb
58
+ - app/sample_view_controller.rb
59
+ - lib/motion-now.rb
60
+ - lib/motion-now/additions/uiview.rb
61
+ - lib/motion-now/behaviors/controllable.rb
62
+ - lib/motion-now/behaviors/positioning.rb
63
+ - lib/motion-now/behaviors/sizing.rb
64
+ - lib/motion-now/class_methods/view_creation.rb
65
+ - lib/motion-now/now.rb
66
+ - lib/motion-now/now_drawing.rb
67
+ - lib/motion-now/version.rb
68
+ - motion-now.gemspec
69
+ - spec/now_spec.rb
70
+ homepage:
71
+ licenses: []
72
+ post_install_message:
73
+ rdoc_options: []
74
+ require_paths:
75
+ - lib
76
+ required_ruby_version: !ruby/object:Gem::Requirement
77
+ none: false
78
+ requirements:
79
+ - - ! '>='
80
+ - !ruby/object:Gem::Version
81
+ version: '0'
82
+ required_rubygems_version: !ruby/object:Gem::Requirement
83
+ none: false
84
+ requirements:
85
+ - - ! '>='
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ requirements: []
89
+ rubyforge_project:
90
+ rubygems_version: 1.8.21
91
+ signing_key:
92
+ specification_version: 3
93
+ summary: A DSL for UIViews
94
+ test_files:
95
+ - spec/now_spec.rb