Added support for Ruby 1.9

This commit is contained in:
Paul van Tilburg 2012-06-06 11:28:59 +02:00
parent 53ec809f08
commit 3b54b93504
1 changed files with 22 additions and 13 deletions

View File

@ -1,4 +1,5 @@
#!/usr/bin/env camping #!/usr/bin/env camping
# encoding: UTF-8
# #
# stoptime.rb - The Stop… Camping Time! time registration and invoicing application. # stoptime.rb - The Stop… Camping Time! time registration and invoicing application.
# #
@ -31,6 +32,12 @@ unless defined? PUBLIC_DIR
# Set up SASS. # Set up SASS.
Sass::Plugin.options[:template_location] = "templates/sass" Sass::Plugin.options[:template_location] = "templates/sass"
# Set the default encodings.
if RUBY_VERSION =~ /^1\.9/
Encoding.default_external = Encoding::UTF_8
Encoding.default_internal = Encoding::UTF_8
end
# Set the default date(/time) format. # Set the default date(/time) format.
ActiveSupport::CoreExtensions::Time::Conversions::DATE_FORMATS.merge!( ActiveSupport::CoreExtensions::Time::Conversions::DATE_FORMATS.merge!(
:default => "%Y-%m-%d %H:%M", :default => "%Y-%m-%d %H:%M",
@ -2037,8 +2044,10 @@ module StopTime::Views
def _format_period(period) def _format_period(period)
period = period.map { |m| m.to_formatted_s(:month_and_year) }.uniq period = period.map { |m| m.to_formatted_s(:month_and_year) }.uniq
case period.length case period.length
when 1: period.first when 1
when 2: period.join("") period.first
when 2
period.join("")
end end
end end
@ -2058,11 +2067,11 @@ module StopTime::Views
def _form_input_radio(name, value, default=false, *opts) def _form_input_radio(name, value, default=false, *opts)
input_val = @input[name] input_val = @input[name]
if input_val == value or (input_val.blank? and default) if input_val == value or (input_val.blank? and default)
input :type => "radio", :id => "#{name}_#{value}", input({:type => "radio", :id => "#{name}_#{value}",
:name => name, :value => value, :checked => true, *opts :name => name, :value => value, :checked => true}, *opts)
else else
input :type => "radio", :id => "#{name}_#{value}", input({:type => "radio", :id => "#{name}_#{value}",
:name => name, :value => value, *opts :name => name, :value => value}, *opts)
end end
end end
@ -2071,11 +2080,11 @@ module StopTime::Views
# Additional options can be passed via the collection _opts_. # Additional options can be passed via the collection _opts_.
def _form_input_checkbox(name, value=true, *opts) def _form_input_checkbox(name, value=true, *opts)
if @input[name] == value if @input[name] == value
input :type => "checkbox", :id => "#{name}_#{value}", :name => name, input({:type => "checkbox", :id => "#{name}_#{value}", :name => name,
:value => value, :checked => true, *opts :value => value, :checked => true}, *opts)
else else
input :type => "checkbox", :id => "#{name}_#{value}", :name => name, input({:type => "checkbox", :id => "#{name}_#{value}", :name => name,
:value => value, *opts :value => value}, *opts)
end end
end end
@ -2119,12 +2128,12 @@ module StopTime::Views
else else
select :name => name, :id => name do select :name => name, :id => name do
opts.keys.sort.each do |key| opts.keys.sort.each do |key|
option "#{key}", :disabled => true option("#{key}", {:disabled => true})
opts[key].sort_by { |o| o.last }.each do |opt_val, opt_str| opts[key].sort_by { |o| o.last }.each do |opt_val, opt_str|
if @input[name] == opt_val if @input[name] == opt_val
option opt_str, :value => opt_val, :selected => true option(opt_str, {:value => opt_val, :selected => true})
else else
option opt_str, :value => opt_val option(opt_str, {:value => opt_val})
end end
end end
end end