Guest User

Untitled

a guest
Feb 19th, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.52 KB | None | 0 0
  1. # helpers you put in here will be accessible to your tumblelog and are
  2. # super portable. if you're looking for the core ozi helpers, check out
  3. # app/helpers/tumble_helper.rb
  4. module ThemeHelper
  5. #
  6. # general theme helpers
  7. #
  8.  
  9. # get an array of tag names and generate a comma separated, linked string of tags
  10. def linked_tags_with_commas(tags, sep = ", ")
  11. tags.dup.map { |tag|
  12. tag_link(tag.name)
  13. }.join(sep)
  14. end
  15.  
  16. def popular_tags
  17. Tag.find_most_popular(4).map { |t| tag_link(t.name) }.to_sentence
  18. end
  19.  
  20. #
  21. # ajaxy editing
  22. #
  23. def ajaxy_edit(type, post)
  24. return unless logged_in? && controller.perform_caching == false
  25. oz_render_theme_partial "ajax/edit_#{type}", { :locals => { :post => post } }
  26. end
  27.  
  28. #
  29. # type helpers
  30. #
  31.  
  32. # for titles -- protect irc channel names, specifically
  33. def t(x)
  34. return r(x).gsub(/<(\/)?p>/,'') unless x[0,1] == '#'
  35. x
  36. end
  37.  
  38. # RedCloth wrapper -- clean this up if you have redcloth installed for sure
  39. def r(x, options = [])
  40. RedCloth.new(x, options).to_html
  41. end
  42.  
  43. # RedCloth lite
  44. def rl(x)
  45. r(x, [:lite_mode])
  46. end
  47.  
  48. # syntax highlight ruby code -- same as redcloth, clean it up
  49. def rc(x)
  50. begin
  51. require 'syntax'
  52. require 'syntax/convertors/html'
  53. Syntax::Convertors::HTML.for_syntax("ruby").convert(x)
  54. rescue
  55. x
  56. end
  57. end
  58.  
  59. # see if we have dependencies -- feel free to nuke this
  60. def require_test(file, gem = false)
  61. begin
  62. require file unless gem == true
  63. require_gem file if gem == true
  64. %[<span style="color: green;">found</span>]
  65. rescue MissingSourceFile, Gem::LoadError
  66. %[<span style="color: red;">not found</span>]
  67. end
  68. end
  69.  
  70. #
  71. # type specific helper functions for atom and rss feeds!
  72. #
  73. # check app/helpers/feed_helper.rb for more info on these
  74. #
  75.  
  76. # for the quote type
  77. def feed_content_quote(content)
  78. ret = %["#{content.quote}"]
  79. ret += " -- #{content.author}" if content.author
  80. strip_textile ret
  81. end
  82.  
  83. # slip an image into a feed
  84. def feed_content_image(content)
  85. %[<img src="#{content.src}" alt="#{content.alt}">]
  86. end
  87.  
  88. # use the alt if we provided no title
  89. def feed_title_image(post)
  90. post.title.blank? ? post.content.alt : post.title
  91. end
  92.  
  93. # just show the code
  94. def feed_content_code(content)
  95. content
  96. end
  97.  
  98. # quote title - same as the content
  99. def feed_title_quote(post)
  100. feed_content_quote(post.content)
  101. end
  102.  
  103. end
Add Comment
Please, Sign In to add comment