carender 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/MIT-LICENSE +20 -0
- data/README.md +43 -0
- data/Rakefile +27 -0
- data/lib/carender.rb +5 -0
- data/lib/carender/calendar.rb +57 -0
- data/lib/carender/collection.rb +25 -0
- data/lib/carender/core.rb +17 -0
- data/lib/carender/helper.rb +8 -0
- data/lib/carender/railtie.rb +7 -0
- data/lib/carender/version.rb +3 -0
- data/lib/tasks/carender_tasks.rake +4 -0
- metadata +83 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 88e0c15f59567a53434dd82e22782af60a5a39f49fc3bf83a972dfb05e954b69
|
4
|
+
data.tar.gz: efbe7f96ea6f269c3f5675337b002889496919f44a5c2ecdf7fcc6f91e3b81eb
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 47d6ca78188311e16aed2bfbf22435403f6f8e2db8180c0bafe8e341603717e7eef957627f92e870653c56ce17fdefcf97bea57de2c3efcd8f6d30b31db888b1
|
7
|
+
data.tar.gz: af6874f2e6600f1ecc3ed6295cd9718f270dd53c00dd5ddfe0e237056ef0c0c4f01afe97564287df86252d0b7d3c940a9e7c832ceaa9f2267aa4521936eed3b8
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2018 kami-zh
|
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,43 @@
|
|
1
|
+
# Carender
|
2
|
+
|
3
|
+
[WIP] A simple calendar gem for Rails application.
|
4
|
+
|
5
|
+
## Synopsis
|
6
|
+
|
7
|
+
This library automatically renders the calendar by reading `params[:year]` and `params[:month]`.
|
8
|
+
|
9
|
+
A simple calendar:
|
10
|
+
|
11
|
+
```erb
|
12
|
+
<%= carender do |date| %>
|
13
|
+
<%= date.day %>
|
14
|
+
<% end %>
|
15
|
+
```
|
16
|
+
|
17
|
+
With a collection which is grouped by specified column:
|
18
|
+
|
19
|
+
```erb
|
20
|
+
<%= carender collection: @posts, column: :posted_on do |date, posts| %>
|
21
|
+
<% posts.each do |post| %>
|
22
|
+
<%= link_to post.title, post %>
|
23
|
+
<% end %>
|
24
|
+
<% end %>
|
25
|
+
```
|
26
|
+
|
27
|
+
## Installation
|
28
|
+
|
29
|
+
Add this line to your application's Gemfile:
|
30
|
+
|
31
|
+
```ruby
|
32
|
+
gem 'carender'
|
33
|
+
```
|
34
|
+
|
35
|
+
And then execute:
|
36
|
+
|
37
|
+
```bash
|
38
|
+
$ bundle
|
39
|
+
```
|
40
|
+
|
41
|
+
## License
|
42
|
+
|
43
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
@@ -0,0 +1,27 @@
|
|
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
|
+
|
9
|
+
RDoc::Task.new(:rdoc) do |rdoc|
|
10
|
+
rdoc.rdoc_dir = 'rdoc'
|
11
|
+
rdoc.title = 'Carender'
|
12
|
+
rdoc.options << '--line-numbers'
|
13
|
+
rdoc.rdoc_files.include('README.md')
|
14
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
15
|
+
end
|
16
|
+
|
17
|
+
require 'bundler/gem_tasks'
|
18
|
+
|
19
|
+
require 'rake/testtask'
|
20
|
+
|
21
|
+
Rake::TestTask.new(:test) do |t|
|
22
|
+
t.libs << 'test'
|
23
|
+
t.pattern = 'test/**/*_test.rb'
|
24
|
+
t.verbose = false
|
25
|
+
end
|
26
|
+
|
27
|
+
task default: :test
|
data/lib/carender.rb
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
module Carender
|
2
|
+
class Calendar
|
3
|
+
def initialize(year, month, collection)
|
4
|
+
@year = year
|
5
|
+
@month = month
|
6
|
+
@collection = collection
|
7
|
+
end
|
8
|
+
|
9
|
+
def render(view_context, &block)
|
10
|
+
html = <<-EOS
|
11
|
+
<table>
|
12
|
+
<tr>
|
13
|
+
<th>Sun</th>
|
14
|
+
<th>Mon</th>
|
15
|
+
<th>Tue</th>
|
16
|
+
<th>Wed</th>
|
17
|
+
<th>Thu</th>
|
18
|
+
<th>Fri</th>
|
19
|
+
<th>Sat</th>
|
20
|
+
</tr>
|
21
|
+
EOS
|
22
|
+
|
23
|
+
(date..date.end_of_month).each do |d|
|
24
|
+
if d.wday == 0
|
25
|
+
html += '<tr>'
|
26
|
+
end
|
27
|
+
|
28
|
+
if d == date
|
29
|
+
d.wday.times { html += '<td></td>' }
|
30
|
+
end
|
31
|
+
|
32
|
+
html += '<td>'
|
33
|
+
html += view_context.capture { block.call(d, collection[d] || []) }
|
34
|
+
html += '</td>'
|
35
|
+
|
36
|
+
if d == date.end_of_month
|
37
|
+
(6 - d.wday).times { html += '<td></td>' }
|
38
|
+
end
|
39
|
+
|
40
|
+
if d.wday == 6
|
41
|
+
html += '</tr>'
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
html += '</table>'
|
46
|
+
html
|
47
|
+
end
|
48
|
+
|
49
|
+
private
|
50
|
+
|
51
|
+
attr_reader :year, :month, :collection
|
52
|
+
|
53
|
+
def date
|
54
|
+
@date ||= Date.new(year, month)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module Carender
|
2
|
+
class Collection
|
3
|
+
def initialize(collection, column)
|
4
|
+
@collection = collection || []
|
5
|
+
@column = column
|
6
|
+
@grouped = {}
|
7
|
+
end
|
8
|
+
|
9
|
+
def grouped
|
10
|
+
return @grouped unless @grouped.empty?
|
11
|
+
|
12
|
+
collection.each do |c|
|
13
|
+
date = c.send(column).to_date
|
14
|
+
@grouped[date] = [] unless @grouped[date]
|
15
|
+
@grouped[date] << c
|
16
|
+
end
|
17
|
+
|
18
|
+
@grouped
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
attr_reader :collection, :column
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Carender
|
2
|
+
class Core
|
3
|
+
def initialize(view_context, options)
|
4
|
+
@view_context = view_context
|
5
|
+
@collection = Carender::Collection.new(*options.values_at(:collection, :column)).grouped
|
6
|
+
end
|
7
|
+
|
8
|
+
def render(&block)
|
9
|
+
calendar = Carender::Calendar.new(*view_context.params.values_at(:year, :month).map(&:to_i), collection)
|
10
|
+
calendar.render(view_context, &block).html_safe
|
11
|
+
end
|
12
|
+
|
13
|
+
private
|
14
|
+
|
15
|
+
attr_reader :view_context, :collection
|
16
|
+
end
|
17
|
+
end
|
metadata
ADDED
@@ -0,0 +1,83 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: carender
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- kami-zh
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-01-17 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rails
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 5.2.0.beta2
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 5.2.0.beta2
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: sqlite3
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
description: A simple calendar gem for Rails application.
|
42
|
+
email:
|
43
|
+
- hiroki.zenigami@gmail.com
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- MIT-LICENSE
|
49
|
+
- README.md
|
50
|
+
- Rakefile
|
51
|
+
- lib/carender.rb
|
52
|
+
- lib/carender/calendar.rb
|
53
|
+
- lib/carender/collection.rb
|
54
|
+
- lib/carender/core.rb
|
55
|
+
- lib/carender/helper.rb
|
56
|
+
- lib/carender/railtie.rb
|
57
|
+
- lib/carender/version.rb
|
58
|
+
- lib/tasks/carender_tasks.rake
|
59
|
+
homepage: https://github.com/kami-zh/carender
|
60
|
+
licenses:
|
61
|
+
- MIT
|
62
|
+
metadata: {}
|
63
|
+
post_install_message:
|
64
|
+
rdoc_options: []
|
65
|
+
require_paths:
|
66
|
+
- lib
|
67
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
68
|
+
requirements:
|
69
|
+
- - ">="
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
version: '0'
|
72
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
73
|
+
requirements:
|
74
|
+
- - ">="
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '0'
|
77
|
+
requirements: []
|
78
|
+
rubyforge_project:
|
79
|
+
rubygems_version: 2.7.3
|
80
|
+
signing_key:
|
81
|
+
specification_version: 4
|
82
|
+
summary: A simple calendar gem for Rails application.
|
83
|
+
test_files: []
|