metaa 0.0.11 → 0.0.12
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.
- data/README.md +29 -1
- data/lib/metaa/concern.rb +1 -1
- data/lib/metaa/meta.rb +9 -14
- data/lib/metaa/tag.rb +1 -1
- data/lib/metaa/tag_collection.rb +2 -2
- data/lib/metaa/version.rb +1 -1
- data/spec/metaa/concern_spec.rb +1 -1
- data/spec/metaa/meta_spec.rb +5 -4
- data/spec/metaa/tag_collection_spec.rb +2 -2
- data/spec/metaa/tag_spec.rb +5 -3
- metadata +1 -1
data/README.md
CHANGED
@@ -35,11 +35,39 @@ end
|
|
35
35
|
|
36
36
|
You can define meta tags multiple times and these tags will be displayed in the order you define in meta class.
|
37
37
|
|
38
|
-
To access to the
|
38
|
+
To access to the rendered html, just use method `meta_tags` on your ActiveRecord instance:
|
39
39
|
|
40
40
|
```
|
41
41
|
product.meta_tags
|
42
42
|
```
|
43
|
+
All ActiveRecord instances will have this behavior if appropriate meta class is defined, e.g. `ProductMeta` for model `Product`.
|
44
|
+
|
45
|
+
## Non ActiveRecord
|
46
|
+
|
47
|
+
With non ActiveRecord instances, you can still generate the meta class and define the meta tags normally with any class name. However, you have to handle the meta object manually:
|
48
|
+
|
49
|
+
```
|
50
|
+
# app/meta/non_active_record_model_meta.rb
|
51
|
+
class NonActiveRecordModelMeta < Metaa::Meta
|
52
|
+
def define_meta
|
53
|
+
meta name: "title",
|
54
|
+
content: object.title
|
55
|
+
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
...
|
60
|
+
|
61
|
+
ruby_object.respond_to? :title #=> true
|
62
|
+
|
63
|
+
...
|
64
|
+
|
65
|
+
# create meta object from ruby_object
|
66
|
+
meta_object = NonActiveRecordModelMeta.new(ruby_object)
|
67
|
+
|
68
|
+
# access rendered html of the defined meta tags
|
69
|
+
meta_object.to_html
|
70
|
+
```
|
43
71
|
|
44
72
|
## Installation
|
45
73
|
|
data/lib/metaa/concern.rb
CHANGED
data/lib/metaa/meta.rb
CHANGED
@@ -15,24 +15,19 @@ module Metaa
|
|
15
15
|
end
|
16
16
|
|
17
17
|
# lazy define meta tags then collect
|
18
|
-
def
|
19
|
-
@
|
18
|
+
def tag_collection
|
19
|
+
@tag_collection ||= begin
|
20
20
|
define_meta
|
21
|
-
|
21
|
+
TagCollection.new(
|
22
|
+
definitions.map do |definition|
|
23
|
+
definition.attributes_for(object)
|
24
|
+
end
|
25
|
+
)
|
22
26
|
end
|
23
27
|
end
|
24
28
|
|
25
|
-
def
|
26
|
-
|
27
|
-
end
|
28
|
-
|
29
|
-
private
|
30
|
-
def collect_tags
|
31
|
-
TagCollection.new(
|
32
|
-
definitions.map do |definition|
|
33
|
-
definition.attributes_for(object)
|
34
|
-
end
|
35
|
-
).tags
|
29
|
+
def to_html
|
30
|
+
tag_collection.to_html
|
36
31
|
end
|
37
32
|
end
|
38
33
|
end
|
data/lib/metaa/tag.rb
CHANGED
data/lib/metaa/tag_collection.rb
CHANGED
data/lib/metaa/version.rb
CHANGED
data/spec/metaa/concern_spec.rb
CHANGED
@@ -21,7 +21,7 @@ module Metaa
|
|
21
21
|
|
22
22
|
describe "#meta_tags" do
|
23
23
|
it "returns html meta tags for self" do
|
24
|
-
meta_mock = double :meta,
|
24
|
+
meta_mock = double :meta, to_html: "<meta content=\"a title\" name=\"title\" property=\"text\" />"
|
25
25
|
model = Model.new
|
26
26
|
model.stub meta: meta_mock
|
27
27
|
|
data/spec/metaa/meta_spec.rb
CHANGED
@@ -35,10 +35,11 @@ module Metaa
|
|
35
35
|
object_mock = double title: 'a title'
|
36
36
|
meta = klass.new(object_mock)
|
37
37
|
|
38
|
-
expect(meta.tags.length).to eq 1
|
39
38
|
|
40
|
-
|
41
|
-
|
39
|
+
expect(meta.tag_collection.tags.length).to eq 1
|
40
|
+
|
41
|
+
tag = meta.tag_collection.tags.first
|
42
|
+
expect(tag.to_html).to eq "<meta content=\"a title\" name=\"title\" property=\"text\" />"
|
42
43
|
end
|
43
44
|
end
|
44
45
|
|
@@ -55,7 +56,7 @@ module Metaa
|
|
55
56
|
|
56
57
|
meta = klass.new(object_mock)
|
57
58
|
|
58
|
-
expect(meta.
|
59
|
+
expect(meta.to_html).to eq "<meta content=\"a title\" name=\"title\" property=\"text\" />"
|
59
60
|
end
|
60
61
|
end
|
61
62
|
end
|
@@ -16,14 +16,14 @@ module Metaa
|
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
19
|
-
describe '#
|
19
|
+
describe '#to_html' do
|
20
20
|
it 'converts list of meta objects to html' do
|
21
21
|
meta_list = [
|
22
22
|
Tag.new({name: 'keywords', content: 'abc'}),
|
23
23
|
Tag.new({name: 'keywords', content: '123, 456'})
|
24
24
|
]
|
25
25
|
meta_collection = TagCollection.new(meta_list)
|
26
|
-
expect(meta_collection.
|
26
|
+
expect(meta_collection.to_html).to eq "<meta content=\"abc\" name=\"keywords\" /><meta content=\"123, 456\" name=\"keywords\" />"
|
27
27
|
end
|
28
28
|
end
|
29
29
|
end
|
data/spec/metaa/tag_spec.rb
CHANGED
@@ -2,9 +2,11 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
module Metaa
|
4
4
|
describe Tag do
|
5
|
-
|
6
|
-
|
7
|
-
|
5
|
+
describe '#to_html' do
|
6
|
+
it 'converts a meta tag to html' do
|
7
|
+
tag = Tag.new({name: 'keywords', content: 'abc'})
|
8
|
+
expect(tag.to_html).to eq "<meta content=\"abc\" name=\"keywords\" />"
|
9
|
+
end
|
8
10
|
end
|
9
11
|
end
|
10
12
|
end
|