bcms_mobile 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,3 @@
1
+ require 'bcms_mobile/engine'
2
+ require 'bcms_mobile/routes'
3
+
@@ -0,0 +1,68 @@
1
+ require 'browsercms'
2
+ require 'mobylette'
3
+ require 'bcms_mobile/mobile_aware'
4
+
5
+ module BcmsMobile
6
+ class Engine < Rails::Engine
7
+ include Cms::Module
8
+ config.to_prepare do
9
+
10
+ ApplicationHelper.class_eval do
11
+ include BcmsMobile::MobileHelpers
12
+ end
13
+
14
+ Cms::ContentController.class_eval do
15
+ include BcmsMobile::MobileAware
16
+
17
+ #before_filter :print_request_info
18
+ before_filter :configure_cache_directory
19
+
20
+ def print_request_info
21
+ w "*" * 20
22
+ w "User Agent: #{request.user_agent}"
23
+ m = "Mobile Request?: "
24
+ if respond_as_mobile?
25
+ m += "Yes"
26
+ else
27
+ m += "No"
28
+ end
29
+ w m
30
+ end
31
+
32
+ def configure_cache_directory
33
+ if respond_as_mobile?
34
+ self.class.page_cache_directory = mobile_cache_directory
35
+ else
36
+ self.class.page_cache_directory = cms_cache_directory
37
+ end
38
+ end
39
+
40
+ # Because of caching, CMS pages should only return mobile content on a separate subdomain.
41
+ # or if a CMS editor wants to see the mobile version of the page.
42
+ def respond_as_mobile?
43
+ w "Checking the subdomain for #{request.domain} is #{request.subdomain}"
44
+ if params[:template] =='mobile'
45
+ session[:mobile_mode] = true
46
+ elsif params[:template] =='full'
47
+ session[:mobile_mode] = false
48
+ end
49
+
50
+ request.subdomain == "m" || (session[:mobile_mode] == true && current_user.able_to?(:edit_content))
51
+ end
52
+
53
+ private
54
+ # Overrides core behavior to swap layouts based on whether this is a mobile request or not.
55
+ def render_page
56
+ @_page_route.execute(self) if @_page_route
57
+ prepare_connectables_for_render
58
+ template = determine_page_template
59
+ render :layout => template, :action => 'show'
60
+ end
61
+
62
+
63
+ end
64
+ end
65
+
66
+
67
+ end
68
+ end
@@ -0,0 +1,69 @@
1
+ module BcmsMobile
2
+
3
+ module MobileHelpers
4
+
5
+ def full_site_url
6
+ url_for(:host=>SITE_DOMAIN, :prefer_full_site=>true)
7
+ end
8
+
9
+ def mobile_site_url
10
+ url_for(:host=>SITE_DOMAIN, :prefer_mobile_site=>true)
11
+ end
12
+
13
+
14
+ end
15
+
16
+ module MobileAware
17
+
18
+ def w(m)
19
+ logger.warn m
20
+ end
21
+
22
+ def banner(m)
23
+ w "*" * 20
24
+ w m
25
+ end
26
+
27
+ # Returns the directory where BrowserCMS should write out it's Page cache files for the mobile version of the site.
28
+ # (Optionally) It can be configured in environment files via:
29
+ # config.bcms_mobile_cache_directory = File.join(Rails.root, 'some', 'mobile_dir')
30
+ def mobile_cache_directory
31
+ configured_dir = Rails.application.config.bcms_mobile_cache_directory
32
+ configured_dir ? configured_dir : default_mobile_cache_directory
33
+ end
34
+
35
+ # Returns the directory where BrowserCMS should write out it's Page cache files for the full version of the site.
36
+ # This should be exactly the same as where a typical CMS project stores it's files.
37
+ # (Optionally) It can be configured in environment files via:
38
+ # config.browsercms_cache_directory = File.join(Rails.root, 'some', 'dir')
39
+ def cms_cache_directory
40
+ configured_dir = Rails.application.config.browsercms_cache_directory
41
+ configured_dir ? configured_dir : default_browsercms_cache_directory
42
+ end
43
+
44
+ # Looks for a mobile template if the request is mobile, falling back to the html template if it can't be found.
45
+ def determine_page_template
46
+ layout = @page.layout
47
+ layout_name = @page.template_file_name
48
+
49
+ if respond_as_mobile?
50
+ w "Does html layout exist?:#{template_exists?(layout_name, "layouts/templates")}"
51
+ mobile_exists = template_exists?(layout_name, "layouts/mobile")
52
+ w "Does mobile layout exist?:#{mobile_exists}"
53
+ layout = "mobile/#{layout_name}" if mobile_exists
54
+ end
55
+ w "layout = #{layout}"
56
+ layout
57
+ end
58
+
59
+ private
60
+ def default_browsercms_cache_directory
61
+ File.join(Rails.root, 'public', 'cache')
62
+ end
63
+
64
+ def default_mobile_cache_directory
65
+ File.join(Rails.root, 'public', 'mobile_cache')
66
+ end
67
+ end
68
+
69
+ end
@@ -0,0 +1,7 @@
1
+ module Cms::Routes
2
+ def routes_for_bcms_mobile
3
+ namespace(:cms) do
4
+ #content_blocks :bcms_mobiles
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,3 @@
1
+ module BcmsMobile
2
+ VERSION = "1.0.0"
3
+ end
@@ -0,0 +1,10 @@
1
+ Description:
2
+ Installs the bcms_mobile module.
3
+
4
+ Example:
5
+ rails generate bcms_mobile:install
6
+
7
+ This will:
8
+ 1. Copy any migrations from the gem into the project.
9
+ 2. Add the routes to the config/routes.rb
10
+
@@ -0,0 +1,12 @@
1
+ require 'cms/module_installation'
2
+
3
+ class BcmsMobile::InstallGenerator < Cms::ModuleInstallation
4
+ add_migrations_directory_to_source_root __FILE__
5
+
6
+ # Add migrations to be copied, by uncommenting the following file and editing as needed.
7
+ # copy_migration_file 'DATESTAMP_create_name_of_content_block.rb'
8
+
9
+ def make_mobile_templates_directory
10
+ empty_directory 'app/views/layouts/mobile'
11
+ end
12
+ end
metadata ADDED
@@ -0,0 +1,88 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: bcms_mobile
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - BrowserMedia
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-02-09 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: mobylette
16
+ requirement: &70342244972020 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 1.6.0
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *70342244972020
25
+ - !ruby/object:Gem::Dependency
26
+ name: browsercms
27
+ requirement: &70342244966100 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ~>
31
+ - !ruby/object:Gem::Version
32
+ version: 3.3.3
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: *70342244966100
36
+ description:
37
+ email: github@browsermedia.com
38
+ executables: []
39
+ extensions: []
40
+ extra_rdoc_files:
41
+ - README.markdown
42
+ files:
43
+ - app/views/bcms_mobile/_mobile_toggle.html.erb
44
+ - app/views/layouts/_page_toolbar.html.erb
45
+ - db/migrate/20100117144039_browsercms315.rb
46
+ - lib/bcms_mobile/engine.rb
47
+ - lib/bcms_mobile/mobile_aware.rb
48
+ - lib/bcms_mobile/routes.rb
49
+ - lib/bcms_mobile/version.rb
50
+ - lib/bcms_mobile.rb
51
+ - lib/generators/bcms_mobile/install/install_generator.rb
52
+ - lib/generators/bcms_mobile/install/USAGE
53
+ - LICENSE.txt
54
+ - GPL.txt
55
+ - Gemfile
56
+ - Copyright.txt
57
+ - README.markdown
58
+ homepage: http://www.github.com/browsermedia/bcms_mobile
59
+ licenses: []
60
+ post_install_message:
61
+ rdoc_options: []
62
+ require_paths:
63
+ - lib
64
+ required_ruby_version: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ segments:
71
+ - 0
72
+ hash: 1881617308010632469
73
+ required_rubygems_version: !ruby/object:Gem::Requirement
74
+ none: false
75
+ requirements:
76
+ - - ! '>='
77
+ - !ruby/object:Gem::Version
78
+ version: '0'
79
+ segments:
80
+ - 0
81
+ hash: 1881617308010632469
82
+ requirements: []
83
+ rubyforge_project: bcms_mobile
84
+ rubygems_version: 1.8.15
85
+ signing_key:
86
+ specification_version: 3
87
+ summary: A Bcms Mobile Module for BrowserCMS
88
+ test_files: []