/app/helpers/spanish_verb_conjugation_helper.rb
Ruby | 71 lines | 55 code | 10 blank | 6 comment | 7 complexity | 72b0dccd96fd6cd3e7c25f0221614127 MD5 | raw file
- module SpanishVerbConjugationHelper
- COMMON_VERBS = %w[ser ir hacer tener estar ver decir poder comer dar querer poner saber venir hablar salir haber pedir leer dormir traer llegar jugar conocer empezar volver vivir oir seguir pensar escribir]
- def common_verbs
- COMMON_VERBS
- end
- def verb_links
- more_verbs = GlobalVerb.random_verbs(20).find_all{|v| !v.lookup_key.index('_') && !common_verbs.member?(v.verb) && v.verb.length < 12}.collect{|v| v.verb}
- all_verbs = more_verbs + common_verbs
- verbs_html = all_verbs.sort.collect{|cv| %Q{<a href="/spanish_verb_conjugation/#{cv}">#{cv}</a>} }.join(" ")
- message = %Q{
- <style>
- .verb-conjugation-links a { display:block; float:left; width: 60px; height:20px; padding:3px; margin-right: 10px; text-align:left; }
- </style>
- <p>Listed below are some of the commonly selected verbs. Click on the verb and you will see its full conjugation and translation.
- <br />
- <br />
- <div class="verb-conjugation-links">
- #{verbs_html}
- </div>
- <br clear="all" />
- </p>
- }
- message.html_safe
- end
- def most_recent_verb_links
- more_verbs = GlobalVerb.last(5).find_all{|v| !v.lookup_key.index('_') && !common_verbs.member?(v.verb) && v.verb.length < 12}.collect{|v| v.verb}
- all_verbs = more_verbs
- verbs_html = all_verbs.sort.collect{|cv| %Q{<a href="/spanish_verb_conjugation/#{cv}">#{cv}</a>} }.join("<br /> ")
- message = %Q{
- <div class="verb-conjugation-links">
- #{verbs_html}
- </div>
- <br clear="all" />
- }
- message.html_safe
- end
- # this is purely for SEO purposes - ask before changing
- def seo_for_conjugation_home
- return '' if at_conjugation_home?
- link = %Q{<a href="/spanish_verb_conjugation">Spanish Verb Conjugation</a>}
- return "Please spread the word about our #{link} tool!".html_safe if request.fullpath.end_with?('er') # Vary message slightly for 'er' verbs
- return '' if request.fullpath.end_with?('se') # Remove message completely for some verbs
- return "Return to the #{link} index page".html_safe
- end
- # true if this is the conjugation home page
- # false if it's on a verb page
- def at_conjugation_home?
- request.fullpath.end_with?('spanish_verb_conjugation')
- end
- def format_conjugation(global_verb)
- conjugation = global_verb.conjugations
- return conjugation if global_verb.source!='jehle'
- html = conjugation.gsub( %r{.*?(<TABLE.*?</TABLE>).*}m, '\1')
- html.gsub!( %r{<SUP>.*?</SUP>}, '')
- html.gsub!( %r{<i>(.*?)</i>}i, '\1')
- html.gsub!( %r{osotros, +-as}, 'osotros')
- html.gsub!( %r{Uds./ellos/ellas}, 'ellos/ellas/Uds.')
- #html.gsub!( %r{Ud./..?l/ella}u, '?Šl/ella/Ud.')
- html
- end
- end