-
-
Save ypetya/312253 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# config.yaml : (Load this into an OpenStruct at the initializers, as usual...) | |
# | |
# test_legnths: | |
# default: 20 | |
# title: 150 | |
# description_in_list: 450 | |
module ApplicationHelper | |
# {{{ this will cut the labels length from a template name | |
def cut_string_length string,len,suffix | |
max_count = "{#{len}}" | |
string.gsub(/^(.#{max_count}).*$/u) {"#{$1}#{suffix}"} | |
end | |
# call this function to use it | |
def fix(string, max_length = nil) | |
len = CONFIG.text_lengths[max_length.to_s] || CONFIG.text_lengths['default'] if max_length | |
h( max_length ? cut_string_length( string, len, '...' ) : string ) | |
end | |
# }}} | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment