Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug fix and gemspec #8

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pkg/*
14 changes: 14 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,20 @@ require 'rake'
require 'rake/testtask'
require 'rake/rdoctask'

begin
require 'jeweler'
Jeweler::Tasks.new do |gemspec|
gemspec.name = "mobile_fu"
gemspec.summary = "Automatically detect mobile devices that access your Rails application"
gemspec.description = "Want to automatically detect mobile devices that access your Rails application? Mobile Fu allows you to do just that. People can access your site from a Palm, Blackberry, iPhone, iPad, Nokia, etc. and it will automatically adjust the format of the request from :html to :mobile."
gemspec.email = "[email protected]"
gemspec.homepage = "http://github.com/brendanlim/mobile-fu"
gemspec.authors = ["Brendan G. Lim"]
end
rescue LoadError
puts "Jeweler not available. Install it with: gem install jeweler"
end

desc 'Default: run unit tests.'
task :default => :test

Expand Down
1 change: 1 addition & 0 deletions VERSION
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0.3.0
12 changes: 5 additions & 7 deletions init.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
require File.dirname(__FILE__) + '/lib/mobile_fu_helper.rb'
require File.dirname(__FILE__) + '/lib/mobilized_styles'
require File.dirname(__FILE__) + '/lib/mobile_fu'

ActionView::Base.send(:include, MobileFuHelper)
ActionView::Base.send(:include, MobilizedStyles)
ActionView::Base.send(:alias_method_chain, :stylesheet_link_tag, :mobilization)
begin
require File.join(File.dirname(__FILE__), 'lib', 'mobile_fu') # From here
rescue LoadError
require 'mobile_fu' # From gem
end
10 changes: 9 additions & 1 deletion lib/mobile_fu.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
dir = File.dirname(__FILE__)
$LOAD_PATH.unshift dir unless $LOAD_PATH.include?(dir)
require 'mobile_fu_helper.rb'
require 'mobilized_styles'

module ActionController
module MobileFu
# These are various strings that can be found in mobile devices. Please feel free
Expand Down Expand Up @@ -99,4 +104,7 @@ def is_device?(type)

end

ActionController::Base.send(:include, ActionController::MobileFu)
ActionController::Base.send(:include, ActionController::MobileFu)
ActionView::Base.send(:include, MobileFuHelper)
ActionView::Base.send(:include, MobilizedStyles)
ActionView::Base.send(:alias_method_chain, :stylesheet_link_tag, :mobilization)
38 changes: 21 additions & 17 deletions lib/mobile_fu_helper.rb
Original file line number Diff line number Diff line change
@@ -1,24 +1,28 @@
module MobileFuHelper
ACCEPTABLE_TYPES = [:mobile, :basic]

def self.included(base)
base.extend(ClassMethods)
end

def mobile_xhtml_doctype(type = :mobile, version = '1.0')
raise Exception.new("MobileFu: XHTML DOCTYPE type must either be ':mobile' or ':basic'") unless ACCEPTABLE_TYPES.include?(type)
raise Exception.new("MobileFu: XHTML DOCTYPE version must be in the format of '1.0' or '1.1', etc.") unless version.include?('.')
module ClassMethods
def mobile_xhtml_doctype(type = :mobile, version = '1.0')
raise Exception.new("MobileFu: XHTML DOCTYPE type must either be ':mobile' or ':basic'") unless ACCEPTABLE_TYPES.include?(type)
raise Exception.new("MobileFu: XHTML DOCTYPE version must be in the format of '1.0' or '1.1', etc.") unless version.include?('.')

doc_type = "<?xml version=\"1.0\" charset=\"UTF-8\" ?>\n"
doc_type += "<!DOCTYPE html PUBLIC "
doc_type += case type
when :mobile
"\"-//WAPFORUM//DTD XHTML Mobile #{version}//EN\" \"http://www.openmobilealliance.org/tech/DTD/xhtml-mobile#{version.gsub('.','')}.dtd\">"
when :basic
"\"-//W3C//DTD XHTML Basic #{version}//EN\" \"http://www.w3.org/TR/xhtml-basic/xhtml-basic#{version.gsub('.','')}.dtd\">"
end
doc_type
end
doc_type = "<?xml version=\"1.0\" charset=\"UTF-8\" ?>\n"
doc_type += "<!DOCTYPE html PUBLIC "
doc_type += case type
when :mobile
"\"-//WAPFORUM//DTD XHTML Mobile #{version}//EN\" \"http://www.openmobilealliance.org/tech/DTD/xhtml-mobile#{version.gsub('.','')}.dtd\">"
when :basic
"\"-//W3C//DTD XHTML Basic #{version}//EN\" \"http://www.w3.org/TR/xhtml-basic/xhtml-basic#{version.gsub('.','')}.dtd\">"
end
doc_type
end

def js_enabled_mobile_device?
is_device?('iphone') || is_device?('ipod') || is_device?('ipad') || is_device?('mobileexplorer') || is_device?('android')
def js_enabled_mobile_device?
is_device?('iphone') || is_device?('ipod') || is_device?('ipad') || is_device?('mobileexplorer') || is_device?('android')
end
end
end

ActionView::Base.send(:include, MobileFuHelper)
3 changes: 1 addition & 2 deletions lib/mobilized_styles.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ def stylesheet_link_tag_with_mobilization(*sources)
mobilized_sources << possible_source if File.exist?(path) || File.exist?(sass_path)
end
end

stylesheet_link_tag_without_mobilization(*mobilized_sources)
end
end
end
56 changes: 56 additions & 0 deletions mobile_fu.gemspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# Generated by jeweler
# DO NOT EDIT THIS FILE DIRECTLY
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
# -*- encoding: utf-8 -*-

Gem::Specification.new do |s|
s.name = %q{mobile_fu}
s.version = "0.3.0"

s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.authors = ["Brendan G. Lim"]
s.date = %q{2010-09-22}
s.description = %q{Want to automatically detect mobile devices that access your Rails application? Mobile Fu allows you to do just that. People can access your site from a Palm, Blackberry, iPhone, iPad, Nokia, etc. and it will automatically adjust the format of the request from :html to :mobile.}
s.email = %q{[email protected]}
s.extra_rdoc_files = [
"README.rdoc"
]
s.files = [
".gitignore",
"CHANGELOG",
"MIT-LICENSE",
"README.rdoc",
"Rakefile",
"VERSION",
"init.rb",
"install.rb",
"lib/mobile_fu.rb",
"lib/mobile_fu_helper.rb",
"lib/mobilized_styles.rb",
"mobile_fu.gemspec",
"spec/mobilized_styles_spec.rb",
"spec/spec.opts",
"spec/spec_helper.rb",
"uninstall.rb"
]
s.homepage = %q{http://github.com/brendanlim/mobile-fu}
s.rdoc_options = ["--charset=UTF-8"]
s.require_paths = ["lib"]
s.rubygems_version = %q{1.3.7}
s.summary = %q{Automatically detect mobile devices that access your Rails application}
s.test_files = [
"spec/mobilized_styles_spec.rb",
"spec/spec_helper.rb"
]

if s.respond_to? :specification_version then
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
s.specification_version = 3

if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
else
end
else
end
end