Giter Club home page Giter Club logo

motion-momentum's Introduction

Momentum

Gem Version Build Status Code Climate Dependency Status

Momentum is a RubyMotion framework for creating iOS and OS X applications the "Rails" way.

I suggest you use this framework with RMQ and CDQ.

This framework is being developed along side the RubyMotion for Rails Developers book, but my vision for it is most certainly to help the long term happiness of the RubyMotion community. Please share your ideas by submitting an issue here on GitHub. Show support by purchasing the book or subscribe to my screencasts.

You can see sample application in the MomentumSampleApps repo.

Installation

Add this line to your application's Gemfile:

gem 'motion-momentum'

And then execute:

$ bundle

Or install it yourself as:

$ gem install motion-momentum

Usage

This framework is still in it's early days. Feel free to use it, but understand that until v1.x the API may change between releases. Proposed ideas can be found in this gist: https://gist.github.com/FluffyJack/9409243.

Application Structure

Momentum tries to take a convention-over-configuration approach. A controller called MainController will assign it's view to be MainView, it's delegate (and the view's delegate and dataSource attribtues if they exist) to be MainDelegate, and it's stylesheet to be MainStylesheet, though stylesheets have not been properly integrated yet, and so, using a stylesheet gem is suggested.

The suggested application structure is as follows:

app
\- app_delegate.rb
\- controllers
   \- posts_controller.rb
\- delegates
   \- posts_delegate.rb
\- models
   \- post.rb
\- stylesheets
   \- posts_stylesheet.rb
\- views
   \- posts_view.rb

Controllers

To create a Momentum controller which will help you clean up your controller code, you can just inherit from Momentum::ViewController for iOS. OS X support is coming soon and a Momentum::WindowController will be available then.

class PostsController < Momentum::ViewController
  title "Posts"

  def setup
    self.delegate.data[:posts] = Post.all
  end
end

You can also just include the Momentum::ViewControllerModule, though this isn't well tested with support for other types of view controllers yet (remember, very early days).

If you want to choose which view, delegate, or stylesheet class is used, you can do so.

class PostsController < Momentum::ViewController
  view "PostsView"
  delegate "PostsDelegate"
  stylesheet "PostsStylesheet"
  title "Posts"

  def setup
    self.delegate.data[:posts] = Post.all
  end
end

Views

Views are currently just standard UIViews.

class PostsView < UITableView
end

Delegates

Delegates are fairly stock standard, but you can inherit from Momentum::Delegate to get a nice data attribute to pass data to your delegate for you view to consume.

class PostsDelegate < Momentum::Delegate
  def tableView(tableView, numberOfRowsInSection:section)
    self.data[:posts].count
  end

  def tableView(tableView, cellForRowAtIndexPath:indexPath)
    @reuseIdentifier ||= "CELL_IDENTIFIER"

    cell = tableView.dequeueReusableCellWithIdentifier(@reuseIdentifier) || begin
      UITableViewCell.alloc.initWithStyle(UITableViewCellStyleDefault, reuseIdentifier:@reuseIdentifier)
    end

    cell.textLabel.text = self.data[:posts][indexPath.row].title

    cell
  end

  def tableView(tableView, didSelectRowAtIndexPath:indexPath)
    # push the detail controller with the post
  end
end

Contributing

  1. Fork it ( http://github.com/FluffyJack/motion-momentum/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

motion-momentum's People

Watchers

Artur Krasnyh avatar James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.