radiant-mobile-extension 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/README.md +91 -0
- data/Rakefile +136 -0
- data/app/views/admin/configuration/_edit_mobile.html.haml +7 -0
- data/app/views/admin/configuration/_mobile.html.haml +6 -0
- data/config/initializers/radiant_config.rb +4 -0
- data/config/locales/en.yml +9 -0
- data/config/routes.rb +5 -0
- data/cucumber.yml +1 -0
- data/features/support/env.rb +16 -0
- data/features/support/paths.rb +14 -0
- data/lib/mobile_page.rb +31 -0
- data/lib/mobile_site_controller.rb +46 -0
- data/lib/tasks/mobile_extension_tasks.rake +55 -0
- data/mobile_extension.rb +16 -0
- data/spec/controllers/mobile_site_controller_spec.rb +72 -0
- data/spec/models/mobile_page_spec.rb +14 -0
- data/spec/spec.opts +6 -0
- data/spec/spec_helper.rb +36 -0
- metadata +86 -0
data/README.md
ADDED
@@ -0,0 +1,91 @@
|
|
1
|
+
# Mobile
|
2
|
+
|
3
|
+
This very simple extension allows you to offer a cache-friendly mobile version of your radiant site.
|
4
|
+
|
5
|
+
## Basic usage
|
6
|
+
|
7
|
+
1. Any request to a host whose address begins 'm.' is considered to be a request for the mobile site. If you want to use a different address, put its hostname in 'mobile.host'. You can do that through the admin settings interface.
|
8
|
+
|
9
|
+
2. Set 'mobile.redirect?' to true and put the full hostname in 'mobile.hostname' if you want to bounce iphone and other mobile users to your mobile site when they first arrive.
|
10
|
+
|
11
|
+
3. Provide a link back to your main site by appending ?nomobile. We will skip the redirect on that request and set a session flag that will carry on blocking it for future requests.
|
12
|
+
|
13
|
+
4. Use the radius tags `<r:if_mobile_>` and `<r:unless_mobile>` to make layout or content decisions based on whether this is a request for the mobile site.
|
14
|
+
|
15
|
+
## Possibly AQ
|
16
|
+
|
17
|
+
### Why not just set :format (or use mobile-fu)?
|
18
|
+
|
19
|
+
* Because radiant renders pages within the model, using layouts chosen by association. The rails layout is always the same and there is no show-page template in the usual sense.
|
20
|
+
|
21
|
+
### Why not just detect mobile devices?
|
22
|
+
|
23
|
+
* We can give visitors more control this way.
|
24
|
+
* We can't deliver variant pages through the cache: different versions of the same page must have different addresses.
|
25
|
+
|
26
|
+
## Building a mobile site
|
27
|
+
|
28
|
+
It's up to you how broadly the mobile context affects your site delivery. Here are some likely scenarios:
|
29
|
+
|
30
|
+
### Omitted content
|
31
|
+
|
32
|
+
<r:unless_mobile>
|
33
|
+
<r:content part="sidebar" />
|
34
|
+
<r:unless_mobile>
|
35
|
+
|
36
|
+
### Different CSS
|
37
|
+
|
38
|
+
<r:if_mobile>
|
39
|
+
<r:stylesheet slug="mobile.css" as="link" />
|
40
|
+
</r:if_mobile>
|
41
|
+
<r:unless_mobile>
|
42
|
+
<r:stylesheet slug="standard.css" as="link" />
|
43
|
+
<r:unless_mobile>
|
44
|
+
|
45
|
+
### Different content
|
46
|
+
|
47
|
+
<r:if_mobile>
|
48
|
+
<r:content part="iphone" />
|
49
|
+
</r:if_mobile>
|
50
|
+
<r:unless_mobile>
|
51
|
+
<r:content />
|
52
|
+
<r:unless_mobile>
|
53
|
+
|
54
|
+
### Different page components
|
55
|
+
|
56
|
+
<r:if_mobile>
|
57
|
+
<r:snippet name="mobile_masthead" />
|
58
|
+
</r:if_mobile>
|
59
|
+
<r:unless_mobile>
|
60
|
+
<r:snippet name="standard_masthead" />
|
61
|
+
</r:unless_mobile>
|
62
|
+
|
63
|
+
### Different layout
|
64
|
+
|
65
|
+
With the `layouts` or `nested_layouts` extension you could create a simple layout-chooser layout. I haven't tried it, but this ought to work:
|
66
|
+
|
67
|
+
<r:if_mobile>
|
68
|
+
<r:inside_layout name="Mobile">
|
69
|
+
<r:content_for_layout />
|
70
|
+
</r:inside_layout>
|
71
|
+
</r:if_mobile>
|
72
|
+
<r:unless_mobile>
|
73
|
+
<r:inside_layout name="Standard">
|
74
|
+
<r:content_for_layout />
|
75
|
+
</r:inside_layout>
|
76
|
+
</r:unless_mobile>
|
77
|
+
|
78
|
+
## Status
|
79
|
+
|
80
|
+
Brand new and not well tested, but there's not much to it.
|
81
|
+
|
82
|
+
## Bugs and comments
|
83
|
+
|
84
|
+
Github issues, please, or write to Will.
|
85
|
+
|
86
|
+
## Author and copyright
|
87
|
+
|
88
|
+
* Copyright spanner ltd 2010.
|
89
|
+
* Released under the same terms as Rails and/or Radiant.
|
90
|
+
* Contact will at spanner.org
|
91
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,136 @@
|
|
1
|
+
begin
|
2
|
+
require 'jeweler'
|
3
|
+
Jeweler::Tasks.new do |gem|
|
4
|
+
gem.name = "radiant-mobile-extension"
|
5
|
+
gem.summary = %Q{Mobile Extension for Radiant CMS}
|
6
|
+
gem.description = %Q{An easy, flexible, cache-friendly mobile version of your site}
|
7
|
+
gem.email = "will@spanner.org"
|
8
|
+
gem.homepage = "http://github.com/spanner/radiant-mobile-extension"
|
9
|
+
gem.authors = ["spanner"]
|
10
|
+
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
11
|
+
end
|
12
|
+
rescue LoadError
|
13
|
+
puts "Jeweler (or a dependency) not available. This is only required if you plan to package mobile as a gem."
|
14
|
+
end
|
15
|
+
|
16
|
+
# In rails 1.2, plugins aren't available in the path until they're loaded.
|
17
|
+
# Check to see if the rspec plugin is installed first and require
|
18
|
+
# it if it is. If not, use the gem version.
|
19
|
+
|
20
|
+
# Determine where the RSpec plugin is by loading the boot
|
21
|
+
unless defined? RADIANT_ROOT
|
22
|
+
ENV["RAILS_ENV"] = "test"
|
23
|
+
case
|
24
|
+
when ENV["RADIANT_ENV_FILE"]
|
25
|
+
require File.dirname(ENV["RADIANT_ENV_FILE"]) + "/boot"
|
26
|
+
when File.dirname(__FILE__) =~ %r{vendor/radiant/vendor/extensions}
|
27
|
+
require "#{File.expand_path(File.dirname(__FILE__) + "/../../../../../")}/config/boot"
|
28
|
+
else
|
29
|
+
require "#{File.expand_path(File.dirname(__FILE__) + "/../../../")}/config/boot"
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
require 'rake'
|
34
|
+
require 'rake/rdoctask'
|
35
|
+
require 'rake/testtask'
|
36
|
+
|
37
|
+
rspec_base = File.expand_path(RADIANT_ROOT + '/vendor/plugins/rspec/lib')
|
38
|
+
$LOAD_PATH.unshift(rspec_base) if File.exist?(rspec_base)
|
39
|
+
require 'spec/rake/spectask'
|
40
|
+
require 'cucumber'
|
41
|
+
require 'cucumber/rake/task'
|
42
|
+
|
43
|
+
# Cleanup the RADIANT_ROOT constant so specs will load the environment
|
44
|
+
Object.send(:remove_const, :RADIANT_ROOT)
|
45
|
+
|
46
|
+
extension_root = File.expand_path(File.dirname(__FILE__))
|
47
|
+
|
48
|
+
task :default => :spec
|
49
|
+
task :stats => "spec:statsetup"
|
50
|
+
|
51
|
+
desc "Run all specs in spec directory"
|
52
|
+
Spec::Rake::SpecTask.new(:spec) do |t|
|
53
|
+
t.spec_opts = ['--options', "\"#{extension_root}/spec/spec.opts\""]
|
54
|
+
t.spec_files = FileList['spec/**/*_spec.rb']
|
55
|
+
end
|
56
|
+
|
57
|
+
task :features => 'spec:integration'
|
58
|
+
|
59
|
+
namespace :spec do
|
60
|
+
desc "Run all specs in spec directory with RCov"
|
61
|
+
Spec::Rake::SpecTask.new(:rcov) do |t|
|
62
|
+
t.spec_opts = ['--options', "\"#{extension_root}/spec/spec.opts\""]
|
63
|
+
t.spec_files = FileList['spec/**/*_spec.rb']
|
64
|
+
t.rcov = true
|
65
|
+
t.rcov_opts = ['--exclude', 'spec', '--rails']
|
66
|
+
end
|
67
|
+
|
68
|
+
desc "Print Specdoc for all specs"
|
69
|
+
Spec::Rake::SpecTask.new(:doc) do |t|
|
70
|
+
t.spec_opts = ["--format", "specdoc", "--dry-run"]
|
71
|
+
t.spec_files = FileList['spec/**/*_spec.rb']
|
72
|
+
end
|
73
|
+
|
74
|
+
[:models, :controllers, :views, :helpers].each do |sub|
|
75
|
+
desc "Run the specs under spec/#{sub}"
|
76
|
+
Spec::Rake::SpecTask.new(sub) do |t|
|
77
|
+
t.spec_opts = ['--options', "\"#{extension_root}/spec/spec.opts\""]
|
78
|
+
t.spec_files = FileList["spec/#{sub}/**/*_spec.rb"]
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
desc "Run the Cucumber features"
|
83
|
+
Cucumber::Rake::Task.new(:integration) do |t|
|
84
|
+
t.fork = true
|
85
|
+
t.cucumber_opts = ['--format', (ENV['CUCUMBER_FORMAT'] || 'pretty')]
|
86
|
+
# t.feature_pattern = "#{extension_root}/features/**/*.feature"
|
87
|
+
t.profile = "default"
|
88
|
+
end
|
89
|
+
|
90
|
+
# Setup specs for stats
|
91
|
+
task :statsetup do
|
92
|
+
require 'code_statistics'
|
93
|
+
::STATS_DIRECTORIES << %w(Model\ specs spec/models)
|
94
|
+
::STATS_DIRECTORIES << %w(View\ specs spec/views)
|
95
|
+
::STATS_DIRECTORIES << %w(Controller\ specs spec/controllers)
|
96
|
+
::STATS_DIRECTORIES << %w(Helper\ specs spec/views)
|
97
|
+
::CodeStatistics::TEST_TYPES << "Model specs"
|
98
|
+
::CodeStatistics::TEST_TYPES << "View specs"
|
99
|
+
::CodeStatistics::TEST_TYPES << "Controller specs"
|
100
|
+
::CodeStatistics::TEST_TYPES << "Helper specs"
|
101
|
+
::STATS_DIRECTORIES.delete_if {|a| a[0] =~ /test/}
|
102
|
+
end
|
103
|
+
|
104
|
+
namespace :db do
|
105
|
+
namespace :fixtures do
|
106
|
+
desc "Load fixtures (from spec/fixtures) into the current environment's database. Load specific fixtures using FIXTURES=x,y"
|
107
|
+
task :load => :environment do
|
108
|
+
require 'active_record/fixtures'
|
109
|
+
ActiveRecord::Base.establish_connection(RAILS_ENV.to_sym)
|
110
|
+
(ENV['FIXTURES'] ? ENV['FIXTURES'].split(/,/) : Dir.glob(File.join(RAILS_ROOT, 'spec', 'fixtures', '*.{yml,csv}'))).each do |fixture_file|
|
111
|
+
Fixtures.create_fixtures('spec/fixtures', File.basename(fixture_file, '.*'))
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
desc 'Generate documentation for the mobile extension.'
|
119
|
+
Rake::RDocTask.new(:rdoc) do |rdoc|
|
120
|
+
rdoc.rdoc_dir = 'rdoc'
|
121
|
+
rdoc.title = 'MobileExtension'
|
122
|
+
rdoc.options << '--line-numbers' << '--inline-source'
|
123
|
+
rdoc.rdoc_files.include('README')
|
124
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
125
|
+
end
|
126
|
+
|
127
|
+
# For extensions that are in transition
|
128
|
+
desc 'Test the mobile extension.'
|
129
|
+
Rake::TestTask.new(:test) do |t|
|
130
|
+
t.libs << 'lib'
|
131
|
+
t.pattern = 'test/**/*_test.rb'
|
132
|
+
t.verbose = true
|
133
|
+
end
|
134
|
+
|
135
|
+
# Load any custom rakefiles for extension
|
136
|
+
Dir[File.dirname(__FILE__) + '/tasks/*.rake'].sort.each { |f| require f }
|
data/config/routes.rb
ADDED
data/cucumber.yml
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
default: --format progress features --tags ~@proposed,~@in_progress
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# Sets up the Rails environment for Cucumber
|
2
|
+
ENV["RAILS_ENV"] = "test"
|
3
|
+
# Extension root
|
4
|
+
extension_env = File.expand_path(File.dirname(__FILE__) + '/../../../../../config/environment')
|
5
|
+
require extension_env+'.rb'
|
6
|
+
|
7
|
+
Dir.glob(File.join(RADIANT_ROOT, "features", "**", "*.rb")).each {|step| require step}
|
8
|
+
|
9
|
+
Cucumber::Rails::World.class_eval do
|
10
|
+
include Dataset
|
11
|
+
datasets_directory "#{RADIANT_ROOT}/spec/datasets"
|
12
|
+
Dataset::Resolver.default = Dataset::DirectoryResolver.new("#{RADIANT_ROOT}/spec/datasets", File.dirname(__FILE__) + '/../../spec/datasets', File.dirname(__FILE__) + '/../datasets')
|
13
|
+
self.datasets_database_dump_path = "#{Rails.root}/tmp/dataset"
|
14
|
+
|
15
|
+
# dataset :mobile
|
16
|
+
end
|
data/lib/mobile_page.rb
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
module MobilePage
|
2
|
+
attr_accessor :mobile
|
3
|
+
|
4
|
+
def mobile?
|
5
|
+
!!@mobile
|
6
|
+
end
|
7
|
+
|
8
|
+
include Radiant::Taggable
|
9
|
+
|
10
|
+
desc %{
|
11
|
+
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.)
|
13
|
+
|
14
|
+
*Usage:*
|
15
|
+
<pre><code><r:if_mobile>...</r:if_mobile></code></pre>
|
16
|
+
}
|
17
|
+
tag 'if_mobile' do |tag|
|
18
|
+
tag.expand if mobile?
|
19
|
+
end
|
20
|
+
|
21
|
+
desc %{
|
22
|
+
Expands unless the url of the current request matches the host name defined in Radiant::Config['mobile.host'].
|
23
|
+
(or if there is no such definition, unless it begins with m.)
|
24
|
+
|
25
|
+
*Usage:*
|
26
|
+
<pre><code><r:unless_mobile>...</r:unless_mobile></code></pre>
|
27
|
+
}
|
28
|
+
tag 'unless_mobile' do |tag|
|
29
|
+
tag.expand if mobile?
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
module MobileSiteController
|
2
|
+
# appraoch and UA strings borrowed from mobile-fu
|
3
|
+
# http://github.com/brendanlim/mobile-fu/tree/master
|
4
|
+
MOBILE_USER_AGENTS = 'palm|blackberry|nokia|phone|midp|mobi|symbian|chtml|ericsson|minimo|' +
|
5
|
+
'audiovox|motorola|samsung|telit|upg1|windows ce|ucweb|astel|plucker|' +
|
6
|
+
'x320|x240|j2me|sgh|portable|sprint|docomo|kddi|softbank|android|mmp|' +
|
7
|
+
'pdxgw|netfront|xiino|vodafone|portalmmm|sagem|mot-|sie-|ipod|up\\.b|' +
|
8
|
+
'webos|amoi|novarra|cdm|alcatel|pocket|ipad|iphone|mobileexplorer|' +
|
9
|
+
'mobile'
|
10
|
+
|
11
|
+
def mobile?
|
12
|
+
if mobile_host = @config['mobile.host']
|
13
|
+
request.host == mobile_host
|
14
|
+
else
|
15
|
+
request.host =~ /^m\./
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def mobile_device?
|
20
|
+
request.user_agent.to_s.downcase =~ Regexp.new(MobileSiteController::MOBILE_USER_AGENTS)
|
21
|
+
end
|
22
|
+
|
23
|
+
def process_page_with_mobile(page)
|
24
|
+
page.mobile = mobile?
|
25
|
+
process_page_without_mobile(page)
|
26
|
+
end
|
27
|
+
|
28
|
+
def redirect_if_mobile
|
29
|
+
if params['url'] =~ /\?mobile/
|
30
|
+
session[:nomobile] = false
|
31
|
+
elsif params['url'] =~ /\?nomobile/
|
32
|
+
session[:nomobile] = true
|
33
|
+
end
|
34
|
+
if @config['mobile.redirect?'] && @config['mobile.host'] && !session[:nomobile] && !mobile? && mobile_device?
|
35
|
+
redirect_to request.protocol + @config['mobile.host'] + request.path_parameters['url']
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def self.included(base)
|
40
|
+
base.class_eval do
|
41
|
+
before_filter :redirect_if_mobile
|
42
|
+
alias_method_chain :process_page, :mobile
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
namespace :radiant do
|
2
|
+
namespace :extensions do
|
3
|
+
namespace :mobile do
|
4
|
+
|
5
|
+
desc "Runs the migration of the Mobile extension"
|
6
|
+
task :migrate => :environment do
|
7
|
+
require 'radiant/extension_migrator'
|
8
|
+
if ENV["VERSION"]
|
9
|
+
MobileExtension.migrator.migrate(ENV["VERSION"].to_i)
|
10
|
+
Rake::Task['db:schema:dump'].invoke
|
11
|
+
else
|
12
|
+
MobileExtension.migrator.migrate
|
13
|
+
Rake::Task['db:schema:dump'].invoke
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
desc "Copies public assets of the Mobile to the instance public/ directory."
|
18
|
+
task :update => :environment do
|
19
|
+
is_svn_or_dir = proc {|path| path =~ /\.svn/ || File.directory?(path) }
|
20
|
+
puts "Copying assets from MobileExtension"
|
21
|
+
Dir[MobileExtension.root + "/public/**/*"].reject(&is_svn_or_dir).each do |file|
|
22
|
+
path = file.sub(MobileExtension.root, '')
|
23
|
+
directory = File.dirname(path)
|
24
|
+
mkdir_p RAILS_ROOT + directory, :verbose => false
|
25
|
+
cp file, RAILS_ROOT + path, :verbose => false
|
26
|
+
end
|
27
|
+
unless MobileExtension.root.starts_with? RAILS_ROOT # don't need to copy vendored tasks
|
28
|
+
puts "Copying rake tasks from MobileExtension"
|
29
|
+
local_tasks_path = File.join(RAILS_ROOT, %w(lib tasks))
|
30
|
+
mkdir_p local_tasks_path, :verbose => false
|
31
|
+
Dir[File.join MobileExtension.root, %w(lib tasks *.rake)].each do |file|
|
32
|
+
cp file, local_tasks_path, :verbose => false
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
desc "Syncs all available translations for this ext to the English ext master"
|
38
|
+
task :sync => :environment do
|
39
|
+
# The main translation root, basically where English is kept
|
40
|
+
language_root = MobileExtension.root + "/config/locales"
|
41
|
+
words = TranslationSupport.get_translation_keys(language_root)
|
42
|
+
|
43
|
+
Dir["#{language_root}/*.yml"].each do |filename|
|
44
|
+
next if filename.match('_available_tags')
|
45
|
+
basename = File.basename(filename, '.yml')
|
46
|
+
puts "Syncing #{basename}"
|
47
|
+
(comments, other) = TranslationSupport.read_file(filename, basename)
|
48
|
+
words.each { |k,v| other[k] ||= words[k] } # Initializing hash variable as empty if it does not exist
|
49
|
+
other.delete_if { |k,v| !words[k] } # Remove if not defined in en.yml
|
50
|
+
TranslationSupport.write_file(filename, basename, comments, other)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
data/mobile_extension.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
# Uncomment this if you reference any of your controllers in activate
|
2
|
+
# require_dependency 'application_controller'
|
3
|
+
|
4
|
+
class MobileExtension < Radiant::Extension
|
5
|
+
version "0.1.0"
|
6
|
+
description "An easy, cache-friendly mobile version of your site"
|
7
|
+
url "http://github.com/spanner/radiant-mobile-extension"
|
8
|
+
|
9
|
+
def activate
|
10
|
+
Page.send :include, MobilePage
|
11
|
+
SiteController.send :include, MobileSiteController
|
12
|
+
|
13
|
+
admin.configuration.show.add :config, "mobile", :after => "defaults"
|
14
|
+
admin.configuration.edit.add :form, "edit_mobile", :after => "edit_defaults"
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,72 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
+
|
3
|
+
describe SiteController do
|
4
|
+
dataset :pages
|
5
|
+
|
6
|
+
before do
|
7
|
+
@host = "m.test.host"
|
8
|
+
@page = pages(:first)
|
9
|
+
Radiant::Config['mobile.host'] = @host
|
10
|
+
Radiant::Config['mobile.redirect?'] = true
|
11
|
+
end
|
12
|
+
|
13
|
+
describe "responding to a mobile-site request" do
|
14
|
+
before do
|
15
|
+
request.stub!(:host).and_return(@host)
|
16
|
+
controller.stub!(:find_page).and_return(@page)
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should notice that this is a request for the mobile site" do
|
20
|
+
controller.mobile?.should be_true
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should set the mobile flag on a processed page to true" do
|
24
|
+
@page.should_receive(:mobile=).with(true)
|
25
|
+
get :show_page, :url => @page.url
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
describe "responding to a standard-site request" do
|
30
|
+
before do
|
31
|
+
request.stub!(:host).and_return('test.host')
|
32
|
+
controller.stub!(:find_page).and_return(@page)
|
33
|
+
end
|
34
|
+
|
35
|
+
it "should notice that this is not a request for the mobile site" do
|
36
|
+
controller.mobile?.should be_false
|
37
|
+
end
|
38
|
+
|
39
|
+
it "should set the mobile flag on a processed page to false" do
|
40
|
+
@page.should_receive(:mobile=).with(false)
|
41
|
+
get :show_page, :url => @page.url
|
42
|
+
end
|
43
|
+
|
44
|
+
describe "from a mobile device" do
|
45
|
+
before do
|
46
|
+
controller.stub!(:mobile_device?).and_return(true)
|
47
|
+
end
|
48
|
+
|
49
|
+
it "should redirect to the mobile site" do
|
50
|
+
get :show_page, :url => @page.url
|
51
|
+
response.should be_redirect
|
52
|
+
response.should redirect_to("http://#{@host}#{@page.url}")
|
53
|
+
end
|
54
|
+
|
55
|
+
describe "inisting on the standard site" do
|
56
|
+
before do
|
57
|
+
get :show_page, :url => "#{@page.url}?nomobile"
|
58
|
+
end
|
59
|
+
|
60
|
+
it "should not redirect to the mobile site" do
|
61
|
+
response.should_not be_redirect
|
62
|
+
end
|
63
|
+
|
64
|
+
it "should set a nomobile session flag" do
|
65
|
+
session[:nomobile].should be_true
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
+
|
3
|
+
describe Page do
|
4
|
+
let(:page){
|
5
|
+
Page.new(:title => "Page", :slug => "page", :breadcrumb => "page", :status_id => '1')
|
6
|
+
}
|
7
|
+
|
8
|
+
it "should get and set a mobile? attribute" do
|
9
|
+
page.mobile?.should be_false
|
10
|
+
lambda{ page.mobile = true }.should_not raise_error
|
11
|
+
page.mobile.should be_true
|
12
|
+
page.mobile?.should be_true
|
13
|
+
end
|
14
|
+
end
|
data/spec/spec.opts
ADDED
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
unless defined? RADIANT_ROOT
|
2
|
+
ENV["RAILS_ENV"] = "test"
|
3
|
+
case
|
4
|
+
when ENV["RADIANT_ENV_FILE"]
|
5
|
+
require ENV["RADIANT_ENV_FILE"]
|
6
|
+
when File.dirname(__FILE__) =~ %r{vendor/radiant/vendor/extensions}
|
7
|
+
require "#{File.expand_path(File.dirname(__FILE__) + "/../../../../../../")}/config/environment"
|
8
|
+
else
|
9
|
+
require "#{File.expand_path(File.dirname(__FILE__) + "/../../../../")}/config/environment"
|
10
|
+
end
|
11
|
+
end
|
12
|
+
require "#{RADIANT_ROOT}/spec/spec_helper"
|
13
|
+
|
14
|
+
Dataset::Resolver.default << (File.dirname(__FILE__) + "/datasets")
|
15
|
+
|
16
|
+
if File.directory?(File.dirname(__FILE__) + "/matchers")
|
17
|
+
Dir[File.dirname(__FILE__) + "/matchers/*.rb"].each {|file| require file }
|
18
|
+
end
|
19
|
+
|
20
|
+
Spec::Runner.configure do |config|
|
21
|
+
# config.use_transactional_fixtures = true
|
22
|
+
# config.use_instantiated_fixtures = false
|
23
|
+
# config.fixture_path = RAILS_ROOT + '/spec/fixtures'
|
24
|
+
|
25
|
+
# You can declare fixtures for each behaviour like this:
|
26
|
+
# describe "...." do
|
27
|
+
# fixtures :table_a, :table_b
|
28
|
+
#
|
29
|
+
# Alternatively, if you prefer to declare them only once, you can
|
30
|
+
# do so here, like so ...
|
31
|
+
#
|
32
|
+
# config.global_fixtures = :table_a, :table_b
|
33
|
+
#
|
34
|
+
# If you declare global fixtures, be aware that they will be declared
|
35
|
+
# for all of your examples, even those that don't use them.
|
36
|
+
end
|
metadata
ADDED
@@ -0,0 +1,86 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: radiant-mobile-extension
|
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
|
+
- spanner
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2010-10-27 00:00:00 +01:00
|
19
|
+
default_executable:
|
20
|
+
dependencies: []
|
21
|
+
|
22
|
+
description: An easy, flexible, cache-friendly mobile version of your site
|
23
|
+
email: will@spanner.org
|
24
|
+
executables: []
|
25
|
+
|
26
|
+
extensions: []
|
27
|
+
|
28
|
+
extra_rdoc_files:
|
29
|
+
- README.md
|
30
|
+
files:
|
31
|
+
- README.md
|
32
|
+
- Rakefile
|
33
|
+
- app/views/admin/configuration/_edit_mobile.html.haml
|
34
|
+
- app/views/admin/configuration/_mobile.html.haml
|
35
|
+
- config/initializers/radiant_config.rb
|
36
|
+
- config/locales/en.yml
|
37
|
+
- config/routes.rb
|
38
|
+
- cucumber.yml
|
39
|
+
- features/support/env.rb
|
40
|
+
- features/support/paths.rb
|
41
|
+
- lib/mobile_page.rb
|
42
|
+
- lib/mobile_site_controller.rb
|
43
|
+
- lib/tasks/mobile_extension_tasks.rake
|
44
|
+
- mobile_extension.rb
|
45
|
+
- spec/controllers/mobile_site_controller_spec.rb
|
46
|
+
- spec/models/mobile_page_spec.rb
|
47
|
+
- spec/spec.opts
|
48
|
+
- spec/spec_helper.rb
|
49
|
+
has_rdoc: true
|
50
|
+
homepage: http://github.com/spanner/radiant-mobile-extension
|
51
|
+
licenses: []
|
52
|
+
|
53
|
+
post_install_message:
|
54
|
+
rdoc_options:
|
55
|
+
- --charset=UTF-8
|
56
|
+
require_paths:
|
57
|
+
- lib
|
58
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
59
|
+
none: false
|
60
|
+
requirements:
|
61
|
+
- - ">="
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
hash: 3
|
64
|
+
segments:
|
65
|
+
- 0
|
66
|
+
version: "0"
|
67
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
68
|
+
none: false
|
69
|
+
requirements:
|
70
|
+
- - ">="
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
hash: 3
|
73
|
+
segments:
|
74
|
+
- 0
|
75
|
+
version: "0"
|
76
|
+
requirements: []
|
77
|
+
|
78
|
+
rubyforge_project:
|
79
|
+
rubygems_version: 1.3.7
|
80
|
+
signing_key:
|
81
|
+
specification_version: 3
|
82
|
+
summary: Mobile Extension for Radiant CMS
|
83
|
+
test_files:
|
84
|
+
- spec/controllers/mobile_site_controller_spec.rb
|
85
|
+
- spec/models/mobile_page_spec.rb
|
86
|
+
- spec/spec_helper.rb
|