module Material::Text
Constants
- DEFAULT_TRUNCATE_LENGTH
Public Instance Methods
default_title()
click to toggle source
# File lib/material/concerns/text.rb, line 63 def default_title source.try(:title) || source.try(:name) || try(:model_name)&.human || source.class.name end
default_truncation_length()
click to toggle source
# File lib/material/concerns/text.rb, line 10 def default_truncation_length DEFAULT_TRUNCATE_LENGTH end
define_truncation_formatter(key)
click to toggle source
# File lib/material/concerns/text.rb, line 34 def define_truncation_formatter(key) define_method(key) { public_send("#{key}_value".to_sym).truncate(truncation_length(key)) } memoize key end
define_truncation_predicate(key)
click to toggle source
# File lib/material/concerns/text.rb, line 39 def define_truncation_predicate(key) method_name = "#{key}_truncated?".to_sym define_method(method_name) { public_send("#{key}_value".to_sym).length > truncation_length(key) } memoize method_name end
register_index_title_truncator(key)
click to toggle source
# File lib/material/concerns/text.rb, line 24 def register_index_title_truncator(key) register_truncator(key) { title.pluralize } end
register_title_truncator(key)
click to toggle source
# File lib/material/concerns/text.rb, line 20 def register_title_truncator(key) register_truncator(key) { title } end
register_truncator(key, max_length = nil, &block)
click to toggle source
# File lib/material/concerns/text.rb, line 28 def register_truncator(key, max_length = nil, &block) register_component(key, max_length: max_length, &block) define_truncation_formatter(key) define_truncation_predicate(key) end
truncation_length(key)
click to toggle source
# File lib/material/concerns/text.rb, line 14 def truncation_length(key) public_send("#{key}_component".to_sym).options[:max_length] || default_truncation_length end