Module: MobileFu::ActionView::MobilizedStyles

Defined in:
lib/mobile_fu/mobilized_styles.rb

Instance Method Summary collapse

Instance Method Details



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/mobile_fu/mobilized_styles.rb', line 51

def stylesheet_link_tag_with_mobilization(*sources)
  mobilized_sources = Array.new
  sources.each do |source|
    subbed_source = source.to_s.gsub('.css', '')

    possible_sources = ["#{subbed_source.to_s}_#{user_agent_device_name}"]

    mobilized_sources << source

    for possible_source in possible_sources
      path = File.join(config.stylesheets_dir,"#{possible_source}.css")
      sass_path = File.join(config.stylesheets_dir,"sass","#{possible_source}.sass")
      mobilized_sources << possible_source if File.exist?(path) || File.exist?(sass_path)
    end
  end

  stylesheet_link_tag_without_mobilization(*mobilized_sources)
end

#user_agent_device_nameObject

This logic was taken from Michael Bleigh’s browserized styles with modification to work for mobile browsers.



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/mobile_fu/mobilized_styles.rb', line 27

def user_agent_device_name
  @user_agent_device_name ||= begin
    ua = request.user_agent.to_s
    return nil if ua.nil?
    ua.downcase!

    if ua.index('mobileexplorer') or ua.index('windows ce')
      'mobileexplorer'
    elsif ua.index('blackberry') 
      'blackberry'
    elsif ua.index('iphone') or ua.index('ipod')
      'iphone'
    elsif ua.index('ipad')
      'ipad'
    elsif ua.index('android')
      'android'
    elsif ua.index('nokia') 
      'nokia'
    elsif ua.index('palm') 
      'palm'
    end
  end
end