sniffux 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +40 -0
- data/Rakefile +1 -0
- data/lib/sniffux.rb +69 -0
- data/lib/sniffux/action_controller.rb +19 -0
- data/lib/sniffux/version.rb +3 -0
- data/sniffux.gemspec +21 -0
- metadata +71 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Simon George
|
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,40 @@
|
|
1
|
+
# Sniffux
|
2
|
+
|
3
|
+
Use user-agent string to reason about UX expectations. E.g. Should the Cancel button in dialigues be on the left or the right? You may then use this information to serve your users a version of your site that matches their expectations and is consistent with the UX they are used to.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'sniffux'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install sniffux
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
Rails:
|
22
|
+
|
23
|
+
<div id="alert" class="cancel-on-#{sniffux.cancel_side}">
|
24
|
+
|
25
|
+
Other framework:
|
26
|
+
|
27
|
+
sniffux = Sniffux.new(request.user_agent)
|
28
|
+
if sniffux.cancel_left?
|
29
|
+
'Cancel button is on the left!!1'
|
30
|
+
else
|
31
|
+
'Cancel button is on the anti-left xoxo'
|
32
|
+
end
|
33
|
+
|
34
|
+
## Contributing
|
35
|
+
|
36
|
+
1. Fork it
|
37
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
38
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
39
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
40
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/lib/sniffux.rb
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
require "sniffux/version"
|
2
|
+
require "user_agent"
|
3
|
+
|
4
|
+
class Sniffux
|
5
|
+
# Add Rails helper if ActionController::Base is available
|
6
|
+
require "sniffux/action_controller" if defined?(ActionController::Base)
|
7
|
+
|
8
|
+
def initialize(string)
|
9
|
+
@user_agent = UserAgent.parse(string)
|
10
|
+
end
|
11
|
+
|
12
|
+
def cancel_left?
|
13
|
+
# OS X, iOS, Linux, ChromeOS, WebOS, Haiku
|
14
|
+
# Default because it's better:
|
15
|
+
# http://uxmovement.com/buttons/why-ok-buttons-in-dialog-boxes-work-best-on-the-right/
|
16
|
+
!cancel_right?
|
17
|
+
end
|
18
|
+
|
19
|
+
def cancel_right?
|
20
|
+
# Windows, Android, Amiga (AROS)
|
21
|
+
%w(Windows).include?(@user_agent.platform) ||
|
22
|
+
%w(AROS).include?(@user_agent.os) ||
|
23
|
+
!!(@user_agent.os =~ /Android/)
|
24
|
+
end
|
25
|
+
|
26
|
+
def cancel_side
|
27
|
+
if cancel_right?
|
28
|
+
'right'
|
29
|
+
else
|
30
|
+
'left'
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def ok_left?
|
35
|
+
cancel_right?
|
36
|
+
end
|
37
|
+
|
38
|
+
def ok_right?
|
39
|
+
cancel_left?
|
40
|
+
end
|
41
|
+
|
42
|
+
def ok_side
|
43
|
+
if ok_right?
|
44
|
+
'right'
|
45
|
+
else
|
46
|
+
'left'
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def close_left?
|
51
|
+
# OS X, iOS, Linux (Ubuntu, can vary), Haiku, Amiga
|
52
|
+
# Default because it matches having Cancel on the left
|
53
|
+
!close_right?
|
54
|
+
end
|
55
|
+
|
56
|
+
def close_right?
|
57
|
+
# Windows, ChromeOS
|
58
|
+
%w(Windows).include?(@user_agent.platform) ||
|
59
|
+
!!(@user_agent.os =~ /CrOS/)
|
60
|
+
end
|
61
|
+
|
62
|
+
def close_side
|
63
|
+
if close_right?
|
64
|
+
'right'
|
65
|
+
else
|
66
|
+
'left'
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
class Sniffux
|
2
|
+
module ActionController # :nodoc: all
|
3
|
+
def self.included(base)
|
4
|
+
base.send :helper_method, :browser
|
5
|
+
end
|
6
|
+
|
7
|
+
private
|
8
|
+
def sniffux
|
9
|
+
@sniffux ||= Sniffux.new(
|
10
|
+
#:accept_language => request.headers["Accept-Language"],
|
11
|
+
#:ua => request.headers["User-Agent"]
|
12
|
+
|
13
|
+
request.user_agent
|
14
|
+
)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
ActionController::Base.send :include, Browser::ActionController
|
data/sniffux.gemspec
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'sniffux/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = "sniffux"
|
8
|
+
gem.version = Sniffux::VERSION
|
9
|
+
gem.authors = ["Simon George"]
|
10
|
+
gem.email = ["simon@sfcgeorge.co.uk"]
|
11
|
+
gem.description = %q{Use user-agent string to reason about UX expectations. E.g. Should the Cancel button in dialigues be on the left or the right?}
|
12
|
+
gem.summary = %q{Reason about UX expectations.}
|
13
|
+
gem.homepage = "http://www.sfcgeorge.co.uk/posts/2013/04/20/enhancing-web-ux-consistency-sniffux"
|
14
|
+
|
15
|
+
gem.files = `git ls-files`.split($/)
|
16
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
17
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
|
+
gem.require_paths = ["lib"]
|
19
|
+
|
20
|
+
gem.add_runtime_dependency "useragent", "~> 0.5.0"
|
21
|
+
end
|
metadata
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: sniffux
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Simon George
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-04-21 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: useragent
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 0.5.0
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 0.5.0
|
30
|
+
description: Use user-agent string to reason about UX expectations. E.g. Should the
|
31
|
+
Cancel button in dialigues be on the left or the right?
|
32
|
+
email:
|
33
|
+
- simon@sfcgeorge.co.uk
|
34
|
+
executables: []
|
35
|
+
extensions: []
|
36
|
+
extra_rdoc_files: []
|
37
|
+
files:
|
38
|
+
- .gitignore
|
39
|
+
- Gemfile
|
40
|
+
- LICENSE.txt
|
41
|
+
- README.md
|
42
|
+
- Rakefile
|
43
|
+
- lib/sniffux.rb
|
44
|
+
- lib/sniffux/action_controller.rb
|
45
|
+
- lib/sniffux/version.rb
|
46
|
+
- sniffux.gemspec
|
47
|
+
homepage: http://www.sfcgeorge.co.uk/posts/2013/04/20/enhancing-web-ux-consistency-sniffux
|
48
|
+
licenses: []
|
49
|
+
post_install_message:
|
50
|
+
rdoc_options: []
|
51
|
+
require_paths:
|
52
|
+
- lib
|
53
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
54
|
+
none: false
|
55
|
+
requirements:
|
56
|
+
- - ! '>='
|
57
|
+
- !ruby/object:Gem::Version
|
58
|
+
version: '0'
|
59
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
60
|
+
none: false
|
61
|
+
requirements:
|
62
|
+
- - ! '>='
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
version: '0'
|
65
|
+
requirements: []
|
66
|
+
rubyforge_project:
|
67
|
+
rubygems_version: 1.8.24
|
68
|
+
signing_key:
|
69
|
+
specification_version: 3
|
70
|
+
summary: Reason about UX expectations.
|
71
|
+
test_files: []
|