radiant-mobile-extension 0.1.4 → 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,4 +1,6 @@
1
1
  Radiant.config do |config|
2
- config.define "mobile.redirect?", :default => true
3
- config.define "mobile.host"
4
- end
2
+ config.namespace('mobile') do |mob|
3
+ mob.define 'host', :allow_blank => true
4
+ mob.define 'redirect?', :default => true
5
+ end
6
+ end
data/lib/mobile_page.rb CHANGED
@@ -1,15 +1,17 @@
1
1
  module MobilePage
2
2
  attr_accessor :mobile
3
3
 
4
+ # The extended site controller calls page.mobile = true if we are in a mobile context
5
+ #
4
6
  def mobile?
5
7
  !!@mobile
6
8
  end
7
-
9
+
8
10
  include Radiant::Taggable
9
11
 
10
12
  desc %{
11
13
  Expands if the url of the current request matches the host name defined in Radiant::Config['mobile.host'].
12
- (or if there is no such definition, if it begins with m.)
14
+ (or if there is no such definition, if the domain begins with m.)
13
15
 
14
16
  *Usage:*
15
17
  <pre><code><r:if_mobile>...</r:if_mobile></code></pre>
@@ -28,4 +30,5 @@ module MobilePage
28
30
  tag 'unless_mobile' do |tag|
29
31
  tag.expand unless mobile?
30
32
  end
33
+
31
34
  end
@@ -1,4 +1,10 @@
1
1
  module MobileSiteController
2
+ #
3
+ # This extends the normal site controller in two ways: if we detect a mobile device,
4
+ # we can redirect to the corresponding page in a mobile site, and if we are on the mobile
5
+ # site we set a flag on the page that radius tags can use to select content.
6
+
7
+
2
8
  # approach and UA strings borrowed from mobile-fu
3
9
  # http://github.com/brendanlim/mobile-fu/tree/master
4
10
  MOBILE_USER_AGENTS = 'palm|blackberry|nokia|phone|midp|mobi|symbian|chtml|ericsson|minimo|' +
@@ -8,23 +14,38 @@ module MobileSiteController
8
14
  'webos|amoi|novarra|cdm|alcatel|pocket|iphone|mobileexplorer|' +
9
15
  'mobile'
10
16
 
17
+ # Returns true if the requested host matches the defined mobile host
18
+ # (or in the absence of such a definition, if the host begins m.)
19
+ #
11
20
  def mobile?
12
- if mobile_host = @config['mobile.host']
21
+ mobile_host = Radiant.config['mobile.host']
22
+ unless mobile_host.blank?
13
23
  request.host == mobile_host
14
24
  else
15
25
  request.host =~ /^m\./
16
26
  end
17
27
  end
18
28
 
29
+ # Returns true if the request comes from a mobile device
30
+ # (based on the supplied user-agent string)
31
+ #
19
32
  def mobile_device?
20
33
  request.user_agent.to_s.downcase =~ Regexp.new(MobileSiteController::MOBILE_USER_AGENTS)
21
34
  end
22
35
 
36
+ # Extends the process_page method to place a 'mobile' flag in the page-rendering
37
+ # context to support presentation choices in radius tags.
38
+ #
23
39
  def process_page_with_mobile(page)
24
40
  page.mobile = mobile?
25
41
  process_page_without_mobile(page)
26
42
  end
27
43
 
44
+ # Issues a redirect to the mobile site if this request comes from a mobile device, and if the
45
+ # mobile site is configured, and if the request does not have a 'nomobile' parameter.
46
+ # If there is a 'nomobile' parameter, a session marker is placed to indicate that the browser
47
+ # should not be redirected in future.
48
+ #
28
49
  def redirect_if_mobile
29
50
  if params['url'] =~ /\?mobile/
30
51
  session[:nomobile] = false
@@ -38,7 +59,7 @@ module MobileSiteController
38
59
  end
39
60
  end
40
61
 
41
- def self.included(base)
62
+ def self.included(base) #:nodoc:
42
63
  base.class_eval do
43
64
  before_filter :redirect_if_mobile
44
65
  alias_method_chain :process_page, :mobile
@@ -0,0 +1,8 @@
1
+ module RadiantMobileExtension
2
+ VERSION = '0.1.5'
3
+ SUMMARY = %q{Provide a mobile version of your radiant site with minimal reworking.}
4
+ DESCRIPTION = %q{This extension provides radius tags and a redirection mechanism that makes it trivially simple to provide a mobile version of your site.}
5
+ URL = "http://github.com/spanner/radiant-mobile-extension"
6
+ AUTHORS = ["William Ross"]
7
+ EMAIL = ["radiant@spanner.org"]
8
+ end
data/mobile_extension.rb CHANGED
@@ -2,9 +2,9 @@
2
2
  # require_dependency 'application_controller'
3
3
 
4
4
  class MobileExtension < Radiant::Extension
5
- version "0.1.4"
6
- description "An easy, cache-friendly mobile version of your site"
7
- url "http://github.com/spanner/radiant-mobile-extension"
5
+ version RadiantMobileExtension::VERSION
6
+ description RadiantMobileExtension::DESCRIPTION
7
+ url RadiantMobileExtension::URL
8
8
 
9
9
  def activate
10
10
  Page.send :include, MobilePage
@@ -1,62 +1,34 @@
1
- # Generated by jeweler
2
- # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
1
  # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "radiant-mobile-extension"
5
4
 
6
5
  Gem::Specification.new do |s|
7
- s.name = %q{radiant-mobile-extension}
8
- s.version = "0.1.4"
6
+ s.name = "radiant-mobile-extension"
7
+ s.version = RadiantMobileExtension::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = RadiantMobileExtension::AUTHORS
10
+ s.email = RadiantMobileExtension::EMAIL
11
+ s.homepage = RadiantMobileExtension::URL
12
+ s.summary = RadiantMobileExtension::SUMMARY
13
+ s.description = RadiantMobileExtension::DESCRIPTION
9
14
 
10
- s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
- s.authors = ["spanner"]
12
- s.date = %q{2010-11-10}
13
- s.description = %q{An easy, flexible, cache-friendly mobile version of your site}
14
- s.email = %q{will@spanner.org}
15
- s.extra_rdoc_files = [
16
- "README.md"
17
- ]
18
- s.files = [
19
- ".gitignore",
20
- "README.md",
21
- "Rakefile",
22
- "VERSION",
23
- "app/views/admin/configuration/_edit_mobile.html.haml",
24
- "app/views/admin/configuration/_mobile.html.haml",
25
- "config/initializers/radiant_config.rb",
26
- "config/locales/en.yml",
27
- "config/routes.rb",
28
- "cucumber.yml",
29
- "features/support/env.rb",
30
- "features/support/paths.rb",
31
- "lib/mobile_page.rb",
32
- "lib/mobile_site_controller.rb",
33
- "lib/tasks/mobile_extension_tasks.rake",
34
- "mobile_extension.rb",
35
- "radiant-mobile-extension.gemspec",
36
- "spec/controllers/mobile_site_controller_spec.rb",
37
- "spec/models/mobile_page_spec.rb",
38
- "spec/spec.opts",
39
- "spec/spec_helper.rb"
40
- ]
41
- s.homepage = %q{http://github.com/spanner/radiant-mobile-extension}
42
- s.rdoc_options = ["--charset=UTF-8"]
43
- s.require_paths = ["lib"]
44
- s.rubygems_version = %q{1.3.7}
45
- s.summary = %q{Mobile Extension for Radiant CMS}
46
- s.test_files = [
47
- "spec/controllers/mobile_site_controller_spec.rb",
48
- "spec/models/mobile_page_spec.rb",
49
- "spec/spec_helper.rb"
50
- ]
51
-
52
- if s.respond_to? :specification_version then
53
- current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
54
- s.specification_version = 3
15
+ s.add_dependency "paperclip", "~> 2.3.16"
55
16
 
56
- if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
57
- else
58
- end
17
+ ignores = if File.exist?('.gitignore')
18
+ File.read('.gitignore').split("\n").inject([]) {|a,p| a + Dir[p] }
59
19
  else
20
+ []
60
21
  end
61
- end
22
+ s.files = Dir['**/*'] - ignores
23
+ s.test_files = Dir['test/**/*','spec/**/*','features/**/*'] - ignores
24
+ # s.executables = Dir['bin/*'] - ignores
25
+ s.require_paths = ["lib"]
26
+
27
+ s.post_install_message = %{
28
+ Add this to your radiant project with a line in your Gemfile:
29
+
30
+ gem 'radiant-mobile-extension', '~> #{RadiantMobileExtension::VERSION}'
31
+
32
+ }
62
33
 
34
+ end
@@ -12,7 +12,7 @@ describe SiteController do
12
12
 
13
13
  describe "responding to a mobile-site request" do
14
14
  before do
15
- request.stub!(:host).and_return(@host)
15
+ request.stub!(:host).and_return("m.test.host")
16
16
  controller.stub!(:find_page).and_return(@page)
17
17
  end
18
18
 
@@ -68,5 +68,4 @@ describe SiteController do
68
68
 
69
69
  end
70
70
  end
71
-
72
71
  end
metadata CHANGED
@@ -1,37 +1,48 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: radiant-mobile-extension
3
3
  version: !ruby/object:Gem::Version
4
- hash: 19
5
- prerelease: false
4
+ hash: 17
5
+ prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 4
10
- version: 0.1.4
9
+ - 5
10
+ version: 0.1.5
11
11
  platform: ruby
12
12
  authors:
13
- - spanner
13
+ - William Ross
14
14
  autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-11-10 00:00:00 +00:00
19
- default_executable:
20
- dependencies: []
21
-
22
- description: An easy, flexible, cache-friendly mobile version of your site
23
- email: will@spanner.org
18
+ date: 2011-10-13 00:00:00 Z
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: paperclip
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ~>
27
+ - !ruby/object:Gem::Version
28
+ hash: 35
29
+ segments:
30
+ - 2
31
+ - 3
32
+ - 16
33
+ version: 2.3.16
34
+ type: :runtime
35
+ version_requirements: *id001
36
+ description: This extension provides radius tags and a redirection mechanism that makes it trivially simple to provide a mobile version of your site.
37
+ email:
38
+ - radiant@spanner.org
24
39
  executables: []
25
40
 
26
41
  extensions: []
27
42
 
28
- extra_rdoc_files:
29
- - README.md
43
+ extra_rdoc_files: []
44
+
30
45
  files:
31
- - .gitignore
32
- - README.md
33
- - Rakefile
34
- - VERSION
35
46
  - app/views/admin/configuration/_edit_mobile.html.haml
36
47
  - app/views/admin/configuration/_mobile.html.haml
37
48
  - config/initializers/radiant_config.rb
@@ -42,20 +53,24 @@ files:
42
53
  - features/support/paths.rb
43
54
  - lib/mobile_page.rb
44
55
  - lib/mobile_site_controller.rb
56
+ - lib/radiant-mobile-extension.rb
45
57
  - lib/tasks/mobile_extension_tasks.rake
46
58
  - mobile_extension.rb
59
+ - radiant-mobile-extension-0.1.5.gem
47
60
  - radiant-mobile-extension.gemspec
61
+ - Rakefile
62
+ - README.md
48
63
  - spec/controllers/mobile_site_controller_spec.rb
49
64
  - spec/models/mobile_page_spec.rb
50
65
  - spec/spec.opts
51
66
  - spec/spec_helper.rb
52
- has_rdoc: true
67
+ - VERSION
53
68
  homepage: http://github.com/spanner/radiant-mobile-extension
54
69
  licenses: []
55
70
 
56
- post_install_message:
57
- rdoc_options:
58
- - --charset=UTF-8
71
+ post_install_message: "\n Add this to your radiant project with a line in your Gemfile:\n\n gem 'radiant-mobile-extension', '~> 0.1.5'\n\n "
72
+ rdoc_options: []
73
+
59
74
  require_paths:
60
75
  - lib
61
76
  required_ruby_version: !ruby/object:Gem::Requirement
@@ -79,11 +94,14 @@ required_rubygems_version: !ruby/object:Gem::Requirement
79
94
  requirements: []
80
95
 
81
96
  rubyforge_project:
82
- rubygems_version: 1.3.7
97
+ rubygems_version: 1.8.10
83
98
  signing_key:
84
99
  specification_version: 3
85
- summary: Mobile Extension for Radiant CMS
100
+ summary: Provide a mobile version of your radiant site with minimal reworking.
86
101
  test_files:
87
102
  - spec/controllers/mobile_site_controller_spec.rb
88
103
  - spec/models/mobile_page_spec.rb
104
+ - spec/spec.opts
89
105
  - spec/spec_helper.rb
106
+ - features/support/env.rb
107
+ - features/support/paths.rb
data/.gitignore DELETED
@@ -1 +0,0 @@
1
- pkg/*