class Sharkey::App
Public Instance Methods
delete_category(id)
click to toggle source
# File lib/sharkey/app.rb, line 61 def delete_category id category = Sharkey::Category.get id return if not category # * `category.parent` is a pointer to # another Category # * `category.categoryParent` is a pointer # to the RELATIONSHIP to another Category # Removing ties to other Categories... if category.parent category.parent.remove_child category end if category.categoryParent category.categoryParent.destroy end if not category.childs.empty? category.childs.each { |child| category.remove_child(child) } end # ...and to other Links... if category.categorizations category.categorizations.destroy end # ...and finally to itself category.reload category.destroy end
delete_link(id)
click to toggle source
# File lib/sharkey/app.rb, line 38 def delete_link id link = Sharkey::Link.get id return if not link # Before deleting the link, we must remove # all Sharkey::Tag associations link.taggings.destroy if link.taggings link.categorization.destroy if link.categorization link.reload link.destroy end
delete_tag(id)
click to toggle source
# File lib/sharkey/app.rb, line 51 def delete_tag id tag = Sharkey::Tag.get id return if not tag tag.taggings.destroy if tag.taggings tag.reload tag.destroy end
formatted_date(datetime)
click to toggle source
Converts ‘datetime` object into a formatted date String suited for HTML5’s <time datetime=“”> attributes!
# File lib/sharkey/app.rb, line 112 def formatted_date datetime return '' if datetime.nil? datetime.strftime '%Y-%m-%d %H:%m' end
get_themes()
click to toggle source
Returns an array with all the themes names
# File lib/sharkey/app.rb, line 119 def get_themes themes_dir = File.join(File.dirname(__FILE__), '/public/themes') themes = [] Dir.entries(themes_dir).sort.each do |dir| themes.push dir if ((dir != 'fonts') and (dir[0] != '.')) end themes end
random_sentence()
click to toggle source
# File lib/sharkey/app.rb, line 92 def random_sentence @sentences ||= File.readlines(File.join(File.dirname(__FILE__), '/public/data/sentences.txt')) @sentences.sample end
relative_date(datetime)
click to toggle source
Converts ‘datetime` object into a relative date String (like “2 days, 8 hours, 15 minutes, 2 seconds”)
# File lib/sharkey/app.rb, line 99 def relative_date datetime return '' if datetime.nil? # Now we'll calculate a short, human-friendly # version of the full date (like '2 days, 5 hours') added_secs = datetime.strftime('%s').to_i now_secs = DateTime.now.strftime('%s').to_i ChronicDuration.output(now_secs - added_secs) end