Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

better include helpers #23

Open
wants to merge 3 commits into from

2 participants

@raszi

hey!

I've modified the include helpers for calendar_date_select to prevent overloading the loaded translations, and I installed the default translation for I18n as well.

If you feel like include this into the upstream.

@timcharper
Owner

is this RJS? Does that still work in rails 3? I wonder if it'd be more obvious to others if it were a HEREDOC, injecting the values in with to_json. What do you think?

I'm not using Rails 3 yet, but as the documentation says: http://api.rubyonrails.org/classes/ActionView/Helpers/PrototypeHelper.html#method-i-update_page_tag it exists.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jun 15, 2011
  1. @raszi
  2. @raszi

    default translations from I18n

    raszi authored
Commits on Jun 27, 2011
  1. @raszi
This page is out of date. Refresh to see the latest.
Showing with 39 additions and 5 deletions.
  1. +39 −5 lib/calendar_date_select/includes_helper.rb
View
44 lib/calendar_date_select/includes_helper.rb
@@ -1,12 +1,28 @@
module CalendarDateSelect::IncludesHelper
+ def calendar_date_select_stylesheets_loaded?
+ @cds_stylesheets_loaded ||= false
+ end
+
+ def calendar_date_select_javascripts_loaded?
+ @cds_javascripts_loaded ||= false
+ end
+
# returns the selected calendar_date_select stylesheet (not an array)
def calendar_date_select_stylesheets(options = {})
+ return [] if @cds_stylesheets_loaded
+
+ @cds_stylesheets_loaded = true
+
options.assert_valid_keys(:style)
"calendar_date_select/#{options[:style] || "default"}"
end
# returns an array of javascripts needed for the selected locale, date_format, and calendar control itself.
def calendar_date_select_javascripts(options = {})
+ return [] if @cds_javascripts_loaded
+
+ @cds_javascripts_loaded = true
+
options.assert_valid_keys(:locale)
files = ["calendar_date_select/calendar_date_select"]
files << "calendar_date_select/locale/#{options[:locale]}" if options[:locale]
@@ -16,14 +32,32 @@ def calendar_date_select_javascripts(options = {})
# returns html necessary to load javascript and css to make calendar_date_select work
def calendar_date_select_includes(*args)
- return "" if @cds_already_included
- @cds_already_included=true
-
options = (Hash === args.last) ? args.pop : {}
options.assert_valid_keys(:style, :locale)
options[:style] ||= args.shift
- javascript_include_tag(*calendar_date_select_javascripts(:locale => options[:locale])) + "\n" +
- stylesheet_link_tag(*calendar_date_select_stylesheets(:style => options[:style])) + "\n"
+ includes = [
+ javascript_include_tag(*calendar_date_select_javascripts(:locale => options[:locale])),
+ stylesheet_link_tag(*calendar_date_select_stylesheets(:style => options[:style]))
+ ]
+ includes << calendar_date_default_translation unless options[:locale]
+ includes
+ end
+
+ # from one of the comments of http://code.google.com/p/calendardateselect/wiki/HowToLocalize
+ def calendar_date_default_translation
+ scope = [ :calendar_date_select ]
+
+ update_page_tag do |page|
+ page.assign '_translations', {
+ 'OK' => I18n.t(:ok, :scope => scope),
+ 'Now' => I18n.t(:now, :scope => scope),
+ 'Today' => I18n.t(:today, :scope => scope),
+ 'Clear' => I18n.t(:clear, :scope => scope)
+ }
+ page.assign 'Date.weekdays', I18n.translate('date.abbr_day_names')
+ page.assign 'Date.months', I18n.translate('date.month_names')[1..-1]
+ end
end
+
end
Something went wrong with that request. Please try again.