ecm_calendar_helper 0.0.1.pre → 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: d7072cf0f66125e3ad61b5c519b2dfbf0bd74d78
4
+ data.tar.gz: ce2e67d2a179dac39d3ad1980caa12d74359327f
5
+ SHA512:
6
+ metadata.gz: 1ef68a0ffb744b761b6518577eb77fc2a9aaef9731cba7268a8c74da21fe4e3385221b447616a69c40bd345a1a03fe52c34ed4486a9aef90f3be308fbf333518
7
+ data.tar.gz: 09ba45e19ae6051bb92c9de273ebe4e0c9d4856a5c8db93eb4adaff2bf866c3d50853d5225d4d3feed401d246affa296d7e29b0b8bb7d181a2e878b88b32109e
@@ -0,0 +1,3 @@
1
+ /*
2
+ *= require_tree ./application
3
+ */
@@ -0,0 +1,31 @@
1
+ @media screen and (max-width: 991px) {
2
+ .calendar .calendar-weekday-name {
3
+ display: none;
4
+ }
5
+ }
6
+
7
+ .calendar-item {
8
+ border: 1px solid transparent;
9
+ border-radius: 4px;
10
+ display: block;
11
+ padding: 4px;
12
+ }
13
+
14
+ .calendar-item {
15
+ text-decoration: none
16
+ }
17
+
18
+ .calendar-item a, .calendar-item a:hover {
19
+ color: white;
20
+
21
+ }
22
+
23
+ .calendar-item a:hover {
24
+ text-decoration: none;
25
+ }
26
+
27
+ .calendar-item-default {
28
+ border-color: darkgrey;
29
+ background-color: grey;
30
+ color: white;
31
+ }
@@ -0,0 +1,17 @@
1
+ .flex-row {
2
+ display: flex;
3
+ flex-direction: row;
4
+ flex-wrap: wrap;
5
+ margin: 0 -5px;
6
+ }
7
+
8
+ .flex-row .column {
9
+ flex-basis: 100%;
10
+ padding: 0 5px;
11
+ }
12
+
13
+ @media screen and (min-width: 992px) {
14
+ .flex-row .column {
15
+ flex: 1;
16
+ }
17
+ }
@@ -0,0 +1,3 @@
1
+ .calendar-pagination {
2
+ margin-bottom: 20px;
3
+ }
@@ -0,0 +1,3 @@
1
+ /*
2
+ *= require ./ecm/calendar_helper/application
3
+ */
@@ -2,15 +2,17 @@ module Ecm
2
2
  module CalendarHelper
3
3
  # renders a calendar table
4
4
  def month_calendar(date = Time.zone.now.to_date, elements = [], options = {})
5
- # default options
6
5
  options.reverse_merge! :date_method => :start_at, :display_method => :to_s, :link_elements => true, :start_day => :sunday
6
+
7
+ display_method = options.delete(:display_method)
8
+ link_elements = options.delete(:link_elements)
7
9
 
8
10
  # calculate beginning and end of month
9
11
  beginning_of_month = date.beginning_of_month.to_date
10
12
  end_of_month = date.end_of_month.to_date
11
13
 
12
14
  # Get localized day names
13
- localized_day_names = I18n.t('date.day_names').dup
15
+ localized_day_names = I18n.t('date.abbr_day_names').dup
14
16
 
15
17
  # Shift day names to suite start day
16
18
  english_day_names = [:sunday, :monday, :tuesday, :wednesday, :thursday, :friday, :saturday]
@@ -20,75 +22,51 @@ module Ecm
20
22
 
21
23
  # Get the offset of start day
22
24
  offset = english_day_names.index(options[:start_day])
25
+ last_day_of_week = Time.zone.now.end_of_week.wday
23
26
 
24
27
 
25
28
  # Change calendar heading if offset is not 0 (offset 0 means sunday is the first day of the week)
26
29
  offset.times do
27
30
  localized_day_names.push(localized_day_names.shift)
28
31
  end
29
-
30
- content_tag(:table, :class => 'calendar') do
31
- table = ''
32
+
33
+ days_by_week = {}
34
+ days_in_week = {}
35
+ week = beginning_of_month.cweek
36
+ (beginning_of_month..end_of_month).each_with_index do |day, index|
37
+ days_in_week[day] = elements.find_all { |e| e.send(options[:date_method]).to_date == day.to_date } || {}
32
38
 
33
- table << content_tag(:tr, localized_day_names.collect { |day| content_tag(:th, day) }.join("").html_safe)
34
- table << content_tag(:tr) do
35
- table_content = ''
36
-
37
- (beginning_of_month..end_of_month).each do |d|
38
- if d == beginning_of_month
39
- column_offset = d.wday - offset
40
- column_offset += 7 if column_offset < 0
41
- column_offset.times do
42
- table_content << content_tag(:td, nil, :class => 'offset')
43
- end
44
- end
45
-
46
- if d.wday == (0 + offset)
47
- table_content << "</tr><tr>"
48
- end
49
-
50
- # Create content for day
51
- day_content = "#{d.day}<br/ >".html_safe
52
- elements_for_day = elements.find_all { |e| e.send(options[:date_method]).to_date == d.to_date }
53
- if options[:link_elements]
54
- elements_for_day.collect! { |e| content_tag(:div, link_to(e.send(options[:display_method]), e), :class => 'calendar_entry') }
55
- else
56
- elements_for_day.collect! { |e| content_tag(:div, e.send(options[:display_method]), :class => 'calendar_entry') }
57
- end
58
-
59
- day_content << elements_for_day.join("").html_safe
60
-
61
- # css classes for day td
62
- if d == Time.zone.now.to_date
63
- day_css_classes = 'calendar_day today'
64
- else
65
- day_css_classes = 'calendar_day'
66
- end
67
-
68
- table_content << content_tag(:td, day_content, :class => day_css_classes)
39
+ if day.wday == last_day_of_week
40
+ (7 - days_in_week.size).times do |i|
41
+ days_in_week[0 - i] = {}
42
+ end
43
+ week = (day + 1.day).cweek
44
+ end
45
+
46
+ if day.wday == last_day_of_week || index == end_of_month.day - 1
47
+ days_by_week[week] = days_in_week
48
+ days_in_week = {}
49
+ end
50
+
51
+ if index == end_of_month.day - 1
52
+ (7 - days_in_week.size).times do |i|
53
+ days_in_week[days_in_week.size - i] = {}
69
54
  end
70
-
71
- table_content.html_safe
72
55
  end
73
-
74
- table.html_safe
75
56
  end
57
+ render partial: 'ecm/calendar_helper/month_calendar', locals: { localized_day_names: localized_day_names, days_by_week: days_by_week, display_method: display_method, link_elements: link_elements }
76
58
  end
77
59
 
78
- def month_calendar_pagination(date)
79
- actual_month = Time.zone.now.beginning_of_month.to_date
80
-
60
+ def month_calendar_pagination(date, options = {})
61
+ options.reverse_merge!(show_today_link: true)
62
+
63
+ show_today_link = options.delete(:show_today_link)
64
+
65
+ actual_month = Time.zone.now.beginning_of_month.to_date
81
66
  previous_month = date.beginning_of_month.to_date - 1.month
82
- next_month = date.beginning_of_month.to_date + 1.months
83
-
84
- content_tag(:div, :class => 'calendar_pagination') do
85
- [
86
- link_to('Heute', url_for(:month => actual_month.month, :year => actual_month.year)),
87
- link_to("<", url_for(:month => previous_month.month, :year => previous_month.year)),
88
- link_to(">", url_for(:month => next_month.month, :year => next_month.year)),
89
- I18n.l(date, :format => :month_with_year),
90
- ].join(" | ").html_safe
91
- end
67
+ next_month = date.beginning_of_month.to_date + 1.months
68
+
69
+ render partial: 'ecm/calendar_helper/month_calendar_pagination', locals: { actual_month: actual_month, previous_month: previous_month, next_month: next_month, show_today_link: show_today_link, date: date }
92
70
  end
93
71
  end
94
72
  end
@@ -0,0 +1,29 @@
1
+ .calendar
2
+ .flex-row.calendar-weekday-names
3
+ - localized_day_names.each do |day|
4
+ .column.calendar-weekday-name
5
+ %h1= day
6
+ - days_by_week.each do |week, days|
7
+ .flex-row
8
+ - days_count = 0
9
+ - days.sort.each do |day, elements|
10
+ - days_count += 1
11
+ - if day < 1
12
+ .column
13
+ - else
14
+ - td_classes = ['calendar-day']
15
+ - td_classes << 'active today' if day == Time.zone.now.to_date
16
+ - td_classes << 'with-elements' if elements.any?
17
+ .column{ class: td_classes.join(" ") }
18
+ .calendar-day-container
19
+ %h1.calendar-day-title= day.day
20
+ %div.calendar-entries
21
+ - elements.each do |element|
22
+ %div.calendar-day-content
23
+ %span.calendar-item.calendar-item-default
24
+ - if link_elements
25
+ = link_to(element.send(display_method), element)
26
+ - else
27
+ = element.send(display_method)
28
+ - (7 - days_count).times do
29
+ .column
@@ -0,0 +1,11 @@
1
+ .calendar-pagination
2
+ - if show_today_link
3
+ = link_to(url_for(month: actual_month.month, year: actual_month.year), class: 'btn btn-default calendar-pagination-today') do
4
+ = t('.today')
5
+ .btn-group
6
+ = link_to(url_for(month: previous_month.month, year: previous_month.year), class: 'btn btn-primary calendar-pagination-back') do
7
+ = t('.previous')
8
+ = button_tag(type: 'button', class: 'btn btn-disabled calendar-pagination-actual') do
9
+ = I18n.l(date, format: :month_with_year)
10
+ = link_to(url_for(month: next_month.month, year: next_month.year), class: 'btn btn-primary calendar-pagination-next') do
11
+ = t('.next')
@@ -0,0 +1 @@
1
+ Rails.application.config.assets.precompile += %w(ecm_calendar_helper.css)
@@ -1,2 +1,6 @@
1
- ---
2
1
  de:
2
+ ecm:
3
+ courses:
4
+ course_category:
5
+ actions:
6
+ back_to_index: 'Zurück'
@@ -1,2 +1,6 @@
1
- ---
2
1
  en:
2
+ ecm:
3
+ courses:
4
+ course_category:
5
+ actions:
6
+ back_to_index: 'Back'
@@ -1,5 +1,5 @@
1
1
  module Ecm
2
2
  module CalendarHelper
3
- VERSION = "0.0.1.pre"
3
+ VERSION = "0.0.1"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,85 +1,89 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: ecm_calendar_helper
3
- version: !ruby/object:Gem::Version
4
- prerelease: 6
5
- version: 0.0.1.pre
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
6
5
  platform: ruby
7
- authors:
6
+ authors:
8
7
  - Roberto Vasquez Angel
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
-
13
- date: 2012-07-22 00:00:00 Z
14
- dependencies:
15
- - !ruby/object:Gem::Dependency
11
+ date: 2017-03-07 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
16
14
  name: rails
17
- prerelease: false
18
- requirement: &id001 !ruby/object:Gem::Requirement
19
- none: false
20
- requirements:
21
- - - ~>
22
- - !ruby/object:Gem::Version
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
23
19
  version: 3.2.6
24
20
  type: :runtime
25
- version_requirements: *id001
26
- - !ruby/object:Gem::Dependency
27
- name: sqlite3
28
21
  prerelease: false
29
- requirement: &id002 !ruby/object:Gem::Requirement
30
- none: false
31
- requirements:
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 3.2.6
27
+ - !ruby/object:Gem::Dependency
28
+ name: sqlite3
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
32
31
  - - ">="
33
- - !ruby/object:Gem::Version
34
- version: "0"
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
35
34
  type: :development
36
- version_requirements: *id002
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
37
41
  description: Rails calendar helper.
38
- email:
42
+ email:
39
43
  - roberto@vasquez-angel.de
40
44
  executables: []
41
-
42
45
  extensions: []
43
-
44
46
  extra_rdoc_files: []
45
-
46
- files:
47
+ files:
48
+ - MIT-LICENSE
49
+ - README.rdoc
50
+ - Rakefile
51
+ - app/assets/stylesheets/ecm/calendar_helper/application.css
52
+ - app/assets/stylesheets/ecm/calendar_helper/application/basic.css
53
+ - app/assets/stylesheets/ecm/calendar_helper/application/bootstrap-extensions.css
54
+ - app/assets/stylesheets/ecm/calendar_helper/application/calendar-pagination.css
55
+ - app/assets/stylesheets/ecm_calendar_helper.css
47
56
  - app/helpers/ecm/calendar_helper.rb
57
+ - app/views/ecm/calendar_helper/_month_calendar.haml
58
+ - app/views/ecm/calendar_helper/_month_calendar_pagination.haml
59
+ - config/initializers/assets.rb
48
60
  - config/locales/ecm.calendar_helper.de.yml
49
61
  - config/locales/ecm.calendar_helper.en.yml
50
- - lib/ecm_calendar_helper.rb
51
- - lib/tasks/ecm_calendar_helper_tasks.rake
52
62
  - lib/ecm/calendar_helper/engine.rb
53
63
  - lib/ecm/calendar_helper/version.rb
54
- - MIT-LICENSE
55
- - Rakefile
56
- - README.rdoc
64
+ - lib/ecm_calendar_helper.rb
65
+ - lib/tasks/ecm_calendar_helper_tasks.rake
57
66
  homepage: https://github.com/robotex82/ecm_calendar_helper.git
58
67
  licenses: []
59
-
68
+ metadata: {}
60
69
  post_install_message:
61
70
  rdoc_options: []
62
-
63
- require_paths:
71
+ require_paths:
64
72
  - lib
65
- required_ruby_version: !ruby/object:Gem::Requirement
66
- none: false
67
- requirements:
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:
68
80
  - - ">="
69
- - !ruby/object:Gem::Version
70
- version: "0"
71
- required_rubygems_version: !ruby/object:Gem::Requirement
72
- none: false
73
- requirements:
74
- - - ">"
75
- - !ruby/object:Gem::Version
76
- version: 1.3.1
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
77
83
  requirements: []
78
-
79
84
  rubyforge_project:
80
- rubygems_version: 1.8.24
85
+ rubygems_version: 2.4.8
81
86
  signing_key:
82
- specification_version: 3
87
+ specification_version: 4
83
88
  summary: Rails calendar helper.
84
89
  test_files: []
85
-