public
Description: Uber lightweight Merb blogging engine. Make sure you check out the feather-plugins repo as well!
Homepage:
Clone URL: git://github.com/mleung/feather.git
Click here to lend your support to: feather and make a donation at www.pledgie.com !
feather / app / helpers / global_helpers.rb
5af60253 » mleung 2008-03-13 Adding user model 1 module Merb
2 module GlobalHelpers
0afb2eca » ejdraper 2008-04-11 * added separate before/aft... 3 def render_title
19632b01 » ejdraper 2008-04-25 this tidies up various bits... 4 @settings.title
0afb2eca » ejdraper 2008-04-11 * added separate before/aft... 5 end
6
7 def render_tag_line
19632b01 » ejdraper 2008-04-25 this tidies up various bits... 8 @settings.tag_line
0afb2eca » ejdraper 2008-04-11 * added separate before/aft... 9 end
19632b01 » ejdraper 2008-04-25 this tidies up various bits... 10
11 ##
12 # This formats the specified text using the specified formatter, returning the result
787900fc » ejdraper 2008-04-10 multiple changes 13 def render_text(formatter, text)
14 Hooks::Formatters.format_text(formatter, text)
15 end
19632b01 » ejdraper 2008-04-25 this tidies up various bits... 16
17 ##
18 # This formats the specified article, using it's configured formatter, returning the result
787900fc » ejdraper 2008-04-10 multiple changes 19 def render_article(article)
20 Hooks::Formatters.format_article(article)
21 end
19632b01 » ejdraper 2008-04-25 this tidies up various bits... 22
23 ##
24 # This builds the menu list from the menu items, returning the markup
787900fc » ejdraper 2008-04-10 multiple changes 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 Added textile support with ... 31 end
19632b01 » ejdraper 2008-04-25 this tidies up various bits... 32
33 ##
34 # This returns the date as a relative date (today, yesterday etc)
b594482a » mleung 2008-03-14 Put in relative time for po... 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 Added in support hooks for ... 39 return 'today' if days >= 0 and days < 1
40 return 'tomorrow' if days >= 1 and days < 2
b594482a » mleung 2008-03-14 Put in relative time for po... 41 return 'yesterday' if days >= -1 and days < 0
42
e69534b8 » mleung 2008-04-11 Added in support hooks for ... 43 return "in #{days} days" if days.abs < 60 and days > 0
b594482a » mleung 2008-03-14 Put in relative time for po... 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 this tidies up various bits... 50 ##
51 # This returns the contents of the notifications in the session, clearing it at the same time
01329638 » ejdraper 2008-03-15 all ajax settings now work,... 52 def notifications
53 notifications = session[:notifications]
54 session[:notifications] = nil
55 notifications
56 end
19632b01 » ejdraper 2008-04-25 this tidies up various bits... 57
58 ##
59 # This returns the names of all possible timezones
a6d34c96 » ejdraper 2008-03-15 added user timezones for ar... 60 def get_timezones
61 TZInfo::Timezone.all.collect { |tz| tz.name }
62 end
19632b01 » ejdraper 2008-04-25 this tidies up various bits... 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 added user timezones for ar... 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 this tidies up various bits... 69
70 ##
71 # This returns the markup for the about text in the sidebar
4f879171 » mleung 2008-03-21 XHTML for articles/index an... 72 def render_about_text
ba5495d1 » mleung 2008-03-22 Changed nil || empty check ... 73 unless @settings.nil? || @settings.about.blank?
4f879171 » mleung 2008-03-21 XHTML for articles/index an... 74 markup = <<-MARKUP
a3416322 » mleung 2008-03-21 Ported the Scribbish theme ... 75 <div class="sidebar-node">
4f879171 » mleung 2008-03-21 XHTML for articles/index an... 76 <h3>About</h3>
10863ce9 » ejdraper 2008-04-10 added an in-place dropdown ... 77 <p>#{render_text(@settings.about_formatter, @settings.about)}</p>
4f879171 » mleung 2008-03-21 XHTML for articles/index an... 78 </div>
79 MARKUP
80 end
81 markup
82 end
19632b01 » ejdraper 2008-04-25 this tidies up various bits... 83
84 ##
85 # This returns the url for the year article index
55a110cb » ejdraper 2008-03-22 adding route to handle year... 86 def year_url(year)
87 url(:year, {:year => year})
88 end
19632b01 » ejdraper 2008-04-25 this tidies up various bits... 89
90 ##
91 # This returns the url for the month article index
55a110cb » ejdraper 2008-03-22 adding route to handle year... 92 def month_url(year, month)
93 url(:month, {:year => year, :month => Padding::pad_single_digit(month)})
94 end
19632b01 » ejdraper 2008-04-25 this tidies up various bits... 95
96 ##
97 # This returns the url for the day article index
55a110cb » ejdraper 2008-03-22 adding route to handle year... 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 this adds initial plugin su... 101
102 ##
19632b01 » ejdraper 2008-04-25 this tidies up various bits... 103 # This returns all menu items, including those provided by plugins
d58ce832 » ejdraper 2008-03-28 this adds initial plugin su... 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 Initial migration to merb-a... 110 items << {:text => "Users", :url => url(:users)}
d58ce832 » ejdraper 2008-03-28 this adds initial plugin su... 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 Changing link style on scri... 116 Hooks::Menu.menu_items.each { |item| items << item }
d58ce832 » ejdraper 2008-03-28 this adds initial plugin su... 117 items
118 end
19632b01 » ejdraper 2008-04-25 this tidies up various bits... 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 Refactored showing the dot ... 122 def render_link_dot(index, collection_size)
123 "&nbsp;•" unless index == collection_size
124 end
19632b01 » ejdraper 2008-04-25 this tidies up various bits... 125
6e441683 » ejdraper 2008-04-01 refactored view hooks to wo... 126 ##
127 # This renders all plugin views for the specified hook
19482ab5 » mleung 2008-04-02 Added options hash to rende... 128 def render_plugin_views(name, options = {})
6e441683 » ejdraper 2008-04-01 refactored view hooks to wo... 129 output = ""
130 Hooks::View.plugin_views.each do |view|
508ade4f » ejdraper 2008-04-01 fixed plugin views to only ... 131 if view[:name] == name
163431e5 » ejdraper 2008-04-12 non-breaking change to the ... 132 if view[:partial]
19632b01 » ejdraper 2008-04-25 this tidies up various bits... 133 # Set the template root, create the template method and call the partial
163431e5 » ejdraper 2008-04-12 non-breaking change to the ... 134 _template_root = File.join(view[:plugin].path, "views")
261681fe » fujin 2008-07-20 Somehow my render_plugin_vi... 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 non-breaking change to the ... 137 else
19632b01 » ejdraper 2008-04-25 this tidies up various bits... 138 # Render the specified text using ERB and the options
69c7f813 » ejdraper 2008-04-12 this improves the dynamic v... 139 output << Proc.new { |args| ERB.new(view[:content]).result(binding) }.call(options[:with])
163431e5 » ejdraper 2008-04-12 non-breaking change to the ... 140 end
508ade4f » ejdraper 2008-04-01 fixed plugin views to only ... 141 end
6e441683 » ejdraper 2008-04-01 refactored view hooks to wo... 142 end
19632b01 » ejdraper 2008-04-25 this tidies up various bits... 143 # Return the view markup generated by plugins
6e441683 » ejdraper 2008-04-01 refactored view hooks to wo... 144 output
145 end
19632b01 » ejdraper 2008-04-25 this tidies up various bits... 146
049267e7 » ejdraper 2008-04-08 added helper method for que... 147 ##
69c7f813 » ejdraper 2008-04-12 this improves the dynamic v... 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 this tidies up various bits... 152
69c7f813 » ejdraper 2008-04-12 this improves the dynamic v... 153 ##
154 # This escapes the specified url
155 def escape_url(url)
156 CGI.escape(url)
157 end
19632b01 » ejdraper 2008-04-25 this tidies up various bits... 158
69c7f813 » ejdraper 2008-04-12 this improves the dynamic v... 159 ##
19632b01 » ejdraper 2008-04-25 this tidies up various bits... 160 # This returns true if the specified plugin is active, false if it isn't or is unavailable
049267e7 » ejdraper 2008-04-08 added helper method for que... 161 def is_plugin_active(name)
162 plugin = Plugin.first(:name => name)
163 plugin && plugin.active
164 end
91c961f3 » ejdraper 2008-06-06 fixed plugin installation f... 165
166 def link_to_author(author)
167 link_to author["name"], author["homepage"]
168 end
5af60253 » mleung 2008-03-13 Adding user model 169 end
749739aa » thewordnerd 2008-06-24 Initial migration to merb-a... 170 end