ObjC2RubyMotion
Objective-C to RubyMotion Code Converter for Sublime Text
Details
Installs
- Total 1K
- Win 175
- Mac 766
- Linux 62
| Jan 30 | Jan 29 | Jan 28 | Jan 27 | Jan 26 | Jan 25 | Jan 24 | Jan 23 | Jan 22 | Jan 21 | Jan 20 | Jan 19 | Jan 18 | Jan 17 | Jan 16 | Jan 15 | Jan 14 | Jan 13 | Jan 12 | Jan 11 | Jan 10 | Jan 9 | Jan 8 | Jan 7 | Jan 6 | Jan 5 | Jan 4 | Jan 3 | Jan 2 | Jan 1 | Dec 31 | Dec 30 | Dec 29 | Dec 28 | Dec 27 | Dec 26 | Dec 25 | Dec 24 | Dec 23 | Dec 22 | Dec 21 | Dec 20 | Dec 19 | Dec 18 | Dec 17 | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Windows | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| Mac | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| Linux | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
Readme
- Source
- raw.githubusercontent.com
ObjC2RubyMotion Converter for Sublime Text 2/3
A command plugin that enables to convert Objective-C code to Ruby Motion.
Screenshot:
Using iShowU, KeyCastr, GIFBrewery
How It Works
Code in the line of the cursor or selection are converted:
// original
_window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window.rootViewController = self.myNavController;
[self.window makeKeyAndVisible];
// select lines and run "objc_to_ruby_motion"
_window = UIWindow.alloc.initWithFrame(UIScreen.mainScreen.bounds)
self.window.rootViewController = self.myNavController
self.window.makeKeyAndVisible
Install
Package Control
Install the ObjC2RubyMotion package from Package Control.
Manual
Clone this repository from your Sublime packages directory:
Macosx
$ cd ~/Library/Application\ Support/Sublime\ Text\ 2/Packages
$ git clone https://github.com/kyamaguchi/SublimeObjC2RubyMotion.git ObjC2RubyMotion
Key Binding
By default,
For Conversion
super+ctrl+i objc_to_ruby_motion
Conversions
In internal order
- Replace NSString
@"String"->"String" - Remove inline comments
// - Convert blocks (may be not perfect)
- Convert square brackets expression
[[Obj alloc] init]->Obj.alloc.init - Remove semicolon
;at the end of line - Remove
autoreleaseat the end - Remove type declaration for Object
Type *before= - YES/NO
- Float
100.0f->100 - CGRectMake
CGRectMake(10, 10, 20, 20)->[[10, 10], [20, 20]]
NOT supported
- Complex block
- if else conditions etc.
- actions
action:@selector(tapped:) - Method name and args conversion
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section - Others
Note
This converter is not intended to convert perfectly. This is intended to help the conversion of Objective-C code snippets.
Some complex expression may not be converted correctly.
Tests
:smile: Fortunately ObjC2RubyMotion has tests.
Run test from command line
$ cd ~/Library/Application\ Support/Sublime\ Text\ 2/Packages/ObjC2RubyMotion
$ python tests/all_test.py
OR
:racehorse: Use guard
# Requirement: ruby
$ gem install guard
$ gem install guard-shell
$ guard
Customize
Fork it
Remove original ObjC2RubyMotion and clone yours OR add your repository as another git remote
$ cd ~/Library/Application\ Support/Sublime\ Text\ 2/Packages
$ git clone git@github.com:yourname/SublimeObjC2RubyMotion.git ObjC2RubyMotion
- Copy test file and write new test
cp tests/test_basic.py tests/test_custom.py
- :snake: Change and Test
Normally, you should change CodeConverter.py and test_*.py.
$ guard is recommended.
Note
Probably most users of this plugin are rubyist, not pythonista.
This converter is mostly composed of regular expression for now.
If we try to improve this to convert more complex expressions, probably we need to replace the converter with the one using parser/tokenizer/scanner.
Fork is welcomed.
Care about unexpected string replacements. They could happen and they will be problems.
