mobile_intent 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/.rspec +2 -0
- data/.travis.yml +3 -0
- data/Gemfile +9 -0
- data/Guardfile +9 -0
- data/LICENSE.txt +22 -0
- data/README.md +53 -0
- data/Rakefile +6 -0
- data/lib/assets/javascripts/mobile_intent.js.coffee.erb +31 -0
- data/lib/mobile_intent.rb +17 -0
- data/lib/mobile_intent/application.rb +45 -0
- data/lib/mobile_intent/config.rb +19 -0
- data/lib/mobile_intent/engine.rb +6 -0
- data/lib/mobile_intent/helpers.rb +31 -0
- data/lib/mobile_intent/railtie.rb +21 -0
- data/lib/mobile_intent/version.rb +3 -0
- data/mobile_intent.gemspec +28 -0
- data/spec/controllers/top_controller_spec.rb +10 -0
- data/spec/dummy/.gitignore +16 -0
- data/spec/dummy/Gemfile +46 -0
- data/spec/dummy/README.rdoc +28 -0
- data/spec/dummy/Rakefile +6 -0
- data/spec/dummy/app/assets/images/.keep +0 -0
- data/spec/dummy/app/assets/javascripts/application.js +17 -0
- data/spec/dummy/app/assets/stylesheets/application.css +13 -0
- data/spec/dummy/app/controllers/application_controller.rb +5 -0
- data/spec/dummy/app/controllers/concerns/.keep +0 -0
- data/spec/dummy/app/controllers/top_controller.rb +4 -0
- data/spec/dummy/app/helpers/application_helper.rb +2 -0
- data/spec/dummy/app/mailers/.keep +0 -0
- data/spec/dummy/app/models/.keep +0 -0
- data/spec/dummy/app/models/concerns/.keep +0 -0
- data/spec/dummy/app/views/layouts/application.html.erb +14 -0
- data/spec/dummy/app/views/top/index.html.erb +5 -0
- data/spec/dummy/bin/bundle +3 -0
- data/spec/dummy/bin/rails +4 -0
- data/spec/dummy/bin/rake +4 -0
- data/spec/dummy/config.ru +4 -0
- data/spec/dummy/config/application.rb +20 -0
- data/spec/dummy/config/boot.rb +4 -0
- data/spec/dummy/config/database.yml +25 -0
- data/spec/dummy/config/environment.rb +5 -0
- data/spec/dummy/config/environments/development.rb +29 -0
- data/spec/dummy/config/environments/production.rb +80 -0
- data/spec/dummy/config/environments/test.rb +36 -0
- data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -0
- data/spec/dummy/config/initializers/inflections.rb +16 -0
- data/spec/dummy/config/initializers/mime_types.rb +5 -0
- data/spec/dummy/config/initializers/mobile_intent.rb +3 -0
- data/spec/dummy/config/initializers/secret_token.rb +12 -0
- data/spec/dummy/config/initializers/session_store.rb +3 -0
- data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/spec/dummy/config/locales/en.yml +23 -0
- data/spec/dummy/config/routes.rb +56 -0
- data/spec/dummy/db/seeds.rb +7 -0
- data/spec/dummy/lib/assets/.keep +0 -0
- data/spec/dummy/lib/tasks/.keep +0 -0
- data/spec/dummy/log/.keep +0 -0
- data/spec/dummy/public/404.html +58 -0
- data/spec/dummy/public/422.html +58 -0
- data/spec/dummy/public/500.html +57 -0
- data/spec/dummy/public/favicon.ico +0 -0
- data/spec/dummy/public/robots.txt +5 -0
- data/spec/dummy/vendor/assets/javascripts/.keep +0 -0
- data/spec/dummy/vendor/assets/stylesheets/.keep +0 -0
- data/spec/helpers/mobile_intent_helpers_spec.rb +4 -0
- data/spec/mobile_intent/application_spec.rb +50 -0
- data/spec/mobile_intent/config_spec.rb +17 -0
- data/spec/mobile_intent_spec.rb +17 -0
- data/spec/spec_helper.rb +10 -0
- metadata +259 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 08518e358d8c071b28f56d5d477b930c16d41e99
|
4
|
+
data.tar.gz: 3eac4cc844868ae003910f0636c6b01ee74dc392
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: ba660efd4a51d6a0117c21562a5bfe30a9dc3aadc9236d33786264bd0b59be1ae91066247981a5d339627d32793babff8ff24331f4d748d08ff1f34249ed19ee
|
7
|
+
data.tar.gz: f10ff8598172f5d6f43d642cb22f934c740c1b97ff890706dd9fecbcafb8d601710d8f72905eadb0c8a9d98016bb72d84d2ac408b5b24cfc55f5615cfbcd5a92
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Guardfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 masarakki
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
# MobileIntent
|
2
|
+
|
3
|
+
link to start application.
|
4
|
+
full of fuck'n shit.
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
|
8
|
+
Add this line to your application's Gemfile:
|
9
|
+
|
10
|
+
gem 'mobile_intent'
|
11
|
+
|
12
|
+
And then execute:
|
13
|
+
|
14
|
+
$ bundle
|
15
|
+
|
16
|
+
Or install it yourself as:
|
17
|
+
|
18
|
+
$ gem install mobile_intent
|
19
|
+
|
20
|
+
## Usage
|
21
|
+
|
22
|
+
### setup
|
23
|
+
|
24
|
+
in config/initializer/mobile_intent.rb
|
25
|
+
|
26
|
+
```ruby
|
27
|
+
MobileIntent.setup do
|
28
|
+
register :myapp, :android => 'com.example.myapp', :ios => 'myappname'
|
29
|
+
end
|
30
|
+
```
|
31
|
+
|
32
|
+
### link_to
|
33
|
+
|
34
|
+
in your view
|
35
|
+
|
36
|
+
```ruby
|
37
|
+
<%= launch_app 'open app', :myapp, 'mypage', :class => 'btn' %>
|
38
|
+
|
39
|
+
<%= launch_app :myapp, 'mypage', :class => 'btn' do %>
|
40
|
+
<i class="icon-app" />
|
41
|
+
open app
|
42
|
+
<% end %>
|
43
|
+
```
|
44
|
+
|
45
|
+
it create A-tag to start application with "myapp://mypage" or redirect to store.
|
46
|
+
|
47
|
+
## Contributing
|
48
|
+
|
49
|
+
1. Fork it
|
50
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
51
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
52
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
53
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
class MobileIntent
|
2
|
+
@detect: (ua) ->
|
3
|
+
if ua.match /Android/
|
4
|
+
"android"
|
5
|
+
else if ua.match /iPhone/ || ua.match /iPad/
|
6
|
+
"ios"
|
7
|
+
|
8
|
+
<% MobileIntent.config.apps.each_pair do |name, app| %>
|
9
|
+
@<%= name %> = {
|
10
|
+
<% [:ios, :android].map do |platform| %>
|
11
|
+
<%= "#{platform}: '#{app.market_url(platform)}'" if app.send("#{platform}?") %>
|
12
|
+
<% end %>
|
13
|
+
}
|
14
|
+
<% end %>
|
15
|
+
|
16
|
+
|
17
|
+
$(document).ready ->
|
18
|
+
$(".launch_app").on 'click', (e) ->
|
19
|
+
target = $(e.target)
|
20
|
+
app = target.attr "data-app-scheme"
|
21
|
+
platform = MobileIntent.detect window.navigator.userAgent
|
22
|
+
|
23
|
+
if market_url = MobileIntent[app][platform]
|
24
|
+
e.stopPropagation()
|
25
|
+
e.preventDefault()
|
26
|
+
setTimeout ->
|
27
|
+
window.location = market_url
|
28
|
+
, 500
|
29
|
+
window.location = target.attr "href"
|
30
|
+
false
|
31
|
+
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require "mobile_intent/version"
|
2
|
+
require "mobile_intent/application"
|
3
|
+
require "mobile_intent/config"
|
4
|
+
require "mobile_intent/railtie"
|
5
|
+
require "mobile_intent/engine"
|
6
|
+
|
7
|
+
require "mobile_intent/helpers"
|
8
|
+
|
9
|
+
module MobileIntent
|
10
|
+
def self.config
|
11
|
+
@config ||= Config.new
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.setup(&block)
|
15
|
+
config.instance_exec(&block)
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
module MobileIntent
|
2
|
+
class Application
|
3
|
+
attr_reader :name
|
4
|
+
|
5
|
+
def initialize(name, urls = {})
|
6
|
+
@name = name
|
7
|
+
@ios = urls[:ios]
|
8
|
+
@android = urls[:android]
|
9
|
+
end
|
10
|
+
|
11
|
+
def ios? ; !!@ios ; end
|
12
|
+
def android? ; !!@android ; end
|
13
|
+
|
14
|
+
def android_intent_url(url)
|
15
|
+
raise unless android?
|
16
|
+
"intent://#{url}#Intent;scheme=#{name};package=#{@android};end"
|
17
|
+
end
|
18
|
+
|
19
|
+
def android_market_url
|
20
|
+
raise unless android?
|
21
|
+
"market://details?id=#{@android}"
|
22
|
+
end
|
23
|
+
|
24
|
+
def ios_market_url
|
25
|
+
raise unless ios?
|
26
|
+
"itms://itunes.com/apps/#{@ios}"
|
27
|
+
end
|
28
|
+
|
29
|
+
def market_url(platform)
|
30
|
+
send("#{platform}_market_url")
|
31
|
+
end
|
32
|
+
|
33
|
+
def intent_url(url)
|
34
|
+
"#{name}://#{url}"
|
35
|
+
end
|
36
|
+
|
37
|
+
def launch_url(url, user_agent)
|
38
|
+
if user_agent =~ /Chrome/ && user_agent =~ /Android/
|
39
|
+
android_intent_url(url)
|
40
|
+
else
|
41
|
+
intent_url(url)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module MobileIntent
|
2
|
+
class Config
|
3
|
+
attr_reader :apps
|
4
|
+
|
5
|
+
def initialize
|
6
|
+
@apps = {}
|
7
|
+
end
|
8
|
+
|
9
|
+
def has?(name)
|
10
|
+
@apps.has_key?(name)
|
11
|
+
end
|
12
|
+
|
13
|
+
protected
|
14
|
+
def register(name, urls = {})
|
15
|
+
@apps[name] = Application.new(name, urls)
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module MobileIntent
|
2
|
+
module Helpers
|
3
|
+
def launch_app(*args, &block)
|
4
|
+
if block_given?
|
5
|
+
app_name = args.shift
|
6
|
+
app_path = args.shift
|
7
|
+
else
|
8
|
+
text = args.shift
|
9
|
+
app_name = args.shift
|
10
|
+
app_path = args.shift
|
11
|
+
end
|
12
|
+
app = MobileIntent.config.apps[app_name.to_sym]
|
13
|
+
url = app.launch_url(app_path, request.user_agent)
|
14
|
+
options = args.shift
|
15
|
+
unless request.user_agent =~ /Android/ && request.user_agent =~ /Chrome/
|
16
|
+
options["data-app-scheme"] = app_name
|
17
|
+
if options[:class]
|
18
|
+
options[:class] += ' launch_app'
|
19
|
+
else
|
20
|
+
options[:class] = 'launch_app'
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
if block_given?
|
25
|
+
link_to(url, options, &block)
|
26
|
+
else
|
27
|
+
link_to(text, url, options)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'rails'
|
2
|
+
|
3
|
+
module MobileIntent
|
4
|
+
class Railtie < ::Rails::Railtie
|
5
|
+
initializer "mobile_intent.helpers" do
|
6
|
+
ActiveSupport.on_load(:action_controller) do
|
7
|
+
include MobileIntent::Helpers
|
8
|
+
end
|
9
|
+
|
10
|
+
ActiveSupport.on_load(:action_view) do
|
11
|
+
include MobileIntent::Helpers
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
config.before_configuration do
|
16
|
+
if config.action_view.javascript_expansions
|
17
|
+
config.action_view.javascript_expansions[:defaults] |= ['mobile_intent']
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'mobile_intent/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "mobile_intent"
|
8
|
+
spec.version = MobileIntent::VERSION
|
9
|
+
spec.authors = ["masarakki"]
|
10
|
+
spec.email = ["masaki@hisme.net"]
|
11
|
+
spec.description = %q{start application via custom scheme}
|
12
|
+
spec.summary = %q{start application via custom scheme}
|
13
|
+
spec.homepage = "https://github.com/masarakki/mobile_intent"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_dependency "rails", ">= 3.0", "< 5.0"
|
22
|
+
|
23
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
24
|
+
spec.add_development_dependency "rake"
|
25
|
+
spec.add_development_dependency "rspec"
|
26
|
+
spec.add_development_dependency "rspec-rails"
|
27
|
+
spec.add_development_dependency "sqlite3"
|
28
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# See https://help.github.com/articles/ignoring-files for more about ignoring files.
|
2
|
+
#
|
3
|
+
# If you find yourself ignoring temporary files generated by your text editor
|
4
|
+
# or operating system, you probably want to add a global ignore instead:
|
5
|
+
# git config --global core.excludesfile '~/.gitignore_global'
|
6
|
+
|
7
|
+
# Ignore bundler config.
|
8
|
+
/.bundle
|
9
|
+
|
10
|
+
# Ignore the default SQLite database.
|
11
|
+
/db/*.sqlite3
|
12
|
+
/db/*.sqlite3-journal
|
13
|
+
|
14
|
+
# Ignore all logfiles and tempfiles.
|
15
|
+
/log/*.log
|
16
|
+
/tmp
|
data/spec/dummy/Gemfile
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
source 'https://rubygems.org'
|
2
|
+
|
3
|
+
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
|
4
|
+
gem 'rails', '4.0.1'
|
5
|
+
|
6
|
+
# Use sqlite3 as the database for Active Record
|
7
|
+
gem 'sqlite3'
|
8
|
+
|
9
|
+
# Use SCSS for stylesheets
|
10
|
+
gem 'sass-rails', '~> 4.0.0'
|
11
|
+
|
12
|
+
# Use Uglifier as compressor for JavaScript assets
|
13
|
+
gem 'uglifier', '>= 1.3.0'
|
14
|
+
|
15
|
+
# Use CoffeeScript for .js.coffee assets and views
|
16
|
+
gem 'coffee-rails', '~> 4.0.0'
|
17
|
+
|
18
|
+
# See https://github.com/sstephenson/execjs#readme for more supported runtimes
|
19
|
+
# gem 'therubyracer', platforms: :ruby
|
20
|
+
|
21
|
+
# Use jquery as the JavaScript library
|
22
|
+
gem 'jquery-rails'
|
23
|
+
|
24
|
+
# Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks
|
25
|
+
gem 'turbolinks'
|
26
|
+
|
27
|
+
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
|
28
|
+
gem 'jbuilder', '~> 1.2'
|
29
|
+
|
30
|
+
group :doc do
|
31
|
+
# bundle exec rake doc:rails generates the API under doc/api.
|
32
|
+
gem 'sdoc', require: false
|
33
|
+
end
|
34
|
+
|
35
|
+
# Use ActiveModel has_secure_password
|
36
|
+
# gem 'bcrypt-ruby', '~> 3.1.2'
|
37
|
+
|
38
|
+
# Use unicorn as the app server
|
39
|
+
# gem 'unicorn'
|
40
|
+
|
41
|
+
# Use Capistrano for deployment
|
42
|
+
# gem 'capistrano', group: :development
|
43
|
+
|
44
|
+
# Use debugger
|
45
|
+
# gem 'debugger', group: [:development, :test]
|
46
|
+
gemspec path: File.expand_path('../../../', __FILE__)
|
@@ -0,0 +1,28 @@
|
|
1
|
+
== README
|
2
|
+
|
3
|
+
This README would normally document whatever steps are necessary to get the
|
4
|
+
application up and running.
|
5
|
+
|
6
|
+
Things you may want to cover:
|
7
|
+
|
8
|
+
* Ruby version
|
9
|
+
|
10
|
+
* System dependencies
|
11
|
+
|
12
|
+
* Configuration
|
13
|
+
|
14
|
+
* Database creation
|
15
|
+
|
16
|
+
* Database initialization
|
17
|
+
|
18
|
+
* How to run the test suite
|
19
|
+
|
20
|
+
* Services (job queues, cache servers, search engines, etc.)
|
21
|
+
|
22
|
+
* Deployment instructions
|
23
|
+
|
24
|
+
* ...
|
25
|
+
|
26
|
+
|
27
|
+
Please feel free to use a different markup language if you do not plan to run
|
28
|
+
<tt>rake doc:app</tt>.
|