Module: Sinatra::DateForms

Defined in:
lib/sinatra/support/dateforms.rb

Overview

Date helpers.

require 'sinatra/support/dateforms'

class Main < Sinatra::Base
  register Sinatra::DateForms
end

Helpers

This plugin provides the following helpers:

month_choices - Provides month choices for dropdowns.

<select name="birthday[month]">
  <%= month_choices %>
</select>

day_choices - Day choices.

<select name="birthday[day]">
  <%= day_choices %>
</select>

year_choices - Year dropdown.

<select name="birthday[year]">
  <%= year_choices %>
</select>

Settings

Provides the following settings in your application:

default_year_loffset

(Numeric) How many years back to display. Defaults to -60.

default_year_loffset

(Numeric) How many years forward. Defaults to 0.

default_month_names

(Array) The names of the months. Defaults To Date::MONTHNAMES.

You may change them like this:

Main.configure do |m|
  m.set :default_year_loffset, -60 
  m.set :default_year_uoffset, 0
  m.set :default_month_names, Date::MONTHNAMES
end

Defined Under Namespace

Modules: Helpers

Class Method Summary (collapse)

Class Method Details

+ (Object) registered(app)



53
54
55
56
57
58
59
# File 'lib/sinatra/support/dateforms.rb', line 53

def self.registered(app)
  app.set :default_year_loffset, -60
  app.set :default_year_uoffset, 0
  app.set :default_month_names, Date::MONTHNAMES

  app.helpers Helpers
end