action_meta_tags 0.1.1 → 0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +3 -0
- data/README.md +3 -0
- data/action_meta_tags.gemspec +0 -2
- data/lib/action_meta_tags.rb +2 -0
- data/lib/action_meta_tags/base.rb +30 -30
- data/lib/action_meta_tags/helpers.rb +1 -11
- data/lib/action_meta_tags/tags/link.rb +10 -0
- data/lib/action_meta_tags/tags/meta.rb +1 -8
- data/lib/action_meta_tags/tags/self_closing_tag.rb +18 -0
- data/lib/action_meta_tags/tags/title.rb +2 -0
- data/lib/action_meta_tags/version.rb +1 -1
- data/spec/action_meta_tags/base_spec.rb +56 -0
- data/spec/action_meta_tags/helpers_spec.rb +26 -0
- data/spec/action_meta_tags/tags/link_spec.rb +12 -0
- data/spec/action_meta_tags/tags/meta_spec.rb +12 -0
- data/spec/action_meta_tags/tags/self_closing_tag_spec.rb +11 -0
- data/spec/action_meta_tags/tags/title_spec.rb +11 -0
- data/spec/spec_helper.rb +3 -2
- metadata +16 -36
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 559c6f20f592f5ac0bc6e4c81931f903510cdfa5
|
4
|
+
data.tar.gz: 671728b9a3a0b43d8f2f7a5e2b7fc1845f23673c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5f372a497d58cc7e5ad89635cd97ca20155571b5b78653f8ba5b10ea1aae201c264693dab2fe29e7b0d75ffbeece38a2caf3a66de2d935a8add67e600fd82c81
|
7
|
+
data.tar.gz: be3ff875898c30e91c1b9a1f0117e1e251e5e95ad65f1431dec178f42d5931e7a2eae2f6d09fbefd5ee62f0fdce624b813cec414ba64fd78868494b53ecc7df0
|
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -1,7 +1,10 @@
|
|
1
|
+
Better SEO for the content pages of your Rails app with less code and better design.
|
2
|
+
|
1
3
|
# ActionMetaTags
|
2
4
|
|
3
5
|
[![Build Status](https://travis-ci.org/andrewgr/action_meta_tags.png)](https://travis-ci.org/andrewgr/action_meta_tags)
|
4
6
|
[![Code Climate](https://codeclimate.com/github/andrewgr/action_meta_tags/badges/gpa.svg)](https://codeclimate.com/github/andrewgr/action_meta_tags)
|
7
|
+
[![Test Coverage](https://codeclimate.com/github/andrewgr/action_meta_tags/badges/coverage.svg)](https://codeclimate.com/github/andrewgr/action_meta_tags/coverage)
|
5
8
|
|
6
9
|
## Installation
|
7
10
|
|
data/action_meta_tags.gemspec
CHANGED
@@ -21,6 +21,4 @@ Gem::Specification.new do |gem|
|
|
21
21
|
gem.add_development_dependency 'actionpack', '~> 4'
|
22
22
|
gem.add_development_dependency 'rubocop', '~> 0.30'
|
23
23
|
gem.add_development_dependency 'cane', '~> 2.6', '>= 2.6.1'
|
24
|
-
gem.add_development_dependency 'shoulda', '~> 3.5'
|
25
|
-
gem.add_development_dependency 'shoulda-matchers', '~> 2.8', '>= 2.8.0'
|
26
24
|
end
|
data/lib/action_meta_tags.rb
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
require 'active_support'
|
2
2
|
require 'action_meta_tags/version'
|
3
3
|
require 'action_meta_tags/helpers'
|
4
|
+
require 'action_meta_tags/tags/self_closing_tag'
|
5
|
+
require 'action_meta_tags/tags/link'
|
4
6
|
require 'action_meta_tags/tags/meta'
|
5
7
|
require 'action_meta_tags/tags/title'
|
6
8
|
require 'action_meta_tags/base'
|
@@ -4,36 +4,36 @@ module ActionMetaTags
|
|
4
4
|
@object = object
|
5
5
|
end
|
6
6
|
|
7
|
-
|
8
|
-
tags
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
7
|
+
class << self
|
8
|
+
def tags
|
9
|
+
@tags ||= []
|
10
|
+
end
|
11
|
+
|
12
|
+
def title(&block)
|
13
|
+
tags << Tags::Title.new(&block)
|
14
|
+
end
|
15
|
+
|
16
|
+
def meta(attrs, &block)
|
17
|
+
tags << Tags::Meta.new(attrs, &block)
|
18
|
+
end
|
19
|
+
|
20
|
+
def link(attrs, &block)
|
21
|
+
tags << Tags::Link.new(attrs, &block)
|
22
|
+
end
|
23
|
+
|
24
|
+
%w(keywords description).each do |method|
|
25
|
+
define_method method do |&block|
|
26
|
+
meta(name: method, &block)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
%w(og:title og:image og:description).each do |property|
|
31
|
+
method = property.gsub(':', '_')
|
32
|
+
|
33
|
+
define_method method do |&block|
|
34
|
+
meta(property: property, &block)
|
35
|
+
end
|
36
|
+
end
|
37
37
|
end
|
38
38
|
|
39
39
|
def render(view)
|
@@ -3,18 +3,8 @@ module ActionMetaTags
|
|
3
3
|
extend ActiveSupport::Concern
|
4
4
|
|
5
5
|
def meta_tags(object)
|
6
|
-
class_name = [
|
7
|
-
'Meta',
|
8
|
-
params[:controller].capitalize,
|
9
|
-
params[:action].capitalize
|
10
|
-
].join('::')
|
6
|
+
class_name = ['Meta', params[:controller].classify, params[:action].classify].join('::')
|
11
7
|
class_name.constantize.new(object).render(self)
|
12
8
|
end
|
13
|
-
|
14
|
-
private
|
15
|
-
|
16
|
-
def find_domain(host)
|
17
|
-
host
|
18
|
-
end
|
19
9
|
end
|
20
10
|
end
|
@@ -1,17 +1,10 @@
|
|
1
1
|
module ActionMetaTags
|
2
2
|
module Tags
|
3
|
-
class Meta
|
4
|
-
def initialize(attrs, &block)
|
5
|
-
@attrs = attrs
|
6
|
-
@renderer = block
|
7
|
-
end
|
8
|
-
|
3
|
+
class Meta < SelfClosingTag
|
9
4
|
def render(view, object)
|
10
5
|
content = object.instance_exec(&renderer)
|
11
6
|
view.tag(:meta, attrs.merge(content: content))
|
12
7
|
end
|
13
|
-
|
14
|
-
attr_reader :renderer, :attrs
|
15
8
|
end
|
16
9
|
end
|
17
10
|
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module ActionMetaTags
|
2
|
+
module Tags
|
3
|
+
class SelfClosingTag
|
4
|
+
def initialize(attrs, &block)
|
5
|
+
@attrs = attrs
|
6
|
+
@renderer = block
|
7
|
+
end
|
8
|
+
|
9
|
+
def render(view, object)
|
10
|
+
fail NotImplementedError
|
11
|
+
end
|
12
|
+
|
13
|
+
protected
|
14
|
+
|
15
|
+
attr_reader :renderer, :attrs
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
class ResourceTags < ActionMetaTags::Base
|
4
|
+
title { "#{title} | Site" }
|
5
|
+
|
6
|
+
meta('http-equiv' => 'refresh') { "0;URL='http://example.com/'".html_safe }
|
7
|
+
|
8
|
+
keywords { 'key,words' }
|
9
|
+
description { description }
|
10
|
+
og_title { title }
|
11
|
+
og_image { 'http://example.org/i.png' }
|
12
|
+
og_description { description }
|
13
|
+
|
14
|
+
link(
|
15
|
+
rel: 'search',
|
16
|
+
type: 'application/opensearchdescription+xml',
|
17
|
+
title: 'Site') { '/opensearch.xml' }
|
18
|
+
end
|
19
|
+
|
20
|
+
RSpec.describe ActionMetaTags::Base do
|
21
|
+
let(:view) { ActionView::Base.new }
|
22
|
+
let(:resource) { OpenStruct.new(title: 'Title', description: 'Lorem Ipsum.') }
|
23
|
+
subject { ResourceTags.new(resource).render(view) }
|
24
|
+
|
25
|
+
specify '#title renders the title tag' do
|
26
|
+
is_expected.to include('<title>Title | Site</title>')
|
27
|
+
end
|
28
|
+
|
29
|
+
specify '#meta renders a meta tag' do
|
30
|
+
is_expected.to include(%q(<meta http-equiv="refresh" content="0;URL='http://example.com/'" />))
|
31
|
+
end
|
32
|
+
|
33
|
+
specify '#link renders a link tag' do
|
34
|
+
is_expected.to include('<link rel="search" type="application/opensearchdescription+xml" title="Site" href="/opensearch.xml" />')
|
35
|
+
end
|
36
|
+
|
37
|
+
specify '#keywords renders the appropriate meta tag' do
|
38
|
+
is_expected.to include('<meta name="keywords" content="key,words" />')
|
39
|
+
end
|
40
|
+
|
41
|
+
specify '#description renders the appropriate meta tag' do
|
42
|
+
is_expected.to include('<meta name="description" content="Lorem Ipsum." />')
|
43
|
+
end
|
44
|
+
|
45
|
+
specify '#og_title renders the appropriate meta tag' do
|
46
|
+
is_expected.to include('<meta property="og:title" content="Title" />')
|
47
|
+
end
|
48
|
+
|
49
|
+
specify '#og_image renders the appropriate meta tag' do
|
50
|
+
is_expected.to include('<meta property="og:image" content="http://example.org/i.png" />')
|
51
|
+
end
|
52
|
+
|
53
|
+
specify '#og_description renders the appropriate meta tag' do
|
54
|
+
is_expected.to include('<meta property="og:description" content="Lorem Ipsum." />')
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module Meta
|
4
|
+
module Post
|
5
|
+
class Show < ActionMetaTags::Base
|
6
|
+
title { title }
|
7
|
+
end
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
RSpec.describe ActionMetaTags::Helpers do
|
12
|
+
describe '#meta_tags' do
|
13
|
+
let(:view) do
|
14
|
+
ActionView::Base.new.tap do |view|
|
15
|
+
params = { controller: 'posts', action: 'show' }
|
16
|
+
view.controller = OpenStruct.new(params: params)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
let(:resource) { OpenStruct.new(title: 'Title') }
|
20
|
+
subject { view.meta_tags(resource) }
|
21
|
+
|
22
|
+
specify do
|
23
|
+
is_expected.to eq('<title>Title</title>')
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
RSpec.describe ActionMetaTags::Tags::Link do
|
4
|
+
let(:view) { ActionView::Base.new }
|
5
|
+
let(:resource) { OpenStruct.new(url: 'http://example.org/') }
|
6
|
+
subject(:tag) { described_class.new(rel: :canonical) { url } }
|
7
|
+
|
8
|
+
specify do
|
9
|
+
expected = '<link rel="canonical" href="http://example.org/" />'
|
10
|
+
expect(tag.render(view, resource)).to eq(expected)
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
RSpec.describe ActionMetaTags::Tags::Meta do
|
4
|
+
let(:view) { ActionView::Base.new }
|
5
|
+
let(:resource) { OpenStruct.new(description: 'Lorem ipsum.') }
|
6
|
+
subject(:tag) { described_class.new(name: :description) { description } }
|
7
|
+
|
8
|
+
specify do
|
9
|
+
expected = '<meta name="description" content="Lorem ipsum." />'
|
10
|
+
expect(tag.render(view, resource)).to eq(expected)
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
RSpec.describe ActionMetaTags::Tags::SelfClosingTag do
|
4
|
+
let(:view) { ActionView::Base.new }
|
5
|
+
let(:resource) { OpenStruct.new(url: 'http://example.org/') }
|
6
|
+
subject(:tag) { described_class.new(rel: :canonical) { url } }
|
7
|
+
|
8
|
+
specify do
|
9
|
+
expect { tag.render(view, resource) }.to raise_error(NotImplementedError)
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
RSpec.describe ActionMetaTags::Tags::Title do
|
4
|
+
let(:view) { ActionView::Base.new }
|
5
|
+
let(:resource) { OpenStruct.new(title: 'Title') }
|
6
|
+
subject(:tag) { described_class.new { title } }
|
7
|
+
|
8
|
+
specify do
|
9
|
+
expect(tag.render(view, resource)).to eq('<title>Title</title>')
|
10
|
+
end
|
11
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,2 +1,3 @@
|
|
1
|
-
require '
|
2
|
-
require '
|
1
|
+
require 'action_meta_tags'
|
2
|
+
require 'action_view'
|
3
|
+
require 'ostruct'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: action_meta_tags
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: '0.2'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrei Gridnev
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-05-
|
11
|
+
date: 2015-05-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -86,40 +86,6 @@ dependencies:
|
|
86
86
|
- - ">="
|
87
87
|
- !ruby/object:Gem::Version
|
88
88
|
version: 2.6.1
|
89
|
-
- !ruby/object:Gem::Dependency
|
90
|
-
name: shoulda
|
91
|
-
requirement: !ruby/object:Gem::Requirement
|
92
|
-
requirements:
|
93
|
-
- - "~>"
|
94
|
-
- !ruby/object:Gem::Version
|
95
|
-
version: '3.5'
|
96
|
-
type: :development
|
97
|
-
prerelease: false
|
98
|
-
version_requirements: !ruby/object:Gem::Requirement
|
99
|
-
requirements:
|
100
|
-
- - "~>"
|
101
|
-
- !ruby/object:Gem::Version
|
102
|
-
version: '3.5'
|
103
|
-
- !ruby/object:Gem::Dependency
|
104
|
-
name: shoulda-matchers
|
105
|
-
requirement: !ruby/object:Gem::Requirement
|
106
|
-
requirements:
|
107
|
-
- - "~>"
|
108
|
-
- !ruby/object:Gem::Version
|
109
|
-
version: '2.8'
|
110
|
-
- - ">="
|
111
|
-
- !ruby/object:Gem::Version
|
112
|
-
version: 2.8.0
|
113
|
-
type: :development
|
114
|
-
prerelease: false
|
115
|
-
version_requirements: !ruby/object:Gem::Requirement
|
116
|
-
requirements:
|
117
|
-
- - "~>"
|
118
|
-
- !ruby/object:Gem::Version
|
119
|
-
version: '2.8'
|
120
|
-
- - ">="
|
121
|
-
- !ruby/object:Gem::Version
|
122
|
-
version: 2.8.0
|
123
89
|
description: Well structured meta tags for your Rails app views
|
124
90
|
email:
|
125
91
|
- andrew.gridnev@gmail.com
|
@@ -140,9 +106,17 @@ files:
|
|
140
106
|
- lib/action_meta_tags.rb
|
141
107
|
- lib/action_meta_tags/base.rb
|
142
108
|
- lib/action_meta_tags/helpers.rb
|
109
|
+
- lib/action_meta_tags/tags/link.rb
|
143
110
|
- lib/action_meta_tags/tags/meta.rb
|
111
|
+
- lib/action_meta_tags/tags/self_closing_tag.rb
|
144
112
|
- lib/action_meta_tags/tags/title.rb
|
145
113
|
- lib/action_meta_tags/version.rb
|
114
|
+
- spec/action_meta_tags/base_spec.rb
|
115
|
+
- spec/action_meta_tags/helpers_spec.rb
|
116
|
+
- spec/action_meta_tags/tags/link_spec.rb
|
117
|
+
- spec/action_meta_tags/tags/meta_spec.rb
|
118
|
+
- spec/action_meta_tags/tags/self_closing_tag_spec.rb
|
119
|
+
- spec/action_meta_tags/tags/title_spec.rb
|
146
120
|
- spec/spec_helper.rb
|
147
121
|
homepage: https://github.com/andrewgr/action_meta_tags/
|
148
122
|
licenses:
|
@@ -169,4 +143,10 @@ signing_key:
|
|
169
143
|
specification_version: 4
|
170
144
|
summary: Meta tags
|
171
145
|
test_files:
|
146
|
+
- spec/action_meta_tags/base_spec.rb
|
147
|
+
- spec/action_meta_tags/helpers_spec.rb
|
148
|
+
- spec/action_meta_tags/tags/link_spec.rb
|
149
|
+
- spec/action_meta_tags/tags/meta_spec.rb
|
150
|
+
- spec/action_meta_tags/tags/self_closing_tag_spec.rb
|
151
|
+
- spec/action_meta_tags/tags/title_spec.rb
|
172
152
|
- spec/spec_helper.rb
|