diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..088af20 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +pkg/* diff --git a/Rakefile b/Rakefile index de861dd..c057972 100644 --- a/Rakefile +++ b/Rakefile @@ -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 = "brendangl@gmail.com" + 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 diff --git a/VERSION b/VERSION new file mode 100644 index 0000000..0d91a54 --- /dev/null +++ b/VERSION @@ -0,0 +1 @@ +0.3.0 diff --git a/init.rb b/init.rb index d34defd..70669af 100644 --- a/init.rb +++ b/init.rb @@ -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) \ No newline at end of file +begin + require File.join(File.dirname(__FILE__), 'lib', 'mobile_fu') # From here +rescue LoadError + require 'mobile_fu' # From gem +end diff --git a/lib/mobile_fu.rb b/lib/mobile_fu.rb index b3aac85..c87e8ea 100644 --- a/lib/mobile_fu.rb +++ b/lib/mobile_fu.rb @@ -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 @@ -99,4 +104,7 @@ def is_device?(type) end -ActionController::Base.send(:include, ActionController::MobileFu) \ No newline at end of file +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) diff --git a/lib/mobile_fu_helper.rb b/lib/mobile_fu_helper.rb index 207ba2c..5ba89de 100644 --- a/lib/mobile_fu_helper.rb +++ b/lib/mobile_fu_helper.rb @@ -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 = "\n" - doc_type += "" - 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 = "\n" + doc_type += "" + 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) \ No newline at end of file diff --git a/lib/mobilized_styles.rb b/lib/mobilized_styles.rb index 8c16e0b..a8116c8 100644 --- a/lib/mobilized_styles.rb +++ b/lib/mobilized_styles.rb @@ -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 \ No newline at end of file +end diff --git a/mobile_fu.gemspec b/mobile_fu.gemspec new file mode 100644 index 0000000..bb3f364 --- /dev/null +++ b/mobile_fu.gemspec @@ -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{brendangl@gmail.com} + 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 +