From 5be9a54b7f8531328171c0e2f68f2f98bb04fbd9 Mon Sep 17 00:00:00 2001 From: Mark Rickert Date: Wed, 4 Sep 2013 08:42:49 -0400 Subject: [PATCH 01/10] Fixes issue with indexable table. #287 --- lib/ProMotion/table/extensions/indexable.rb | 2 +- lib/ProMotion/table/table.rb | 14 +++++--------- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/lib/ProMotion/table/extensions/indexable.rb b/lib/ProMotion/table/extensions/indexable.rb index d24b210..205c852 100644 --- a/lib/ProMotion/table/extensions/indexable.rb +++ b/lib/ProMotion/table/extensions/indexable.rb @@ -1,7 +1,7 @@ module ProMotion module Table module Indexable - def index_from_section_titles + def table_data_index @promotion_table_data.filtered ? nil : @promotion_table_data.sections.collect{ |section| section[:title][0] } end end diff --git a/lib/ProMotion/table/table.rb b/lib/ProMotion/table/table.rb index 43463d1..f8d341b 100644 --- a/lib/ProMotion/table/table.rb +++ b/lib/ProMotion/table/table.rb @@ -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 From 7bfcc2eaa8b1e293cb436130ef44d1ad17812f2f Mon Sep 17 00:00:00 2001 From: Mark Rickert Date: Wed, 4 Sep 2013 08:48:36 -0400 Subject: [PATCH 02/10] Automatically add the little magnifying glass to the top of the table index if the table is searchable. --- lib/ProMotion/table/extensions/indexable.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/ProMotion/table/extensions/indexable.rb b/lib/ProMotion/table/extensions/indexable.rb index 205c852..613460d 100644 --- a/lib/ProMotion/table/extensions/indexable.rb +++ b/lib/ProMotion/table/extensions/indexable.rb @@ -2,7 +2,9 @@ module ProMotion module Table module Indexable def table_data_index - @promotion_table_data.filtered ? nil : @promotion_table_data.sections.collect{ |section| section[:title][0] } + index = @promotion_table_data.filtered ? nil : @promotion_table_data.sections.collect{ |section| section[:title][0] } + index.unshift("{search}") if self.class.get_searchable + index end end end From a2a7ae2eb631710b843dcfa8ad2756a8122ced6c Mon Sep 17 00:00:00 2001 From: Mark Rickert Date: Wed, 4 Sep 2013 09:04:31 -0400 Subject: [PATCH 03/10] Add passing tests for indexable tablescreens --- spec/helpers/table_screen_indexable.rb | 4 ++++ spec/unit/tables/table_indexable_spec.rb | 19 ++++++++++++++++--- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/spec/helpers/table_screen_indexable.rb b/spec/helpers/table_screen_indexable.rb index 08c8551..d5098cb 100644 --- a/spec/helpers/table_screen_indexable.rb +++ b/spec/helpers/table_screen_indexable.rb @@ -11,3 +11,7 @@ class TableScreenIndexable < PM::TableScreen end end + +class TableScreenIndexableSearchable < TableScreenIndexable + searchable +end diff --git a/spec/unit/tables/table_indexable_spec.rb b/spec/unit/tables/table_indexable_spec.rb index 9020a1b..0f6027c 100644 --- a/spec/unit/tables/table_indexable_spec.rb +++ b/spec/unit/tables/table_indexable_spec.rb @@ -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 From 9925cfee3d4be2dd035c3f60312ee987a1079290 Mon Sep 17 00:00:00 2001 From: Mark Rickert Date: Wed, 4 Sep 2013 09:21:43 -0400 Subject: [PATCH 04/10] Fix code to pass tests for indexable. --- lib/ProMotion/table/extensions/indexable.rb | 4 +++- spec/helpers/table_screen_indexable.rb | 1 + 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/ProMotion/table/extensions/indexable.rb b/lib/ProMotion/table/extensions/indexable.rb index 613460d..3adac5e 100644 --- a/lib/ProMotion/table/extensions/indexable.rb +++ b/lib/ProMotion/table/extensions/indexable.rb @@ -2,7 +2,9 @@ module ProMotion module Table module Indexable def table_data_index - index = @promotion_table_data.filtered ? nil : @promotion_table_data.sections.collect{ |section| section[:title][0] } + 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 diff --git a/spec/helpers/table_screen_indexable.rb b/spec/helpers/table_screen_indexable.rb index d5098cb..57746fc 100644 --- a/spec/helpers/table_screen_indexable.rb +++ b/spec/helpers/table_screen_indexable.rb @@ -13,5 +13,6 @@ class TableScreenIndexable < PM::TableScreen end class TableScreenIndexableSearchable < TableScreenIndexable + indexable searchable end From 7c382cecd435a3023c480f3873a219f5f37aba96 Mon Sep 17 00:00:00 2001 From: Jamon Holmgren Date: Wed, 4 Sep 2013 08:18:48 -0700 Subject: [PATCH 05/10] Version 1.0.4 --- lib/ProMotion/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/ProMotion/version.rb b/lib/ProMotion/version.rb index fdf5231..13fd193 100644 --- a/lib/ProMotion/version.rb +++ b/lib/ProMotion/version.rb @@ -1,3 +1,3 @@ module ProMotion - VERSION = "1.0.3" unless defined?(ProMotion::VERSION) + VERSION = "1.0.4" unless defined?(ProMotion::VERSION) end From 5948ded28eaed535962e3157dc85fd0ed4754a70 Mon Sep 17 00:00:00 2001 From: Jamon Holmgren Date: Wed, 4 Sep 2013 08:18:58 -0700 Subject: [PATCH 06/10] Bundled --- Gemfile.lock | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gemfile.lock b/Gemfile.lock index cdfedb3..4420ec0 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,7 @@ PATH remote: . specs: - ProMotion (1.0.3) + ProMotion (1.0.4) GEM remote: https://rubygems.org/ From 707fcf57ecb78cda0b7e53eae963d764a36af194 Mon Sep 17 00:00:00 2001 From: Ryan Linton Date: Tue, 17 Sep 2013 11:05:04 -0700 Subject: [PATCH 07/10] make add_to and remove accept an array of elements --- lib/ProMotion/view/styling.rb | 41 ++++++++++++++++++----------------- 1 file changed, 21 insertions(+), 20 deletions(-) diff --git a/lib/ProMotion/view/styling.rb b/lib/ProMotion/view/styling.rb index 48325d7..ce5f5d1 100644 --- a/lib/ProMotion/view/styling.rb +++ b/lib/ProMotion/view/styling.rb @@ -1,7 +1,7 @@ module ProMotion module Styling include Conversions - + def set_attributes(element, args = {}) args.each { |k, v| set_attribute(element, k, v) } element @@ -64,33 +64,34 @@ module ProMotion end nil end - + def add(element, attrs = {}) add_to view_or_self, element, attrs end 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 self.respond_to?(:view) ? self.view : self end - + # These three color methods are stolen from BubbleWrap. def rgb_color(r,g,b) rgba_color(r,g,b,1) @@ -103,7 +104,7 @@ module ProMotion def hex_color(str) hex_color = str.gsub("#", "") - case hex_color.size + case hex_color.size when 3 colors = hex_color.scan(%r{[0-9A-Fa-f]}).map{ |el| (el * 2).to_i(16) } when 6 @@ -111,16 +112,16 @@ module ProMotion else raise ArgumentError end - + if colors.size == 3 rgb_color(colors[0], colors[1], colors[2]) else raise ArgumentError - end + end end - + protected - + def map_resize_symbol(symbol) @_resize_symbols ||= { left: UIViewAutoresizingFlexibleLeftMargin, @@ -128,10 +129,10 @@ module ProMotion top: UIViewAutoresizingFlexibleTopMargin, bottom: UIViewAutoresizingFlexibleBottomMargin, width: UIViewAutoresizingFlexibleWidth, - height: UIViewAutoresizingFlexibleHeight + height: UIViewAutoresizingFlexibleHeight } @_resize_symbols[symbol] || symbol end - + end end From ea513edc5685f25a406d563dba0f39c79769ae5c Mon Sep 17 00:00:00 2001 From: Ryan Linton Date: Tue, 17 Sep 2013 11:45:56 -0700 Subject: [PATCH 08/10] add tests --- spec/unit/screen_helpers_spec.rb | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/spec/unit/screen_helpers_spec.rb b/spec/unit/screen_helpers_spec.rb index 4b41caa..895a0f8 100644 --- a/spec/unit/screen_helpers_spec.rb +++ b/spec/unit/screen_helpers_spec.rb @@ -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 } @@ -153,7 +170,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 @@ -189,7 +206,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 From b204a942b089a63f33edf34d2b97d03b6da9c403 Mon Sep 17 00:00:00 2001 From: Jens Balvig Date: Thu, 19 Sep 2013 18:28:39 +0200 Subject: [PATCH 09/10] return true when launched from background --- .../delegate/delegate_notifications.rb | 2 +- spec/unit/delegate_spec.rb | 29 +++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/lib/ProMotion/delegate/delegate_notifications.rb b/lib/ProMotion/delegate/delegate_notifications.rb index 6e7dd38..185269b 100644 --- a/lib/ProMotion/delegate/delegate_notifications.rb +++ b/lib/ProMotion/delegate/delegate_notifications.rb @@ -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 diff --git a/spec/unit/delegate_spec.rb b/spec/unit/delegate_spec.rb index 316491f..00a568d 100644 --- a/spec/unit/delegate_spec.rb +++ b/spec/unit/delegate_spec.rb @@ -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) From d56fa5a8ef0c6ec718478063cc533c5d5c6177fb Mon Sep 17 00:00:00 2001 From: Jamon Holmgren Date: Thu, 19 Sep 2013 15:36:39 -0700 Subject: [PATCH 10/10] Added Motion Meetup link --- README.md | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 9e025e1..ab7f13c 100644 --- a/README.md +++ b/README.md @@ -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: [