ecm_calendar_helper 0.0.1.pre
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.
- data/MIT-LICENSE +20 -0
- data/README.rdoc +3 -0
- data/Rakefile +27 -0
- data/app/helpers/ecm/calendar_helper.rb +94 -0
- data/config/locales/ecm.calendar_helper.de.yml +2 -0
- data/config/locales/ecm.calendar_helper.en.yml +2 -0
- data/lib/ecm/calendar_helper/engine.rb +6 -0
- data/lib/ecm/calendar_helper/version.rb +5 -0
- data/lib/ecm_calendar_helper.rb +1 -0
- data/lib/tasks/ecm_calendar_helper_tasks.rake +4 -0
- metadata +85 -0
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2012 YOURNAME
|
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.rdoc
ADDED
data/Rakefile
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
#!/usr/bin/env rake
|
2
|
+
begin
|
3
|
+
require 'bundler/setup'
|
4
|
+
rescue LoadError
|
5
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
6
|
+
end
|
7
|
+
begin
|
8
|
+
require 'rdoc/task'
|
9
|
+
rescue LoadError
|
10
|
+
require 'rdoc/rdoc'
|
11
|
+
require 'rake/rdoctask'
|
12
|
+
RDoc::Task = Rake::RDocTask
|
13
|
+
end
|
14
|
+
|
15
|
+
RDoc::Task.new(:rdoc) do |rdoc|
|
16
|
+
rdoc.rdoc_dir = 'rdoc'
|
17
|
+
rdoc.title = 'EcmCalendarHelper'
|
18
|
+
rdoc.options << '--line-numbers'
|
19
|
+
rdoc.rdoc_files.include('README.rdoc')
|
20
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
21
|
+
end
|
22
|
+
|
23
|
+
|
24
|
+
|
25
|
+
|
26
|
+
Bundler::GemHelper.install_tasks
|
27
|
+
|
@@ -0,0 +1,94 @@
|
|
1
|
+
module Ecm
|
2
|
+
module CalendarHelper
|
3
|
+
# renders a calendar table
|
4
|
+
def month_calendar(date = Time.zone.now.to_date, elements = [], options = {})
|
5
|
+
# default options
|
6
|
+
options.reverse_merge! :date_method => :start_at, :display_method => :to_s, :link_elements => true, :start_day => :sunday
|
7
|
+
|
8
|
+
# calculate beginning and end of month
|
9
|
+
beginning_of_month = date.beginning_of_month.to_date
|
10
|
+
end_of_month = date.end_of_month.to_date
|
11
|
+
|
12
|
+
# Get localized day names
|
13
|
+
localized_day_names = I18n.t('date.day_names').dup
|
14
|
+
|
15
|
+
# Shift day names to suite start day
|
16
|
+
english_day_names = [:sunday, :monday, :tuesday, :wednesday, :thursday, :friday, :saturday]
|
17
|
+
|
18
|
+
# Raise an exception if the passed start day is not an english day name
|
19
|
+
raise ":start_day option for month_calendar must be in: #{english_day_names.join(', ')}, but you passed: #{options[:start_day].to_s} (class: #{options[:start_day].class.to_s})" unless english_day_names.include?(options[:start_day])
|
20
|
+
|
21
|
+
# Get the offset of start day
|
22
|
+
offset = english_day_names.index(options[:start_day])
|
23
|
+
|
24
|
+
|
25
|
+
# Change calendar heading if offset is not 0 (offset 0 means sunday is the first day of the week)
|
26
|
+
offset.times do
|
27
|
+
localized_day_names.push(localized_day_names.shift)
|
28
|
+
end
|
29
|
+
|
30
|
+
content_tag(:table, :class => 'calendar') do
|
31
|
+
table = ''
|
32
|
+
|
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)
|
69
|
+
end
|
70
|
+
|
71
|
+
table_content.html_safe
|
72
|
+
end
|
73
|
+
|
74
|
+
table.html_safe
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
def month_calendar_pagination(date)
|
79
|
+
actual_month = Time.zone.now.beginning_of_month.to_date
|
80
|
+
|
81
|
+
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
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'ecm/calendar_helper/engine'
|
metadata
ADDED
@@ -0,0 +1,85 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ecm_calendar_helper
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: 6
|
5
|
+
version: 0.0.1.pre
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Roberto Vasquez Angel
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
|
13
|
+
date: 2012-07-22 00:00:00 Z
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: rails
|
17
|
+
prerelease: false
|
18
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
19
|
+
none: false
|
20
|
+
requirements:
|
21
|
+
- - ~>
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 3.2.6
|
24
|
+
type: :runtime
|
25
|
+
version_requirements: *id001
|
26
|
+
- !ruby/object:Gem::Dependency
|
27
|
+
name: sqlite3
|
28
|
+
prerelease: false
|
29
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
30
|
+
none: false
|
31
|
+
requirements:
|
32
|
+
- - ">="
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: "0"
|
35
|
+
type: :development
|
36
|
+
version_requirements: *id002
|
37
|
+
description: Rails calendar helper.
|
38
|
+
email:
|
39
|
+
- roberto@vasquez-angel.de
|
40
|
+
executables: []
|
41
|
+
|
42
|
+
extensions: []
|
43
|
+
|
44
|
+
extra_rdoc_files: []
|
45
|
+
|
46
|
+
files:
|
47
|
+
- app/helpers/ecm/calendar_helper.rb
|
48
|
+
- config/locales/ecm.calendar_helper.de.yml
|
49
|
+
- config/locales/ecm.calendar_helper.en.yml
|
50
|
+
- lib/ecm_calendar_helper.rb
|
51
|
+
- lib/tasks/ecm_calendar_helper_tasks.rake
|
52
|
+
- lib/ecm/calendar_helper/engine.rb
|
53
|
+
- lib/ecm/calendar_helper/version.rb
|
54
|
+
- MIT-LICENSE
|
55
|
+
- Rakefile
|
56
|
+
- README.rdoc
|
57
|
+
homepage: https://github.com/robotex82/ecm_calendar_helper.git
|
58
|
+
licenses: []
|
59
|
+
|
60
|
+
post_install_message:
|
61
|
+
rdoc_options: []
|
62
|
+
|
63
|
+
require_paths:
|
64
|
+
- lib
|
65
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
66
|
+
none: false
|
67
|
+
requirements:
|
68
|
+
- - ">="
|
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
|
77
|
+
requirements: []
|
78
|
+
|
79
|
+
rubyforge_project:
|
80
|
+
rubygems_version: 1.8.24
|
81
|
+
signing_key:
|
82
|
+
specification_version: 3
|
83
|
+
summary: Rails calendar helper.
|
84
|
+
test_files: []
|
85
|
+
|