Momentum
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.
Help support this gem by learning
The only reason I can keep making gems and keep them up to date is because lovely people like yourself support me. I run the MotionInMotion screencasts which you can sign up to for $9/month, I also have a book coming out called RubyMotion for Rails Developers which you can pay what you like to buy, and I provide one-on-one training through pairing on AirPair{}Me. All support, even small amounts really helps.
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
- Fork it ( http://github.com/FluffyJack/motion-momentum/fork )
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request