action_meta_tags 0.1 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/lib/action_meta_tags/base.rb +44 -0
- data/lib/action_meta_tags/tags/meta.rb +17 -0
- data/lib/action_meta_tags/tags/title.rb +16 -0
- data/lib/action_meta_tags/version.rb +1 -1
- data/lib/action_meta_tags.rb +3 -0
- metadata +4 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cb0724440db0b13d505e59a9fe781a80a9eeb9e0
|
4
|
+
data.tar.gz: d8e07d80da23e246ca2f9ced17282bcebb847e48
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 961925683903b5c9fb188825debee30848353eb847154e769945abd3a42c81ee84d8097a9b84892bd88382d0ac9cd7b22c7a39887aca3563051cb6eb36735d60
|
7
|
+
data.tar.gz: f866b0cbc6643574a4c287dd2775673e375535d30b539386029aadc0a688707a43fb5f007260c982f32454e1a1a71cf318050cd51d6070e2d9f23644d0d36674
|
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
#
|
1
|
+
# ActionMetaTags
|
2
2
|
|
3
3
|
[![Build Status](https://travis-ci.org/andrewgr/action_meta_tags.png)](https://travis-ci.org/andrewgr/action_meta_tags)
|
4
4
|
[![Code Climate](https://codeclimate.com/github/andrewgr/action_meta_tags/badges/gpa.svg)](https://codeclimate.com/github/andrewgr/action_meta_tags)
|
@@ -0,0 +1,44 @@
|
|
1
|
+
module ActionMetaTags
|
2
|
+
class Base
|
3
|
+
def initialize(object)
|
4
|
+
@object = object
|
5
|
+
end
|
6
|
+
|
7
|
+
def self.title(&block)
|
8
|
+
tags << Tags::Title.new(&block)
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.meta(attrs, &block)
|
12
|
+
tags << Tags::Meta.new(attrs, &block)
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.keywords(&block)
|
16
|
+
tags << Tags::Meta.new(name: 'keywords', &block)
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.description(&block)
|
20
|
+
tags << Tags::Meta.new(name: 'description', &block)
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.og_title(&block)
|
24
|
+
tags << Tags::Meta.new(property: 'og:title', &block)
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.og_image(&block)
|
28
|
+
tags << Tags::Meta.new(property: 'og:image', &block)
|
29
|
+
end
|
30
|
+
|
31
|
+
def self.og_description(&block)
|
32
|
+
tags << Tags::Meta.new(property: 'og:description', &block)
|
33
|
+
end
|
34
|
+
|
35
|
+
def self.tags
|
36
|
+
@tags ||= []
|
37
|
+
end
|
38
|
+
|
39
|
+
def render(view)
|
40
|
+
html = self.class.tags.map { |tag| tag.render(view, @object) }.join("\n")
|
41
|
+
view.raw(html)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module ActionMetaTags
|
2
|
+
module Tags
|
3
|
+
class Meta
|
4
|
+
def initialize(attrs, &block)
|
5
|
+
@attrs = attrs
|
6
|
+
@renderer = block
|
7
|
+
end
|
8
|
+
|
9
|
+
def render(view, object)
|
10
|
+
content = object.instance_exec(&renderer)
|
11
|
+
view.tag(:meta, attrs.merge(content: content))
|
12
|
+
end
|
13
|
+
|
14
|
+
attr_reader :renderer, :attrs
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module ActionMetaTags
|
2
|
+
module Tags
|
3
|
+
class Title
|
4
|
+
def initialize(&block)
|
5
|
+
@renderer = block
|
6
|
+
end
|
7
|
+
|
8
|
+
def render(view, object)
|
9
|
+
content = object.instance_exec(&renderer)
|
10
|
+
view.content_tag(:title, content)
|
11
|
+
end
|
12
|
+
|
13
|
+
attr_reader :renderer
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
data/lib/action_meta_tags.rb
CHANGED
@@ -1,6 +1,9 @@
|
|
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/meta'
|
5
|
+
require 'action_meta_tags/tags/title'
|
6
|
+
require 'action_meta_tags/base'
|
4
7
|
|
5
8
|
ActiveSupport.on_load(:action_view) do
|
6
9
|
include ActionMetaTags::Helpers
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: action_meta_tags
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrei Gridnev
|
@@ -138,7 +138,10 @@ files:
|
|
138
138
|
- Rakefile
|
139
139
|
- action_meta_tags.gemspec
|
140
140
|
- lib/action_meta_tags.rb
|
141
|
+
- lib/action_meta_tags/base.rb
|
141
142
|
- lib/action_meta_tags/helpers.rb
|
143
|
+
- lib/action_meta_tags/tags/meta.rb
|
144
|
+
- lib/action_meta_tags/tags/title.rb
|
142
145
|
- lib/action_meta_tags/version.rb
|
143
146
|
- spec/spec_helper.rb
|
144
147
|
homepage: https://github.com/andrewgr/action_meta_tags/
|