meta_tags_simple_builder 0.1.2

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 950fa43cfbbd0d45632ae46f14584ea680e86e3a
4
+ data.tar.gz: fb069df511360abd24d1adf826c8e45b7e69f81b
5
+ SHA512:
6
+ metadata.gz: e20772cc6bd8694d6512d061baa809e63fb82d8ba5261ff9d0e39bf196c7acae6848cad4ec6335a47d36938c1cf040712c9253df78c048b3966c9b9f14fb39e4
7
+ data.tar.gz: c573a37b16772bceb001b95d805fe00af64dcdd8857ad0d84c1c9e5448f708135c558bf26d16cd2e902423aa718aa5ed2cffcf1249791d7205a07cc97f3c9b72
@@ -0,0 +1,19 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .rspec
6
+ .rvmrc
7
+ .yardoc
8
+ _yardoc
9
+ Gemfile.lock
10
+ InstalledFiles
11
+ coverage
12
+ doc/
13
+ lib/bundler/man
14
+ pkg
15
+ rdoc
16
+ spec/reports
17
+ test/tmp
18
+ test/version_tmp
19
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in meta_tags_simple_builder.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2014 Marat Khusnetdinov
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Marat Khusnetdinov
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.
@@ -0,0 +1,128 @@
1
+ # MetaTagsSimpleBuilder
2
+
3
+ Gem allow you to simply create seo friendly custom meta tags, blocks of meta tags.
4
+
5
+ ## Dependency
6
+
7
+ rails >= 4.0.0
8
+
9
+ ## Installation
10
+
11
+ Add this line to your application's Gemfile:
12
+
13
+ gem 'meta_tags_simple_builder'
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install meta_tags_simple_builder
22
+
23
+ ## Usage for stand alone meta, link tags
24
+
25
+ ### Title
26
+
27
+ <%= title_meta_tag('MetaTagsSimpleBuilder gem page.')%>
28
+ # <title>MetaTagsSimpleBuilder gem page.</title>
29
+
30
+ Use title for layout helper if you want to set title for application from view and caption view name:
31
+
32
+ # application.html
33
+
34
+ <%= title_meta_tag(yield(:title))%>
35
+ # <title>Title for application from view.html</title>
36
+
37
+ # views.html
38
+
39
+ <h1>
40
+ <%= title_for_layout('Title for application from view.html')%>
41
+ </h1>
42
+ # <h1>Title for application from view.html</h1>
43
+
44
+ ### Charset
45
+
46
+ <%= charset_meta_tag('utf-16')%>
47
+ # <meta charset="utf-16" />
48
+
49
+ ### Http equiv data
50
+
51
+ <%= http_equiv_meta_tag('X-UA-Compatible', 'IE=Edge')%>
52
+ # <meta http-equiv="X-UA-Compatible" content="IE=Edge" />
53
+
54
+ ### Author
55
+
56
+ <%= author_meta_tag('Marat Khusnetdinov')%>
57
+ # <meta content="Marat Khusnetdinov" name="author" />
58
+
59
+ ### Keywords
60
+
61
+ <%= keywords_meta_tag(['gem', 'rails'])%>
62
+ <%= keywords_meta_tag('gem, rails')%>
63
+ # <meta content="gem, rails" name="keywords" />
64
+
65
+ ### Description
66
+
67
+ <%= description_meta_tag('Gem for simply creating meta tags, blocks of meta tags')%>
68
+ # <meta content="Gem for simply creating meta tags, blocks of meta tags" name="description" />')
69
+
70
+ ### Viewport
71
+
72
+ <%= viewport_meta_tag('width=1')
73
+ # <meta content="width=1" name="viewport" />'
74
+
75
+ <%= viewport_meta_tag(['width=1', 'scale=1'])
76
+ # <meta content="width=1, scale=1" name="viewport" />'
77
+
78
+ ### Customs meta tag, robots, nofollow examples
79
+
80
+ This helper helps you to set meta tag with custom name:
81
+
82
+ <%= meta_tag_for :robots, 'noindex'>
83
+ # <meta content="noindex" name="robots" />
84
+
85
+ Use custom meta tags if you want more flexibility:
86
+
87
+ <%= custom_meta_tag_for(:custom_property, 'cutstom content', custom_options: 'custom content for options')%>
88
+ # <meta custom-property="cutstom content" custom-options="custom content for options" />
89
+
90
+ Notice: "_" underscore in attributes simbol names will be rendered to "-" dash
91
+
92
+ ### Links
93
+
94
+ <%= link_tag_for :canonical, url: 'http://github.com', type: 'web')%>
95
+ # <link rel="canonical" url="http://github.com" type="web" />')
96
+
97
+ ## Usage for meta, link tags blocks
98
+
99
+ Blocks helpers are used than you need render collection meta tags. It takes a hash, which you can create in controller.rb:
100
+
101
+ # somewhere in controller we create and want to render this:
102
+ @meta = { title: 'Page title', charset: 'utf-16', author: 'John Doe', namespace: { title: 'content', attr_name: :property} }
103
+
104
+ # application.html
105
+
106
+ <%= meta_tags_block_for(@meta)%>
107
+ # <title>Page title</title>
108
+ # <meta charset="utf-16" />
109
+ # <meta content="John Doe" name="author" />
110
+ # <meta content="content" property="namespace:title" />
111
+
112
+ Notice: If you pass a pair key: :value with value as hash, key: will be the namespace of name attribute. For change 'name' attribute pass options :attr_name.
113
+
114
+ Links block have options:
115
+
116
+ @links = { prev: { href: 'http://github.com/prev', type: 'web' }, next: { href: 'http://github.com/next'} }
117
+
118
+ <%= link_tags_block_for(@links)%>
119
+ # <link href="http://github.com/prev" rel="prev" type="web" />
120
+ # <link href="http://github.com/next" rel="next" />
121
+
122
+ ## Contributing
123
+
124
+ 1. Fork it
125
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
126
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
127
+ 4. Push to the branch (`git push origin my-new-feature`)
128
+ 5. Create new Pull Request
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,7 @@
1
+ require 'meta_tags_simple_builder/version'
2
+ require 'meta_tags_simple_builder/view_helper'
3
+
4
+ module MetaTagsSimpleBuilder
5
+ end
6
+
7
+ require 'meta_tags_simple_builder/railtie' if defined?(Rails)
@@ -0,0 +1,11 @@
1
+ require 'meta_tags_simple_builder/view_helper'
2
+
3
+ module MetaTagsSimpleBuilder
4
+
5
+ class Railtie < Rails::Railtie
6
+
7
+ initializer 'meta_tags_simple_builder.view_helper' do
8
+ ActionView::Base.send :include, ViewHelper
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,3 @@
1
+ module MetaTagsSimpleBuilder
2
+ VERSION = "0.1.2"
3
+ end
@@ -0,0 +1,119 @@
1
+ module MetaTagsSimpleBuilder
2
+
3
+ module ViewHelper
4
+
5
+ include ActionView::Helpers
6
+
7
+ def title_for_layout(title)
8
+ content_for :title, title
9
+ title
10
+ end
11
+
12
+ def title_meta_tag(title)
13
+ content_tag :title, title
14
+ end
15
+
16
+ def charset_meta_tag(charset)
17
+ meta_tag charset: charset
18
+ end
19
+
20
+ def http_equiv_meta_tag(name, content)
21
+ meta_tag http_equiv: name, content: content
22
+ end
23
+
24
+ def author_meta_tag(content)
25
+ meta_tag_for :author, content
26
+ end
27
+
28
+ def keywords_meta_tag(content)
29
+ meta_tag_for :keywords, normalized(content)
30
+ end
31
+
32
+ def description_meta_tag(content)
33
+ meta_tag_for :description, content
34
+ end
35
+
36
+ def viewport_meta_tag(content)
37
+ meta_tag_for :viewport, normalized(content)
38
+ end
39
+
40
+ def meta_tag_for(name, content)
41
+ meta_tag name: name, content: content
42
+ end
43
+
44
+ def custom_meta_tag_for(name, content, options = {})
45
+ options[name] = content
46
+ meta_tag options
47
+ end
48
+
49
+ def meta_tags_block_for(options = {})
50
+ return unless options.is_a?(Hash)
51
+ tags = []
52
+ tags << title_meta_tag(options.delete :title) if options.has_key?(:title)
53
+ tags << charset_meta_tag(options.delete :charset) if options.has_key?(:charset)
54
+ if options.has_key?(:http_equiv)
55
+ http_equiv = options.delete :http_equiv
56
+ tags << http_equiv_meta_tag(http_equiv[:name], http_equiv[:content])
57
+ end
58
+ options.each_pair do |k, v|
59
+ if v.is_a?(Hash)
60
+ attr_name = v.has_key?(:attr_name) ? v.delete(:attr_name) : :property
61
+ tags.concat(plane_option k, v, attr_name)
62
+ else
63
+ tags << meta_tag_for(k.to_s.dasherize, v)
64
+ end
65
+ end
66
+ render_html_for tags
67
+ end
68
+
69
+ def link_tag_for(name, options = {})
70
+ options[:rel] = name
71
+ link_tag options
72
+ end
73
+
74
+ def link_tags_block_for(options = {})
75
+ return unless options.is_a?(Hash)
76
+ tags = []
77
+ options.each_pair { |k, v| tags << link_tag_for(k, v) }
78
+ render_html_for tags
79
+ end
80
+
81
+
82
+ private
83
+
84
+ def meta_tag(options = nil, escape = true)
85
+ "<meta#{tag_options(options, escape) if options} />".html_safe
86
+ end
87
+
88
+ def link_tag(options = {})
89
+ tag :link, options
90
+ end
91
+
92
+ def tag_options(options, escape = true)
93
+ return if options.blank?
94
+ attrs = []
95
+ options.each_pair { |k, v| attrs << tag_option(k.to_s.dasherize, v, escape) if v }
96
+ " #{attrs.sort * ' '}".html_safe unless attrs.empty?
97
+ end
98
+
99
+ def plane_option(key, val, attr_name)
100
+ tags = []
101
+ if val.is_a?(Hash)
102
+ val.each_pair { |k, v| tags.concat plane_option("#{key}:#{k}", v, attr_name) }
103
+ else
104
+ tags << meta_tag(attr_name => "#{key}", content: val)
105
+ end
106
+ tags
107
+ end
108
+
109
+ def normalized(content)
110
+ content = content.join(', ') if content.is_a?(Array)
111
+ content
112
+ end
113
+
114
+ def render_html_for(array_of_tags)
115
+ tags = array_of_tags.join('')
116
+ tags.respond_to?(:html_safe) ? tags.html_safe : tags
117
+ end
118
+ end
119
+ end
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'meta_tags_simple_builder/version'
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = "meta_tags_simple_builder"
8
+ s.version = MetaTagsSimpleBuilder::VERSION
9
+ s.authors = ["Marat Khusnetdinov"]
10
+ s.email = ["marat@khusnetdinov.ru"]
11
+ s.description = %q{Gem allow you to simply create custom meta tags, blocks of seo friendly meta tags.}
12
+ s.summary = %q{MetaTagsSimpleBuilder gem}
13
+ s.homepage = ""
14
+ s.license = "MIT"
15
+
16
+ s.files = `git ls-files`.split($/)
17
+ s.executables = s.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ s.test_files = s.files.grep(%r{^(test|spec|features)/})
19
+ s.require_paths = ["lib"]
20
+
21
+ s.add_dependency "rails", ">= 4.0.0"
22
+
23
+ s.add_development_dependency "bundler", "~> 1.3"
24
+ s.add_development_dependency "rake"
25
+ s.add_development_dependency "rspec"
26
+ end
@@ -0,0 +1,3 @@
1
+ require 'bundler/setup'
2
+ require 'action_view'
3
+ require 'meta_tags_simple_builder'
@@ -0,0 +1,98 @@
1
+ require 'spec_helper'
2
+
3
+ class TestViewHelper
4
+ include MetaTagsSimpleBuilder::ViewHelper
5
+ end
6
+
7
+ describe TestViewHelper do
8
+
9
+ let (:view_helper) { TestViewHelper.new }
10
+
11
+ describe 'title meta tag' do
12
+ it 'return title' do
13
+ expect(view_helper.title_meta_tag 'MetaTagSimpleBuilder').to eq('<title>MetaTagSimpleBuilder</title>')
14
+ end
15
+ end
16
+
17
+ describe 'charset meta tag' do
18
+ it 'return charset' do
19
+ expect(view_helper.charset_meta_tag 'utf-1024').to eq('<meta charset="utf-1024" />')
20
+ end
21
+ end
22
+
23
+ describe 'http equiv meta tag' do
24
+ it 'return http equiv' do
25
+ expect(view_helper.http_equiv_meta_tag 'X-UA', 'chrome=1').to eq('<meta content="chrome=1" http-equiv="X-UA" />')
26
+ end
27
+ end
28
+
29
+ describe 'author meta tag' do
30
+ it 'return author' do
31
+ expect(view_helper.author_meta_tag 'Marat Khusnetdinov').to eq('<meta content="Marat Khusnetdinov" name="author" />')
32
+ end
33
+ end
34
+
35
+ describe 'keyword meta tag' do
36
+ it 'string: return keywords from array' do
37
+ expect(view_helper.keywords_meta_tag ['gem','rails']).to eq('<meta content="gem, rails" name="keywords" />')
38
+ end
39
+
40
+ it 'array: return keywords' do
41
+ expect(view_helper.keywords_meta_tag 'gem rails').to eq('<meta content="gem rails" name="keywords" />')
42
+ end
43
+ end
44
+
45
+ describe 'description meta nag' do
46
+ it 'return description' do
47
+ expect(view_helper.description_meta_tag 'Gem creating meta tags').to eq('<meta content="Gem creating meta tags" name="description" />')
48
+ end
49
+ end
50
+
51
+ describe 'viewport meta tag' do
52
+ it 'return settings from array' do
53
+ expect(view_helper.viewport_meta_tag ['width=1', 'scale=1']).to eq('<meta content="width=1, scale=1" name="viewport" />')
54
+ end
55
+
56
+ it 'return settings' do
57
+ expect(view_helper.viewport_meta_tag 'width=1').to eq('<meta content="width=1" name="viewport" />')
58
+ end
59
+ end
60
+
61
+ describe 'meta tag for exist settings' do
62
+ it 'return meta tag with name attribute' do
63
+ expect(view_helper.meta_tag_for 'name', 'content').to eq('<meta content="content" name="name" />')
64
+ end
65
+ end
66
+
67
+ describe 'custom meta tag' do
68
+ it 'returns custom meta tag' do
69
+ expect(view_helper.custom_meta_tag_for :itemprop, 'content', http: 'www.com').to eq('<meta http="www.com" itemprop="content" />')
70
+ end
71
+ end
72
+
73
+ describe 'meta tags block for @variable' do
74
+ meta = { http_equiv: {name: 'X-UA', content: 'chrome=1'},
75
+ og: {type: 'First level', sub:{ type: 'Second'},
76
+ attr_name: :itemprop}}
77
+
78
+ it 'return block of meta tags' do
79
+ expect(view_helper.meta_tags_block_for meta).to eq('<meta content="chrome=1" http-equiv="X-UA" /><meta content="First level" itemprop="og:type" /><meta content="Second" itemprop="og:sub:type" />')
80
+ end
81
+ end
82
+
83
+ describe 'link tag' do
84
+ it 'returns link tag' do
85
+ expect(view_helper.link_tag_for 'can', url: 'www', type: 'web').to eq('<link rel="can" type="web" url="www" />')
86
+ end
87
+ end
88
+
89
+ describe 'link tags block for @variable' do
90
+ link = {prev: {href: 'prev.com', type: 'link',
91
+ custom_field: 'custom-content'},
92
+ can: {href: 'www'}}
93
+
94
+ it 'return link tags block for @variable' do
95
+ expect(view_helper.link_tags_block_for link).to eq('<link custom-field="custom-content" href="prev.com" rel="prev" type="link" /><link href="www" rel="can" />')
96
+ end
97
+ end
98
+ end
metadata ADDED
@@ -0,0 +1,116 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: meta_tags_simple_builder
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.2
5
+ platform: ruby
6
+ authors:
7
+ - Marat Khusnetdinov
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-03-28 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 4.0.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 4.0.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.3'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.3'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: Gem allow you to simply create custom meta tags, blocks of seo friendly
70
+ meta tags.
71
+ email:
72
+ - marat@khusnetdinov.ru
73
+ executables: []
74
+ extensions: []
75
+ extra_rdoc_files: []
76
+ files:
77
+ - ".gitignore"
78
+ - Gemfile
79
+ - LICENSE
80
+ - LICENSE.txt
81
+ - README.md
82
+ - Rakefile
83
+ - lib/meta_tags_simple_builder.rb
84
+ - lib/meta_tags_simple_builder/railtie.rb
85
+ - lib/meta_tags_simple_builder/version.rb
86
+ - lib/meta_tags_simple_builder/view_helper.rb
87
+ - meta_tags_simple_builder.gemspec
88
+ - spec/spec_helper.rb
89
+ - spec/view_helper_spec.rb
90
+ homepage: ''
91
+ licenses:
92
+ - MIT
93
+ metadata: {}
94
+ post_install_message:
95
+ rdoc_options: []
96
+ require_paths:
97
+ - lib
98
+ required_ruby_version: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ version: '0'
103
+ required_rubygems_version: !ruby/object:Gem::Requirement
104
+ requirements:
105
+ - - ">="
106
+ - !ruby/object:Gem::Version
107
+ version: '0'
108
+ requirements: []
109
+ rubyforge_project:
110
+ rubygems_version: 2.1.10
111
+ signing_key:
112
+ specification_version: 4
113
+ summary: MetaTagsSimpleBuilder gem
114
+ test_files:
115
+ - spec/spec_helper.rb
116
+ - spec/view_helper_spec.rb