Merge branch 'master' into edge

This commit is contained in:
Jamon Holmgren
2013-09-19 15:36:48 -07:00
11 changed files with 99 additions and 31 deletions

View File

@@ -1,7 +1,7 @@
PATH
remote: .
specs:
ProMotion (1.0.3)
ProMotion (1.0.4)
GEM
remote: https://rubygems.org/

View File

@@ -1,12 +1,15 @@
# ProMotion [![Build Status](https://travis-ci.org/clearsightstudio/ProMotion.png)](https://travis-ci.org/clearsightstudio/ProMotion) [![Code Climate](https://codeclimate.com/github/clearsightstudio/ProMotion.png)](https://codeclimate.com/github/clearsightstudio/ProMotion)
## A new way to easily build RubyMotion apps.
## iPhone Apps, Ruby-style
ProMotion is a RubyMotion gem that makes iOS development more like Ruby and less like Objective-C.
It introduces a clean, Ruby-style syntax for building screens that is easy to learn and remember and
abstracts a ton of boilerplate UIViewController, UINavigationController, and other iOS code into a
simple, Ruby-like DSL.
Watch the [September Motion Meetup](http://www.youtube.com/watch?v=rf7h-3AiMRQ) where Gant Laborde
interviews Jamon Holmgren about ProMotion!
```ruby
class AppDelegate < PM::Delegate
def on_load(app, options)
@@ -16,7 +19,7 @@ end
class RootScreen < PM::Screen
title "Root Screen"
def push_new_screen
open NewScreen
end
@@ -24,7 +27,7 @@ end
class NewScreen < PM::TableScreen
title "Table Screen"
def table_data
[{
cells: [

View File

@@ -51,7 +51,7 @@ module ProMotion
end
def application(application, didReceiveRemoteNotification:notification)
received_push_notification(notification, false)
received_push_notification(notification, application.applicationState != UIApplicationStateActive)
end
protected

View File

@@ -1,8 +1,12 @@
module ProMotion
module Table
module Indexable
def index_from_section_titles
@promotion_table_data.filtered ? nil : @promotion_table_data.sections.collect{ |section| section[:title][0] }
def table_data_index
return nil if @promotion_table_data.filtered || !self.class.get_indexable
index = @promotion_table_data.sections.collect{ |section| section[:title][0] }
index.unshift("{search}") if self.class.get_searchable
index
end
end
end

View File

@@ -180,16 +180,12 @@ module ProMotion
# Set table_data_index if you want the right hand index column (jumplist)
def sectionIndexTitlesForTableView(table_view)
if @promotion_table_data.filtered
nil
return nil if @promotion_table_data.filtered
if self.respond_to?(:table_data_index)
self.table_data_index
else
if self.respond_to?(:table_data_index)
self.table_data_index
elsif self.class.respond_to?(:get_indexable) && self.class.get_indexable
self.index_from_section_titles
else
nil
end
nil
end
end

View File

@@ -1,3 +1,3 @@
module ProMotion
VERSION = "1.0.3" unless defined?(ProMotion::VERSION)
VERSION = "1.0.4" unless defined?(ProMotion::VERSION)
end

View File

@@ -73,20 +73,21 @@ module ProMotion
alias :add_element :add
alias :add_view :add
def remove(element)
element.removeFromSuperview
element = nil
def remove(elements)
Array(elements).each(&:removeFromSuperview)
end
alias :remove_element :remove
alias :remove_view :remove
def add_to(parent_element, element, attrs = {})
parent_element.addSubview element
if attrs && attrs.length > 0
set_attributes(element, attrs)
set_easy_attributes(parent_element, element, attrs)
def add_to(parent_element, elements, attrs = {})
Array(elements).each do |element|
parent_element.addSubview element
if attrs && attrs.length > 0
set_attributes(element, attrs)
set_easy_attributes(parent_element, element, attrs)
end
end
element
elements
end
def view_or_self

View File

@@ -11,3 +11,8 @@ class TableScreenIndexable < PM::TableScreen
end
end
class TableScreenIndexableSearchable < TableScreenIndexable
indexable
searchable
end

View File

@@ -27,6 +27,35 @@ describe "PM::Delegate" do
end
it "should return false for was_launched if the app is currently active on screen" do
@subject.mock!(:on_push_notification) do |notification, was_launched|
was_launched.should.be.false
end
UIApplication.sharedApplication.stub!(:applicationState, return: UIApplicationStateActive)
remote_notification = PM::PushNotification.fake_notification.notification
@subject.application(UIApplication.sharedApplication, didReceiveRemoteNotification: remote_notification)
end
it "should return true for was_launched if app was launched from background" do
@subject.mock!(:on_push_notification) do |notification, was_launched|
was_launched.should.be.true
end
UIApplication.sharedApplication.stub!(:applicationState, return: UIApplicationStateBackground)
remote_notification = PM::PushNotification.fake_notification.notification
@subject.application(UIApplication.sharedApplication, didReceiveRemoteNotification: remote_notification)
end
it "should return true for was_launched if the app wasn't running" do
@subject.mock!(:on_push_notification) do |notification, was_launched|
was_launched.should.be.true
end
launch_options = { UIApplicationLaunchOptionsRemoteNotificationKey => PM::PushNotification.fake_notification.notification }
@subject.application(UIApplication.sharedApplication, didFinishLaunchingWithOptions:launch_options )
end
it "should set home_screen when opening a new screen" do
@subject.application(UIApplication.sharedApplication, willFinishLaunchingWithOptions: nil)
@subject.application(UIApplication.sharedApplication, didFinishLaunchingWithOptions: nil)

View File

@@ -24,12 +24,29 @@ describe "screen helpers" do
@screen.view.subviews.count.should == 0
end
it "should let you remove an array of subviews" do
subview_a = UIView.alloc.initWithFrame CGRectZero
subview_b = UIView.alloc.initWithFrame CGRectZero
@screen.view.addSubview subview_a
@screen.view.addSubview subview_b
@screen.remove [subview_a, subview_b]
@screen.view.subviews.count.should == 0
end
it "should add a subview to another element" do
sub_subview = UIView.alloc.initWithFrame CGRectZero
@screen.add_to @subview, sub_subview
@subview.subviews.include?(sub_subview).should == true
end
it "should add an array of subviews to another element" do
sub_subview_a = UIView.alloc.initWithFrame CGRectZero
sub_subview_b = UIView.alloc.initWithFrame CGRectZero
@screen.add_to @subview, [sub_subview_a, sub_subview_b]
@subview.subviews.include?(sub_subview_a).should == true
@subview.subviews.include?(sub_subview_b).should == true
end
it "should add a subview to another element with attributes" do
sub_subview = UIView.alloc.initWithFrame CGRectZero
@screen.add_to @subview, sub_subview, { backgroundColor: UIColor.redColor }
@@ -142,7 +159,7 @@ describe "screen helpers" do
screen = @screen.open BasicScreen, modal: true
screen.should.be.kind_of BasicScreen
end
it "should present a modal screen if open_modal is used" do
@screen.mock!(:present_modal_view_controller) do |screen, animated|
screen.should.be.instance_of BasicScreen
@@ -178,7 +195,7 @@ describe "screen helpers" do
screen = @screen.open BasicScreen
screen.should.be.kind_of BasicScreen
end
it "should ignore its own navigation controller if current screen has a navigation controller" do
basic = BasicScreen.new(nav_bar: true) # creates a dangling nav_bar that will be discarded.
screen = @screen.open basic

View File

@@ -1,12 +1,25 @@
describe "PM::Table module" do
describe "PM::Table module indexable" do
before do
@screen = TableScreenIndexable.new
end
it "should automatically return the first letter of each section" do
result = %w{ A G M O S U }
@screen.sectionIndexTitlesForTableView(@screen.table_view).should == result
end
end
describe "PM::Table module indexable/searchable" do
before do
@screen = TableScreenIndexableSearchable.new
end
it "should automatically return the first letter of each section" do
result = %w{ {search} A G M O S U }
@screen.sectionIndexTitlesForTableView(@screen.table_view).should == result
end
end