# Native [![Gem Version](https://badge.fury.io/rb/native.svg)](https://badge.fury.io/rb/native) Creating cross-platform apps with Rails has never been this simple, pleasing & powerful. With very little code you can bring any Rails web application to every desktop or mobile platform you can think of. **Features:** * Convert your Rails app to a native app * Add custom assets for any of your platforms * Customize your code for every platform by utilizing Native's view helpers * Remember what apps/platforms your users are on * Add native notifications **Platforms:** * Android (`android`) * iOS (`ios`) * Universal Windows Platform (Windows 10) (`uwp`) * Chrome (`chrome`) * OSX / MacOS (`osx`) * Windows x32 / x64 (`win32`, `win64`) * Linux x32 / x64 (`lin32`, `lin64`) --- Native is being powered by **[NativeGap](https://nativegap.com)**. --- ## Table of Contents * [Installation](#installation) * [Usage](#usage) * [NativeGap](#nativegap) * [Assets](#assets) * [App methods](#app-methods) * [Associate objects](#associate-objects) * [View methods](#view-methods) * [Notifications](#notifications) * [Content scaling (Android)](#content-scaling-android) * [Configuration](#configuration) * [To Do](#to-do) * [Contributing](#contributing) * [Contributors](#contributors) * [Semantic versioning](#semantic-versioning) * [License](#license) --- ## Installation Native works with Rails 5.0 onwards. You can add it to your `Gemfile` with: ```ruby gem 'native' ``` And then execute: $ bundle Or install it yourself as: $ gem install native If you always want to be up to date fetch the latest from GitHub in your `Gemfile`: ```ruby gem 'native', github: 'NativeGap/native' ``` Now run the generator: $ rails g native To wrap things up, migrate the changes into your database: $ rails db:migrate Let's move on to your devise class. For instance `User` located in `app/models/user.rb`. Associate belonging `App` objects: ```ruby uses_native_apps ``` Lastly, got to your routes file (`config/routes.rb`) and mount the `Native::Engine` class: ```ruby mount Native::Engine, at: '/native' ``` ## Usage ### NativeGap While this gem assists you in creating a true cross-platform app, [NativeGap](https://nativegap.com) is still needed to create the actual native code. That's not too big of a deal though, NativeApp can be used entirely for free ([learn more](https://nativegap.com/pricing)) and it has an extensive [documentation](https://nativegap.com/guide). Getting started with NativeGap: 1. Create a new NativeGap app 2. Wait until platforms processed 3. For each platform you want to support: click `Update` and enter the start path. The start path consists of your `Native::Engine` mount path and the platform. It could look like this: `native/android` That's it! **Note:** Native also supports the coexistence of multiple NativeGap apps with only one Rails app as a source. ### Assets With Native it is fairly simple to add platform specific stylesheets and scripts. In your assets directory you have a new folder for your `javascripts` and `stylesheets` (`app/assets/.../native`). In these two folders you are able to add custom assets for specific platforms including `web` specific assets. You simple have to include ... ```ruby = native_assets ``` ... in the `head` tag of your layout after your other asset include tags. ### App methods Native introduces an `App` ActiveRecord model. Every object of your devise class can have multiple apps. ```ruby a = App.first # Returns associated object. Can return `nil`. a.owner # Returns lowercase string of platform. d.platform # Returns url of mounted `NativeGap::Engine` class. This can be used to differentiate between apps, if you have multiple NativeGap apps with one Rails app as source. d.url # Some timestamps d.last_used d.created_at d.updated_at # Returns activerecord array of apps from a specific platform d.android # ... d.lin64 # Group apps by `platform` d.platforms # Group apps by `url` d.apps ``` #### Associate objects If you are using Devise and your model is named `User`, the object returned by `current_user` will automatically be associated with the current app. If your Devise model is not named `User` or you are using a different user-management solution that does not implement a `current_user` method, you are able to override this default behavior. Let's say our Devise model is named `Admin`. Just add a `protected` method to your `ApplicationController`: ```ruby protected def set_app_owner current_admin if current_admin end ``` **Note:** Essentially `set_app_owner` has to return a class object *or* `nil`. Now you are able to access the applications used by an user: ```ruby User.first.native_apps ``` ### View methods **`current_app`** Returns `App` object related to current session. Returns `nil` when the Rails is being used normally. **`current_platform`** Returns lowercase string of current platform. Returns `'web'` when the Rails is being used normally. **`native_assets`** Returns platform specific `` and `