simple_calendar 0.1.9 → 0.1.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9cf7dd7da58c164946cc463de914d5dccaa6c276
4
- data.tar.gz: 41e7930f9ca72998c17c2e3696f4d3f42cbd5ac8
3
+ metadata.gz: 9f1bef2fdf230945b581621112f8c7b46b9cb9d9
4
+ data.tar.gz: 40d6aab11c406a80bdbb4a53dbfdecc7eec80870
5
5
  SHA512:
6
- metadata.gz: 9de2b8ede0f7af25ae69cde985e6904ee0b45072b7fc788d7e78de6e0abb857b0251686f7aa8ed9d61a5e01765b40caccb1bfd57154275c266c293c838e4e54c
7
- data.tar.gz: d85e2eca8b75807c5dc9a3dd27693b2ba30825052186c9d3a21cb1f84b4707c0d5c68943fe0ae623d5153a805b1a8d970a94f037a8b69b71937ad0bdb77872a6
6
+ metadata.gz: e13e563237199144c692d14266d37f60855ca9011700ea63f0756943015af38b331948012d0dea4d374763d3c1f0115615e69bd6a1f9e19ae5fd7073ee41bfc3
7
+ data.tar.gz: 9dac84908ee7a8405b8702fab311f487e32220a26876a87e24a434fb3e7ce9de87162be6964a1e8b3ca253700650a89b7750bc9b0b53ff9b974ad93c26db91cc
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/Gemfile CHANGED
@@ -2,3 +2,8 @@ source "http://rubygems.org"
2
2
 
3
3
  # Specify your gem's dependencies in simple_calendar.gemspec
4
4
  gemspec
5
+
6
+ group :test do
7
+ gem 'rspec'
8
+ gem 'pry'
9
+ end
data/README.md CHANGED
@@ -6,14 +6,14 @@ Theming is up to you, but it works nicely with Twitter Bootstrap. It's
6
6
  compatible with pure Ruby classes, ActiveRecord, Mongoid, and any other
7
7
  ORM.
8
8
 
9
- Thanks to Josh Chernoff and all other contributors.
9
+ Thanks to all of the awesome contributors!
10
10
 
11
11
  Installation
12
12
  ------------
13
13
 
14
14
  Just add this into your Gemfile followed by a bundle install:
15
15
 
16
- gem "simple_calendar", "~> 0.1.9"
16
+ gem "simple_calendar", "~> 0.1.10"
17
17
 
18
18
  Usage
19
19
  -----
@@ -124,6 +124,16 @@ represents the day that has no events.
124
124
  <%= event.name %>
125
125
  <% end %>
126
126
  ```
127
+ The `not_empty_date` option accepts a block that will be called when a day
128
+ in the calendar has at least one event. It will be called with the date object that
129
+ represents the day that has some events.
130
+
131
+ ```erb
132
+ <%= calendar @events, not_empty_date: lambda{ |date| "hello from #{date}" } do |event| %>
133
+ <%= event.name %>
134
+ <% end %>
135
+ ```
136
+
127
137
 
128
138
  CSS
129
139
  ---
@@ -1,3 +1,3 @@
1
1
  module SimpleCalendar
2
- VERSION = "0.1.9"
2
+ VERSION = "0.1.10"
3
3
  end
@@ -4,20 +4,11 @@ module SimpleCalendar
4
4
  def calendar(events, options={}, &block)
5
5
  raise 'SimpleCalendar requires a block to be passed in' unless block_given?
6
6
 
7
-
8
- opts = {
9
- :year => (params[:year] || Time.zone.now.year).to_i,
10
- :month => (params[:month] || Time.zone.now.month).to_i,
11
- :prev_text => raw("&laquo;"),
12
- :next_text => raw("&raquo;"),
13
- :start_day => :sunday,
14
- :class => "table table-bordered table-striped calendar",
15
- :params => {}
16
- }
7
+ opts = default_options
17
8
  options.reverse_merge! opts
18
9
  events ||= []
19
10
  selected_month = Date.new(options[:year], options[:month])
20
- current_date = Date.today
11
+ current_date = Time.zone.now.to_date
21
12
  range = build_range selected_month, options
22
13
  month_array = range.each_slice(7).to_a
23
14
 
@@ -25,7 +16,19 @@ module SimpleCalendar
25
16
  end
26
17
 
27
18
  private
28
-
19
+ def default_options
20
+ {
21
+ :year => (params[:year] || Time.zone.now.year).to_i,
22
+ :month => (params[:month] || Time.zone.now.month).to_i,
23
+ :prev_text => raw("&laquo;"),
24
+ :next_text => raw("&raquo;"),
25
+ :start_day => :sunday,
26
+ :class => "table table-bordered table-striped calendar",
27
+ :params => {},
28
+ :time_selector => "start_time"
29
+ }
30
+ end
31
+ # Returns array of dates between start date and end date for selected month
29
32
  def build_range(selected_month, options)
30
33
  start_date = selected_month.beginning_of_month.beginning_of_week(options[:start_day])
31
34
  end_date = selected_month.end_of_month.end_of_week(options[:start_day])
@@ -36,16 +39,16 @@ module SimpleCalendar
36
39
  # Renders the calendar table
37
40
  def draw_calendar(selected_month, month, current_date, events, options, block)
38
41
  tags = []
39
- today = Date.today
42
+ today = Time.zone.now.to_date
40
43
  content_tag(:table, :class => options[:class]) do
41
44
  tags << month_header(selected_month, options)
42
45
  day_names = I18n.t("date.abbr_day_names")
43
46
  day_names = day_names.rotate((Date::DAYS_INTO_WEEK[options[:start_day]] + 1) % 7)
44
- tags << content_tag(:thead, content_tag(:tr, day_names.collect { |name| content_tag :th, name, :class => (selected_month.month == Date.today.month && Date.today.strftime("%a") == name ? "current-day" : nil)}.join.html_safe))
47
+ tags << content_tag(:thead, content_tag(:tr, day_names.collect { |name| content_tag :th, name, :class => (selected_month.month == today.month && today.strftime("%a") == name ? "current-day" : nil)}.join.html_safe))
45
48
  tags << content_tag(:tbody, :'data-month'=>selected_month.month, :'data-year'=>selected_month.year) do
46
49
 
47
50
  month.collect do |week|
48
- content_tag(:tr, :class => (week.include?(Date.today) ? "current-week week" : "week")) do
51
+ content_tag(:tr, :class => (week.include?(today) ? "current-week week" : "week")) do
49
52
 
50
53
  week.collect do |date|
51
54
  td_class = ["day"]
@@ -55,7 +58,7 @@ module SimpleCalendar
55
58
  td_class << "future" if today < date
56
59
  td_class << "wday-#{date.wday.to_s}" # <- to enable different styles for weekend, etc
57
60
 
58
- cur_events = day_events(date, events)
61
+ cur_events = day_events(date, events, options[:time_selector])
59
62
 
60
63
  td_class << (cur_events.any? ? "events" : "no-events")
61
64
 
@@ -67,6 +70,9 @@ module SimpleCalendar
67
70
  if cur_events.empty? && options[:empty_date]
68
71
  concat options[:empty_date].call(date)
69
72
  else
73
+ if options[:not_empty_date]
74
+ concat options[:not_empty_date].call(date)
75
+ end
70
76
  divs << cur_events.collect{ |event| block.call(event) }
71
77
  end
72
78
 
@@ -85,8 +91,8 @@ module SimpleCalendar
85
91
  end
86
92
 
87
93
  # Returns an array of events for a given day
88
- def day_events(date, events)
89
- events.select { |e| e.start_time.to_date == date }.sort_by { |e| e.start_time }
94
+ def day_events(date, events, time_selector)
95
+ events.select { |e| e.send(time_selector).to_date == date }.sort_by { |e| e.send(time_selector) }
90
96
  end
91
97
 
92
98
  # Generates the header that includes the month and next and previous months
data/spec/helper.rb ADDED
@@ -0,0 +1,24 @@
1
+ require 'pathname'
2
+ require 'rubygems'
3
+ require 'bundler'
4
+ require 'pry'
5
+ require 'active_support/all'
6
+ require 'action_view'
7
+
8
+ root_path = Pathname(__FILE__).dirname.join('..').expand_path
9
+ lib_path = root_path.join('lib')
10
+
11
+ Dir[root_path.join("spec/support/*.rb")].each { |f| require f }
12
+ Dir[lib_path.join("simple_calendar/*.rb")].each { |f| require f }
13
+
14
+ Bundler.setup(:default)
15
+
16
+ RSpec.configure do |config|
17
+ config.fail_fast = true
18
+
19
+ config.filter_run :focused => true
20
+ config.alias_example_to :fit, :focused => true
21
+ config.alias_example_to :xit, :pending => true
22
+ config.run_all_when_everything_filtered = true
23
+ end
24
+ Time.zone = "UTC"
@@ -0,0 +1,94 @@
1
+ require 'helper'
2
+
3
+ class View
4
+ include SimpleCalendar::ViewHelpers
5
+ include ActionView::Helpers
6
+ include ActionView::Context
7
+
8
+ def raw(argument)
9
+ argument
10
+ end
11
+
12
+ end
13
+
14
+ describe "SimpleCalendar" do
15
+ subject { View.new }
16
+
17
+ before do
18
+ subject.stub(:params => {:year => 2013, :month => 5})
19
+ end
20
+
21
+ describe "#calendar" do
22
+ context "with invalid arguments" do
23
+ it "should raise an error" do
24
+ expect { subject.calendar("foo") }.to raise_error(StandardError, /block/)
25
+ end
26
+ end
27
+
28
+ context "with valid arguments" do
29
+ it "should draw a calendar" do
30
+ subject.should_receive(:draw_calendar)
31
+ subject.calendar("foo") { "test" }
32
+ end
33
+
34
+ it "should not overwrite passed in arguments" do
35
+ subject.should_receive(:build_range).and_return([2,2,3])
36
+ subject.should_receive(:draw_calendar)
37
+ subject.calendar("foo") { "test" }
38
+ end
39
+ end
40
+ end
41
+
42
+ describe "#build_range" do
43
+ it "should return an array representing the days of the month" do
44
+ selected_month = Date.new(2013, 1)
45
+ options = {:start_day => :tuesday}
46
+ result = subject.send(:build_range, selected_month, options)
47
+ result.class.should == Array
48
+ result.first.class.should == Date
49
+ result.last.class.should == Date
50
+ end
51
+ end
52
+
53
+ describe "#draw_calendar" do
54
+ it "should render a calendar table" do
55
+ #TODO: refactor draw_calendar to not require so much build up
56
+ subject.should_receive(:month_header)
57
+ selected_month = Date.new(2013, 1)
58
+ month = []
59
+ current_date = Date.new(2013, 1, 14)
60
+ events = {}
61
+ options = {:start_day => :monday}
62
+ block = Proc.new {}
63
+ subject.send(:draw_calendar, selected_month, month, current_date, events, options, block).should match(/^<table/)
64
+ end
65
+ end
66
+
67
+ describe "#day_events" do
68
+ it "should return an array of events for a given day" do
69
+ date = Date.new(2013, 1, 14)
70
+ matching_event = stub(:start_time => Date.new(2013, 1, 14))
71
+ other_event = stub(:start_time => Date.new(2013,1,15))
72
+ events = [matching_event, other_event]
73
+ subject.send(:day_events, date, events, "start_time").should == [matching_event]
74
+ end
75
+ end
76
+
77
+ describe "#month_header" do
78
+ it "should generate html including the month, next and previous month" do
79
+ subject.should_receive(:month_link).exactly(2)
80
+ selected_month = Date.new(2013, 1)
81
+ options = {}
82
+ #TODO: add coverage for actual output other than just the starting tag
83
+ subject.send(:month_header, selected_month, options).should match(/^<h2/)
84
+ end
85
+ end
86
+
87
+ describe "#month_link" do
88
+ it "should return a link" do
89
+ #TODO: test even needed?
90
+ subject.should_receive(:link_to)
91
+ subject.send(:month_link, "previous", Date.new(2013, 1), {})
92
+ end
93
+ end
94
+ end
@@ -0,0 +1,9 @@
1
+ module SimpleCalendar
2
+ class Rails
3
+ class Railtie
4
+ def self.initializer(object)
5
+ end
6
+ end
7
+ end
8
+ end
9
+
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simple_calendar
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.9
4
+ version: 0.1.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Oliver
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-06-05 00:00:00.000000000 Z
11
+ date: 2014-03-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -32,6 +32,7 @@ extensions: []
32
32
  extra_rdoc_files: []
33
33
  files:
34
34
  - .gitignore
35
+ - .rspec
35
36
  - Gemfile
36
37
  - README.md
37
38
  - Rakefile
@@ -40,6 +41,9 @@ files:
40
41
  - lib/simple_calendar/version.rb
41
42
  - lib/simple_calendar/view_helpers.rb
42
43
  - simple_calendar.gemspec
44
+ - spec/helper.rb
45
+ - spec/simple_calendar_spec.rb
46
+ - spec/support/railtie.rb
43
47
  homepage: https://github.com/excid3/simple_calendar
44
48
  licenses: []
45
49
  metadata: {}
@@ -59,8 +63,11 @@ required_rubygems_version: !ruby/object:Gem::Requirement
59
63
  version: '0'
60
64
  requirements: []
61
65
  rubyforge_project: simple_calendar
62
- rubygems_version: 2.0.3
66
+ rubygems_version: 2.1.11
63
67
  signing_key:
64
68
  specification_version: 4
65
69
  summary: A simple Rails 3 calendar
66
- test_files: []
70
+ test_files:
71
+ - spec/helper.rb
72
+ - spec/simple_calendar_spec.rb
73
+ - spec/support/railtie.rb