mobylette 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (120) hide show
  1. data/MIT-LICENSE +20 -0
  2. data/README.rdoc +83 -0
  3. data/Rakefile +37 -0
  4. data/lib/mobylette.rb +12 -0
  5. data/lib/mobylette/controllers/helpers.rb +52 -0
  6. data/lib/mobylette/controllers/respond_to_mobile_requests.rb +86 -0
  7. data/lib/mobylette/helmet.rb +41 -0
  8. data/lib/mobylette/helmet/faker.rb +19 -0
  9. data/lib/mobylette/helmet/helpers.rb +34 -0
  10. data/lib/mobylette/railtie.rb +10 -0
  11. data/lib/mobylette/version.rb +3 -0
  12. data/lib/tasks/mobylette_tasks.rake +4 -0
  13. data/spec/controllers/actioncontroller_base_spec.rb +16 -0
  14. data/spec/controllers/default_fallback_controller_spec.rb +36 -0
  15. data/spec/controllers/desktop_only_controller_spec.rb +17 -0
  16. data/spec/controllers/force_fallback_controller_spec.rb +41 -0
  17. data/spec/controllers/home_controller_spec.rb +89 -0
  18. data/spec/controllers/no_fallback_controller_spec.rb +56 -0
  19. data/spec/dummy/Rakefile +7 -0
  20. data/spec/dummy/app/assets/javascripts/application.js +9 -0
  21. data/spec/dummy/app/assets/javascripts/application_mobile.js +9 -0
  22. data/spec/dummy/app/assets/javascripts/default_fallback.js +2 -0
  23. data/spec/dummy/app/assets/javascripts/desktop_only.js +2 -0
  24. data/spec/dummy/app/assets/javascripts/fallbacks.js +2 -0
  25. data/spec/dummy/app/assets/javascripts/force_fallback.js +2 -0
  26. data/spec/dummy/app/assets/javascripts/home.js +2 -0
  27. data/spec/dummy/app/assets/javascripts/no_fallback.js +2 -0
  28. data/spec/dummy/app/assets/javascripts/testing.js +2 -0
  29. data/spec/dummy/app/assets/stylesheets/application.css +11 -0
  30. data/spec/dummy/app/assets/stylesheets/application_mobile.css +11 -0
  31. data/spec/dummy/app/assets/stylesheets/default_fallback.css +4 -0
  32. data/spec/dummy/app/assets/stylesheets/desktop_only.css +4 -0
  33. data/spec/dummy/app/assets/stylesheets/fallbacks.css +4 -0
  34. data/spec/dummy/app/assets/stylesheets/force_fallback.css +4 -0
  35. data/spec/dummy/app/assets/stylesheets/home.css +4 -0
  36. data/spec/dummy/app/assets/stylesheets/no_fallback.css +4 -0
  37. data/spec/dummy/app/assets/stylesheets/testing.css +4 -0
  38. data/spec/dummy/app/controllers/application_controller.rb +4 -0
  39. data/spec/dummy/app/controllers/default_fallback_controller.rb +13 -0
  40. data/spec/dummy/app/controllers/desktop_only_controller.rb +2 -0
  41. data/spec/dummy/app/controllers/fallbacks_controller.rb +7 -0
  42. data/spec/dummy/app/controllers/force_fallback_controller.rb +13 -0
  43. data/spec/dummy/app/controllers/home_controller.rb +19 -0
  44. data/spec/dummy/app/controllers/no_fallback_controller.rb +13 -0
  45. data/spec/dummy/app/controllers/testing_controller.rb +9 -0
  46. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  47. data/spec/dummy/app/helpers/default_fallback_helper.rb +2 -0
  48. data/spec/dummy/app/helpers/desktop_only_helper.rb +2 -0
  49. data/spec/dummy/app/helpers/fallbacks_helper.rb +2 -0
  50. data/spec/dummy/app/helpers/force_fallback_helper.rb +2 -0
  51. data/spec/dummy/app/helpers/home_helper.rb +2 -0
  52. data/spec/dummy/app/helpers/no_fallback_helper.rb +2 -0
  53. data/spec/dummy/app/helpers/testing_helper.rb +2 -0
  54. data/spec/dummy/app/views/default_fallback/index.html.erb +1 -0
  55. data/spec/dummy/app/views/default_fallback/index.js.erb +1 -0
  56. data/spec/dummy/app/views/default_fallback/index.mobile.erb +1 -0
  57. data/spec/dummy/app/views/default_fallback/test.html.erb +1 -0
  58. data/spec/dummy/app/views/default_fallback/test.js.erb +1 -0
  59. data/spec/dummy/app/views/fallbacks/index.html.erb +2 -0
  60. data/spec/dummy/app/views/fallbacks/index.js.erb +1 -0
  61. data/spec/dummy/app/views/fallbacks/index.mobile.erb +0 -0
  62. data/spec/dummy/app/views/fallbacks/index.xml.erb +0 -0
  63. data/spec/dummy/app/views/fallbacks/no_mobile.html.erb +0 -0
  64. data/spec/dummy/app/views/force_fallback/index.html.erb +1 -0
  65. data/spec/dummy/app/views/force_fallback/index.js.erb +1 -0
  66. data/spec/dummy/app/views/force_fallback/index.mobile.erb +1 -0
  67. data/spec/dummy/app/views/force_fallback/test.html.erb +1 -0
  68. data/spec/dummy/app/views/force_fallback/test.js.erb +1 -0
  69. data/spec/dummy/app/views/home/desktop.html.erb +1 -0
  70. data/spec/dummy/app/views/home/index.html.erb +7 -0
  71. data/spec/dummy/app/views/home/index.mobile.erb +7 -0
  72. data/spec/dummy/app/views/home/mobile.mobile.erb +1 -0
  73. data/spec/dummy/app/views/home/no_mobile_view.html.erb +1 -0
  74. data/spec/dummy/app/views/layouts/application.html.erb +16 -0
  75. data/spec/dummy/app/views/layouts/application.mobile.erb +16 -0
  76. data/spec/dummy/app/views/no_fallback/index.html.erb +1 -0
  77. data/spec/dummy/app/views/no_fallback/index.js.erb +1 -0
  78. data/spec/dummy/app/views/no_fallback/index.mobile.erb +1 -0
  79. data/spec/dummy/app/views/no_fallback/test.html.erb +1 -0
  80. data/spec/dummy/app/views/no_fallback/test.js.erb +1 -0
  81. data/spec/dummy/config.ru +4 -0
  82. data/spec/dummy/config/application.rb +46 -0
  83. data/spec/dummy/config/boot.rb +10 -0
  84. data/spec/dummy/config/database.yml +25 -0
  85. data/spec/dummy/config/environment.rb +5 -0
  86. data/spec/dummy/config/environments/development.rb +33 -0
  87. data/spec/dummy/config/environments/production.rb +51 -0
  88. data/spec/dummy/config/environments/test.rb +42 -0
  89. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  90. data/spec/dummy/config/initializers/inflections.rb +10 -0
  91. data/spec/dummy/config/initializers/mime_types.rb +5 -0
  92. data/spec/dummy/config/initializers/secret_token.rb +7 -0
  93. data/spec/dummy/config/initializers/session_store.rb +8 -0
  94. data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
  95. data/spec/dummy/config/locales/en.yml +5 -0
  96. data/spec/dummy/config/routes.rb +22 -0
  97. data/spec/dummy/db/development.sqlite3 +0 -0
  98. data/spec/dummy/db/schema.rb +16 -0
  99. data/spec/dummy/db/test.sqlite3 +0 -0
  100. data/spec/dummy/log/development.log +32 -0
  101. data/spec/dummy/log/test.log +1537 -0
  102. data/spec/dummy/public/404.html +26 -0
  103. data/spec/dummy/public/422.html +26 -0
  104. data/spec/dummy/public/500.html +26 -0
  105. data/spec/dummy/public/favicon.ico +0 -0
  106. data/spec/dummy/script/rails +6 -0
  107. data/spec/dummy/tmp/cache/assets/C82/3E0/sprockets%2F48eb4ac616538f8f36870451073315da +0 -0
  108. data/spec/dummy/tmp/cache/assets/CE4/1C0/sprockets%2F18d93e1533d585b2f64ec90b33176ac9 +0 -0
  109. data/spec/dummy/tmp/cache/assets/CED/A70/sprockets%2F621683d8791730a9cc7ce45e17a7e46d +0 -0
  110. data/spec/dummy/tmp/cache/assets/CFC/200/sprockets%2F716f89d85d4855706b8a9abec1969c62 +0 -0
  111. data/spec/dummy/tmp/cache/assets/D32/A10/sprockets%2F13fe41fee1fe35b49d145bcc06610705 +0 -0
  112. data/spec/dummy/tmp/cache/assets/D54/ED0/sprockets%2F71c9fa01091d432b131da3bb73faf3d4 +0 -0
  113. data/spec/dummy/tmp/cache/assets/D84/210/sprockets%2Fabd0103ccec2b428ac62c94e4c40b384 +0 -0
  114. data/spec/dummy/tmp/cache/assets/E04/890/sprockets%2F2f5173deea6c795b8fdde723bb4b63af +0 -0
  115. data/spec/dummy/tmp/pids/server.pid +1 -0
  116. data/spec/helpers/mobylette_helpers_spec.rb +59 -0
  117. data/spec/integration/navigation_spec.rb +9 -0
  118. data/spec/mobylette_spec.rb +7 -0
  119. data/spec/spec_helper.rb +35 -0
  120. metadata +320 -0
@@ -0,0 +1,2 @@
1
+ module HomeHelper
2
+ end
@@ -0,0 +1,2 @@
1
+ module NoFallbackHelper
2
+ end
@@ -0,0 +1,2 @@
1
+ module TestingHelper
2
+ end
@@ -0,0 +1,2 @@
1
+ <h1>Fallbacks#index</h1>
2
+ <p>Find me in app/views/fallbacks/index.html.erb</p>
@@ -0,0 +1 @@
1
+ alert(js view);
@@ -0,0 +1 @@
1
+ this is a desktop html mime type
@@ -0,0 +1,7 @@
1
+ this is the html view
2
+
3
+ <% if is_mobile_request? %>
4
+ THIS A MOBILE DEVICE
5
+ <% else %>
6
+ THIS IS NOT A MOBILE DEVICE
7
+ <% end %>
@@ -0,0 +1,7 @@
1
+ this is the mobile view
2
+
3
+ <% if is_mobile_request? %>
4
+ THIS A MOBILE DEVICE
5
+ <% else %>
6
+ THIS IS NOT A MOBILE DEVICE
7
+ <% end %>
@@ -0,0 +1 @@
1
+ this is a mobile mobile view
@@ -0,0 +1 @@
1
+ This is the only view, and it's html
@@ -0,0 +1,16 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>Dummy</title>
5
+ <%= mobylette_stylesheet_link_tag "application" %>
6
+ <%= mobylette_javascript_include_tag "application" %>
7
+ <%= csrf_meta_tags %>
8
+ </head>
9
+ <body>
10
+
11
+ <h1>Normal Layout</h1>
12
+
13
+ <%= yield %>
14
+
15
+ </body>
16
+ </html>
@@ -0,0 +1,16 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>Dummy</title>
5
+ <%= mobylette_stylesheet_link_tag "application" %>
6
+ <%= mobylette_javascript_include_tag "application" %>
7
+ <%= csrf_meta_tags %>
8
+ </head>
9
+ <body>
10
+
11
+ <h1>Mobile Layout</h1>
12
+
13
+ <%= yield %>
14
+
15
+ </body>
16
+ </html>
@@ -0,0 +1,4 @@
1
+ # This file is used by Rack-based servers to start the application.
2
+
3
+ require ::File.expand_path('../config/environment', __FILE__)
4
+ run Dummy::Application
@@ -0,0 +1,46 @@
1
+ require File.expand_path('../boot', __FILE__)
2
+
3
+ require "rails"
4
+ require 'action_controller/railtie'
5
+ require 'action_mailer/railtie'
6
+ require 'active_resource/railtie'
7
+ require 'sprockets/railtie'
8
+
9
+ Bundler.require
10
+ require "mobylette"
11
+
12
+ module Dummy
13
+ class Application < Rails::Application
14
+ # Settings in config/environments/* take precedence over those specified here.
15
+ # Application configuration should go into files in config/initializers
16
+ # -- all .rb files in that directory are automatically loaded.
17
+
18
+ # Custom directories with classes and modules you want to be autoloadable.
19
+ # config.autoload_paths += %W(#{config.root}/extras)
20
+
21
+ # Only load the plugins named here, in the order given (default is alphabetical).
22
+ # :all can be used as a placeholder for all plugins not explicitly named.
23
+ # config.plugins = [ :exception_notification, :ssl_requirement, :all ]
24
+
25
+ # Activate observers that should always be running.
26
+ # config.active_record.observers = :cacher, :garbage_collector, :forum_observer
27
+
28
+ # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
29
+ # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
30
+ # config.time_zone = 'Central Time (US & Canada)'
31
+
32
+ # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
33
+ # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
34
+ # config.i18n.default_locale = :de
35
+
36
+ # Configure the default encoding used in templates for Ruby 1.9.
37
+ config.encoding = "utf-8"
38
+
39
+ # Configure sensitive parameters which will be filtered from the log file.
40
+ config.filter_parameters += [:password]
41
+
42
+ # Enable the asset pipeline
43
+ config.assets.enabled = true
44
+ end
45
+ end
46
+
@@ -0,0 +1,10 @@
1
+ require 'rubygems'
2
+ gemfile = File.expand_path('../../../../Gemfile', __FILE__)
3
+
4
+ if File.exist?(gemfile)
5
+ ENV['BUNDLE_GEMFILE'] = gemfile
6
+ require 'bundler'
7
+ Bundler.setup
8
+ end
9
+
10
+ $:.unshift File.expand_path('../../../../lib', __FILE__)
@@ -0,0 +1,25 @@
1
+ # SQLite version 3.x
2
+ # gem install sqlite3
3
+ #
4
+ # Ensure the SQLite 3 gem is defined in your Gemfile
5
+ # gem 'sqlite3'
6
+ development:
7
+ adapter: sqlite3
8
+ database: db/development.sqlite3
9
+ pool: 5
10
+ timeout: 5000
11
+
12
+ # Warning: The database defined as "test" will be erased and
13
+ # re-generated from your development database when you run "rake".
14
+ # Do not set this db to the same as development or production.
15
+ test:
16
+ adapter: sqlite3
17
+ database: db/test.sqlite3
18
+ pool: 5
19
+ timeout: 5000
20
+
21
+ production:
22
+ adapter: sqlite3
23
+ database: db/production.sqlite3
24
+ pool: 5
25
+ timeout: 5000
@@ -0,0 +1,5 @@
1
+ # Load the rails application
2
+ require File.expand_path('../application', __FILE__)
3
+
4
+ # Initialize the rails application
5
+ Dummy::Application.initialize!
@@ -0,0 +1,33 @@
1
+ Dummy::Application.configure do
2
+ # Settings specified here will take precedence over those in config/application.rb
3
+
4
+ # In the development environment your application's code is reloaded on
5
+ # every request. This slows down response time but is perfect for development
6
+ # since you don't have to restart the web server when you make code changes.
7
+ config.cache_classes = false
8
+
9
+ # Log error messages when you accidentally call methods on nil.
10
+ config.whiny_nils = true
11
+
12
+ # Show full error reports and disable caching
13
+ config.consider_all_requests_local = true
14
+ config.action_controller.perform_caching = false
15
+
16
+ # Don't care if the mailer can't send
17
+ config.action_mailer.raise_delivery_errors = false
18
+
19
+ # Print deprecation notices to the Rails logger
20
+ config.active_support.deprecation = :log
21
+
22
+ # Only use best-standards-support built into browsers
23
+ config.action_dispatch.best_standards_support = :builtin
24
+
25
+ # Do not compress assets
26
+ config.assets.compress = false
27
+
28
+ # Allow pass debug_assets=true as a query parameter to load pages with unpackaged assets
29
+ config.assets.allow_debugging = true
30
+
31
+ # Expands the lines which load the assets
32
+ config.assets.debug = true
33
+ end
@@ -0,0 +1,51 @@
1
+ Dummy::Application.configure do
2
+ # Settings specified here will take precedence over those in config/application.rb
3
+
4
+ # Code is not reloaded between requests
5
+ config.cache_classes = true
6
+
7
+ # Full error reports are disabled and caching is turned on
8
+ config.consider_all_requests_local = false
9
+ config.action_controller.perform_caching = true
10
+
11
+ # Disable Rails's static asset server (Apache or nginx will already do this)
12
+ config.serve_static_assets = false
13
+
14
+ # Compress JavaScripts and CSS
15
+ config.assets.compress = true
16
+
17
+ # Specifies the header that your server uses for sending files
18
+ # config.action_dispatch.x_sendfile_header = "X-Sendfile" # for apache
19
+ # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for nginx
20
+
21
+ # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies.
22
+ # config.force_ssl = true
23
+
24
+ # See everything in the log (default is :info)
25
+ # config.log_level = :debug
26
+
27
+ # Use a different logger for distributed setups
28
+ # config.logger = SyslogLogger.new
29
+
30
+ # Use a different cache store in production
31
+ # config.cache_store = :mem_cache_store
32
+
33
+ # Enable serving of images, stylesheets, and JavaScripts from an asset server
34
+ # config.action_controller.asset_host = "http://assets.example.com"
35
+
36
+ # Precompile additional assets (application.js, application.css, and all non-JS/CSS are already added)
37
+ # config.assets.precompile += %w( search.js )
38
+
39
+ # Disable delivery errors, bad email addresses will be ignored
40
+ # config.action_mailer.raise_delivery_errors = false
41
+
42
+ # Enable threaded mode
43
+ # config.threadsafe!
44
+
45
+ # Enable locale fallbacks for I18n (makes lookups for any locale fall back to
46
+ # the I18n.default_locale when a translation can not be found)
47
+ config.i18n.fallbacks = true
48
+
49
+ # Send deprecation notices to registered listeners
50
+ config.active_support.deprecation = :notify
51
+ end
@@ -0,0 +1,42 @@
1
+ Dummy::Application.configure do
2
+ # Settings specified here will take precedence over those in config/application.rb
3
+
4
+ # The test environment is used exclusively to run your application's
5
+ # test suite. You never need to work with it otherwise. Remember that
6
+ # your test database is "scratch space" for the test suite and is wiped
7
+ # and recreated between test runs. Don't rely on the data there!
8
+ config.cache_classes = true
9
+
10
+ # Configure static asset server for tests with Cache-Control for performance
11
+ config.serve_static_assets = true
12
+ config.static_cache_control = "public, max-age=3600"
13
+
14
+ # Log error messages when you accidentally call methods on nil
15
+ config.whiny_nils = true
16
+
17
+ # Show full error reports and disable caching
18
+ config.consider_all_requests_local = true
19
+ config.action_controller.perform_caching = false
20
+
21
+ # Raise exceptions instead of rendering exception templates
22
+ config.action_dispatch.show_exceptions = false
23
+
24
+ # Disable request forgery protection in test environment
25
+ config.action_controller.allow_forgery_protection = false
26
+
27
+ # Tell Action Mailer not to deliver emails to the real world.
28
+ # The :test delivery method accumulates sent emails in the
29
+ # ActionMailer::Base.deliveries array.
30
+ config.action_mailer.delivery_method = :test
31
+
32
+ # Use SQL instead of Active Record's schema dumper when creating the test database.
33
+ # This is necessary if your schema can't be completely dumped by the schema dumper,
34
+ # like if you have constraints or database-specific column types
35
+ # config.active_record.schema_format = :sql
36
+
37
+ # Print deprecation notices to the stderr
38
+ config.active_support.deprecation = :stderr
39
+
40
+ # Allow pass debug_assets=true as a query parameter to load pages with unpackaged assets
41
+ config.assets.allow_debugging = true
42
+ end
@@ -0,0 +1,7 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ # You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces.
4
+ # Rails.backtrace_cleaner.add_silencer { |line| line =~ /my_noisy_library/ }
5
+
6
+ # You can also remove all the silencers if you're trying to debug a problem that might stem from framework code.
7
+ # Rails.backtrace_cleaner.remove_silencers!
@@ -0,0 +1,10 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ # Add new inflection rules using the following format
4
+ # (all these examples are active by default):
5
+ # ActiveSupport::Inflector.inflections do |inflect|
6
+ # inflect.plural /^(ox)$/i, '\1en'
7
+ # inflect.singular /^(ox)en/i, '\1'
8
+ # inflect.irregular 'person', 'people'
9
+ # inflect.uncountable %w( fish sheep )
10
+ # end
@@ -0,0 +1,5 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ # Add new mime types for use in respond_to blocks:
4
+ # Mime::Type.register "text/richtext", :rtf
5
+ # Mime::Type.register_alias "text/html", :iphone
@@ -0,0 +1,7 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ # Your secret key for verifying the integrity of signed cookies.
4
+ # If you change this key, all old signed cookies will become invalid!
5
+ # Make sure the secret is at least 30 characters and all random,
6
+ # no regular words or you'll be exposed to dictionary attacks.
7
+ Dummy::Application.config.secret_token = 'f8dcf26823456ca9e2699cd232224adc813e82616c36cb65fc7498a7fc3a545bc3f798bb97dc6de1354604bfd5bf337f83c0da8dd461b5e8ca484fa869f3770f'
@@ -0,0 +1,8 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ Dummy::Application.config.session_store :cookie_store, :key => '_dummy_session'
4
+
5
+ # Use the database for sessions instead of the cookie-based default,
6
+ # which shouldn't be used to store highly confidential information
7
+ # (create the session table with "rails generate session_migration")
8
+ # Dummy::Application.config.session_store :active_record_store
@@ -0,0 +1,14 @@
1
+ # Be sure to restart your server when you modify this file.
2
+ #
3
+ # This file contains settings for ActionController::ParamsWrapper which
4
+ # is enabled by default.
5
+
6
+ # Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array.
7
+ ActiveSupport.on_load(:action_controller) do
8
+ wrap_parameters :format => [:json]
9
+ end
10
+
11
+ # Disable root element in JSON by default.
12
+ ActiveSupport.on_load(:active_record) do
13
+ self.include_root_in_json = false
14
+ end
@@ -0,0 +1,5 @@
1
+ # Sample localization file for English. Add more files in this directory for other locales.
2
+ # See https://github.com/svenfuchs/rails-i18n/tree/master/rails%2Flocale for starting points.
3
+
4
+ en:
5
+ hello: "Hello world"
@@ -0,0 +1,22 @@
1
+ Dummy::Application.routes.draw do
2
+
3
+ get "fallbacks/index"
4
+
5
+ get "testing" => "testing#index"
6
+
7
+ get "home(.:format)" => "home#index"
8
+ get "respond_to_test(.:format)" => "home#respond_to_test"
9
+ get "no_mobile_view(.:format)" => "home#no_mobile_view"
10
+
11
+
12
+ get "no_fallback/index(.:format)" => "no_fallback#index"
13
+ get "no_fallback/test(.:format)" => "no_fallback#test"
14
+
15
+ get "default_fallback/index(.:format)" => "default_fallback#index"
16
+ get "default_fallback/test(.:format)" => "default_fallback#test"
17
+
18
+ get "force_fallback/index(.:format)" => "force_fallback#index"
19
+ get "force_fallback/test(.:format)" => "force_fallback#test"
20
+
21
+ root :to => "home#index"
22
+ end