crispy-mobile 0.1.0
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.
- data/MIT-LICENSE +20 -0
- data/README.md +67 -0
- data/lib/crispy-mobile/device.rb +47 -0
- data/lib/crispy-mobile/helpers.rb +19 -0
- data/lib/crispy-mobile/railtie.rb +9 -0
- data/lib/crispy-mobile.rb +4 -0
- metadata +87 -0
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2012 Christian Peters
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,67 @@
|
|
1
|
+
# Crispy Mobile
|
2
|
+
|
3
|
+
## What does it do?
|
4
|
+
|
5
|
+
Crispy Mobile empowers your Rails application with easy-accessible device-detection.
|
6
|
+
In your controller or view, you can access device properties or add switches like:
|
7
|
+
|
8
|
+
``` haml
|
9
|
+
- if device == :desktop
|
10
|
+
= stylesheet_link_tag :desktop
|
11
|
+
- else
|
12
|
+
= stylesheet_link_tag :mobile
|
13
|
+
|
14
|
+
= image_tag @photo.dynamic_url(device > :handheld_480 ? '600x400' : '300x200')
|
15
|
+
|
16
|
+
= image_tag @photo.dynamic_url("#{device.display_width}x")
|
17
|
+
```
|
18
|
+
|
19
|
+
## Why should my app be responsive on the server side?
|
20
|
+
|
21
|
+
CSS media queries are nice. But not for mobile.
|
22
|
+
|
23
|
+
They just add up code you send to your clients instead of reducing it
|
24
|
+
for mobile devices.
|
25
|
+
|
26
|
+
Imagine you want to make a responsive product page.
|
27
|
+
|
28
|
+
* Do you really want to deliver a big 90KB product photo, if a
|
29
|
+
15KB photo would already fill the mobile screen?
|
30
|
+
* Do you really want to compute personalized product recommendations if
|
31
|
+
they are just hidden afterwards?
|
32
|
+
* Do you really want mobile devices to download and interpret your whole
|
33
|
+
stylesheet if half of the interface elements are going to be hidden anyway?
|
34
|
+
|
35
|
+
You don't.
|
36
|
+
|
37
|
+
If you start mobile-first, don't let your mobile performance be affected by
|
38
|
+
additional desktop features.
|
39
|
+
|
40
|
+
Be kind, serve the clients exactly what they need.
|
41
|
+
|
42
|
+
### How is it done?
|
43
|
+
|
44
|
+
A middleware is introduced which looks up the user agent string in the
|
45
|
+
[WURFL repository](http://wurfl.sourceforge.net/).
|
46
|
+
|
47
|
+
## Usage
|
48
|
+
|
49
|
+
Pending. Please have a look at the source.
|
50
|
+
|
51
|
+
## Installation
|
52
|
+
|
53
|
+
In your Gemfile add:
|
54
|
+
|
55
|
+
``` ruby
|
56
|
+
gem 'crispy-mobile'
|
57
|
+
```
|
58
|
+
|
59
|
+
In your ApplicationController add:
|
60
|
+
|
61
|
+
``` ruby
|
62
|
+
include Crispy::DeviceHelpers
|
63
|
+
```
|
64
|
+
|
65
|
+
## License
|
66
|
+
|
67
|
+
See MIT-LICENSE.
|
@@ -0,0 +1,47 @@
|
|
1
|
+
module Crispy
|
2
|
+
|
3
|
+
class Device
|
4
|
+
include Comparable
|
5
|
+
|
6
|
+
attr_accessor :profile
|
7
|
+
attr_accessor :display_width
|
8
|
+
|
9
|
+
SUPPORTED_DISPLAY_WIDTHS = {handheld_320: 320, handheld_640: 640, desktop: 950}
|
10
|
+
|
11
|
+
def initialize(profile)
|
12
|
+
self.profile = profile
|
13
|
+
self.display_width = profile.resolution_width
|
14
|
+
end
|
15
|
+
|
16
|
+
def to_s
|
17
|
+
profile[:id]
|
18
|
+
end
|
19
|
+
|
20
|
+
def <=>(other)
|
21
|
+
raise "Comparison of devices failed. Tried to compare #{self} with nil." if other.nil?
|
22
|
+
|
23
|
+
other_width = if other.respond_to? :display_width
|
24
|
+
other.display_width
|
25
|
+
elsif other.respond_to?(:to_i) && other.to_i.integer?
|
26
|
+
other.to_i
|
27
|
+
elsif SUPPORTED_DISPLAY_WIDTHS.has_key? other
|
28
|
+
SUPPORTED_DISPLAY_WIDTHS[other]
|
29
|
+
end
|
30
|
+
|
31
|
+
raise "Comparison of devices failed. No valid display_width can be infered from #{other}." unless other_width && other_width > 0
|
32
|
+
display_width <=> other_width
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
class DesktopDevice < Device
|
37
|
+
def initialize(profile = WURFL::Hash.new)
|
38
|
+
profile.reverse_merge! resolution_width: display_width, id: 'desktop'
|
39
|
+
super(profile)
|
40
|
+
end
|
41
|
+
|
42
|
+
def display_width
|
43
|
+
SUPPORTED_DISPLAY_WIDTHS[:desktop] || 1024
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Crispy
|
2
|
+
|
3
|
+
module DeviceHelpers
|
4
|
+
|
5
|
+
def device
|
6
|
+
if request.env['WURFL'].nil?
|
7
|
+
@device ||= DesktopDevice.new
|
8
|
+
else
|
9
|
+
@device ||= Device.new(request.env['WURFL'])
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
ActiveSupport.on_load(:action_controller) do
|
14
|
+
helper_method :device
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
metadata
ADDED
@@ -0,0 +1,87 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: crispy-mobile
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 27
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
- 0
|
10
|
+
version: 0.1.0
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Christian Peters
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2012-02-18 00:00:00 +01:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: wurfl-lite-middleware
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 27
|
30
|
+
segments:
|
31
|
+
- 1
|
32
|
+
- 0
|
33
|
+
- 6
|
34
|
+
version: 1.0.6
|
35
|
+
type: :runtime
|
36
|
+
version_requirements: *id001
|
37
|
+
description: CSS Media Requeries are a nice idea but don't cut down payload size. Serve only what is needed for each device. This gem lets you access device information in a Rails controller/view. Now be really responsive!
|
38
|
+
email: info@c-peters.net
|
39
|
+
executables: []
|
40
|
+
|
41
|
+
extensions: []
|
42
|
+
|
43
|
+
extra_rdoc_files: []
|
44
|
+
|
45
|
+
files:
|
46
|
+
- README.md
|
47
|
+
- MIT-LICENSE
|
48
|
+
- lib/crispy-mobile/device.rb
|
49
|
+
- lib/crispy-mobile/helpers.rb
|
50
|
+
- lib/crispy-mobile/railtie.rb
|
51
|
+
- lib/crispy-mobile.rb
|
52
|
+
has_rdoc: true
|
53
|
+
homepage: https://github.com/ChristianPeters/crispy-mobile
|
54
|
+
licenses: []
|
55
|
+
|
56
|
+
post_install_message:
|
57
|
+
rdoc_options: []
|
58
|
+
|
59
|
+
require_paths:
|
60
|
+
- lib
|
61
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
62
|
+
none: false
|
63
|
+
requirements:
|
64
|
+
- - ">="
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
hash: 3
|
67
|
+
segments:
|
68
|
+
- 0
|
69
|
+
version: "0"
|
70
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
71
|
+
none: false
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
hash: 3
|
76
|
+
segments:
|
77
|
+
- 0
|
78
|
+
version: "0"
|
79
|
+
requirements: []
|
80
|
+
|
81
|
+
rubyforge_project:
|
82
|
+
rubygems_version: 1.3.7
|
83
|
+
signing_key:
|
84
|
+
specification_version: 3
|
85
|
+
summary: Crispy Mobile tells you which device requests your Rails page. Be responsive on the server side!
|
86
|
+
test_files: []
|
87
|
+
|