Permalink
Browse files

fixed gem load/init issues

  • Loading branch information...
1 parent b272124 commit 5b8d8748d7635267837182664b3e8f9976d9440c @zerobearing2 committed Sep 3, 2010
Showing with 36 additions and 27 deletions.
  1. +5 −7 init.rb
  2. +9 −1 lib/mobile_fu.rb
  3. +21 −17 lib/mobile_fu_helper.rb
  4. +1 −2 lib/mobilized_styles.rb
View
12 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)
+begin
+ require File.join(File.dirname(__FILE__), 'lib', 'mobile_fu') # From here
+rescue LoadError
+ require 'mobile_fu' # From gem
+end
View
10 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)
+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)
View
38 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 = "<?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)
View
3 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
+end

0 comments on commit 5b8d874

Please sign in to comment.