twitter-bootstrap-calendar 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +6 -0
- data/app/helpers/bootstrap_calendar_helper.rb +3 -50
- data/lib/twitter/bootstrap/calendar/bootstrap.rb +1 -0
- data/lib/twitter/bootstrap/calendar/bootstrap_calendar.rb +93 -0
- data/lib/twitter/bootstrap/calendar/version.rb +1 -1
- data/vendor/assets/javascripts/twitter-bootstrap-calendar/index.js +0 -4
- data/vendor/assets/stylesheets/twitter-bootstrap-calendar/index.css.scss +0 -14
- metadata +3 -3
data/README.md
CHANGED
@@ -57,6 +57,12 @@ But really you can do anything you want in there. There are no required models o
|
|
57
57
|
/ Do whatever you want here!
|
58
58
|
```
|
59
59
|
|
60
|
+
Now you can also send in options
|
61
|
+
```haml
|
62
|
+
= bootstrap_calendar month, start_day: :monday do |date|
|
63
|
+
/ Do whatever you want here!
|
64
|
+
```
|
65
|
+
|
60
66
|
Here's a sample app if you need to see this in action, thanks to Jeff Lunt.
|
61
67
|
https://github.com/normalocity/tbc-heroku
|
62
68
|
|
@@ -1,52 +1,5 @@
|
|
1
1
|
module BootstrapCalendarHelper
|
2
|
-
def bootstrap_calendar(date = Date.today, &block)
|
3
|
-
BootstrapCalendar.new(self, date, block).calendar_div
|
2
|
+
def bootstrap_calendar(date = Date.today, options={}, &block)
|
3
|
+
Twitter::Bootstrap::Calendar::BootstrapCalendar.new(self, date, options, block).calendar_div
|
4
4
|
end
|
5
|
-
|
6
|
-
BootstrapCalendar = Struct.new(:view, :date, :callback) do
|
7
|
-
HEADER = %w[Sunday Monday Tuesday Wednesday Thursday Friday Saturday]
|
8
|
-
START_DAY = :sunday
|
9
|
-
|
10
|
-
delegate :content_tag, to: :view
|
11
|
-
|
12
|
-
def calendar_div
|
13
|
-
content_tag 'div', class: "calendar_grid" do
|
14
|
-
header + week_rows
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
def header
|
19
|
-
content_tag 'div', class: 'month_header row-fluid' do
|
20
|
-
HEADER.map { |day| content_tag :div, class: 'span1' do
|
21
|
-
day
|
22
|
-
end }.join.html_safe
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
def week_rows
|
27
|
-
weeks.map {|week|
|
28
|
-
content_tag :div, class: 'row-fluid week' do
|
29
|
-
week.map { |day| day_cell(day) }.join.html_safe
|
30
|
-
end
|
31
|
-
}.join.html_safe
|
32
|
-
end
|
33
|
-
|
34
|
-
def day_cell(day)
|
35
|
-
content_tag :div, view.capture(day, &callback), class: day_classes(day)
|
36
|
-
end
|
37
|
-
|
38
|
-
def day_classes(day)
|
39
|
-
classes = ['span1']
|
40
|
-
classes << "today" if day == Date.today
|
41
|
-
classes << "notmonth" if day.month != date.month
|
42
|
-
classes << "month" if day.month == date.month
|
43
|
-
classes.empty? ? nil : classes.join(" ")
|
44
|
-
end
|
45
|
-
|
46
|
-
def weeks
|
47
|
-
first = date.beginning_of_month.beginning_of_week(START_DAY)
|
48
|
-
last = date.end_of_month.end_of_week(START_DAY)
|
49
|
-
(first..last).to_a.in_groups_of(7)
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|
5
|
+
end
|
@@ -0,0 +1,93 @@
|
|
1
|
+
require 'active_support/core_ext'
|
2
|
+
module Twitter
|
3
|
+
module Bootstrap
|
4
|
+
module Calendar
|
5
|
+
class BootstrapCalendar
|
6
|
+
DAY_NAMES = %w[Sunday Monday Tuesday Wednesday Thursday Friday Saturday]
|
7
|
+
MOBILE_DAY_NAMES = %w[Sun Mon Tues Wed Thur Fri Sat]
|
8
|
+
START_DAY = :sunday
|
9
|
+
|
10
|
+
attr_reader :view, :date, :callback, :options
|
11
|
+
|
12
|
+
def content_tag *args, &block
|
13
|
+
view.content_tag(*args, &block)
|
14
|
+
end
|
15
|
+
|
16
|
+
def initialize(view, date, options={}, callback)
|
17
|
+
@view = view
|
18
|
+
@date = date
|
19
|
+
@options = options.symbolize_keys
|
20
|
+
@callback = callback
|
21
|
+
end
|
22
|
+
|
23
|
+
def start_day
|
24
|
+
@start_day ||= (options[:start_day] && DAY_NAMES.include?(options[:start_day].to_s.humanize)) ? options[:start_day].to_s.downcase.to_sym : :sunday
|
25
|
+
end
|
26
|
+
|
27
|
+
|
28
|
+
def calendar_div
|
29
|
+
content_tag 'div', class: "calendar_grid" do
|
30
|
+
header + week_rows
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def start_day_index
|
35
|
+
@start_day_index ||= DAY_NAMES.index {|n| n.downcase == start_day.to_s} || 0
|
36
|
+
end
|
37
|
+
|
38
|
+
def day_names
|
39
|
+
return DAY_NAMES if start_day_index.zero?
|
40
|
+
DAY_NAMES[start_day_index, DAY_NAMES.size - start_day_index] + DAY_NAMES[0, start_day_index]
|
41
|
+
end
|
42
|
+
|
43
|
+
def mobile_day_names
|
44
|
+
return MOBILE_DAY_NAMES if start_day_index.zero?
|
45
|
+
MOBILE_DAY_NAMES[start_day_index, MOBILE_DAY_NAMES.size - start_day_index] + MOBILE_DAY_NAMES[0, start_day_index]
|
46
|
+
end
|
47
|
+
|
48
|
+
def header
|
49
|
+
content_tag 'div', class: 'month_header row-fluid' do
|
50
|
+
standard = day_names.map { |day|
|
51
|
+
content_tag :div, class: 'span1 visible-desktop' do
|
52
|
+
day
|
53
|
+
end
|
54
|
+
}.join.html_safe
|
55
|
+
mobile = mobile_day_names.map { |day|
|
56
|
+
content_tag :div, class: 'span1 hidden-desktop', style: 'width: 14.1%' do
|
57
|
+
day
|
58
|
+
end
|
59
|
+
}.join.html_safe
|
60
|
+
|
61
|
+
standard + mobile
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
def week_rows
|
66
|
+
weeks.map {|week|
|
67
|
+
content_tag :div, class: 'row-fluid week' do
|
68
|
+
week.map { |day| day_cell(day) }.join.html_safe
|
69
|
+
end
|
70
|
+
}.join.html_safe
|
71
|
+
end
|
72
|
+
|
73
|
+
def day_cell(day)
|
74
|
+
content_tag :div, view.capture(day, &callback), class: day_classes(day)
|
75
|
+
end
|
76
|
+
|
77
|
+
def day_classes(day)
|
78
|
+
classes = ['span1']
|
79
|
+
classes << "today" if day == Date.today
|
80
|
+
classes << "notmonth" if day.month != date.month
|
81
|
+
classes << "month" if day.month == date.month
|
82
|
+
classes.empty? ? nil : classes.join(" ")
|
83
|
+
end
|
84
|
+
|
85
|
+
def weeks
|
86
|
+
first = date.beginning_of_month.beginning_of_week(start_day)
|
87
|
+
last = date.end_of_month.end_of_week(start_day)
|
88
|
+
(first..last).to_a.in_groups_of(7)
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
@@ -17,25 +17,11 @@
|
|
17
17
|
background-color: #D7F2FF;
|
18
18
|
}
|
19
19
|
.month {
|
20
|
-
a {
|
21
|
-
color: gray;
|
22
|
-
}
|
23
20
|
background-color: #ededed;
|
24
21
|
border: 1px solid whitesmoke;
|
25
22
|
}
|
26
23
|
.week .span1 {
|
27
24
|
padding: 2px;
|
28
|
-
// height: 100px;
|
29
|
-
ul.event_summary {
|
30
|
-
margin: 0;
|
31
|
-
li {
|
32
|
-
list-style: none;
|
33
|
-
padding: 2px;
|
34
|
-
-moz-border-radius:4px;
|
35
|
-
-webkit-border-radius:4px;
|
36
|
-
border-radius:4px;
|
37
|
-
}
|
38
|
-
}
|
39
25
|
}
|
40
26
|
/*!
|
41
27
|
* Bootstrap v2.2.1
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: twitter-bootstrap-calendar
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-05-08 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: sass
|
@@ -83,6 +83,7 @@ extensions: []
|
|
83
83
|
extra_rdoc_files: []
|
84
84
|
files:
|
85
85
|
- lib/twitter/bootstrap/calendar/bootstrap.rb
|
86
|
+
- lib/twitter/bootstrap/calendar/bootstrap_calendar.rb
|
86
87
|
- lib/twitter/bootstrap/calendar/engine.rb
|
87
88
|
- lib/twitter/bootstrap/calendar/version.rb
|
88
89
|
- lib/twitter-bootstrap-calendar.rb
|
@@ -120,4 +121,3 @@ summary: Bootstrap based responsive calendar
|
|
120
121
|
test_files:
|
121
122
|
- test/bootstrap_calendar_helper_test.rb
|
122
123
|
- test/test_helper.rb
|
123
|
-
has_rdoc:
|