meta-tags-helpers 0.1.7 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (59) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +117 -0
  3. data/Gemfile +3 -7
  4. data/LICENSE.txt +22 -0
  5. data/README.md +26 -6
  6. data/Rakefile +4 -51
  7. data/lib/meta_tags_helpers.rb +35 -32
  8. data/meta-tags-helpers.gemspec +21 -47
  9. data/test_app/Gemfile +4 -0
  10. data/test_app/README.rdoc +28 -0
  11. data/test_app/Rakefile +6 -0
  12. data/test_app/app/assets/javascripts/application.js +13 -0
  13. data/test_app/app/assets/javascripts/metatags.js +2 -0
  14. data/test_app/app/assets/stylesheets/application.css +13 -0
  15. data/test_app/app/assets/stylesheets/metatags.css +4 -0
  16. data/test_app/app/controllers/application_controller.rb +5 -0
  17. data/test_app/app/controllers/metatags_controller.rb +33 -0
  18. data/test_app/app/helpers/application_helper.rb +2 -0
  19. data/test_app/app/helpers/metatags_helper.rb +2 -0
  20. data/test_app/app/views/layouts/application.html.erb +17 -0
  21. data/test_app/app/views/metatags/arrays.html.erb +0 -0
  22. data/test_app/app/views/metatags/default.html.erb +0 -0
  23. data/test_app/app/views/metatags/namespaced.html.erb +0 -0
  24. data/test_app/app/views/metatags/options.html.erb +0 -0
  25. data/test_app/app/views/metatags/override_controller.html.erb +0 -0
  26. data/test_app/app/views/metatags/override_view.html.erb +1 -0
  27. data/test_app/bin/bundle +3 -0
  28. data/test_app/bin/rails +4 -0
  29. data/test_app/bin/rake +4 -0
  30. data/test_app/config.ru +4 -0
  31. data/test_app/config/application.rb +31 -0
  32. data/test_app/config/boot.rb +4 -0
  33. data/test_app/config/environment.rb +5 -0
  34. data/test_app/config/environments/development.rb +23 -0
  35. data/test_app/config/environments/production.rb +65 -0
  36. data/test_app/config/environments/test.rb +36 -0
  37. data/test_app/config/initializers/backtrace_silencers.rb +7 -0
  38. data/test_app/config/initializers/filter_parameter_logging.rb +4 -0
  39. data/test_app/config/initializers/inflections.rb +16 -0
  40. data/test_app/config/initializers/mime_types.rb +5 -0
  41. data/test_app/config/initializers/secret_token.rb +12 -0
  42. data/test_app/config/initializers/session_store.rb +3 -0
  43. data/test_app/config/initializers/wrap_parameters.rb +9 -0
  44. data/test_app/config/locales/en.yml +23 -0
  45. data/test_app/config/routes.rb +8 -0
  46. data/test_app/db/seeds.rb +7 -0
  47. data/test_app/log/development.log +0 -0
  48. data/test_app/log/test.log +123 -0
  49. data/test_app/public/404.html +58 -0
  50. data/test_app/public/422.html +58 -0
  51. data/test_app/public/500.html +57 -0
  52. data/test_app/public/favicon.ico +0 -0
  53. data/test_app/public/robots.txt +5 -0
  54. data/test_app/test/controllers/metatags_controller_test.rb +89 -0
  55. data/test_app/test/helpers/metatags_helper_test.rb +4 -0
  56. data/test_app/test/test_helper.rb +7 -0
  57. metadata +127 -34
  58. data/Gemfile.lock +0 -93
  59. data/VERSION +0 -1
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: da68ee4c3c07370f7b41fbca573c38cfecf5398c
4
+ data.tar.gz: 3483ced9ffb0496a8855e78a4158df86eb081449
5
+ SHA512:
6
+ metadata.gz: 5e4fc8b3a89d66a3fc9ae5d5ef48d6c80917e642c9e261f433e7aa20afe58f4fa1a172a09391a9ab0eed63bc3724eaaf12dd3bc5999d19e462b8ebd8989523ec
7
+ data.tar.gz: e0709490ffe13ab1d4e6c9862bb36890d9ab09e1ac22d24ce8b11e2a4cb3004575058ddf190f6176f5be223a70ebeb46de3dc307ad1c621c2cb198e7eb0fa441
@@ -0,0 +1,117 @@
1
+ # Created by http://gitignore.io
2
+
3
+ Gemfile.lock
4
+
5
+ ### Ruby ###
6
+ *.gem
7
+ *.rbc
8
+ .bundle
9
+ .config
10
+ coverage
11
+ InstalledFiles
12
+ lib/bundler/man
13
+ pkg
14
+ rdoc
15
+ spec/reports
16
+ test/tmp
17
+ test/version_tmp
18
+ tmp
19
+
20
+ # YARD artifacts
21
+ .yardoc
22
+ _yardoc
23
+ doc/
24
+
25
+ ### Rails ###
26
+ *.rbc
27
+ *.sassc
28
+ .sass-cache
29
+ capybara-*.html
30
+ .rspec
31
+ .rvmrc
32
+ /.bundle
33
+ /vendor/bundle
34
+ /log/*
35
+ /tmp/*
36
+ /db/*.sqlite3
37
+ /public/system/*
38
+ /coverage/
39
+ /spec/tmp/*
40
+ **.orig
41
+ rerun.txt
42
+ pickle-email-*.html
43
+ .project
44
+ !.keep
45
+
46
+
47
+ ### SublimeText ###
48
+ # SublimeText project files
49
+ *.sublime-workspace
50
+
51
+ ### TextMate ###
52
+ *.tmproj
53
+ *.tmproject
54
+ tmtags
55
+
56
+ ### OSX ###
57
+ .DS_Store
58
+ .AppleDouble
59
+ .LSOverride
60
+ Icon
61
+
62
+
63
+ # Thumbnails
64
+ ._*
65
+
66
+ # Files that might appear on external disk
67
+ .Spotlight-V100
68
+ .Trashes
69
+
70
+ ### Windows ###
71
+ # Windows image file caches
72
+ Thumbs.db
73
+ ehthumbs.db
74
+
75
+ # Folder config file
76
+ Desktop.ini
77
+
78
+ # Recycle Bin used on file shares
79
+ $RECYCLE.BIN/
80
+
81
+ ### Linux ###
82
+ .*
83
+ !.gitignore
84
+ !.git*
85
+ *~
86
+
87
+
88
+ ### RubyMine ###
89
+ .idea/workspace.xml
90
+
91
+ ### Eclipse ###
92
+ *.pydevproject
93
+ .project
94
+ .metadata
95
+ bin/**
96
+ tmp/**
97
+ tmp/**/*
98
+ *.tmp
99
+ *.bak
100
+ *.swp
101
+ *~.nib
102
+ local.properties
103
+ .classpath
104
+ .settings/
105
+ .loadpath
106
+
107
+ # External tool builders
108
+ .externalToolBuilders/
109
+
110
+ # Locally stored "Eclipse launch configurations"
111
+ *.launch
112
+
113
+ # CDT-specific
114
+ .cproject
115
+
116
+ # PDT-specific
117
+ .buildpath
data/Gemfile CHANGED
@@ -1,8 +1,4 @@
1
- source "http://rubygems.org"
1
+ source 'https://rubygems.org'
2
2
 
3
- gem 'rails'
4
-
5
- group :development do
6
- gem "bundler"
7
- gem "jeweler", "~> 1.8.4"
8
- end
3
+ # Specify your gem's dependencies in meta-tags-helpers.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 mcasimir
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 CHANGED
@@ -4,10 +4,12 @@
4
4
 
5
5
  The `meta-tags-helpers` gem consists of a set of helpers to setup and render html meta tags in a simple way. It has good customizable defaults that also come with built-in support for open-graph and csrf: all your meta tags in a single call.
6
6
 
7
+ Supports both Rails 3 and 4.
8
+
7
9
  ### Install
8
10
 
9
11
  ``` rb
10
- gem 'meta-tags-helpers'
12
+ gem 'meta-tags-helpers', '~> 0.2.0'
11
13
  ```
12
14
 
13
15
  ### Examples
@@ -24,7 +26,7 @@ if you don't like the defaults you can override them passing other values as a p
24
26
  ``` erb
25
27
  <%= meta_tags(
26
28
  :title => "MyBlog - This is a Blog",
27
- :description => "The blog of mine & a reserved character",
29
+ :description => "My blog description & a reserved character that will be escaped",
28
30
  :og => {:type => "website"}
29
31
  :ns => {
30
32
  :my_custom_meta => "a value"
@@ -35,9 +37,7 @@ if you don't like the defaults you can override them passing other values as a p
35
37
 
36
38
  You can further override these values in your controller, views and partials using the `set_meta` method (see below).
37
39
 
38
- **NOTE:** You can set namespaced keys (eg. `og:type`) either as key-value pairs (eg. `:"og:type" => "..."`) or as nested hashes (eg. `:og => {:type => "..."}`), both of the syntaxes would address the same meta tag.
39
-
40
- ### What it generates?
40
+ ### Generated HTML
41
41
 
42
42
  The first example above will produce the following html:
43
43
 
@@ -57,7 +57,27 @@ The first example above will produce the following html:
57
57
 
58
58
  ```
59
59
 
60
- **NOTE:** namespaced meta (eg. `og:title`) are supposed to be RDF properties and so they are marked using a `property` attribute.
60
+ ### Namespaced Keys
61
+
62
+ Metas with namespaced keys (eg. `og:title`) are supposed to be RDF properties and so they are rendered using a `property` attribute.
63
+
64
+ You can equally set namespaced keys through simple key-value pairs (eg. `:"og:type" => "..."`) or with nested hashes (eg. `:og => {:type => "..."}`).
65
+
66
+ Note that you can also easily render arrays of metas having the same key passing an array as value.
67
+
68
+ ``` rhtml
69
+ <%= meta_tags(
70
+ :title => "Escape from New York",
71
+ :description => "Sci-fi film by John Carpenter"
72
+ :og => {
73
+ :type => "video.movie"
74
+ },
75
+ :video => {
76
+ :year => 1981,
77
+ :actor => ["Kurt Russell", "Lee Van Cleef"]
78
+ })
79
+ %>
80
+ ```
61
81
 
62
82
  ### Setting and overriding meta tags from controller/partials/other views
63
83
 
data/Rakefile CHANGED
@@ -1,53 +1,6 @@
1
- # encoding: utf-8
1
+ require "bundler/gem_tasks"
2
2
 
3
- require 'rubygems'
4
- require 'bundler'
5
- begin
6
- Bundler.setup(:default, :development)
7
- rescue Bundler::BundlerError => e
8
- $stderr.puts e.message
9
- $stderr.puts "Run `bundle install` to install missing gems"
10
- exit e.status_code
11
- end
12
- require 'rake'
13
-
14
- require 'jeweler'
15
- Jeweler::Tasks.new do |gem|
16
- # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
17
- gem.name = "meta-tags-helpers"
18
- gem.homepage = "http://github.com/mcasimir/kaminari-bootstrap"
19
- gem.license = "MIT"
20
- gem.summary = %Q{Rails meta tags helpers}
21
- gem.description = %Q{Rails meta tags helpers}
22
- gem.email = "maurizio.cas@gmail.com"
23
- gem.authors = ["mcasimir"]
24
- # dependencies defined in Gemfile
25
- end
26
- Jeweler::RubygemsDotOrgTasks.new
27
-
28
-
29
- task :push do
30
- message = ENV["message"] || "commit #{Time.now}"
31
- `git add . && git commit -a -m '#{message}' && git push`
32
- end
33
-
34
- task "release:patch" do
35
- Rake::Task["gemspec"].invoke
36
- Rake::Task["version:bump:patch"]
37
- Rake::Task["push"].invoke
38
- Rake::Task["release"].invoke
39
- end
40
-
41
- task "release:minor" do
42
- Rake::Task["gemspec"].invoke
43
- Rake::Task["version:bump:minor"]
44
- Rake::Task["push"].invoke
45
- Rake::Task["release"].invoke
46
- end
47
-
48
- task "release:major" do
49
- Rake::Task["gemspec"].invoke
50
- Rake::Task["version:bump:major"]
51
- Rake::Task["push"].invoke
52
- Rake::Task["release"].invoke
3
+ desc "Run tests on test app"
4
+ task :test do
5
+ exec "cd test_app && rake test"
53
6
  end
@@ -20,8 +20,8 @@
20
20
  # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21
21
  # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
22
 
23
-
24
23
  module MetaTagsHelpers
24
+
25
25
  module ActionViewExtension
26
26
 
27
27
  def meta_tags(opts = {})
@@ -40,17 +40,21 @@ module MetaTagsHelpers
40
40
  :"csrf-param" => request_forgery_protection_token,
41
41
  :"csrf-token" => form_authenticity_token
42
42
  }
43
-
44
- meta_hash = default.deep_merge(opts).deep_merge(@_meta_tags_hash || {})
43
+
44
+ override_hash = controller.instance_variable_get("@_meta_tags_hash") || {}
45
+ meta_hash = default.deep_merge(opts).deep_merge(override_hash)
45
46
 
46
47
  html = ""
47
48
  html << "<title>#{h(meta_hash.delete(:title)) }</title>\n"
48
- meta_hash.each {|k,v|
49
- if k.to_s =~ /[a-zA-Z_][-a-zA-Z0-9_.]\:/
50
- html << "<meta property=\"#{h(k)}\" content=\"#{h(v)}\" />\n"
51
- else
52
- html << "<meta name=\"#{h(k)}\" content=\"#{h(v)}\" />\n"
53
- end
49
+ meta_hash.each {|k,value_or_array|
50
+ values = value_or_array.is_a?(Array) ? value_or_array : [value_or_array]
51
+ values.each { |v|
52
+ if k.to_s =~ /[a-zA-Z_][-a-zA-Z0-9_.]\:/
53
+ html << "<meta property=\"#{h(k)}\" content=\"#{h(v)}\" />\n"
54
+ else
55
+ html << "<meta name=\"#{h(k)}\" content=\"#{h(v)}\" />\n"
56
+ end
57
+ }
54
58
  }
55
59
  html.html_safe
56
60
  end
@@ -58,7 +62,7 @@ module MetaTagsHelpers
58
62
  end #~ ActionViewExtension
59
63
 
60
64
  module ActionControllerExtension
61
- extend ActiveSupport::Concern
65
+ extend ::ActiveSupport::Concern
62
66
  included do
63
67
  helper_method :set_meta, :meta_title, :meta_description, :meta_image, :meta_type, :normalize_meta_hash
64
68
  end
@@ -68,7 +72,7 @@ module MetaTagsHelpers
68
72
  end
69
73
 
70
74
  def set_meta(options)
71
- _meta_tags_hash.deep_merge(normalize_meta_hash(options))
75
+ _meta_tags_hash.deep_merge!(normalize_meta_hash(options))
72
76
  end
73
77
 
74
78
  def meta_title(val = nil)
@@ -107,29 +111,28 @@ module MetaTagsHelpers
107
111
  protected
108
112
 
109
113
  def normalize_meta_hash(hash)
110
-
111
- meta_hash = hash.dup
112
-
113
- # separates namespaced keys
114
- namespaces = meta_hash.select { |k,v| v.is_a?(Hash) }
115
-
116
- # delete nil/false/namespaced keys
117
- meta_hash.delete_if { |k,v| v.blank? || v == false || v.is_a?(Hash)}
118
-
119
- namespaces.each { |ns, namespaced|
120
- namespaced.delete_if { |k,v|
121
- v.blank? || v == false || v.is_a?(Hash)
122
- }
123
- namespaced.each {|k,v|
124
- meta_hash[:"#{ns}:#{k}"] = v
125
- }
126
- }
127
-
128
- meta_hash
129
-
114
+ normalized = {}
115
+ normalize_meta_hash_walker(hash, normalized)
116
+ normalized
130
117
  end
118
+
119
+ private
131
120
 
121
+ def normalize_meta_hash_walker(hash, normalized, current = nil)
122
+ hash.each do |k, v|
123
+ thisPath = current ? current.dup : []
124
+ thisPath << k.to_s
125
+
126
+ if v.is_a?(Hash)
127
+ normalize_meta_hash_walker(v, normalized, thisPath)
128
+ elsif v
129
+ key = thisPath.join ":"
130
+ normalized[:"#{key}"] = v
131
+ end
132
+ end
133
+ end
134
+
132
135
  end
133
136
  end
134
137
  ActionController::Base.send :include, MetaTagsHelpers::ActionControllerExtension
135
- ActionView::Base.send :include, MetaTagsHelpers::ActionViewExtension
138
+ ActionView::Base.send :include, MetaTagsHelpers::ActionViewExtension
@@ -1,52 +1,26 @@
1
- # Generated by jeweler
2
- # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
- # -*- encoding: utf-8 -*-
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
4
 
6
- Gem::Specification.new do |s|
7
- s.name = "meta-tags-helpers"
8
- s.version = "0.1.7"
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "meta-tags-helpers"
7
+ spec.version = "0.2.0"
8
+ spec.authors = ["mcasimir"]
9
+ spec.email = ["maurizio.cas@gmail.com"]
10
+ spec.description = "Rails meta tags helpers"
11
+ spec.summary = "Seo and future-proof meta tags for Rails"
12
+ spec.homepage = "https://github.com/mcasimir/meta-tags-helpers"
13
+ spec.license = "MIT"
9
14
 
10
- s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
- s.authors = ["mcasimir"]
12
- s.date = "2013-06-01"
13
- s.description = "Rails meta tags helpers"
14
- s.email = "maurizio.cas@gmail.com"
15
- s.extra_rdoc_files = [
16
- "README.md"
17
- ]
18
- s.files = [
19
- "Gemfile",
20
- "Gemfile.lock",
21
- "README.md",
22
- "Rakefile",
23
- "VERSION",
24
- "lib/meta-tags-helpers.rb",
25
- "lib/meta_tags_helpers.rb",
26
- "meta-tags-helpers.gemspec"
27
- ]
28
- s.homepage = "http://github.com/mcasimir/kaminari-bootstrap"
29
- s.licenses = ["MIT"]
30
- s.require_paths = ["lib"]
31
- s.rubygems_version = "1.8.25"
32
- s.summary = "Rails meta tags helpers"
15
+ spec.files = `git ls-files`.split($/)
16
+ spec.require_paths = ["lib"]
33
17
 
34
- if s.respond_to? :specification_version then
35
- s.specification_version = 3
18
+ spec.add_dependency "rails", "> 3"
36
19
 
37
- if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
38
- s.add_runtime_dependency(%q<rails>, [">= 0"])
39
- s.add_development_dependency(%q<bundler>, [">= 0"])
40
- s.add_development_dependency(%q<jeweler>, ["~> 1.8.4"])
41
- else
42
- s.add_dependency(%q<rails>, [">= 0"])
43
- s.add_dependency(%q<bundler>, [">= 0"])
44
- s.add_dependency(%q<jeweler>, ["~> 1.8.4"])
45
- end
46
- else
47
- s.add_dependency(%q<rails>, [">= 0"])
48
- s.add_dependency(%q<bundler>, [">= 0"])
49
- s.add_dependency(%q<jeweler>, ["~> 1.8.4"])
50
- end
20
+ spec.add_development_dependency "bundler", "~> 1.3"
21
+ spec.add_development_dependency "rake"
22
+ spec.add_development_dependency "rspec"
23
+ spec.add_development_dependency "combustion", "~> 0.5.1"
24
+ spec.add_development_dependency "actionpack"
25
+ spec.add_development_dependency "activesupport"
51
26
  end
52
-