meta_tags_helper 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: d2991a2a3b7f46eea39ca4af16531b0bc92d4662
4
+ data.tar.gz: 79f2d246e5eb99cde430461cfaa3b3574c2a0631
5
+ SHA512:
6
+ metadata.gz: 8ba23924da2269b3c0831ceb38bdcbdb055ef3148cb8b9afd48a87925060fb719a3dc4a2dbcb3a0b8000cb9590cf031d8751fffef92744a42f333e0e207784fa
7
+ data.tar.gz: 529484fda16771dd45c385f8a9cd24ac933d17a0cb41b400bf3c02d5297a431123f0aedbcfc71903f3d857679a09b05b30f00eb215f7cc52d98293cb360781b2
data/.editorconfig ADDED
@@ -0,0 +1,11 @@
1
+
2
+ root = true
3
+
4
+ [*]
5
+ indent_style = space
6
+ indent_size = 2
7
+ end_of_line = lf
8
+ charset = utf-8
9
+
10
+ trim_trailing_whitespace = true
11
+ insert_final_newline = true
data/.gitignore ADDED
@@ -0,0 +1,7 @@
1
+ /.bundle
2
+ /Gemfile.lock
3
+ /coverage
4
+ /pkg/
5
+ /tmp/
6
+ *.gem
7
+ /log
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format=doc
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in meta_tags_helper.gemspec
4
+ gemspec
data/README.md ADDED
@@ -0,0 +1,69 @@
1
+ # MetaTagsHelper
2
+
3
+ Rails helpers for building meta tags.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'meta_tags_helper'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install meta_tags_helper
20
+
21
+ ## Usage
22
+
23
+ ```html
24
+ <head>
25
+ <%= meta_tags og: {
26
+ url: 'https://github.com',
27
+ site_name: 'GitHub',
28
+ title: 'Build software better, together'
29
+ } %>
30
+ </head>
31
+ ```
32
+
33
+ Also you can manage title tag:
34
+ ```html
35
+ <head>
36
+ <%= title_tag 'Sitename' %>
37
+ </head>
38
+ ```
39
+
40
+ View:
41
+ ```html
42
+ <h1><%= title 'Title' %></h1>
43
+ ```
44
+
45
+
46
+ ## License
47
+
48
+ Copyright (c) 2014 Okhlopkov Anatoly
49
+
50
+ MIT License
51
+
52
+ Permission is hereby granted, free of charge, to any person obtaining
53
+ a copy of this software and associated documentation files (the
54
+ "Software"), to deal in the Software without restriction, including
55
+ without limitation the rights to use, copy, modify, merge, publish,
56
+ distribute, sublicense, and/or sell copies of the Software, and to
57
+ permit persons to whom the Software is furnished to do so, subject to
58
+ the following conditions:
59
+
60
+ The above copyright notice and this permission notice shall be
61
+ included in all copies or substantial portions of the Software.
62
+
63
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
64
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
65
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
66
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
67
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
68
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
69
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task default: :spec
@@ -0,0 +1,33 @@
1
+ require "meta_tags_helper/version"
2
+
3
+ module MetaTagsHelper
4
+ def title(new_title = nil)
5
+ content_for(:title, new_title) || new_title
6
+ end
7
+
8
+ def title_tag(base = nil)
9
+ content_tag(:title, [ title, base ].reject(&:blank?).join(' — '))
10
+ end
11
+
12
+ def meta_tag(name, content = nil)
13
+ if /:/ =~ name
14
+ tag(:meta, property: name, content: content)
15
+ else
16
+ tag(:meta, name: name, content: content)
17
+ end
18
+ end
19
+
20
+ def meta_tags(tags, namespace = nil)
21
+ ns_prefix = namespace.present? ? "#{namespace}:" : ''
22
+
23
+ tags = tags.map do |name, content|
24
+ if content.kind_of?(Hash)
25
+ meta_tags(content, name)
26
+ else
27
+ meta_tag(ns_prefix + name.to_s, content)
28
+ end
29
+ end
30
+
31
+ safe_join(tags)
32
+ end
33
+ end
@@ -0,0 +1,3 @@
1
+ module MetaTagsHelper
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,26 @@
1
+ lib = File.expand_path('../lib', __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require 'meta_tags_helper/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'meta_tags_helper'
7
+ spec.version = MetaTagsHelper::VERSION
8
+ spec.authors = ['Okhlopkov Anatoly']
9
+ spec.email = ['ohlopkov0211@gmail.com']
10
+ spec.summary = 'Rails helpers for building meta tags.'
11
+ spec.description = 'Rails helpers for building meta tags.'
12
+ spec.homepage = 'https://github.com/VortexGrenade/meta_tags_helper.git'
13
+ spec.license = 'MIT'
14
+
15
+ spec.files = `git ls-files -z`.split("\x0")
16
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
+ spec.require_paths = ["lib"]
19
+
20
+ spec.add_dependency 'rails', '~> 4'
21
+
22
+ spec.add_development_dependency 'bundler', '~> 1'
23
+ spec.add_development_dependency 'rake', '~> 10'
24
+ spec.add_development_dependency 'rspec', '~> 3'
25
+ spec.add_development_dependency 'rspec-rails'
26
+ end
@@ -0,0 +1,55 @@
1
+ require 'spec_helper'
2
+ require 'meta_tags_helper'
3
+
4
+ describe MetaTagsHelper, type: [:helper] do
5
+ describe '#title' do
6
+ it 'sets and returns page title' do
7
+ title = helper.title('Foo bar')
8
+
9
+ expect(title).to eq('Foo bar')
10
+ expect(helper.title).to eq('Foo bar')
11
+ end
12
+ end
13
+
14
+ describe '#title_tag' do
15
+ it 'builds "title" tag with base suffix' do
16
+ helper.title('Foo bar')
17
+
18
+ expect(helper.title_tag('Baz')).to eq('<title>Foo bar — Baz</title>')
19
+ end
20
+ end
21
+
22
+ describe '#meta_tag' do
23
+ it 'builds meta tag' do
24
+ meta = helper.meta_tag('name', 'content')
25
+ meta_html = '<meta content="content" name="name" />'
26
+
27
+ expect(meta).to eq(meta_html)
28
+ end
29
+
30
+ it 'uses "property" attribute for namespaced names' do
31
+ meta = helper.meta_tag('ns:name', 'content')
32
+ meta_html = '<meta content="content" property="ns:name" />'
33
+
34
+ expect(meta).to eq(meta_html)
35
+ end
36
+ end
37
+
38
+ describe '#meta_tags' do
39
+ it 'builds list of meta tags' do
40
+ meta = meta_tags(description: 'Foo bar baz', keywords: %[foo bar baz])
41
+ meta_html = '<meta content="Foo bar baz" name="description" />' +
42
+ '<meta content="foo bar baz" name="keywords" />'
43
+
44
+ expect(meta).to eq(meta_html)
45
+ end
46
+
47
+ it 'allows to specify properties namespace' do
48
+ og = meta_tags(og: { description: 'Foo bar baz', image: 'image.jpg' })
49
+ og_html = '<meta content="Foo bar baz" property="og:description" />' +
50
+ '<meta content="image.jpg" property="og:image" />'
51
+
52
+ expect(og).to eq(og_html)
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,14 @@
1
+ ENV['RAILS_ENV'] = 'test'
2
+
3
+ require 'rails'
4
+ require 'action_controller/railtie'
5
+ require 'rspec/rails'
6
+
7
+ module Dummy
8
+ class Application < Rails::Application
9
+ config.secret_key_base = 'dummy_key'
10
+ config.eager_load = false
11
+ end
12
+ end
13
+
14
+ Rails.application.initialize!
@@ -0,0 +1,5 @@
1
+ require 'micro_dummy_app'
2
+
3
+ RSpec.configure do |config|
4
+ config.order = 'random'
5
+ end
metadata ADDED
@@ -0,0 +1,129 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: meta_tags_helper
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Okhlopkov Anatoly
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-11-10 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'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '4'
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'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec-rails
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: Rails helpers for building meta tags.
84
+ email:
85
+ - ohlopkov0211@gmail.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".editorconfig"
91
+ - ".gitignore"
92
+ - ".rspec"
93
+ - Gemfile
94
+ - README.md
95
+ - Rakefile
96
+ - lib/meta_tags_helper.rb
97
+ - lib/meta_tags_helper/version.rb
98
+ - meta_tags_helper.gemspec
99
+ - spec/helpers/meta_tags_helper_spec.rb
100
+ - spec/micro_dummy_app.rb
101
+ - spec/spec_helper.rb
102
+ homepage: https://github.com/VortexGrenade/meta_tags_helper.git
103
+ licenses:
104
+ - MIT
105
+ metadata: {}
106
+ post_install_message:
107
+ rdoc_options: []
108
+ require_paths:
109
+ - lib
110
+ required_ruby_version: !ruby/object:Gem::Requirement
111
+ requirements:
112
+ - - ">="
113
+ - !ruby/object:Gem::Version
114
+ version: '0'
115
+ required_rubygems_version: !ruby/object:Gem::Requirement
116
+ requirements:
117
+ - - ">="
118
+ - !ruby/object:Gem::Version
119
+ version: '0'
120
+ requirements: []
121
+ rubyforge_project:
122
+ rubygems_version: 2.4.2
123
+ signing_key:
124
+ specification_version: 4
125
+ summary: Rails helpers for building meta tags.
126
+ test_files:
127
+ - spec/helpers/meta_tags_helper_spec.rb
128
+ - spec/micro_dummy_app.rb
129
+ - spec/spec_helper.rb