PageRenderTime 115ms CodeModel.GetById 10ms RepoModel.GetById 0ms app.codeStats 1ms

/app/helpers/spanish_verb_conjugation_helper.rb

https://bitbucket.org/kapilnakhwa/demo-teachme
Ruby | 71 lines | 55 code | 10 blank | 6 comment | 7 complexity | 72b0dccd96fd6cd3e7c25f0221614127 MD5 | raw file
  1. module SpanishVerbConjugationHelper
  2. 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]
  3. def common_verbs
  4. COMMON_VERBS
  5. end
  6. def verb_links
  7. 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}
  8. all_verbs = more_verbs + common_verbs
  9. verbs_html = all_verbs.sort.collect{|cv| %Q{<a href="/spanish_verb_conjugation/#{cv}">#{cv}</a>} }.join(" ")
  10. message = %Q{
  11. <style>
  12. .verb-conjugation-links a { display:block; float:left; width: 60px; height:20px; padding:3px; margin-right: 10px; text-align:left; }
  13. </style>
  14. <p>Listed below are some of the commonly selected verbs. Click on the verb and you will see its full conjugation and translation.
  15. <br />
  16. <br />
  17. <div class="verb-conjugation-links">
  18. #{verbs_html}
  19. </div>
  20. <br clear="all" />
  21. </p>
  22. }
  23. message.html_safe
  24. end
  25. def most_recent_verb_links
  26. 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}
  27. all_verbs = more_verbs
  28. verbs_html = all_verbs.sort.collect{|cv| %Q{<a href="/spanish_verb_conjugation/#{cv}">#{cv}</a>} }.join("<br /> ")
  29. message = %Q{
  30. <div class="verb-conjugation-links">
  31. #{verbs_html}
  32. </div>
  33. <br clear="all" />
  34. }
  35. message.html_safe
  36. end
  37. # this is purely for SEO purposes - ask before changing
  38. def seo_for_conjugation_home
  39. return '' if at_conjugation_home?
  40. link = %Q{<a href="/spanish_verb_conjugation">Spanish Verb Conjugation</a>}
  41. return "Please spread the word about our #{link} tool!".html_safe if request.fullpath.end_with?('er') # Vary message slightly for 'er' verbs
  42. return '' if request.fullpath.end_with?('se') # Remove message completely for some verbs
  43. return "Return to the #{link} index page".html_safe
  44. end
  45. # true if this is the conjugation home page
  46. # false if it's on a verb page
  47. def at_conjugation_home?
  48. request.fullpath.end_with?('spanish_verb_conjugation')
  49. end
  50. def format_conjugation(global_verb)
  51. conjugation = global_verb.conjugations
  52. return conjugation if global_verb.source!='jehle'
  53. html = conjugation.gsub( %r{.*?(<TABLE.*?</TABLE>).*}m, '\1')
  54. html.gsub!( %r{<SUP>.*?</SUP>}, '')
  55. html.gsub!( %r{<i>(.*?)</i>}i, '\1')
  56. html.gsub!( %r{osotros,&nbsp;+-as}, 'osotros')
  57. html.gsub!( %r{Uds./ellos/ellas}, 'ellos/ellas/Uds.')
  58. #html.gsub!( %r{Ud./..?l/ella}u, '?Šl/ella/Ud.')
  59. html
  60. end
  61. end