dsparling-sinatra_mobile_fu 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
data/History.txt ADDED
@@ -0,0 +1,30 @@
1
+ == 0.0.6 2009-07-10
2
+
3
+ * 1 minor enhancement:
4
+ * removed lib/sinatra/templates.rb, moved code to lib/sinatra/sinatra_mobile_fu.rb
5
+ * added alias to erb method
6
+
7
+ == 0.0.5 2009-07-10
8
+
9
+ * 1 minor enhancement:
10
+ * set project at github as gem
11
+
12
+ == 0.0.4 2009-07-10
13
+
14
+ * 1 minor enhancement:
15
+ * sinatra_mobile_fu extension now a gem
16
+
17
+ == 0.0.3 2009-07-09
18
+
19
+ * 1 minor enhancement:
20
+ * Making sinatra_mobile_fu into an extension
21
+
22
+ == 0.0.2 2009-07-09
23
+
24
+ * 1 minor enhancement:
25
+ * No longer need to check is_mobile in app
26
+
27
+ == 0.0.1 2009-06-28
28
+
29
+ * 1 major enhancement:
30
+ * Initial release
data/Manifest.txt ADDED
@@ -0,0 +1,18 @@
1
+ History.txt
2
+ Manifest.txt
3
+ README.rdoc
4
+ Rakefile
5
+ examples/Rakefile
6
+ examples/app_force_mobile.rb
7
+ examples/app.rb
8
+ examples/spec/sinatra_mobile_fu_force_mobile_spec.rb
9
+ examples/spec/sinatra_mobile_fu_spec.rb
10
+ examples/views/index.erb
11
+ examples/views/index.mobile.erb
12
+ lib/sinatra/sinatra_mobile_fu.rb
13
+ script/console
14
+ script/destroy
15
+ script/generate
16
+ sinatra_mobile_fu.gemspec
17
+ test/test_helper.rb
18
+ test/test_sinatra_mobile_fu.rb
data/README.rdoc ADDED
@@ -0,0 +1,61 @@
1
+ = sinatra_mobile_fu
2
+
3
+ * http://github.com/dsparilng/sinatra_mobile_fu
4
+
5
+ == DESCRIPTION:
6
+
7
+ mobile_fu for Sinatra, sort of.
8
+
9
+ Based on mobile_fu by Brendan G. Lim
10
+
11
+ This is very alpha, enough to get me going...
12
+
13
+ == FEATURES/PROBLEMS:
14
+
15
+ * rename 'has_sinatra_mobile_fu'??
16
+ * add support for browserized styles
17
+
18
+ == SYNOPSIS:
19
+
20
+ require 'rubygems'
21
+ require 'sinatra'
22
+ require 'sinatra/sinatra_mobile_fu'
23
+
24
+ has_sinatra_mobile_fu
25
+
26
+ get '/' do
27
+ erb :index
28
+ end
29
+
30
+ == REQUIREMENTS:
31
+
32
+ * Sinatra
33
+
34
+ == INSTALL:
35
+
36
+ * sudo gem install dsparling-sinatra_mobile_fu
37
+
38
+ == LICENSE:
39
+
40
+ (The MIT License)
41
+
42
+ Copyright (c) 2009 Doug Sparling
43
+
44
+ Permission is hereby granted, free of charge, to any person obtaining
45
+ a copy of this software and associated documentation files (the
46
+ 'Software'), to deal in the Software without restriction, including
47
+ without limitation the rights to use, copy, modify, merge, publish,
48
+ distribute, sublicense, and/or sell copies of the Software, and to
49
+ permit persons to whom the Software is furnished to do so, subject to
50
+ the following conditions:
51
+
52
+ The above copyright notice and this permission notice shall be
53
+ included in all copies or substantial portions of the Software.
54
+
55
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
56
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
57
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
58
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
59
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
60
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
61
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1,29 @@
1
+ %w[rubygems rake rake/clean fileutils newgem rubigen].each { |f| require f }
2
+ require File.dirname(__FILE__) + '/lib/sinatra/sinatra_mobile_fu'
3
+
4
+ # Generate all the Rake tasks
5
+ # Run 'rake -T' to see list of generated tasks (from gem root directory)
6
+ $hoe = Hoe.new('sinatra_mobile_fu', Sinatra::SinatraMobileFu::VERSION) do |p|
7
+ p.developer('doug sparling', 'doug.sparling@gmail.com')
8
+ p.changes = p.paragraphs_of("History.txt", 0..1).join("\n\n")
9
+ #p.post_install_message = 'PostInstall.txt' # TODO remove if post-install message not required
10
+ #p.rubyforge_name = p.name # TODO this is default value
11
+ p.extra_deps = [
12
+ ['rest-client'],
13
+ ]
14
+ p.extra_dev_deps = [
15
+ ['newgem', ">= #{::Newgem::VERSION}"]
16
+ ]
17
+
18
+ p.clean_globs |= %w[**/.DS_Store tmp *.log]
19
+ #path = (p.rubyforge_name == p.name) ? p.rubyforge_name : "\#{p.rubyforge_name}/\#{p.name}"
20
+ #p.remote_rdoc_dir = File.join(path.gsub(/^#{p.rubyforge_name}\/?/,''), 'rdoc')
21
+ #p.rsync_args = '-av --delete --ignore-errors'
22
+ end
23
+
24
+ require 'newgem/tasks' # load /tasks/*.rake
25
+ Dir['tasks/**/*.rake'].each { |t| load t }
26
+
27
+ # TODO - want other tests/tasks run by default? Add them to the list
28
+ # task :default => [:spec, :features]
29
+ #task :default => [:spec]
data/examples/Rakefile ADDED
@@ -0,0 +1,15 @@
1
+ require 'rubygems'
2
+ require 'spec/rake/spectask'
3
+
4
+ task :default => :test
5
+ task :test => :spec
6
+
7
+ if !defined?(Spec)
8
+ puts "spec targets require RSpec"
9
+ else
10
+ desc "Run all examples"
11
+ Spec::Rake::SpecTask.new('spec') do |t|
12
+ t.spec_files = FileList['spec/**/*.rb']
13
+ t.spec_opts = ['-cfs']
14
+ end
15
+ end
data/examples/app.rb ADDED
@@ -0,0 +1,12 @@
1
+ require 'rubygems'
2
+ require 'sinatra'
3
+ require 'sinatra/sinatra_mobile_fu'
4
+
5
+ #set :public, File.join(Sinatra::Application.root, 'public')
6
+ set :views, File.join(Sinatra::Application.root, 'views')
7
+
8
+ has_sinatra_mobile_fu
9
+
10
+ get '/' do
11
+ erb :index
12
+ end
@@ -0,0 +1,12 @@
1
+ require 'rubygems'
2
+ require 'sinatra'
3
+ require 'sinatra/sinatra_mobile_fu'
4
+
5
+ #set :public, File.join(Sinatra::Application.root, 'public')
6
+ set :views, File.join(Sinatra::Application.root, 'views')
7
+
8
+ has_sinatra_mobile_fu(true)
9
+
10
+ get '/' do
11
+ erb :index
12
+ end
@@ -0,0 +1,34 @@
1
+ #require File.join(File.dirname(__FILE__), 'spec_helper.rb')
2
+ #require File.join(File.dirname(__FILE__), '..', 'app_force_mobile.rb')
3
+
4
+ require 'rubygems'
5
+ require 'sinatra'
6
+ require 'spec'
7
+ require 'spec/interop/test'
8
+ require 'rack/test'
9
+
10
+ # set test environment
11
+ set :environment, :test
12
+ set :run, false
13
+ set :raise_errors, true
14
+ set :logging, false
15
+
16
+ describe 'Sinatra::SinatraMobileFu' do
17
+ include Rack::Test::Methods
18
+
19
+ def app
20
+ Sinatra::Application.new
21
+ end
22
+
23
+ before do
24
+ require File.join(File.dirname(__FILE__), '..', 'app_force_mobile.rb')
25
+ end
26
+
27
+ context 'mobile' do
28
+ it "should return mobile when mobile requested" do
29
+ get '/'
30
+ last_response.should be_ok
31
+ last_response.body.should == "mobile\n"
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,34 @@
1
+ #require File.join(File.dirname(__FILE__), 'spec_helper.rb')
2
+ require File.join(File.dirname(__FILE__), '..', 'app.rb')
3
+
4
+ require 'rubygems'
5
+ require 'sinatra'
6
+ require 'spec'
7
+ require 'spec/interop/test'
8
+ require 'rack/test'
9
+
10
+ # set test environment
11
+ set :environment, :test
12
+ set :run, false
13
+ set :raise_errors, true
14
+ set :logging, false
15
+
16
+ describe 'Sinatra::SinatraMobileFu' do
17
+ include Rack::Test::Methods
18
+
19
+ def app
20
+ Sinatra::Application.new
21
+ end
22
+
23
+ #before do
24
+ #end
25
+
26
+ context 'html' do
27
+ it "should return html when html requested" do
28
+ get '/'
29
+ last_response.should be_ok
30
+ last_response.body.should == "html\n"
31
+ end
32
+ end
33
+
34
+ end
@@ -0,0 +1 @@
1
+ html
@@ -0,0 +1 @@
1
+ mobile
@@ -0,0 +1,98 @@
1
+ require 'sinatra'
2
+ require 'sinatra/base'
3
+
4
+ module Sinatra
5
+
6
+ module Templates
7
+
8
+ alias orig_erb erb
9
+
10
+ def erb(template, options={}, locals={})
11
+
12
+ if in_mobile_view?
13
+ mob_template = template.to_s + '.mobile'
14
+ template = mob_template.to_sym
15
+ end
16
+
17
+ orig_erb template, options, locals
18
+ end
19
+
20
+ end
21
+
22
+ module SinatraMobileFu
23
+
24
+ VERSION = '0.0.6'
25
+
26
+ helpers {
27
+ include Sinatra::SinatraMobileFu
28
+ }
29
+
30
+ enable :sessions
31
+
32
+ # These are various strings that can be found in mobile devices. Please feel free
33
+ # to add on to this list.
34
+
35
+ MOBILE_USER_AGENTS = 'palm|palmos|palmsource|iphone|blackberry|nokia|phone|midp|mobi|pda|' +
36
+ 'wap|java|nokia|hand|symbian|chtml|wml|ericsson|lg|audiovox|motorola|' +
37
+ 'samsung|sanyo|sharp|telit|tsm|mobile|mini|windows ce|smartphone|' +
38
+ '240x320|320x320|mobileexplorer|j2me|sgh|portable|sprint|vodafone|' +
39
+ 'docomo|kddi|softbank|pdxgw|j-phone|astel|minimo|plucker|netfront|' +
40
+ 'xiino|mot-v|mot-e|portalmmm|sagem|sie-s|sie-m|android|ipod'
41
+
42
+ def has_sinatra_mobile_fu(test_mode = false)
43
+
44
+ before {
45
+ if test_mode
46
+ force_mobile_format
47
+ else
48
+ set_mobile_format
49
+ end
50
+ }
51
+
52
+ end
53
+
54
+ # Forces the request format to be :mobile
55
+
56
+ def force_mobile_format
57
+ session[:format] = :mobile
58
+ session[:mobile_view] = true if session[:mobile_view].nil?
59
+ end
60
+
61
+ # Determines the request format based on whether the device is mobile or if
62
+ # the user has opted to use either the 'Standard' view or 'Mobile' view.
63
+
64
+ def set_mobile_format
65
+ if is_mobile_device?
66
+ session[:format] = session[:mobile_view] == false ? :html : :mobile
67
+ session[:mobile_view] = true if session[:mobile_view].nil?
68
+ else
69
+ session[:format] = :html
70
+ end
71
+ end
72
+
73
+ # Returns either true or false depending on whether or not the format of the
74
+ # request is either :mobile or not.
75
+
76
+ def in_mobile_view?
77
+ session[:format].to_sym == :mobile
78
+ end
79
+
80
+ # Returns either true or false depending on whether or not the user agent of
81
+ # the device making the request is matched to a device in our regex.
82
+
83
+ def is_mobile_device?
84
+ request.user_agent.to_s.downcase =~ Regexp.new(Sinatra::SinatraMobileFu::MOBILE_USER_AGENTS)
85
+ end
86
+
87
+ # Can check for a specific user agent
88
+ # e.g., is_device?('iphone') or is_device?('mobileexplorer')
89
+
90
+ def is_device?(type)
91
+ request.user_agent.to_s.downcase.include?(type.to_s.downcase)
92
+ end
93
+
94
+ end
95
+
96
+ register SinatraMobileFu
97
+
98
+ end
data/script/console ADDED
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env ruby
2
+ # File: script/console
3
+ irb = RUBY_PLATFORM =~ /(:?mswin|mingw)/ ? 'irb.bat' : 'irb'
4
+
5
+ libs = " -r irb/completion"
6
+ # Perhaps use a console_lib to store any extra methods I may want available in the cosole
7
+ # libs << " -r #{File.dirname(__FILE__) + '/../lib/console_lib/console_logger.rb'}"
8
+ libs << " -r #{File.dirname(__FILE__) + '/../lib/sinatra_mobile_fu.rb'}"
9
+ puts "Loading sinatra_mobile_fu gem"
10
+ exec "#{irb} #{libs} --simple-prompt"
data/script/destroy ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+ APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
3
+
4
+ begin
5
+ require 'rubigen'
6
+ rescue LoadError
7
+ require 'rubygems'
8
+ require 'rubigen'
9
+ end
10
+ require 'rubigen/scripts/destroy'
11
+
12
+ ARGV.shift if ['--help', '-h'].include?(ARGV[0])
13
+ RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit]
14
+ RubiGen::Scripts::Destroy.new.run(ARGV)
data/script/generate ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+ APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
3
+
4
+ begin
5
+ require 'rubigen'
6
+ rescue LoadError
7
+ require 'rubygems'
8
+ require 'rubigen'
9
+ end
10
+ require 'rubigen/scripts/generate'
11
+
12
+ ARGV.shift if ['--help', '-h'].include?(ARGV[0])
13
+ RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit]
14
+ RubiGen::Scripts::Generate.new.run(ARGV)
@@ -0,0 +1,44 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = %q{sinatra_mobile_fu}
5
+ s.version = "0.0.6"
6
+
7
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
+ s.authors = ["doug sparling"]
9
+ s.date = %q{2009-07-10}
10
+ s.description = %q{mobile_fu for Sinatra, sort of.
11
+
12
+ Based on mobile_fu by Brendan G. Lim
13
+
14
+ This is very alpha, enough to get me going...}
15
+ s.email = ["doug.sparling@gmail.com"]
16
+ s.extra_rdoc_files = ["History.txt", "Manifest.txt", "README.rdoc"]
17
+ s.files = ["History.txt", "Manifest.txt", "README.rdoc", "Rakefile", "examples/Rakefile", "examples/app_force_mobile.rb", "examples/app.rb", "examples/spec/sinatra_mobile_fu_force_mobile_spec.rb", "examples/spec/sinatra_mobile_fu_spec.rb", "examples/views/index.erb", "examples/views/index.mobile.erb", "lib/sinatra/sinatra_mobile_fu.rb", "script/console", "script/destroy", "script/generate", "sinatra_mobile_fu.gemspec", "test/test_helper.rb", "test/test_sinatra_mobile_fu.rb"]
18
+ s.homepage = %q{http://github.com/dsparilng/sinatra_mobile_fu}
19
+ s.rdoc_options = ["--main", "README.rdoc"]
20
+ s.require_paths = ["lib"]
21
+ s.rubyforge_project = %q{sinatra_mobile_fu}
22
+ s.rubygems_version = %q{1.3.4}
23
+ s.summary = %q{mobile_fu for Sinatra, sort of}
24
+ s.test_files = ["test/test_sinatra_mobile_fu.rb", "test/test_helper.rb"]
25
+
26
+ if s.respond_to? :specification_version then
27
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
28
+ s.specification_version = 3
29
+
30
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
31
+ s.add_runtime_dependency(%q<rest-client>, [">= 0"])
32
+ s.add_development_dependency(%q<newgem>, [">= 1.4.1"])
33
+ s.add_development_dependency(%q<hoe>, [">= 1.8.0"])
34
+ else
35
+ s.add_dependency(%q<rest-client>, [">= 0"])
36
+ s.add_dependency(%q<newgem>, [">= 1.4.1"])
37
+ s.add_dependency(%q<hoe>, [">= 1.8.0"])
38
+ end
39
+ else
40
+ s.add_dependency(%q<rest-client>, [">= 0"])
41
+ s.add_dependency(%q<newgem>, [">= 1.4.1"])
42
+ s.add_dependency(%q<hoe>, [">= 1.8.0"])
43
+ end
44
+ end
@@ -0,0 +1,3 @@
1
+ require 'stringio'
2
+ require 'test/unit'
3
+ require File.dirname(__FILE__) + '/../lib/sinatra/sinatra_mobile_fu'
@@ -0,0 +1,11 @@
1
+ require File.dirname(__FILE__) + '/test_helper.rb'
2
+
3
+ class TestSinatraMobileFu < Test::Unit::TestCase
4
+
5
+ def setup
6
+ end
7
+
8
+ def test_truth
9
+ assert true
10
+ end
11
+ end
metadata ADDED
@@ -0,0 +1,104 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: dsparling-sinatra_mobile_fu
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.6
5
+ platform: ruby
6
+ authors:
7
+ - doug sparling
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-07-10 00:00:00 -07:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: rest-client
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: "0"
24
+ version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: newgem
27
+ type: :development
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 1.4.1
34
+ version:
35
+ - !ruby/object:Gem::Dependency
36
+ name: hoe
37
+ type: :development
38
+ version_requirement:
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: 1.8.0
44
+ version:
45
+ description: mobile_fu for Sinatra, sort of. Based on mobile_fu by Brendan G. Lim This is very alpha, enough to get me going...
46
+ email:
47
+ - doug.sparling@gmail.com
48
+ executables: []
49
+
50
+ extensions: []
51
+
52
+ extra_rdoc_files:
53
+ - History.txt
54
+ - Manifest.txt
55
+ - README.rdoc
56
+ files:
57
+ - History.txt
58
+ - Manifest.txt
59
+ - README.rdoc
60
+ - Rakefile
61
+ - examples/Rakefile
62
+ - examples/app_force_mobile.rb
63
+ - examples/app.rb
64
+ - examples/spec/sinatra_mobile_fu_force_mobile_spec.rb
65
+ - examples/spec/sinatra_mobile_fu_spec.rb
66
+ - examples/views/index.erb
67
+ - examples/views/index.mobile.erb
68
+ - lib/sinatra/sinatra_mobile_fu.rb
69
+ - script/console
70
+ - script/destroy
71
+ - script/generate
72
+ - sinatra_mobile_fu.gemspec
73
+ - test/test_helper.rb
74
+ - test/test_sinatra_mobile_fu.rb
75
+ has_rdoc: false
76
+ homepage: http://github.com/dsparilng/sinatra_mobile_fu
77
+ post_install_message:
78
+ rdoc_options:
79
+ - --main
80
+ - README.rdoc
81
+ require_paths:
82
+ - lib
83
+ required_ruby_version: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - ">="
86
+ - !ruby/object:Gem::Version
87
+ version: "0"
88
+ version:
89
+ required_rubygems_version: !ruby/object:Gem::Requirement
90
+ requirements:
91
+ - - ">="
92
+ - !ruby/object:Gem::Version
93
+ version: "0"
94
+ version:
95
+ requirements: []
96
+
97
+ rubyforge_project: sinatra_mobile_fu
98
+ rubygems_version: 1.2.0
99
+ signing_key:
100
+ specification_version: 3
101
+ summary: mobile_fu for Sinatra, sort of
102
+ test_files:
103
+ - test/test_sinatra_mobile_fu.rb
104
+ - test/test_helper.rb