This repository is private.
All pages are served over SSL and all pushing and pulling is done over SSH.
No one may fork, clone, or view it unless they are added as a member.
Every repository with this icon (
) is private.
Every repository with this icon (
This repository is public.
Anyone may fork, clone, or view it.
Every repository with this icon (
) is public.
Every repository with this icon (
| 5af60253 » | mleung | 2008-03-13 | 1 | module Merb | |
| 2 | module GlobalHelpers | ||||
| 0afb2eca » | ejdraper | 2008-04-11 | 3 | def render_title | |
| 19632b01 » | ejdraper | 2008-04-25 | 4 | @settings.title | |
| 0afb2eca » | ejdraper | 2008-04-11 | 5 | end | |
| 6 | |||||
| 7 | def render_tag_line | ||||
| 19632b01 » | ejdraper | 2008-04-25 | 8 | @settings.tag_line | |
| 0afb2eca » | ejdraper | 2008-04-11 | 9 | end | |
| 19632b01 » | ejdraper | 2008-04-25 | 10 | ||
| 11 | ## | ||||
| 12 | # This formats the specified text using the specified formatter, returning the result | ||||
| 787900fc » | ejdraper | 2008-04-10 | 13 | def render_text(formatter, text) | |
| 14 | Hooks::Formatters.format_text(formatter, text) | ||||
| 15 | end | ||||
| 19632b01 » | ejdraper | 2008-04-25 | 16 | ||
| 17 | ## | ||||
| 18 | # This formats the specified article, using it's configured formatter, returning the result | ||||
| 787900fc » | ejdraper | 2008-04-10 | 19 | def render_article(article) | |
| 20 | Hooks::Formatters.format_article(article) | ||||
| 21 | end | ||||
| 19632b01 » | ejdraper | 2008-04-25 | 22 | ||
| 23 | ## | ||||
| 24 | # This builds the menu list from the menu items, returning the markup | ||||
| 787900fc » | ejdraper | 2008-04-10 | 25 | def render_menu | |
| 26 | menu = "" | ||||
| 27 | menu_items.each_with_index do |item, index| | ||||
| 28 | menu += "<li>#{link_to item[:text], item[:url]} #{render_link_dot(index, menu_items.size - 1)}</li>" | ||||
| 29 | end | ||||
| 30 | menu | ||||
| 15c04ccf » | mleung | 2008-03-14 | 31 | end | |
| 19632b01 » | ejdraper | 2008-04-25 | 32 | ||
| 33 | ## | ||||
| 34 | # This returns the date as a relative date (today, yesterday etc) | ||||
| b594482a » | mleung | 2008-03-14 | 35 | def render_relative_date(date) | |
| 36 | date = Date.parse(date, true) unless /Date.*/ =~ date.class.to_s | ||||
| 37 | days = (date - Date.today).to_i | ||||
| 38 | |||||
| e69534b8 » | mleung | 2008-04-11 | 39 | return 'today' if days >= 0 and days < 1 | |
| 40 | return 'tomorrow' if days >= 1 and days < 2 | ||||
| b594482a » | mleung | 2008-03-14 | 41 | return 'yesterday' if days >= -1 and days < 0 | |
| 42 | |||||
| e69534b8 » | mleung | 2008-04-11 | 43 | return "in #{days} days" if days.abs < 60 and days > 0 | |
| b594482a » | mleung | 2008-03-14 | 44 | return "#{days.abs} days ago" if days.abs < 60 and days < 0 | |
| 45 | |||||
| 46 | return date.strftime('%A, %B %e') if days.abs < 182 | ||||
| 47 | return date.strftime('%A, %B %e, %Y') | ||||
| 48 | end | ||||
| 49 | |||||
| 19632b01 » | ejdraper | 2008-04-25 | 50 | ## | |
| 51 | # This returns the contents of the notifications in the session, clearing it at the same time | ||||
| 01329638 » | ejdraper | 2008-03-15 | 52 | def notifications | |
| 53 | notifications = session[:notifications] | ||||
| 54 | session[:notifications] = nil | ||||
| 55 | notifications | ||||
| 56 | end | ||||
| 19632b01 » | ejdraper | 2008-04-25 | 57 | ||
| 58 | ## | ||||
| 59 | # This returns the names of all possible timezones | ||||
| a6d34c96 » | ejdraper | 2008-03-15 | 60 | def get_timezones | |
| 61 | TZInfo::Timezone.all.collect { |tz| tz.name } | ||||
| 62 | end | ||||
| 19632b01 » | ejdraper | 2008-04-25 | 63 | ||
| 64 | ## | ||||
| 65 | # This returns the published at date for an article as a relative date (taking into account timezones) | ||||
| a6d34c96 » | ejdraper | 2008-03-15 | 66 | def render_relative_published_at(article) | |
| 67 | article.published_at.nil? ? "Not yet" : render_relative_date(TZInfo::Timezone.get(logged_in? ? self.current_user.time_zone : article.user.time_zone).utc_to_local(article.published_at)) | ||||
| 68 | end | ||||
| 19632b01 » | ejdraper | 2008-04-25 | 69 | ||
| 70 | ## | ||||
| 71 | # This returns the markup for the about text in the sidebar | ||||
| 4f879171 » | mleung | 2008-03-21 | 72 | def render_about_text | |
| ba5495d1 » | mleung | 2008-03-22 | 73 | unless @settings.nil? || @settings.about.blank? | |
| 4f879171 » | mleung | 2008-03-21 | 74 | markup = <<-MARKUP | |
| a3416322 » | mleung | 2008-03-21 | 75 | <div class="sidebar-node"> | |
| 4f879171 » | mleung | 2008-03-21 | 76 | <h3>About</h3> | |
| 10863ce9 » | ejdraper | 2008-04-10 | 77 | <p>#{render_text(@settings.about_formatter, @settings.about)}</p> | |
| 4f879171 » | mleung | 2008-03-21 | 78 | </div> | |
| 79 | MARKUP | ||||
| 80 | end | ||||
| 81 | markup | ||||
| 82 | end | ||||
| 19632b01 » | ejdraper | 2008-04-25 | 83 | ||
| 84 | ## | ||||
| 85 | # This returns the url for the year article index | ||||
| 55a110cb » | ejdraper | 2008-03-22 | 86 | def year_url(year) | |
| 87 | url(:year, {:year => year}) | ||||
| 88 | end | ||||
| 19632b01 » | ejdraper | 2008-04-25 | 89 | ||
| 90 | ## | ||||
| 91 | # This returns the url for the month article index | ||||
| 55a110cb » | ejdraper | 2008-03-22 | 92 | def month_url(year, month) | |
| 93 | url(:month, {:year => year, :month => Padding::pad_single_digit(month)}) | ||||
| 94 | end | ||||
| 19632b01 » | ejdraper | 2008-04-25 | 95 | ||
| 96 | ## | ||||
| 97 | # This returns the url for the day article index | ||||
| 55a110cb » | ejdraper | 2008-03-22 | 98 | def day_url(year, month, day) | |
| 99 | url(:day, {:year => year, :month => Padding::pad_single_digit(month), :day => Padding::pad_single_digit(day)}) | ||||
| 100 | end | ||||
| d58ce832 » | ejdraper | 2008-03-28 | 101 | ||
| 102 | ## | ||||
| 19632b01 » | ejdraper | 2008-04-25 | 103 | # This returns all menu items, including those provided by plugins | |
| d58ce832 » | ejdraper | 2008-03-28 | 104 | def menu_items | |
| 105 | items = [] | ||||
| 106 | items << {:text => "Dashboard", :url => url(:admin_dashboard)} | ||||
| 107 | items << {:text => "Articles", :url => url(:admin_articles)} | ||||
| 108 | items << {:text => "Plugins", :url => url(:admin_plugins)} | ||||
| 109 | items << {:text => "Settings", :url => url(:admin_configurations)} | ||||
| 749739aa » | thewordnerd | 2008-06-24 | 110 | items << {:text => "Users", :url => url(:users)} | |
| d58ce832 » | ejdraper | 2008-03-28 | 111 | if self.current_user == :false | |
| 112 | items << {:text => "Login", :url => url(:login)} | ||||
| 113 | else | ||||
| 114 | items << {:text => "Logout", :url => url(:logout)} | ||||
| 115 | end | ||||
| 6f59a545 » | mleung | 2008-04-06 | 116 | Hooks::Menu.menu_items.each { |item| items << item } | |
| d58ce832 » | ejdraper | 2008-03-28 | 117 | items | |
| 118 | end | ||||
| 19632b01 » | ejdraper | 2008-04-25 | 119 | ||
| 120 | ## | ||||
| 121 | # This either adds the breaking • character unless we're at the end of the collection (based on index and size) | ||||
| e525ec6b » | mleung | 2008-03-29 | 122 | def render_link_dot(index, collection_size) | |
| 123 | " •" unless index == collection_size | ||||
| 124 | end | ||||
| 19632b01 » | ejdraper | 2008-04-25 | 125 | ||
| 6e441683 » | ejdraper | 2008-04-01 | 126 | ## | |
| 127 | # This renders all plugin views for the specified hook | ||||
| 19482ab5 » | mleung | 2008-04-02 | 128 | def render_plugin_views(name, options = {}) | |
| 6e441683 » | ejdraper | 2008-04-01 | 129 | output = "" | |
| 130 | Hooks::View.plugin_views.each do |view| | ||||
| 508ade4f » | ejdraper | 2008-04-01 | 131 | if view[:name] == name | |
| 163431e5 » | ejdraper | 2008-04-12 | 132 | if view[:partial] | |
| 19632b01 » | ejdraper | 2008-04-25 | 133 | # Set the template root, create the template method and call the partial | |
| 163431e5 » | ejdraper | 2008-04-12 | 134 | _template_root = File.join(view[:plugin].path, "views") | |
| 261681fe » | fujin | 2008-07-20 | 135 | template_location = _template_root / _template_location("#{view[:partial]}", content_type, view[:name]) | |
| 136 | output << partial(template_location, { :with => options[:with], :as => options[:with].class.to_s.downcase.singular }) | ||||
| 163431e5 » | ejdraper | 2008-04-12 | 137 | else | |
| 19632b01 » | ejdraper | 2008-04-25 | 138 | # Render the specified text using ERB and the options | |
| 69c7f813 » | ejdraper | 2008-04-12 | 139 | output << Proc.new { |args| ERB.new(view[:content]).result(binding) }.call(options[:with]) | |
| 163431e5 » | ejdraper | 2008-04-12 | 140 | end | |
| 508ade4f » | ejdraper | 2008-04-01 | 141 | end | |
| 6e441683 » | ejdraper | 2008-04-01 | 142 | end | |
| 19632b01 » | ejdraper | 2008-04-25 | 143 | # Return the view markup generated by plugins | |
| 6e441683 » | ejdraper | 2008-04-01 | 144 | output | |
| 145 | end | ||||
| 19632b01 » | ejdraper | 2008-04-25 | 146 | ||
| 049267e7 » | ejdraper | 2008-04-08 | 147 | ## | |
| 69c7f813 » | ejdraper | 2008-04-12 | 148 | # This returns the full url for an article | |
| 149 | def get_full_url(article) | ||||
| 150 | "http://#{request.host}#{article.permalink}" | ||||
| 151 | end | ||||
| 19632b01 » | ejdraper | 2008-04-25 | 152 | ||
| 69c7f813 » | ejdraper | 2008-04-12 | 153 | ## | |
| 154 | # This escapes the specified url | ||||
| 155 | def escape_url(url) | ||||
| 156 | CGI.escape(url) | ||||
| 157 | end | ||||
| 19632b01 » | ejdraper | 2008-04-25 | 158 | ||
| 69c7f813 » | ejdraper | 2008-04-12 | 159 | ## | |
| 19632b01 » | ejdraper | 2008-04-25 | 160 | # This returns true if the specified plugin is active, false if it isn't or is unavailable | |
| 049267e7 » | ejdraper | 2008-04-08 | 161 | def is_plugin_active(name) | |
| 162 | plugin = Plugin.first(:name => name) | ||||
| 163 | plugin && plugin.active | ||||
| 164 | end | ||||
| 91c961f3 » | ejdraper | 2008-06-06 | 165 | ||
| 166 | def link_to_author(author) | ||||
| 167 | link_to author["name"], author["homepage"] | ||||
| 168 | end | ||||
| 5af60253 » | mleung | 2008-03-13 | 169 | end | |
| 749739aa » | thewordnerd | 2008-06-24 | 170 | end | |








