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 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 final rendered html, just use method `meta_tags` on your instance
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
 
@@ -7,7 +7,7 @@ module Metaa
7
7
  end
8
8
 
9
9
  def meta_tags
10
- meta.html
10
+ meta.to_html
11
11
  end
12
12
 
13
13
  # (see ClassMethods#meta_class)
@@ -15,24 +15,19 @@ module Metaa
15
15
  end
16
16
 
17
17
  # lazy define meta tags then collect
18
- def tags
19
- @tags ||= begin
18
+ def tag_collection
19
+ @tag_collection ||= begin
20
20
  define_meta
21
- collect_tags
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 html
26
- tags.map(&:html).join.html_safe
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
@@ -7,7 +7,7 @@ module Metaa
7
7
  @attributes = attributes
8
8
  end
9
9
 
10
- def html
10
+ def to_html
11
11
  tag(:meta, @attributes)
12
12
  end
13
13
  end
@@ -16,8 +16,8 @@ module Metaa
16
16
  @tags ||= []
17
17
  end
18
18
 
19
- def html
20
- tags.map(&:html).join.html_safe
19
+ def to_html
20
+ tags.map(&:to_html).join.html_safe
21
21
  end
22
22
  end
23
23
  end
@@ -1,3 +1,3 @@
1
1
  module Metaa
2
- VERSION = "0.0.11"
2
+ VERSION = "0.0.12"
3
3
  end
@@ -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, html: "<meta content=\"a title\" name=\"title\" property=\"text\" />"
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
 
@@ -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
- tag = meta.tags.first
41
- expect(tag.html).to eq "<meta content=\"a title\" name=\"title\" property=\"text\" />"
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.html).to eq "<meta content=\"a title\" name=\"title\" property=\"text\" />"
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 '#html' do
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.html).to eq "<meta content=\"abc\" name=\"keywords\" /><meta content=\"123, 456\" name=\"keywords\" />"
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
@@ -2,9 +2,11 @@ require 'spec_helper'
2
2
 
3
3
  module Metaa
4
4
  describe Tag do
5
- it 'converts a meta tag to html' do
6
- tag = Tag.new({name: 'keywords', content: 'abc'})
7
- expect(tag.html).to eq "<meta content=\"abc\" name=\"keywords\" />"
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: metaa
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.11
4
+ version: 0.0.12
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: