ctrl+shift+p filters: :st2 :st3 :win :osx :linux
Browse

Obj​C2​Ruby​Motion

by kyamaguchi ST2/ST3

Objective-C to RubyMotion Code Converter for Sublime Text

Details

  • 2013.05.26.15.03.47
  • github.​com
  • github.​com
  • 6 years ago
  • 2 hours ago
  • 7 years ago

Installs

  • Total 932
  • Win 135
  • OS X 746
  • Linux 51
Oct 18 Oct 17 Oct 16 Oct 15 Oct 14 Oct 13 Oct 12 Oct 11 Oct 10 Oct 9 Oct 8 Oct 7 Oct 6 Oct 5 Oct 4 Oct 3 Oct 2 Oct 1 Sep 30 Sep 29 Sep 28 Sep 27 Sep 26 Sep 25 Sep 24 Sep 23 Sep 22 Sep 21 Sep 20 Sep 19 Sep 18 Sep 17 Sep 16 Sep 15 Sep 14 Sep 13 Sep 12 Sep 11 Sep 10 Sep 9 Sep 8 Sep 7 Sep 6 Sep 5 Sep 4
Windows 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2 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
OS X 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

Build Status

A command plugin that enables to convert Objective-C code to Ruby Motion.

Screenshot:

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 autorelease at 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

  1. Fork it

  2. 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
  1. Copy test file and write new test

cp tests/test_basic.py tests/test_custom.py

  1. :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.