Skip to content
This repository has been archived by the owner on Mar 20, 2019. It is now read-only.

Latest commit

 

History

History
247 lines (159 loc) · 7.31 KB

README.md

File metadata and controls

247 lines (159 loc) · 7.31 KB

NativeGap on Rails

Gem Version

Build native apps for all major platforms with NativeGap.

Platforms

  • Android
  • iOS
  • Universal Windows Platform (Windows 10)
  • Chrome (Extension)

How it works ...

  1. Create and customize your apps from the NativeGap dashboard.
  2. Add NativeGap.js to your app in order to track currently used apps and to add some custom styling.
  3. Use this gem to track app usage for your users and to add platform specific assets.

Table of Contents


Installation

NativeGap on Rails works with Rails 5 onwards. You can add it to your Gemfile with:

gem 'nativegap'

And then execute:

$ bundle

Or install it yourself as:

$ gem install nativegap

If you always want to be up to date fetch the latest from GitHub in your Gemfile:

gem 'nativegap', github: 'NativeGap/nativegap-rails'

Now run the generator:

$ rails g nativegap

To wrap things up, migrate the changes into your database:

$ rails db:migrate

Make also sure to add the following to your app config (config/application.rb):

config.action_dispatch.default_headers = {
   'X-Frame-Options' => 'ALLOWALL'
}

Usage

Setup

While this gem assists you in creating a true cross-platform app, NativeGap 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) and it has an extensive documentation.

Getting started with NativeGap:

  1. Create a new NativeGap app.
  2. Wait until the platforms processed successfully.

That's it!

Note: Native also supports the coexistence of multiple NativeGap apps with only one Rails app as a source.

Assets

With NativeGap on Rails 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/.../nativegap). In these two folders you are able to add custom assets for specific platforms including web specific assets.

You simple have to add ...

= component 'nativegap/assets'

... to the head tag of your layout after your other asset include tags.

User associations

Define an association in models whose objects are supposed to be associated with NativeGap apps. For example Admin in app/models/admin.rb.

class Admin < ApplicationRecord
    nativegap
end

Next attach an admin record by defining a set_nativegap_user method. Let's say our model is named Admin and current_admin is available at controller level. Just add a method to your ApplicationController:

def set_nativegap_user
    current_admin if current_admin
end

Note: If a current_user method is available at controller level this method is not required.

You are now able to get NativeGap apps for a specific user:

a = Admin.first

# All app records of a user
a.nativegap_apps

Apps

Native introduces an App ActiveRecord model. Every object of an associated user class can have multiple apps.

Methods

a = App.first

# Returns associated object. Can return `nil`.
a.owner

# Returns lowercase string of platform.
d.platform

# Returns the apps start url. 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.ios
d.windows
d.chrome

# Group apps by `platform`
d.platforms

# Group apps by `url`
d.apps

Helpers

NativeGap on Rails adds some helpers which are available in your controllers and views:

  • current_app App record related to current session. Returns nil when the Rails app is being used normally.

  • current_platform Lowercase string of current platform. Returns 'web' when the Rails app is being used normally.

Notifications

You can enable native notifications on most platforms. To handle notifications NativeGem integrates with OneSignal. You could use the NotificationsRails gem and implement the notification-pusher-onesignal component to push notifications to your native applications. OnSignal assists you with managing OneSignal along with a user authentication system.


Configuration

You can configure NativeGap on Rails by passing a block to configure. This can be done in config/initializers/nativegap.rb:

NativeGap.configure do |config|
    config.android = true
end
  • #{platform} Set to false to disable the platform. Takes a boolean. Defaults to true.

To Do

Here is the full list of current projects.

To propose your ideas, initiate the discussion by adding a new issue.


Contributing

We hope that you will consider contributing to NativeGap on Rails. Please read this short overview for some information about how to get started:

Learn more about contributing to this repository, Code of Conduct

Contributors

Give the people some ❤️ who are working on this project. See them all at:

https://github.com/NativeGap/nativegap-rails/graphs/contributors

Semantic Versioning

NativeGap on Rails follows Semantic Versioning 2.0 as defined at http://semver.org.

License

MIT License

Copyright (c) 2017 Jonas Hübotter

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.