h2ocube_rails_helper 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in h2ocube_rails_assets.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 TODO: Write your name
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,37 @@
1
+ # H2ocubeRailsHelper
2
+
3
+ Just an helper collection.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'garelic' # if you use render_ga
10
+ gem 'h2ocube_rails_helper'
11
+
12
+ And then execute:
13
+
14
+ $ bundle
15
+ $ rails g h2ocube_rails_helper
16
+
17
+ ## Usage
18
+
19
+ render_html_class #=> controller_name action_name
20
+
21
+ request.env['X_MOBILE_DEVICE'] #=> such as 'iPhone'
22
+
23
+ render_title
24
+ render_keywords
25
+ render_description
26
+
27
+ render_seo
28
+
29
+ render_ga
30
+
31
+ ## Contributing
32
+
33
+ 1. Fork it
34
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
35
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
36
+ 4. Push to the branch (`git push origin my-new-feature`)
37
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,21 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+
5
+ Gem::Specification.new do |gem|
6
+ gem.name = 'h2ocube_rails_helper'
7
+ gem.version = '0.0.1'
8
+ gem.authors = ['Ben']
9
+ gem.email = ['ben@h2ocube.com']
10
+ gem.description = %q{Just an helper collection}
11
+ gem.summary = %q{Just an helper collection}
12
+ gem.homepage = 'https://github.com/h2ocube/h2ocube_rails_helper'
13
+
14
+ gem.files = `git ls-files`.split($/)
15
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
16
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
17
+ gem.require_paths = ["lib"]
18
+
19
+ gem.add_dependency 'settingslogic'
20
+ gem.add_dependency 'rack-mobile-detect'
21
+ end
@@ -0,0 +1,19 @@
1
+ class H2ocubeRailsHelperGenerator < Rails::Generators::Base
2
+ source_root File.expand_path('../source', __FILE__)
3
+
4
+ desc 'Creates a helper.yml to your config/.'
5
+
6
+ def copy_helper_yml
7
+ template 'helper.yml.erb', 'config/helper.yml'
8
+ end
9
+
10
+ def copy_helper_rb
11
+ template 'helper_settings.rb.erb', 'app/models/helper_settings.rb'
12
+ end
13
+
14
+ private
15
+
16
+ def app_name
17
+ Rails.application.class.to_s.split('::').first
18
+ end
19
+ end
@@ -0,0 +1,15 @@
1
+ defaults: &defaults
2
+ ga: Google Analytics Profile Id
3
+ domain: h2ocube.com
4
+ title: <%= app_name %>
5
+ keywords: <%= app_name %>
6
+ description: <%= app_name %>
7
+
8
+ development:
9
+ <<: *defaults
10
+
11
+ test:
12
+ <<: *defaults
13
+
14
+ production:
15
+ <<: *defaults
@@ -0,0 +1,4 @@
1
+ class HelperSettings < Settingslogic
2
+ source "#{Rails.root}/config/helper.yml"
3
+ namespace Rails.env
4
+ end
@@ -0,0 +1,97 @@
1
+ # coding: utf-8
2
+
3
+ require 'settingslogic'
4
+ require 'rack/mobile-detect'
5
+
6
+ module H2ocubeRailsHelper
7
+ module Rails
8
+ class Rails::Engine < ::Rails::Engine
9
+ initializer 'Rack::MobileDetect' do |app|
10
+ app.middleware.use Rack::MobileDetect
11
+ end
12
+ end
13
+ end
14
+ end
15
+
16
+ def render_html_class
17
+ cls = []
18
+ if params[:controller].include?('/')
19
+ cls.push params[:controller].gsub('/', '_')
20
+ params[:controller].split('/').each { |c| cls.push c }
21
+ else
22
+ cls.push params[:controller]
23
+ end
24
+ cls.push params[:action]
25
+ if params.has_key?(:html_class)
26
+ if params[:html_class].class != Array
27
+ cls.push params[:html_class].to_s
28
+ else
29
+ params[:html_class].each { |c| cls.push c }
30
+ end
31
+ end
32
+ if request.env['X_MOBILE_DEVICE']
33
+ cls.push 'mobile', request.env['X_MOBILE_DEVICE']
34
+ end
35
+ cls.compact.uniq.join ' '
36
+ end
37
+
38
+ def _title
39
+ if defined?(@title)
40
+ title = @title.class.to_s == 'Array' ? @title : [ @title.strip ]
41
+ else
42
+ if defined?(@item)
43
+ if @item.respond_to?(:seo_title) && !@item.seo_title.blank?
44
+ title = @item.seo_title
45
+ elsif @item.respond_to?(:title) && !@item.title.blank?
46
+ title = @item.title
47
+ elsif @item.respond_to?(:name) && !@item.name.blank?
48
+ title = @item.name
49
+ end
50
+ end
51
+ title ||= []
52
+ end
53
+ title.push HelperSettings.title
54
+ title.map{ |t| t.strip }
55
+ end
56
+
57
+ def render_title
58
+ "<title>#{_title.join(' - ')}</title>".html_safe
59
+ end
60
+
61
+ def _keywords
62
+ if defined? @keywords
63
+ keywords = (@keywords.class.to_s == 'Array' ? @keywords : @keywords.strip.split(/(,|,)/))
64
+ elsif defined?(@item) && @item.respond_to?(:seo_keywords) && !@item.seo_keywords.blank?
65
+ keywords = @item.seo_keywords.strip.split(/(,|,)/)
66
+ else
67
+ keywords = HelperSettings.keywords.strip.split(/(,|,)/)
68
+ end
69
+ keywords.map{ |k| k = k.gsub(/(,|,)/, '').strip; k.blank? ? nil : k }.compact.uniq
70
+ end
71
+
72
+ def render_keywords
73
+ "<meta name=\"keywords\" content=\"#{_keywords.join(',')}\" />".html_safe
74
+ end
75
+
76
+ def _description
77
+ if defined? @description
78
+ description = @description
79
+ elsif defined?(@item) && @item.respond_to?(:seo_description) && !@item.seo_description.blank?
80
+ description = @item.seo_description
81
+ else
82
+ description = HelperSettings.description
83
+ end
84
+ description.strip
85
+ end
86
+
87
+ def render_description
88
+ "<meta name=\"description\" content=\"#{_description}\" />".html_safe
89
+ end
90
+
91
+ def render_seo
92
+ render_title << render_keywords << render_description << render_ga
93
+ end
94
+
95
+ def render_ga
96
+ ("<script>_gaq=[['_setDomainName', '#{HelperSettings.domain}'],['_trackPageview'],['_trackPageLoadTime']];</script>" << Garelic.monitoring(HelperSettings.ga)).html_safe if defined?(Garelic)
97
+ end
metadata ADDED
@@ -0,0 +1,87 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: h2ocube_rails_helper
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Ben
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-11-30 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: settingslogic
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: rack-mobile-detect
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ description: Just an helper collection
47
+ email:
48
+ - ben@h2ocube.com
49
+ executables: []
50
+ extensions: []
51
+ extra_rdoc_files: []
52
+ files:
53
+ - .gitignore
54
+ - Gemfile
55
+ - LICENSE.txt
56
+ - README.md
57
+ - Rakefile
58
+ - h2ocube_rails_helper.gemspec
59
+ - lib/generators/h2ocube_rails_helper_generator.rb
60
+ - lib/generators/source/helper.yml.erb
61
+ - lib/generators/source/helper_settings.rb.erb
62
+ - lib/h2ocube_rails_helper.rb
63
+ homepage: https://github.com/h2ocube/h2ocube_rails_helper
64
+ licenses: []
65
+ post_install_message:
66
+ rdoc_options: []
67
+ require_paths:
68
+ - lib
69
+ required_ruby_version: !ruby/object:Gem::Requirement
70
+ none: false
71
+ requirements:
72
+ - - ! '>='
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
75
+ required_rubygems_version: !ruby/object:Gem::Requirement
76
+ none: false
77
+ requirements:
78
+ - - ! '>='
79
+ - !ruby/object:Gem::Version
80
+ version: '0'
81
+ requirements: []
82
+ rubyforge_project:
83
+ rubygems_version: 1.8.24
84
+ signing_key:
85
+ specification_version: 3
86
+ summary: Just an helper collection
87
+ test_files: []