ProMotion
æè¿ RubyMotion ã¦ã¼ã¶ã¼ã®é㧠ProMotion ã¨ããååãè¯ãèãããã«ãªã£ããhttp://rubymotion-wrappers.com/ ã®èª¬æã観ãã¨
A full featured RubyMotion framework that makes iPhone development less like Objective-C and more like Ruby, designed to get up and running fast.
ã¨ãªã£ã¦ãã¦ãRubyMotion åãã®ãã¬ã¼ã ã¯ã¼ã¯ãã¨ãããã¨ãããã
ããã¥ã¡ã³ãã«ãããµã³ãã«ã³ã¼ãã¯ä»¥ä¸ã®ããã«ãªã£ã¦ãã¦ã
class AppDelegate < PM::Delegate def on_load(app, options) open RootScreen.new(nav_bar: true) end end class RootScreen < PM::Screen title "Root Screen" def push_new_screen open NewScreen end end class NewScreen < PM::TableScreen title "Table Screen" def table_data [{ cells: [ { title: "About this app", action: :tapped_about }, { title: "Log out", action: :log_out } ] }] end end
ãªãã»ã©ç¢ºãã« "less Objective-C and more like Ruby" ã§ã¯ããã
RSSãªã¼ãã¼ : ããã©ã¢ã»ã¢ãã¿ã¼
ProMotion ã®ä½¿ç¨æã試ãããã«ãWEB+DB PRESS ã®é£è¼è¨äºã§ä½ã£ã RSS ãªã¼ãã¼ã®å®è£ ããProMotion ã§å®è£ ãç´ãã¦ã¿ããã©ã®ç¨åº¦ã³ã¼ãã«å·®ãåºãã ããã?
ããã©ã¢
class AppDelegate def application(application, didFinishLaunchingWithOptions:launchOptions) @window = UIWindow.alloc.initWithFrame(UIScreen.mainScreen.bounds) @window.rootViewController = UINavigationController.alloc.initWithRootViewController(MainViewController.new) @window.makeKeyAndVisible true end end class MainViewController < UITableViewController FeedURL = 'http://headlines.yahoo.co.jp/rss/all-c_sci.xml' def viewDidLoad super navigationItem.title = 'RSS Motion' @ptrview = SSPullToRefreshView.alloc.initWithScrollView(tableView, delegate:self) @items ||= [] fetch_rss(FeedURL) do |items| @items = items view.reloadData end end def viewDidUnload super @ptrview = nil end def fetch_rss (url, &cb) items = [] BW::HTTP.get(url) do |res| if res.ok? xml = res.body.to_str parser = BW::RSSParser.new(xml, true) parser.parse do |item| items.push(item) end else App.alert(res.error_message) end cb.call(items) end end def pullToRefreshViewDidStartLoading(ptrview) @ptrview.startLoading fetch_rss(FeedURL) do |items| @items = items @ptrview.finishLoading view.reloadData end end def tableView(tableView, numberOfRowsInSection:section) return @items.size end def tableView(tableView, cellForRowAtIndexPath:indexPath) cell = tableView.dequeueReusableCellWithIdentifier('cell') || UITableViewCell.alloc.initWithStyle(UITableViewCellStyleDefault, reuseIdentifier:'cell') cell.accessoryType = :disclosure.uitablecellaccessory cell.textLabel.font = :bold.uifont(14) cell.textLabel.text = @items[indexPath.row].title return cell end def tableView(tableView, didSelectRowAtIndexPath:indexPath) navigationController << WebViewController.new.tap do |c| c.url = @items[indexPath.row].link end end end class WebViewController < UIViewController attr_accessor :url def viewDidLoad super view << UIWebView.new.tap do |wv| wv.scalesPageToFit = true wv.frame = self.view.bounds wv.loadRequest(NSURLRequest.requestWithURL(url.nsurl)) wv.delegate = self end @indicator = UIActivityIndicatorView.gray.tap do |iv| iv.center = [view.frame.size.width / 2, view.frame.size.height / 2 - 42] end view << @indicator end def webViewDidStartLoad(webview) @indicator.startAnimating end def webViewDidFinishLoad(webview) @indicator.stopAnimating navigationItem.title = webview.stringByEvaluatingJavaScriptFromString('document.title') end end
ã¢ãã¿ã¼
class AppDelegate < PM::Delegate def on_load(app, options) open ItemsScreen.new( nav_bar: true, feed_url: 'http://headlines.yahoo.co.jp/rss/all-c_sci.xml' ) end end class ItemsScreen < PM::TableScreen attr_accessor :feed_url title "RssProMotion" refreshable callback: :on_refresh, pull_message: "Pull to refresh", refreshing: "Refreshing data..." def fetch_feed BW::HTTP.get(self.feed_url) do |res| items = [] if res.ok? BW::RSSParser.new(res.body.to_str, true).parse do |item| items.push(item) end else App.alert(res.error_message) end @items = [{ cells: items.map do |item| { title: item.title, action: :tapped_item, arguments: item, } end }] end_refreshing update_table_data end end def on_load fetch_feed end def on_refresh fetch_feed end def table_data @items ||= [] end def tapped_item(item) open WebScreen.new(url: item.link, title: item.title) end end class WebScreen < PM::WebScreen attr_accessor :url def on_load @indicator ||= add UIActivityIndicatorView.gray, { center: [view.frame.size.width / 2, view.frame.size.height / 2 - 42] } end def content self.url.nsurl end def load_started @indicator.startAnimating end def load_finished @indicator.stopAnimating end end
ã¨ããããªå½¢ã«ãªã£ãã
å®å ¨ã«åãå®è£ ã§ã¯ãªãã®ã§æ¯è¼ã¯ãã§ã¢ã§ã¯ãªãããã©ããã³ã¼ãã®é°å²æ°ãã ãã¶å¤ããã¨ãããã¨ã¯ããåãããç¹ã« UITableView å¨ãã PM::TableScreen ã§ç½®ãæããã¨é常ã«ãã£ãããã¦ããã
å ¨è¬çã« iOS SDK ã® API ãç´æ¥å¼ãã§ãããããªç®æãæ¸ã£ã¦ãProMotion ã® API ãå¼ãã§ãããã¨ãã³ã¼ãã®åæ¸ã«å¯ä¸ãã¦ããæãã
ææ³
説æãèªã㨠"ProMotion is a RubyMotion framework" ã¨ãããã¨ã§ããã¬ã¼ã ã¯ã¼ã¯ãã§ãããã¨ã訴ãã¦ãããã©ãå®éã«ã¯ RubyMotion ã®ãã¬ã¼ã ã¯ã¼ã¯ï½¥ï½¥ï½¥ã¨ããã iOS ã®ãã¬ã¼ã ã¯ã¼ã¯ãã¤ã¾ã㯠Cocoa Touch ã UIKit ããã¾ããªãã£ã¦ããè¨è¨ã«ãªã£ã¦ãã¦ãä¸å°ã«ãªã£ã¦ãããã¬ã¼ã ã¯ã¼ã¯ã®ãã©ãã¤ã ãå¤ããã¨ããããããã®ã§ã¯ãªãã¨æã£ããããããæ¸ãã¨ãã¬ãã£ãã®ããã ãã©ãããã§ã¯ãªãéã§ããã¸ãã£ãã§ãã
ãã¼ã¹ã®ãã¬ã¼ã ã¯ã¼ã¯ã®ãã©ãã¤ã ãå¤æ´ãããããªãã¬ã¼ã ã¯ã¼ã¯ on ãã¬ã¼ã ã¯ã¼ã¯å®è£ ã¯ãæ½è±¡åã®ã¬ãã«ãä¸ãã£ã¦ããã¨ä¸å°ã«ãªããã¬ã¼ã ã¯ã¼ã¯ã§ãªãã§ãããã©ãã®ä¸ä½ã®ãã¬ã¼ã ã¯ã¼ã¯ã使ã£ã¦ãã¾ãã¨ã§ããªããã¿ãããªãã¨ãçºçãã¦ãç·åçã«ã¯çç£æ§åä¸ã«å¯ä¸ããªããªãã¦ãã¨ããããããProMotion ã¯èãã©ããã¨ãããã·ã³ã¿ãã¯ã¹ã·ã¥ã¬ã¼ã®éã¾ãã«ãã£ã¦ RubyMotion ã®ãã¬ã¼ã ã¯ã¼ã¯ãè¦ã£ã¦ãããããªæãã§ãä¾ãã°æ®æ®µéã UIView ã«ã¢ã¯ã»ã¹ããããã° self.view ã§ã¢ã¯ã»ã¹ã§ãããã¨ãä¸ã®ã¬ã¤ã¤ã®ãã¬ã¼ã ã¯ã¼ã¯ãé ãã¦ããªãããã£ã¦ ProMotion ã§ã§ãããã¨ã¯ ProMotion ã§ãããã§ã¯ãªãã¨ããã¯ä»ã¾ã§éãã®å¼ã³æ¹ã§ãã¨ãã風ã«ç¡çãªãæ½è±¡åº¦ã®é«ã API ã使ããã¨ãã§ããããã«ãªã£ã¦ããã
ä¸è¨ã®ã³ã¼ãã§ããããã¦ããéã BubbleWrap ã sugarcube ã®ããã« RubyMotion ã®ããç²åº¦ã®ç´°ããã¤ãã£ãªã ããã Ruby ã£ã½ãæ¸ããããã«ããã·ã³ã¿ãã¯ã¹ã·ã¥ã¬ã¼ã©ã¤ãã©ãªã¨ã®ç¸æ§ãè¯ãã¦ãProMotion ã§å¤å´ããBubbleWrap ã sugarcubeãããã㯠NanoStoreInMotion ãªã©ãªã©ã§ä¸èº«ãããããè¦ã£ã¦ããã¨ã³ã¼ãã®å¯èªæ§ãããªãä¸ãããããä¸æ¹ã§ Objective-C API ãæ½è±¡åãããã¯ããªãã³ã¼ãã«ãªãã®ã§ãè£ã§å®éã«ã©ã㪠API ãå¼ã°ãã¦ãããããããªãã¿ãããªä¸å®ã¯æ®ããªããæªããªãã
ProMotion ã¯ã¾ã ã¾ã éçºåæ段éã¨ãã£ãã¨ããã§ã¹ãã¼ããéããä¾ãã°ã¾ã rubygems ã«ã¢ãããã¼ãããã¦ããªããã¼ã¸ã§ã³ (version-1.0 ãã©ã³ã) ã使ã£ã¦ãªãã¼ã¿ãããªãã¬ã¼ã ã¯ã¼ã¯ã§ãããã®ã§ããããã¯ã·ã§ã³ã¿ãããªã®ã«ã¯ã¡ãã£ã¨ï½¥ï½¥ï½¥ã¨ããèãæ¹ãããã¨ã¯æãããã¾ãããã㪠stable ãªäººçãæ±ãããªããããã RubyMotion ã使ã£ã¦ãªãããã§ãããã³ããã¨ããåä¹ããªãç©æ¥µçã«ä½¿ã£ã¦æã¯ãªããã®ã§ããã¨ããã®ãç·åçãªææ³ã§ããã¾ãã対象ã¢ããªã®è¦æ¨¡ã®å¤§å°ã«éããé©ç¨ãããããã¬ã¼ã ã¯ã¼ã¯ãªã®ã§ãä»å¾ã¯èªåãåºæ¬çã«ã¯ ProMotion ã使ã£ã¦æ¸ãã¦ãããããªã¨æãã¾ããã
ã¡ãªã¿ã«ç¥ã㨠@ainame ãããå æ¥ ProMotion ã§ã¢ããªãä½ã£ã¦ãã®æ§åãã¾ã¨ãã¦ãã ãã£ã¦ããã®ã§èå³ã®ããæ¹ã¯ä»¥ä¸ã®ã¨ã³ããªãåç §ã®ãã¨ã
teacup ã Pixate ãªããã¨çµã¿åããã¦ããã¨ããã夢ãã²ããããããªæãããã¾ããã