material 0.3.6 → 0.3.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/material/concerns/text.rb +13 -7
- data/lib/material/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3e2eaa26ed95bfacb3d5457d2e94255f7cba64ca9457db9cf5a59c0ec6d25bb4
|
4
|
+
data.tar.gz: 9599971fef04642baaf5d1f5618eb626795cb52cd52a0c95f274a5a28ea170cd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3eee4688baab8826d259d125552cd442ffe175439c144292d284a72162f6dc67f18b20605e96665ab7c11d5661e707a122b21205dc783363c1677a363f30b438
|
7
|
+
data.tar.gz: d591fec54a9a2421f9b25e9eac798e511b1a1077fa5bcc3972f1043318166e7dd73c195010023066d13e5e656f233ea3b9a1acf758a6d1764a74b260f38a7a7a
|
@@ -7,6 +7,14 @@ module Material
|
|
7
7
|
DEFAULT_TRUNCATE_LENGTH = 50
|
8
8
|
|
9
9
|
class_methods do
|
10
|
+
def default_truncation_length
|
11
|
+
DEFAULT_TRUNCATE_LENGTH
|
12
|
+
end
|
13
|
+
|
14
|
+
def truncation_length(key)
|
15
|
+
public_send("#{key}_component".to_sym).options[:max_length] || default_truncation_length
|
16
|
+
end
|
17
|
+
|
10
18
|
private
|
11
19
|
|
12
20
|
def register_title_truncator(key)
|
@@ -17,29 +25,27 @@ module Material
|
|
17
25
|
register_truncator(key) { title.pluralize }
|
18
26
|
end
|
19
27
|
|
20
|
-
def register_truncator(key, max_length =
|
28
|
+
def register_truncator(key, max_length = nil, &block)
|
21
29
|
register_component(key, max_length: max_length, &block)
|
22
30
|
define_truncation_formatter(key)
|
23
31
|
define_truncation_predicate(key)
|
24
32
|
end
|
25
33
|
|
26
34
|
def define_truncation_formatter(key)
|
27
|
-
define_method(key)
|
28
|
-
public_send("#{key}_value".to_sym).truncate(public_send("#{key}_component".to_sym).options[:max_length])
|
29
|
-
end
|
35
|
+
define_method(key) { public_send("#{key}_value".to_sym).truncate(truncation_length(key)) }
|
30
36
|
memoize key
|
31
37
|
end
|
32
38
|
|
33
39
|
def define_truncation_predicate(key)
|
34
40
|
method_name = "#{key}_truncated?".to_sym
|
35
|
-
define_method(method_name)
|
36
|
-
public_send("#{key}_value".to_sym).length > public_send("#{key}_component".to_sym).options[:max_length]
|
37
|
-
end
|
41
|
+
define_method(method_name) { public_send("#{key}_value".to_sym).length > truncation_length(key) }
|
38
42
|
memoize method_name
|
39
43
|
end
|
40
44
|
end
|
41
45
|
|
42
46
|
included do
|
47
|
+
delegate :truncation_length, to: :class
|
48
|
+
|
43
49
|
register_truncator(:title) { default_title.titleize }
|
44
50
|
|
45
51
|
register_component(:parameterized_title) { title_value.underscore.parameterize }
|
data/lib/material/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: material
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Eric Garside
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2020-04-
|
12
|
+
date: 2020-04-28 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activesupport
|