has_meta 0.0.6 → 0.0.7
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 +7 -0
- data/lib/has_meta/version.rb +1 -1
- data/lib/has_meta.rb +4 -1
- data/test/test_has_meta.rb +9 -0
- metadata +3 -2
data/README.md
CHANGED
@@ -21,6 +21,13 @@ Or install it yourself as:
|
|
21
21
|
|
22
22
|
$ gem install has_meta
|
23
23
|
|
24
|
+
## Configuration
|
25
|
+
|
26
|
+
By default has\_meta will truncate results at 255 characters.
|
27
|
+
You can change this globally by creating an initializer file with the following contents:
|
28
|
+
|
29
|
+
HasMeta::OPTIONS[:truncate] = 999
|
30
|
+
|
24
31
|
## Usage
|
25
32
|
|
26
33
|
class BlogPost < ActiveRecord::Base
|
data/lib/has_meta/version.rb
CHANGED
data/lib/has_meta.rb
CHANGED
@@ -3,6 +3,9 @@ require 'active_record'
|
|
3
3
|
require 'has_meta/version'
|
4
4
|
|
5
5
|
module HasMeta
|
6
|
+
|
7
|
+
OPTIONS = {:truncate => 255}
|
8
|
+
|
6
9
|
module Extensions
|
7
10
|
def self.included(base)
|
8
11
|
base.extend(ClassMethods)
|
@@ -13,7 +16,7 @@ module HasMeta
|
|
13
16
|
options.each_pair do |meth, fields|
|
14
17
|
define_method("meta_#{meth}") {|*args|
|
15
18
|
length = args.first if args.is_a? Array
|
16
|
-
length ||=
|
19
|
+
length ||= HasMeta::OPTIONS[:truncate]
|
17
20
|
|
18
21
|
if fields.is_a? Proc
|
19
22
|
str = fields.call(self)
|
data/test/test_has_meta.rb
CHANGED
@@ -32,6 +32,15 @@ class HasMetaTest < Test::Unit::TestCase
|
|
32
32
|
@widget.some_ivar = 1
|
33
33
|
end
|
34
34
|
|
35
|
+
def test_truncate_length
|
36
|
+
assert_equal HasMeta::OPTIONS[:truncate], 255
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_truncate_length_override
|
40
|
+
HasMeta::OPTIONS.merge!(:truncate => 8)
|
41
|
+
assert_equal "Short...", @widget.meta_description
|
42
|
+
end
|
43
|
+
|
35
44
|
def test_knows_its_meta_description
|
36
45
|
assert_equal "Short Description", @widget.meta_description
|
37
46
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: has_meta
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.7
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-06-18 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: Adds convenience methods to extract "meta" (as in http meta) strings
|
15
15
|
from models.
|
@@ -56,3 +56,4 @@ summary: Adds convenience methods to extract "meta" (as in http meta) strings fr
|
|
56
56
|
and truncated to length (default 255).
|
57
57
|
test_files:
|
58
58
|
- test/test_has_meta.rb
|
59
|
+
has_rdoc:
|