carendar 0.0.1

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 034b4206918c0cb0673a64b4266195068e4af17b
4
+ data.tar.gz: 891179c211001e0cce4c5217e1114e2727a01ae0
5
+ SHA512:
6
+ metadata.gz: 5bfe35f8fb3aec5c407a0dffbd9b1f45e01fcbdd7643847ddde2a72463e409026e889309c7ab8e6268a40321dbccd51e9c579c45278345885b2a041970bca88b
7
+ data.tar.gz: 8aa9429532a0543791b02d80ba1333e95fc6ddf0dbef908f690cb808e1eb059b2139e044093af195ef583318dec2334107ac890a7d3ecf0b6b4af0e6801f54a1
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in carendar.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 Axel Tetzlaff
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,52 @@
1
+ # Carendar
2
+
3
+ Pure CSS rendering for week calendars.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'carendar'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install carendar
20
+
21
+ ## Usage
22
+
23
+ Carendar::Calendar.new(first_day, last_day, array_of_item_hashes)
24
+
25
+ Example:
26
+
27
+ r = Random.new
28
+ week = DateTime.now.beginning_of_week
29
+ ungrouped_items = 40.times.map do |i|
30
+ day = r.rand(12).to_i
31
+ s_time = r.rand(265).to_i
32
+ e_time = r.rand([268 - s_time - 1, 60].min + 15).to_i + 1 + s_time
33
+ opts = {
34
+ title: Faker::Lorem.words(2).join(" ")
35
+ }
36
+ if s_time.even?
37
+ opts[:class] = 'important'
38
+ end
39
+ {starts_at: week + day.days + (5* s_time).minutes,
40
+ ends_at: week + day.days + (5*e_time).minutes,
41
+ options: opts }
42
+ end
43
+ @calendar = Carendar::Calendar.new(DateTime.now.beginning_of_week, DateTime.now.end_of_week + 1.week, ungrouped_items)
44
+
45
+
46
+ ## Contributing
47
+
48
+ 1. Fork it ( https://github.com/[my-github-username]/carendar/fork )
49
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
50
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
51
+ 4. Push to the branch (`git push origin my-new-feature`)
52
+ 5. Create a new Pull Request
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,41 @@
1
+ =unstyled-carender-list
2
+ padding: 0
3
+ margin: 0
4
+ list-style-type: none
5
+
6
+ =carendar($day-height: 500px, $min-per-slot: 5)
7
+ $min-per-day: 60 * 24
8
+ $slots-per-day: $min-per-day / $min-per-slot
9
+ $slot-height: $day-height / $slots-per-day
10
+ +unstyled-carender-list
11
+ width: 100%
12
+ &.week
13
+ display: flex
14
+ flex-direction: row
15
+ flex-wrap: wrap
16
+ .day
17
+ width: (100.0% / 7)
18
+ .items
19
+ +unstyled-carender-list
20
+ height: $day-height
21
+ position: relative
22
+ &:after
23
+ clear: both
24
+
25
+ .item
26
+ position: absolute
27
+
28
+ @for $i from 0 through $slots-per-day
29
+ &[data-start='#{$i*$min-per-slot}']
30
+ top: $i * $slot-height
31
+ &[data-duration='#{$i*$min-per-slot}']
32
+ height: $i*$slot-height
33
+
34
+ left: 0
35
+ right: 0
36
+ @for $i from 0 through 10
37
+ &[data-offset-left='#{$i}']
38
+ left: $i * 10%
39
+ &[data-offset-right='#{$i}']
40
+ right: $i * 10%
41
+
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'carendar/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "carendar"
8
+ spec.version = Carendar::VERSION
9
+ spec.authors = ["Axel Tetzlaff"]
10
+ spec.email = ["axel.tetzlaff@gmx.de"]
11
+ spec.summary = %q{Pure CSS week calendar rendering}
12
+ spec.description = %q{Provides a sass mixin and a rendering helper for simple display of calendar events.}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.6"
22
+ spec.add_development_dependency "rake", "~> 10.0"
23
+ end
@@ -0,0 +1,93 @@
1
+ require "carendar/version"
2
+
3
+ module Carendar
4
+ module Rails
5
+ class Engine < ::Rails::Engine
6
+ end
7
+ end
8
+
9
+ CalendarItem = Struct.new(:starts_at, :ends_at, :options) do
10
+ attr_accessor :overlapping_with_earlier, :overlapping_with_later, :offset_right, :offset_left
11
+ def day
12
+ starts_at.beginning_of_day
13
+ end
14
+
15
+ def duration
16
+ end_min - start_min
17
+ end
18
+
19
+ def start_min
20
+ starts_at.hour * 60 + starts_at.minute
21
+ end
22
+
23
+ def end_min
24
+ ends_at.hour * 60 + ends_at.minute
25
+ end
26
+
27
+ def color
28
+ '#' + (0..2).map do
29
+ VisitorsController.r.rand(255).to_i.to_s(16)
30
+ end.join('')
31
+ end
32
+ end
33
+
34
+ class CalendarDay
35
+ attr_reader :day, :items
36
+
37
+ def initialize(day, items)
38
+ @day = day
39
+ @items = items.map do |item|
40
+ CalendarItem.new(item[:starts_at], item[:ends_at], item[:options] || {})
41
+ end
42
+ @items.sort_by!(&:start_min)
43
+ @items.each do |item|
44
+ item.overlapping_with_earlier = @items.select do |other|
45
+ other.start_min < item.start_min && other.end_min > item.start_min
46
+ end
47
+ item.overlapping_with_later = []
48
+ item.offset_right = 0
49
+ end
50
+
51
+ @items.each do |item|
52
+ item.overlapping_with_earlier.each do |overlapper|
53
+ overlapper.overlapping_with_later << item
54
+ end
55
+ end
56
+
57
+ @items.each do |item|
58
+ item.offset_left = if item.overlapping_with_earlier.any?
59
+ item.overlapping_with_earlier.last.offset_left + 1
60
+ else
61
+ 0
62
+ end
63
+ end
64
+ @items.reverse.each do |item|
65
+ item.offset_right = if item.overlapping_with_later.present?
66
+ item.overlapping_with_later.first.offset_right + 1
67
+ else
68
+ 0
69
+ end
70
+ end
71
+
72
+ end
73
+
74
+ end
75
+
76
+ class Calendar
77
+ attr_reader :days
78
+ def initialize(from, to, item_hashes)
79
+ items_by_day = item_hashes.group_by do |item_hash|
80
+ item_hash[:starts_at].beginning_of_day
81
+ end
82
+
83
+ beginning_of_calendar = from.beginning_of_week
84
+ end_of_calendar = to.end_of_week
85
+ current_day = beginning_of_calendar
86
+ @days = []
87
+ while (current_day <= end_of_calendar) do
88
+ @days << CalendarDay.new(current_day, items_by_day[current_day] || [])
89
+ current_day += 1.day
90
+ end
91
+ end
92
+ end
93
+ end
@@ -0,0 +1,3 @@
1
+ module Carendar
2
+ VERSION = "0.0.1"
3
+ end
metadata ADDED
@@ -0,0 +1,82 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: carendar
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Axel Tetzlaff
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-03-21 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.6'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.6'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ description: Provides a sass mixin and a rendering helper for simple display of calendar
42
+ events.
43
+ email:
44
+ - axel.tetzlaff@gmx.de
45
+ executables: []
46
+ extensions: []
47
+ extra_rdoc_files: []
48
+ files:
49
+ - ".gitignore"
50
+ - Gemfile
51
+ - LICENSE.txt
52
+ - README.md
53
+ - Rakefile
54
+ - app/assets/stylesheets/_carendar.sass
55
+ - carendar.gemspec
56
+ - lib/carendar.rb
57
+ - lib/carendar/version.rb
58
+ homepage: ''
59
+ licenses:
60
+ - MIT
61
+ metadata: {}
62
+ post_install_message:
63
+ rdoc_options: []
64
+ require_paths:
65
+ - lib
66
+ required_ruby_version: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - ">="
69
+ - !ruby/object:Gem::Version
70
+ version: '0'
71
+ required_rubygems_version: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ requirements: []
77
+ rubyforge_project:
78
+ rubygems_version: 2.2.2
79
+ signing_key:
80
+ specification_version: 4
81
+ summary: Pure CSS week calendar rendering
82
+ test_files: []