rails-jquerymobile 0.0.1 → 0.0.3
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/Gemfile +4 -0
- data/README.md +35 -0
- data/init.rb +1 -0
- data/lib/rails-jquerymobile/has_mobile_format.rb +32 -0
- data/lib/rails-jquerymobile/version.rb +1 -1
- data/lib/rails-jquerymobile.rb +19 -0
- data/lib/templates/application.mobile.erb +32 -0
- data/rails-jquerymobile.gemspec +1 -0
- metadata +19 -2
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
JQuery Mobile for Rails
|
2
|
+
=======================
|
3
|
+
|
4
|
+
Adds a :mobile format to a Rails app so that both (desktop) browser optimized and jQuery Mobile optimized pages can be rendered.
|
5
|
+
|
6
|
+
Supports Rails 3.1 (and maybe Rails 3.0?).
|
7
|
+
|
8
|
+
Installation
|
9
|
+
------------
|
10
|
+
|
11
|
+
Include it into your Gemfile:
|
12
|
+
|
13
|
+
gem 'rails-jquerymobile'
|
14
|
+
|
15
|
+
In the relevant controller(s), add:
|
16
|
+
|
17
|
+
has_mobile_format
|
18
|
+
|
19
|
+
Typically, adding this to the ApplicationController is a good idea.
|
20
|
+
|
21
|
+
Now, in order to switch to the mobile site (i.e. the mobile format), use
|
22
|
+
|
23
|
+
mobile=1
|
24
|
+
|
25
|
+
as a query parameter, e.g.:
|
26
|
+
|
27
|
+
http://mysite.com/myresources?mobile=1
|
28
|
+
|
29
|
+
Alternatively, it would be nice if a mobile browser is autodetected, but this is not implemented yet.
|
30
|
+
|
31
|
+
You can generate a mobile format (that uses jQuery Mobile):
|
32
|
+
|
33
|
+
rails generate rails_jquerymobile:layout
|
34
|
+
|
35
|
+
Copyright (c) 2011 Chris, released under the MIT license
|
data/init.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'rails-jquerymobile'
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module HasMobileFormat
|
2
|
+
def self.included(base)
|
3
|
+
base.send :extend, ClassMethods
|
4
|
+
end
|
5
|
+
|
6
|
+
module ClassMethods
|
7
|
+
def has_mobile_format(options = {})
|
8
|
+
send :include, InstanceMethods
|
9
|
+
before_filter :prepare_for_mobile_formats
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
module InstanceMethods
|
14
|
+
def mobile?
|
15
|
+
end
|
16
|
+
# TODO: following should be private?
|
17
|
+
def prepare_for_mobile_formats
|
18
|
+
remember_format(params[:mobile].to_s)
|
19
|
+
puts "before assigning: request.format=#{request.format}, session[:remembered_format]=#{session[:remembered_format]}"
|
20
|
+
format = session[:remembered_format]
|
21
|
+
puts "format=#{format}"
|
22
|
+
request.format = format unless format.blank?
|
23
|
+
puts "request.format=#{request.format}"
|
24
|
+
end
|
25
|
+
def remember_format(format)
|
26
|
+
session[:remembered_format] = :mobile if format == '1'
|
27
|
+
session[:remembered_format] = nil if format == '0'
|
28
|
+
puts "session[:remembered_format]=#{session[:remembered_format]}"
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'rails/generators'
|
2
|
+
require 'rails-jquerymobile/has_mobile_format'
|
3
|
+
|
4
|
+
class RailsJquerymobile::Railtie < Rails::Railtie
|
5
|
+
initializer "RailsJquerymobileRailtie" do
|
6
|
+
Mime::Type.register_alias "text/html", :mobile
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
ActionController::Base.send :include, HasMobileFormat
|
11
|
+
|
12
|
+
class RailsJquerymobile::LayoutGenerator < Rails::Generators::Base
|
13
|
+
source_root File.expand_path("../templates", __FILE__)
|
14
|
+
def create_mobile_layout
|
15
|
+
#create_file "app/views/layouts/application.mobile.erb", "<!-- This may be a layout... -->"
|
16
|
+
copy_file "application.mobile.erb", "app/views/layouts/application.mobile.erb"
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
@@ -0,0 +1,32 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>Mobile Site</title>
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1">
|
6
|
+
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.0/jquery.mobile-1.0.min.css" />
|
7
|
+
<script type="text/javascript" src="http://code.jquery.com/jquery-1.6.4.min.js"></script>
|
8
|
+
<script type="text/javascript" src="http://code.jquery.com/mobile/1.0/jquery.mobile-1.0.min.js"></script>
|
9
|
+
<%# For local testing
|
10
|
+
<link rel="stylesheet" href="/jquery.mobile-1.0.min.css" />
|
11
|
+
<script type="text/javascript" src="/jquery-1.6.4.min.js"></script>
|
12
|
+
<script type="text/javascript" src="/jquery.mobile-1.0.min.js"></script>
|
13
|
+
%>
|
14
|
+
|
15
|
+
</head>
|
16
|
+
<body>
|
17
|
+
<div data-role="page">
|
18
|
+
|
19
|
+
<div data-role="header">
|
20
|
+
<% unless request.referer.blank? %>
|
21
|
+
<a href="#index" data-role="button" data-rel="back" data-icon="arrow-l" data-iconpos="notext">Back</a>
|
22
|
+
<% end %>
|
23
|
+
<h1><%= content_for(:title).blank? ? "Mobile Site" : yield(:title) %></h1>
|
24
|
+
</div>
|
25
|
+
|
26
|
+
<div data-role="content">
|
27
|
+
<%= yield %>
|
28
|
+
</div>
|
29
|
+
|
30
|
+
</div>
|
31
|
+
</body>
|
32
|
+
</html>
|
data/rails-jquerymobile.gemspec
CHANGED
@@ -18,6 +18,7 @@ Gem::Specification.new do |s|
|
|
18
18
|
# s.test_files.reject! { |fn| fn.include? ".swp" }
|
19
19
|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
20
20
|
s.require_paths = ["lib"]
|
21
|
+
s.add_dependency 'rails'
|
21
22
|
# s.add_development_dependency('rspec')
|
22
23
|
[ ].each do |d| # no dependencies right now ;)
|
23
24
|
s.add_development_dependency d
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails-jquerymobile
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,7 +10,18 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
date: 2011-12-20 00:00:00.000000000Z
|
13
|
-
dependencies:
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rails
|
16
|
+
requirement: &2152424580 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *2152424580
|
14
25
|
description: Nuf said.
|
15
26
|
email:
|
16
27
|
- christian.oloff+gem@gmail.com
|
@@ -19,7 +30,13 @@ extensions: []
|
|
19
30
|
extra_rdoc_files: []
|
20
31
|
files:
|
21
32
|
- .gitignore
|
33
|
+
- Gemfile
|
34
|
+
- README.md
|
35
|
+
- init.rb
|
36
|
+
- lib/rails-jquerymobile.rb
|
37
|
+
- lib/rails-jquerymobile/has_mobile_format.rb
|
22
38
|
- lib/rails-jquerymobile/version.rb
|
39
|
+
- lib/templates/application.mobile.erb
|
23
40
|
- rails-jquerymobile.gemspec
|
24
41
|
homepage: http://rails-jquerymobile.org
|
25
42
|
licenses: []
|