Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Rubymotion with ProMotion and Teacup

Jan
May 08, 2014

Rubymotion with ProMotion and Teacup

an overview with examples

Jan

May 08, 2014
Tweet

Other Decks in Programming

Transcript

  1. PROs ’n’ CONs • Ruby compiled into native Objective C


    (based on MacRuby by Laurent Sansonetti) • You are running REAL iOS
 not a sandbox or something else • uses Rake • cocoaPods
 3rd-party Objective-C libraries • iPhone and iPad apps in „ruby style“ • You write now native Mac apps too • It’s commercial (~133,- EUR) • It’s not rails like MVC • sometimes quirky when using gems • Making games or similar 
 is a bad idea
 Learn C#!
  2. More PROs • Unveils your whole iPhone
 internet, sound, cam,

    gyro, 
 compass, gps, camera, 
 datastorage,… • has an active community! • Scaffolding • TTD with rSpec! • BDD with cucumber
 frank-cucumber as base • Fully supported by Rubymine
 (Debugger, Code completion,…) • extendable by gems
 special ones written for Rubymotion
  3. gemfile source "https://rubygems.org" require 'rubygems' ! gem "rake" gem 'motion-cocoapods'

    gem 'ProMotion' gem 'teacup' gem formotion' gem 'ProMotion-formotion'
  4. Scaffolding jan$ motion create myapp Create myapp Create myapp/.gitignore Create

    myapp/app/app_delegate.rb Create myapp/Gemfile Create myapp/Rakefile Create myapp/resources/[email protected] Create myapp/spec/main_spec.rb jan$ promotion new myapp Create myapp Create myapp/.gitignore Create myapp/app/app_delegate.rb Create myapp/app/screens/home_screen.rb Create myapp/Gemfile Create myapp/Rakefile Create myapp/resources/[email protected] Create myapp/spec/main_spec.rb
  5. ProMotion Scaffold app/ models/ event.rb screens/ events/ events_screen.rb show_event_screen.rb edit_event_screen.rb

    home_screen.rb settings_screen.rb styles/ some_stylesheet.rb views/ cells/ event_cell.rb buttons/ save_event_button.rb app_delegate.rb
  6. Bootstrapping : app_delegate.rb class AppDelegate ! def application(application, didFinishLaunchingWithOptions:launchOptions) true

    end end #import "AppDelegate.h" #import "YourViewController.h" ! @implementation AppDelegate ! - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary)launchOptions { return YES; } c# RubyMotion
  7. Bootstrapping : app_delegate.rb class AppDelegate ! def application(application, didFinishLaunchingWithOptions:launchOptions) true

    end end class AppDelegate < PM::Delegate ! def on_load(app, options) true end end Rubymotion ProMotion
  8. ProMotion Screens class AppDelegate < PM::Delegate ! status_bar true, animation:

    :none ! def on_load(app, options) open HomeScreen.new(nav_bar: true) end ! end
  9. Screens class HomeScreen < PM::Screen ! title "Home" ! def

    on_load set_nav_bar_button :left, title: "Help", action: :open_help_screen end ! def open_help_screen open HelpScreen end ! end
  10. TableScreens class HelpScreen < PM::TableScreen title "States" ! def table_data

    [{ title: "States", cells: [ { title: "Alabama", action: :tabbed_details }, { title: "Alaska", action: :log_out } ] }] end ! def tabbed_details(args={}) open DetailsScreen end ! def log_out # Log out! end
  11. TableScreens class HelpScreen < PM::TableScreen title „States" searchable placeholder: "Search

    This Table" ! def table_data [{ title: "States", cells: [ { title: "Alabama", action: :tabbed_details }, { title: "Arkansas", action: :log_out, searchable: false}, { title: "Alaska", action: :log_out, search_text: “cold“} ] }] end ! def tabbed_details(args={}) open DetailsScreen end ! def log_out # Log out! end
  12. MapScreens class MyMapScreen < PM::MapScreen title "My Map" start_position latitude:

    35.090648651123, longitude: -82.965972900391, radius: 4 ! def on_appear update_annotation_data end ! def annotation_data [{ longitude: -82.965972900391, latitude: 35.090648651123, title: "Rainbow Falls", subtitle: "Nantahala National Forest" },{ longitude: -82.966093558105, latitude: 35.092520895652, title: "Turtleback Falls", subtitle: "Nantahala National Forest" } ] end end
  13. Styling with ProMotion class HomeScreen < PM::Screen include HomeStyles def

    on_load set_attributes self.view, :main_view_style add UILabel.new, :label_style end end module HomeStyles def main_view_style { background_color: hex_color("DBDBDB") } end ! def label_style { text: "August", text_color: hex_color("8F8F8D"), background_color: UIColor.clearColor, shadow_color: UIColor.blackColor, text_alignment: UITextAlignmentCenter, font: UIFont.systemFontOfSize(15.0), frame: CGRectMake(10, 0, 300, 35) } end end
  14. Wrappers Accessibility, Accordion, ACL, AddressBookUI, Adhoc, Alerts, Animations, API, AppApp

    Store, AR, Audio, Authorization, Auto Layout, Automation, AVSpeech, Synthesizer, Barcode, Bindings, Bonjour, Bootstrap, Box 2D, Bridge, Support, Build, Camera, CGRect, Charts, Client, Cloud, CocoaPods, Cocos 2D, Concurrency, Configuration, Controllers, Core Data, CoreLocation, CorePlot, Credits, CSV, Cucumber, DDP, Debug, Defaults, Dependency Injection, Design, Device, Distribution, Easter Egg, Email, Environment, Events, Firebase, Fixtures, Font Awesome, Fonts, Forms, Gems, Gestures, Graphs, HTTP, i18n, Image Recognition, In App Purchase, Inspector, Interactive Console, Interface Builder, iOS, JSON, KVO, Localization, Location, Logging, MapKit, MessageUI, Meteor, MockModel, Models, Motion, Model, Notifications, NSCoder, NSNetService, NSString, OCR, OS X, Overlay, Parse, Persistence, Progress, ProMotion, RailsReal-Time, Releases, Reminders, RSS, Scheduling, Schema, Schemaless, Screens, Screenshots, Settings, Slide, Menu, Social, Spec, Speech, SQLite, Storage, StoreKit, Storyboard, StyleStylesheets, Symbol, Tables, Templates, text-to-speech, Twitter, UIColor, UIFont, UIImage, UILocalNotification, UITableView, UITextField, UITextView, UIViewController, Updates, Validation, Video, Video Games, Views, Voiceover, XML
  15. Teacup • CSS like behaviour • creates Layouts and views

    • fits into promotion • using constraints gem install teacup require 'teacup' Rakefile Gemfile
  16. Start using Teacup class MyController < UIViewController stylesheet :main_screen !

    layout do <—— creates a view subview(UIButton, :hi_button) ^^—— creates another view inside view end end Teacup::Stylesheet.new :main_screen do style :hi_button, origin: [10, 10], title: 'Hi!' end
  17. Using Teacup with ProMotion class HomeScreen < PM::Screen # Teacup

    method stylesheet :about def on_load # teacup method which takes the self.view layout self.view do # ProMotion method add adds a UIButton to the view button = add UIButton.new, # TeaCup stylename :clickme added stylename: :clickme, frame: CGRectMake(30, 250, 90, 90) end ! end