html_calendar 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CONTRIBUTING.md +11 -0
- data/MIT-LICENSE +20 -0
- data/README.md +74 -0
- data/Rakefile +13 -0
- data/app/helpers/html_calendar_helper.rb +5 -0
- data/app/views/html_calendar/calendar/_calendar.html.erb +14 -0
- data/app/views/html_calendar/calendar/_day.html.erb +3 -0
- data/app/views/html_calendar/calendar/_header.html.erb +14 -0
- data/app/views/html_calendar/calendar/_other_month_day.html.erb +3 -0
- data/lib/html_calendar.rb +7 -0
- data/lib/html_calendar/calendar.rb +62 -0
- data/lib/html_calendar/date_presenter.rb +12 -0
- data/lib/html_calendar/engine.rb +9 -0
- data/lib/html_calendar/month.rb +20 -0
- data/lib/html_calendar/version.rb +3 -0
- metadata +89 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: fbc1ec30f44e2c6a8cd4022e592742c661d4a66b
|
4
|
+
data.tar.gz: f498ca9d1a674e979fed818c5832a40deb48f0bb
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 1a2ee5248957f00e6e70362e35de851dcd6cd86cb06bfa7d68627ccfa1c4c24b7a13104ca3e68eac784a5927cf8c9ae66d4497c5970a5b357530523265fc10f4
|
7
|
+
data.tar.gz: 7dcf51896b41546066918af2b031a98d12a8782144eba101d1e5f53ac58a1dd9f1cfa572c3ecf9fa4df88a2dbabb7cec06b501950e3f46baff47e662a00f48cb
|
data/CONTRIBUTING.md
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
# Contributing
|
2
|
+
|
3
|
+
Pull requests are empirically awesome, and are most welcome.
|
4
|
+
|
5
|
+
1. [Fork the project](https://help.github.com/articles/fork-a-repo).
|
6
|
+
2. Create a branch - `git checkout -b adding_magic`
|
7
|
+
3. Make your changes, and add some tests!
|
8
|
+
4. Check that the tests pass - `bundle exec rake`
|
9
|
+
5. Commit your changes - `git commit -am "Added some magic"`
|
10
|
+
6. Push the branch to Github - `git push origin adding_magic`
|
11
|
+
7. Send us a [pull request](https://help.github.com/articles/using-pull-requests)!
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2014 Carnes Media
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# HtmlCalendar
|
2
|
+
|
3
|
+
HtmlCalendar is an extremely lightweight/extensible gem for creating HTML
|
4
|
+
calendars in Rails (>= 3.1).
|
5
|
+
|
6
|
+
Want to overwrite the built-in views? No problem. Want clean markup? It'll give
|
7
|
+
you clean markup. Want a full-featured Google Calendar clone? It'll give you
|
8
|
+
clean markup.
|
9
|
+
|
10
|
+
## Installation
|
11
|
+
|
12
|
+
1. Add `gem "html_calendar"` to your `Gemfile`
|
13
|
+
2. `bundle`
|
14
|
+
|
15
|
+
## Creating calendars
|
16
|
+
|
17
|
+
The `html_calendar` helper makes it easy to create a calendar for any date:
|
18
|
+
|
19
|
+
```erb
|
20
|
+
<!-- a calendar for the current month -->
|
21
|
+
<%= html_calendar %>
|
22
|
+
|
23
|
+
<!-- a calender for 3 months in the future -->
|
24
|
+
<%= html_calendar Date.current + 3.months %>
|
25
|
+
```
|
26
|
+
|
27
|
+
If you need customized date logic, you can also pass `html_calendar` a presenter:
|
28
|
+
|
29
|
+
```erb
|
30
|
+
<%= html_calendar Date.current, presenter: MyCustomDatePresenter %>
|
31
|
+
```
|
32
|
+
|
33
|
+
Your presenter class needs to inherit from `HTMLCalendar::DatePresenter`, and
|
34
|
+
should implement the `html_classes` method.
|
35
|
+
|
36
|
+
```ruby
|
37
|
+
class MyCustomDatePresenter < HTMLCalendar::DatePresenter
|
38
|
+
# Available methods: `html_classes`, `date` and `template`
|
39
|
+
|
40
|
+
def html_classes
|
41
|
+
if monday?
|
42
|
+
['a-case-of-the-mundays']
|
43
|
+
else
|
44
|
+
super
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
private
|
49
|
+
|
50
|
+
def monday?
|
51
|
+
date.wday == 1
|
52
|
+
end
|
53
|
+
end
|
54
|
+
```
|
55
|
+
|
56
|
+
|
57
|
+
## Overwriting views
|
58
|
+
|
59
|
+
You can overwrite any of the [view partials](https://github.com/carnesmedia/html_calendar/tree/master/app/views/html_calendar/calendar) by creating a directory at `app/views/html_calendar/calendar` and adding replacement files:
|
60
|
+
|
61
|
+
| Name | Description |
|
62
|
+
| ------------- |------------- |
|
63
|
+
| `_calendar.html.erb` | Main calendar loop |
|
64
|
+
| `_day.html.erb` | Single day cell (in current month) |
|
65
|
+
| `_header.html.erb` | Table header (including day names) |
|
66
|
+
| `_other_month_day.html.erb` | Single day cell for days displayed but not in current month |
|
67
|
+
|
68
|
+
|
69
|
+
## Future Plans
|
70
|
+
|
71
|
+
* I18n support
|
72
|
+
* Better test coverage
|
73
|
+
* Basic stylesheet (opt-in)
|
74
|
+
* Ability to overwrite partial path
|
data/Rakefile
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
begin
|
2
|
+
require 'bundler/setup'
|
3
|
+
rescue LoadError
|
4
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
5
|
+
end
|
6
|
+
|
7
|
+
require 'rdoc/task'
|
8
|
+
require 'rspec/core/rake_task'
|
9
|
+
|
10
|
+
Bundler::GemHelper.install_tasks
|
11
|
+
RSpec::Core::RakeTask.new(:spec)
|
12
|
+
|
13
|
+
task :default => :spec
|
@@ -0,0 +1,14 @@
|
|
1
|
+
<table class="calendar">
|
2
|
+
<thead>
|
3
|
+
<%= calendar.render_header %>
|
4
|
+
</thead>
|
5
|
+
<tbody>
|
6
|
+
<% calendar.renderable_date_range_in_weeks.each do |week_days| %>
|
7
|
+
<tr>
|
8
|
+
<% week_days.each do |date| %>
|
9
|
+
<%= calendar.render_date date %>
|
10
|
+
<% end %>
|
11
|
+
</tr>
|
12
|
+
<% end %>
|
13
|
+
</tbody>
|
14
|
+
</table>
|
@@ -0,0 +1,62 @@
|
|
1
|
+
module HTMLCalendar
|
2
|
+
class Calendar
|
3
|
+
attr_reader :template, :month, :options
|
4
|
+
|
5
|
+
def initialize(template, month, options = {})
|
6
|
+
@template = template
|
7
|
+
@month = Month.new(month)
|
8
|
+
@options = options
|
9
|
+
end
|
10
|
+
|
11
|
+
delegate :date_range,
|
12
|
+
to: :month
|
13
|
+
|
14
|
+
def to_s
|
15
|
+
render 'calendar', calendar: self
|
16
|
+
end
|
17
|
+
|
18
|
+
def renderable_date_range
|
19
|
+
beginning_of_month.at_beginning_of_week(:sunday)..end_of_month.at_end_of_week(:sunday)
|
20
|
+
end
|
21
|
+
|
22
|
+
def renderable_date_range_in_weeks
|
23
|
+
renderable_date_range.to_a.in_groups_of(7)
|
24
|
+
end
|
25
|
+
|
26
|
+
def render_header
|
27
|
+
render 'header', month: month
|
28
|
+
end
|
29
|
+
|
30
|
+
def render_date(date)
|
31
|
+
partial_name = in_month?(date) ? 'day' : 'other_month_day'
|
32
|
+
render partial_name, date: date, presenter: date_presenter_for(date)
|
33
|
+
end
|
34
|
+
|
35
|
+
def in_month?(date)
|
36
|
+
date_range.include? date
|
37
|
+
end
|
38
|
+
|
39
|
+
def prefix
|
40
|
+
self.class.name.underscore
|
41
|
+
end
|
42
|
+
|
43
|
+
private
|
44
|
+
|
45
|
+
def date_presenter_for(date)
|
46
|
+
options.fetch(:presenter, DatePresenter).new(template, date)
|
47
|
+
end
|
48
|
+
|
49
|
+
def render(partial, locals)
|
50
|
+
partial_path = [prefix, partial].join('/')
|
51
|
+
template.render partial: partial_path, locals: locals.merge(calendar: self)
|
52
|
+
end
|
53
|
+
|
54
|
+
def beginning_of_month
|
55
|
+
month.at_beginning_of_month
|
56
|
+
end
|
57
|
+
|
58
|
+
def end_of_month
|
59
|
+
month.at_end_of_month
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module HTMLCalendar
|
2
|
+
class Month
|
3
|
+
|
4
|
+
def initialize(date)
|
5
|
+
@date = date.at_beginning_of_month.to_date
|
6
|
+
end
|
7
|
+
|
8
|
+
def date_range
|
9
|
+
at_beginning_of_month..at_end_of_month
|
10
|
+
end
|
11
|
+
|
12
|
+
delegate :to_date, :at_beginning_of_month, :at_end_of_month,
|
13
|
+
to: :date
|
14
|
+
|
15
|
+
private
|
16
|
+
# Date stores the first of the month
|
17
|
+
attr_reader :date
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
metadata
ADDED
@@ -0,0 +1,89 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: html_calendar
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Amiel Martin
|
8
|
+
- Nathan Carnes
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2014-03-01 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rails
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - ">="
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: '3.1'
|
21
|
+
type: :runtime
|
22
|
+
prerelease: false
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - ">="
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: '3.1'
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: sqlite3
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - ">="
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '0'
|
35
|
+
type: :development
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - ">="
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '0'
|
42
|
+
description: HtmlCalendar is an extremely lightweight/extensible gem for creating
|
43
|
+
HTML calendars in Rails (>= 3.1).
|
44
|
+
email:
|
45
|
+
- amiel@carnesmedia.com
|
46
|
+
- nathan@carnesmedia.com
|
47
|
+
executables: []
|
48
|
+
extensions: []
|
49
|
+
extra_rdoc_files: []
|
50
|
+
files:
|
51
|
+
- CONTRIBUTING.md
|
52
|
+
- MIT-LICENSE
|
53
|
+
- README.md
|
54
|
+
- Rakefile
|
55
|
+
- app/helpers/html_calendar_helper.rb
|
56
|
+
- app/views/html_calendar/calendar/_calendar.html.erb
|
57
|
+
- app/views/html_calendar/calendar/_day.html.erb
|
58
|
+
- app/views/html_calendar/calendar/_header.html.erb
|
59
|
+
- app/views/html_calendar/calendar/_other_month_day.html.erb
|
60
|
+
- lib/html_calendar.rb
|
61
|
+
- lib/html_calendar/calendar.rb
|
62
|
+
- lib/html_calendar/date_presenter.rb
|
63
|
+
- lib/html_calendar/engine.rb
|
64
|
+
- lib/html_calendar/month.rb
|
65
|
+
- lib/html_calendar/version.rb
|
66
|
+
homepage: https://github.com/carnesmedia/html_calendar
|
67
|
+
licenses: []
|
68
|
+
metadata: {}
|
69
|
+
post_install_message:
|
70
|
+
rdoc_options: []
|
71
|
+
require_paths:
|
72
|
+
- lib
|
73
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
74
|
+
requirements:
|
75
|
+
- - ">="
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
requirements: []
|
84
|
+
rubyforge_project:
|
85
|
+
rubygems_version: 2.2.0
|
86
|
+
signing_key:
|
87
|
+
specification_version: 4
|
88
|
+
summary: A lightweight gem for creating HTML calendars in Rails.
|
89
|
+
test_files: []
|