Code Monkey home page Code Monkey logo

cal's Introduction

Cal

A low level calendar engine.

Build Status

Installation

Add this line to your application's Gemfile:

gem 'cal'

And then execute:

$ bundle

Or install it yourself as:

$ gem install cal

Usage

Cal is a simple calendar structure. It does not render a calendar. It does not handle events.

See the Rails app https://github.com/austinthecoder/cal-app for an example.

API

calendar = Cal.new_monthly_calendar 2012, 11, :start_week_on => :monday

calendar.month # a Cal::Month

calendar.first_day # a Cal::Day representing the first day on the calendar, might be in the previous month

calendar.last_day # a Cal::Day representing the last day on the calendar, might be in the next month

calendar.days # a Range of Cal::Day's from the first day to the last

calendar.weeks # an Array of Cal::Day Arrays

calendar.previous # the calendar for the previous month

calendar.next # the calendar for the next month

calendar.day_names # an Array of the day names, e.g. [:sunday, :monday, ...], depends on the `:start_week_on` option

Rails example

# routes
root :to => redirect("/calendars/#{Date.today.year}-#{Date.today.month}")
resources :calendars, :only => :show

# controller
@calendar = Cal.new_monthly_calendar *params[:id].split('-')

# view
%h3
  = link_to 'Previous month', calendar_path(@calendar.previous.month)
  |
  = "#{@calendar.month.to_s "%B"} #{@calendar.year}"
  |
  = link_to 'Next month', calendar_path(@calendar.next.month)

%table
  %thead
    %tr
      - @calendar.day_names.each do |name|
        %th= name
  %tbody
    - @calendar.weeks.each do |week|
      %tr
        - week.each do |day|
          %td{:class => ('today' if day.today?)}
            = day.number

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Added some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

cal's People

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.