Module: Helpers::General
- Defined in:
- lib/helpers/general.rb
Instance Method Summary collapse
- #copyright(from) ⇒ Object
-
#email_link(mail, text = mail) ⇒ Object
mail_to “[email protected]” => “<a href=‘[email protected]’>[email protected]</a>” mail_to “[email protected]”, “Title” => “<a href=‘[email protected]’>Title</a>”.
- #error_messages_for(model_instance) ⇒ Object
- #link_item(name, url) ⇒ Object
- #link_to(name, url, options = Hash.new) ⇒ Object
- #truncate(text, *args) ⇒ Object
Instance Method Details
#copyright(from) ⇒ Object
7 8 9 10 |
# File 'lib/helpers/general.rb', line 7 def copyright(from) now = Time.now.year now.eql?(from) ? now : "#{from} - #{now}" end |
#email_link(mail, text = mail) ⇒ Object
mail_to “[email protected]”
> “<a href=‘[email protected]’>[email protected]</a>”
mail_to “[email protected]”, “Title”
> “<a href=‘[email protected]’>Title</a>”
28 29 30 31 |
# File 'lib/helpers/general.rb', line 28 def email_link(mail, text = mail) mail.gsub!("@" "@") Tag.new(:a, text, href: "mailto:#{mail}") end |
#error_messages_for(model_instance) ⇒ Object
34 35 36 37 38 39 |
# File 'lib/helpers/general.rb', line 34 def (model_instance) Tag.new(:ul) do = model_instance.errors. .map { || tag :li, } end end |
#link_item(name, url) ⇒ Object
19 20 21 |
# File 'lib/helpers/general.rb', line 19 def link_item(name, url) Tag.new(:li, link_to(name, url)) end |
#link_to(name, url, options = Hash.new) ⇒ Object
13 14 15 16 |
# File 'lib/helpers/general.rb', line 13 def link_to(name, url, = Hash.new) default = {href: URI.escape(url), title: name.to_s.gsub(/'/, ''')} Tag.new(:a, name, default.merge()) end |
#truncate(text, *args) ⇒ Object
41 42 43 44 45 46 47 48 49 |
# File 'lib/helpers/general.rb', line 41 def truncate(text, *args) = args. unless args.empty? [:size] = args[0] || 75 [:omission] = args[1] || "..." end = {size: 75, omission: "..."}.merge() text.scan(/(\S+)(\s+)/)[0..[:size]].flatten.join << [:omission] if text end |