metaa 0.0.13 → 0.1.0
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.
- checksums.yaml +8 -8
- data/README.md +34 -23
- data/lib/metaa/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
ZmIzMzFmNWRmNWI2OWIxYWI5OWIwZjc4ZTJlMzUwNWY0ZDRmOTI3Ng==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
OWVkNTBlNTVkNjRjNTk5MGNmYzZkNGRiYjFhN2ExNjhlOTlmZDI1OQ==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
OGRkNGFmZDBjOGU3ZGYwMGNjNmVmMGU2Yjg5NDBhZmM0MTY1OGRkZTFiMTQ2
|
10
|
+
ODU1ZmRiYzFhNzU5MjUyZjJkMWI3NmI0MjI1OTcyZDc2ODgwZTNhNThiNDk1
|
11
|
+
MGYyZGNjYjFhYmY5YjM3YTg2MTZhM2Y0MWI1NTlhZDY5ZGUzYjQ=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
ZDk3NTkyY2JjNDAxOWNhZTQ1YzE2Yzk5YTliOTY2ZjllZThlMmFiYWIzN2Rl
|
14
|
+
Y2ExNjI5ZTI0NWY1ZGQyY2Q4NTI0ZGMwYTBkM2EwZjE3NWI0NWRmYjBjZjQx
|
15
|
+
ZTdmMGZhYWZjYzYxMjA0YmM0N2E2YzlhYmVlZGRhOThhYmZlZmU=
|
data/README.md
CHANGED
@@ -6,6 +6,12 @@ Metaa adds meta tags to your Rails application with ease.
|
|
6
6
|
|
7
7
|
With Metaa, you can easily add meta tags to your current model with simple DSL, then render these tags on your views with a single method.
|
8
8
|
|
9
|
+
## Installation
|
10
|
+
|
11
|
+
Add Metaa to your Gemfile:
|
12
|
+
|
13
|
+
gem 'metaa'
|
14
|
+
|
9
15
|
## Generator
|
10
16
|
|
11
17
|
The command is simple, just add the model you want to create the meta for:
|
@@ -16,11 +22,7 @@ rails generate meta Product
|
|
16
22
|
|
17
23
|
This will generate `ProductMeta` meta class in your app/meta folder.
|
18
24
|
|
19
|
-
|
20
|
-
|
21
|
-
After generated, the meta class will look like this:
|
22
|
-
|
23
|
-
```
|
25
|
+
```ruby
|
24
26
|
# app/meta/product_meta.rb
|
25
27
|
class ProductMeta < Metaa::Meta
|
26
28
|
def define_meta
|
@@ -33,20 +35,38 @@ class ProductMeta < Metaa::Meta
|
|
33
35
|
end
|
34
36
|
```
|
35
37
|
|
36
|
-
|
38
|
+
## Meta definition
|
37
39
|
|
38
|
-
|
40
|
+
We can define the meta tags as following:
|
39
41
|
|
42
|
+
```ruby
|
43
|
+
# app/meta/product_meta.rb
|
44
|
+
class ProductMeta < Metaa::Meta
|
45
|
+
def define_meta
|
46
|
+
meta name: "title",
|
47
|
+
content: object.title
|
48
|
+
|
49
|
+
# You can define multiple meta tags in order
|
50
|
+
meta name: "description",
|
51
|
+
content: object.description
|
52
|
+
end
|
53
|
+
end
|
54
|
+
...
|
55
|
+
|
56
|
+
product.title #=> "product title"
|
57
|
+
product.description #=> "product description"
|
58
|
+
|
59
|
+
# access to the rendered html
|
60
|
+
product.meta_tags #=> "<meta content=\"product title\" name=\"title\" /><meta content=\"product description\" name=\"description\" />"
|
40
61
|
```
|
41
|
-
|
42
|
-
```
|
62
|
+
|
43
63
|
All ActiveRecord instances will have this behavior if appropriate meta class is defined, e.g. `ProductMeta` for model `Product`.
|
44
64
|
|
45
65
|
## Non ActiveRecord
|
46
66
|
|
47
67
|
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
68
|
|
49
|
-
```
|
69
|
+
```ruby
|
50
70
|
# app/meta/non_active_record_model_meta.rb
|
51
71
|
class NonActiveRecordModelMeta < Metaa::Meta
|
52
72
|
def define_meta
|
@@ -55,27 +75,18 @@ class NonActiveRecordModelMeta < Metaa::Meta
|
|
55
75
|
|
56
76
|
end
|
57
77
|
end
|
58
|
-
|
59
78
|
...
|
60
79
|
|
61
|
-
ruby_object.
|
62
|
-
|
63
|
-
...
|
80
|
+
ruby_object.title #=> "a title"
|
64
81
|
|
65
82
|
# create meta object from ruby_object
|
66
83
|
meta_object = NonActiveRecordModelMeta.new(ruby_object)
|
67
84
|
|
68
|
-
# access
|
69
|
-
meta_object.to_html
|
85
|
+
# access to the rendered html
|
86
|
+
meta_object.to_html #=> "<meta content=\"a title\" name=\"title\" />"
|
70
87
|
```
|
71
88
|
|
72
|
-
|
73
|
-
|
74
|
-
Add Metaa to your Gemfile:
|
75
|
-
|
76
|
-
gem 'metaa'
|
77
|
-
|
78
|
-
And run bundle install within your app's directory.
|
89
|
+
Notice that we use `meta_tags` method on ActiveRecord instances instead of `to_html` method on the meta objects in order to avoid method name conflicts on your models.
|
79
90
|
|
80
91
|
|
81
92
|
## Contributing
|
data/lib/metaa/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: metaa
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- anhkind
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-10-
|
11
|
+
date: 2013-10-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|