automatically updating times for posts on topic

moved moment.js into localization file (we need to localize it)
added helpers for date formatting use, moment().shortDate() moment().longDate() moment().shortDateNoYear()
This commit is contained in:
Sam
2013-06-11 17:25:50 +10:00
parent 6d85dc1724
commit c2cfbce9ce
8 changed files with 65 additions and 22 deletions

View File

@ -18,11 +18,26 @@ module JsLocaleHelper
result = generate_message_format(message_formats, locale_str)
result << "I18n.translations = #{translations.to_json};\n"
result << "I18n.locale = '#{locale_str}'\n"
result << "I18n.locale = '#{locale_str}';\n"
# loading moment here cause we must customize it
result << File.read("#{Rails.root}/lib/javascripts/moment.js")
result << moment_locale(locale_str)
result << moment_formats
result
end
def self.moment_formats
result = ""
result << moment_format_function('short_date_no_year')
result << moment_format_function('short_date')
result << moment_format_function('long_date')
end
def self.moment_format_function(name)
format = I18n.t("dates." << name)
result = "moment.fn.#{name.camelize(:lower)} = function(){ return this.format('#{format}'); };\n"
end
def self.moment_locale(locale_str)
filename = Rails.root + "lib/javascript/moment_locale/#{locale_str}.js"
if File.exists?(filename)