jpcalendar 0.0.1 → 1.0.0

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: 68bf30b1d48aef42c55dcc3619525727f1604acb
4
+ data.tar.gz: 45790eedac9b6174d6b6f5ac039d1ce3bef95648
5
+ SHA512:
6
+ metadata.gz: f34f792b91ebd0ee9ee8c6e4c53a8f5807db3d9d3d571fdd829e99afcc4e2c4d6d269ed2cf895e2e28ac6f02d18d409f71674eae67ff5878ab348807ad9659a6
7
+ data.tar.gz: 0a8093ba67346c86bc4aa74016e7784dea6f3c13c42c48c41ce0c3bd472b6b99ea03ce31c758c6a8fd5b8665987b137c87721c5412b01f954a496392d0726bfb
data/.DS_Store ADDED
Binary file
data/.rbenv-gemsets ADDED
@@ -0,0 +1 @@
1
+ jpcalendar
data/Gemfile CHANGED
@@ -3,13 +3,11 @@ source "http://rubygems.org"
3
3
  # Specify your gem's dependencies in jpcalendar.gemspec
4
4
  gemspec
5
5
 
6
- gem 'holiday_jp', :git => 'git://github.com/komagata/holiday_jp.git'
6
+ gem 'holiday_jp', :github => "komagata/holiday_jp"
7
7
 
8
8
  group :development, :test do
9
9
  gem 'jeweler'
10
10
  gem 'rails'
11
- gem 'rspec'
12
- gem 'rspec-rails'
13
- gem 'ruby-debug19'
11
+ gem 'rspec', '~> 2.99'
14
12
  end
15
13
 
data/README.md CHANGED
@@ -3,15 +3,12 @@ Jpcalendar
3
3
  日本の祝日に対応したカレンダーを出力します。
4
4
 
5
5
  install
6
- ------
6
+ ------
7
+ `gem install jpcalendar`
7
8
 
8
- ```zsh
9
- gem build jpcalendar.gemspec
10
- rake install
11
- ```
9
+ もしくはGemfileに記載
10
+ `gem 'jpcalendar'`
12
11
 
13
- もしくはGemfileに追記で使用
14
- ``gem 'jpcalendar', :git => 'git://github.com/YoshitsuguFujii/jpcalendar.git'``
15
12
  usage
16
13
  ------
17
14
 
@@ -303,6 +300,9 @@ Options
303
300
  * 休日を含まない
304
301
  `holiday_off: (true または false)`
305
302
 
303
+ * 前後の月も含めて表示する
304
+ `fill_other_days: (true または false)`
305
+
306
306
  * 一桁の日付を何でパディングするか
307
307
  `padding: 任意の文字列`
308
308
 
data/jpcalendar.gemspec CHANGED
@@ -19,5 +19,5 @@ Gem::Specification.new do |s|
19
19
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
20
  s.require_paths = ["lib"]
21
21
 
22
- s.add_dependency "holiday_jp", "~>0.3.1"
22
+ s.add_dependency "holiday_jp"
23
23
  end
@@ -1,5 +1,6 @@
1
1
  # coding: utf-8
2
2
  require 'json'
3
+ require 'date'
3
4
 
4
5
  module Jpcalendar
5
6
  #
@@ -57,7 +58,7 @@ module Jpcalendar
57
58
  if calendar_weekday.find_by_number(d.wday).number == weekday.number
58
59
  #TODO こことなんとかしたい
59
60
  # class 作成部分
60
- holiday = (calendar_weekday.find_by_number(d.wday).enname == "sun" || ::HolidayJp::HOLIDAYS[d].try(:name))? "holiday" : ""
61
+ holiday = (calendar_weekday.find_by_number(d.wday).enname == "sun" || ::HolidayJp.holiday?(d)) ? "holiday" : ""
61
62
  class_hash = { class: "row_#{date_feed.size} col_#{week_arr.size} #{calendar_weekday.find_by_number(d.wday).enname} #{holiday} day_#{d.day}"}
62
63
 
63
64
  # id 作成部分
@@ -68,9 +69,10 @@ module Jpcalendar
68
69
 
69
70
  # 押し込む
70
71
  week_arr << CalenderDate.new(
72
+ d,
71
73
  date_format(d.day, options),
72
74
  event_name,
73
- ::HolidayJp::HOLIDAYS[d].try(:name),
75
+ ::HolidayJp.holiday?(d).try(:name),
74
76
  id_hash.merge(class_hash)
75
77
  )
76
78
 
@@ -89,7 +91,7 @@ module Jpcalendar
89
91
  else
90
92
  #TODO ここをなんとかしたい
91
93
  # class 作成部分
92
- holiday = (calendar_weekday.find_by_number(d.wday).enname == "sun" || ::HolidayJp::HOLIDAYS[d].try(:name))? "holiday" : ""
94
+ holiday = (calendar_weekday.find_by_number(d.wday).enname == "sun" || ::HolidayJp.holiday?(d)) ? "holiday" : ""
93
95
  class_hash = { class: "row_#{date_feed.size} col_#{week_arr.size} #{calendar_weekday.find_by_number(d.wday).enname} #{holiday} day_#{d.day}"}
94
96
 
95
97
  # id 作成部分
@@ -100,9 +102,10 @@ module Jpcalendar
100
102
 
101
103
  # 押し込む
102
104
  week_arr << CalenderDate.new(
105
+ d,
103
106
  date_format(d.day, options),
104
107
  event_name,
105
- ::HolidayJp::HOLIDAYS[d].try(:name),
108
+ ::HolidayJp.holiday?(d).try(:name),
106
109
  id_hash.merge(class_hash)
107
110
  )
108
111
  # 折り返し
@@ -111,6 +114,36 @@ module Jpcalendar
111
114
  end
112
115
 
113
116
  date_feed << week_arr if week_arr.present?
117
+
118
+
119
+ if options[:fill_other_days]
120
+ # 第1週の日付のないところに前月の日付をいれていく
121
+ blank_date = date_feed[1].take_while{|first_week_day| first_week_day.date == "" }
122
+ blank_date.size.times do |idx|
123
+ prev_month_day = start_date - (idx + 1)
124
+ date_feed[1][idx].date = prev_month_day
125
+ date_feed[1][idx].text = date_format(prev_month_day.day, options)
126
+ date_feed[1][idx].attributes = {:class => "other-month-day prev-month-day"}
127
+ date_feed[1][idx].jp_holiday = ::HolidayJp.holiday?(prev_month_day).try(:name)
128
+ end
129
+
130
+ # 最終週の日付のないところに前月の日付をいれていく
131
+ index = 0
132
+ 7.times do |idx|
133
+ if date_feed.last[idx].nil?
134
+ next_month_day = start_date.next_month + index
135
+ index += 1
136
+ date_feed.last << CalenderDate.new(
137
+ next_month_day,
138
+ date_format(next_month_day.day, options),
139
+ "",
140
+ ::HolidayJp.holiday?(next_month_day).try(:name),
141
+ {:class => "other-month-day prev-month-day"}
142
+ )
143
+ end
144
+ end
145
+ end
146
+
114
147
  date_feed
115
148
 
116
149
  end
@@ -122,7 +155,7 @@ module Jpcalendar
122
155
  def make_header(calendar_weekday)
123
156
  calendar_weekday.map.with_index(0) do |cal,idx|
124
157
  class_text = ["header header_#{idx}", cal.enname].join("\s")
125
- CalenderDate.new(cal.jpname, nil, nil, { class: class_text })
158
+ CalenderDate.new("", cal.jpname, nil, nil, { class: class_text })
126
159
  end
127
160
  end
128
161
  #}}}
@@ -133,15 +166,16 @@ module Jpcalendar
133
166
  end #}}}
134
167
 
135
168
  class CalenderDate #{{{
136
- attr_accessor :text, :event, :attributes, :jp_holiday
169
+ attr_accessor :date, :text, :event, :attributes, :jp_holiday
137
170
  class AttributeTypeError < StandardError
138
171
  def initialize(msg = "CalenderDate attributes is only accept hash")
139
172
  super(msg)
140
173
  end
141
174
  end
142
175
 
143
- def initialize(_text = "", _event = nil, _jp_holiday = nil, _attributes = {})
176
+ def initialize(_date = "", _text = "", _event = nil, _jp_holiday = nil, _attributes = {})
144
177
  raise AttributeTypeError if _attributes.present? && !_attributes.is_a?(Hash)
178
+ self.date = _date
145
179
  self.text = _text
146
180
  self.event = _event
147
181
  self.jp_holiday = _jp_holiday
@@ -1,3 +1,3 @@
1
1
  module Jpcalendar
2
- VERSION = "0.0.1"
2
+ VERSION = "1.0.0"
3
3
  end
data/spec/format_spec.rb CHANGED
@@ -211,6 +211,10 @@ describe Jpcalendar::Format do
211
211
 
212
212
  context "対象月:2008年9月 (スペース詰め)" do
213
213
  before do
214
+ def Date.today
215
+ Date.new(2013, 1, 8)
216
+ end
217
+
214
218
  @options = {padding: " ",wrap_tag: :section, row_tag: :ul, header_cell_tag: :li, body_cell_tag: :li}
215
219
  @expect_str="<section><ul class='header'><li class='header header_0 sun'>日</li><li class='header header_1 mon'>月</li><li class='header header_2 tue'>火</li><li class='header header_3 wed'>水</li><li class='header header_4 thu'>木</li><li class='header header_5 fri'>金</li><li class='header header_6 sat'>土</li></ul><ul class='row_0'><li><span class='day'></span></li><li><span class='day'></span></li><li class='row_1 col_2 tue holiday day_1'><span class='day'>&nbsp;1</span><span class='holiday_name'>元日</span></li><li class='row_1 col_3 wed day_2'><span class='day'>&nbsp;2</span></li><li class='row_1 col_4 thu day_3'><span class='day'>&nbsp;3</span></li><li class='row_1 col_5 fri day_4'><span class='day'>&nbsp;4</span></li><li class='row_1 col_6 sat day_5'><span class='day'>&nbsp;5</span></li></ul><ul class='row_1'><li class='row_2 col_0 sun holiday day_6'><span class='day'>&nbsp;6</span></li><li class='row_2 col_1 mon day_7'><span class='day'>&nbsp;7</span></li><li id='today' class='row_2 col_2 tue day_8'><span class='day'>&nbsp;8</span></li><li class='row_2 col_3 wed day_9'><span class='day'>&nbsp;9</span></li><li class='row_2 col_4 thu day_10'><span class='day'>10</span></li><li class='row_2 col_5 fri day_11'><span class='day'>11</span></li><li class='row_2 col_6 sat day_12'><span class='day'>12</span></li></ul><ul class='row_2'><li class='row_3 col_0 sun holiday day_13'><span class='day'>13</span></li><li class='row_3 col_1 mon holiday day_14'><span class='day'>14</span><span class='holiday_name'>成人の日</span></li><li class='row_3 col_2 tue day_15'><span class='day'>15</span></li><li class='row_3 col_3 wed day_16'><span class='day'>16</span></li><li class='row_3 col_4 thu day_17'><span class='day'>17</span></li><li class='row_3 col_5 fri day_18'><span class='day'>18</span></li><li class='row_3 col_6 sat day_19'><span class='day'>19</span></li></ul><ul class='row_3'><li class='row_4 col_0 sun holiday day_20'><span class='day'>20</span></li><li class='row_4 col_1 mon day_21'><span class='day'>21</span></li><li class='row_4 col_2 tue day_22'><span class='day'>22</span></li><li class='row_4 col_3 wed day_23'><span class='day'>23</span></li><li class='row_4 col_4 thu day_24'><span class='day'>24</span></li><li class='row_4 col_5 fri day_25'><span class='day'>25</span></li><li class='row_4 col_6 sat day_26'><span class='day'>26</span></li></ul><ul class='row_4'><li class='row_5 col_0 sun holiday day_27'><span class='day'>27</span></li><li class='row_5 col_1 mon day_28'><span class='day'>28</span></li><li class='row_5 col_2 tue day_29'><span class='day'>29</span></li><li class='row_5 col_3 wed day_30'><span class='day'>30</span></li><li class='row_5 col_4 thu day_31'><span class='day'>31</span></li></ul></section>"
216
220
  end
metadata CHANGED
@@ -1,40 +1,39 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jpcalendar
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
5
- prerelease:
4
+ version: 1.0.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - yoshitsugu fujii
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-01-09 00:00:00.000000000 Z
11
+ date: 2015-11-12 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: holiday_jp
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
- - - ~>
17
+ - - ">="
20
18
  - !ruby/object:Gem::Version
21
- version: 0.3.1
19
+ version: '0'
22
20
  type: :runtime
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
- - - ~>
24
+ - - ">="
28
25
  - !ruby/object:Gem::Version
29
- version: 0.3.1
30
- description: 日本の祝祭日に対応したカレンダー
26
+ version: '0'
27
+ description: "日本の祝祭日に対応したカレンダー"
31
28
  email:
32
29
  - ishikurasakura@gmail.com
33
30
  executables: []
34
31
  extensions: []
35
32
  extra_rdoc_files: []
36
33
  files:
37
- - .gitignore
34
+ - ".DS_Store"
35
+ - ".gitignore"
36
+ - ".rbenv-gemsets"
38
37
  - Gemfile
39
38
  - LICENSE.md
40
39
  - README.md
@@ -53,27 +52,26 @@ files:
53
52
  - spec/weekday_scale_spec.rb
54
53
  homepage: https://github.com/YoshitsuguFujii/jpcalendar
55
54
  licenses: []
55
+ metadata: {}
56
56
  post_install_message:
57
57
  rdoc_options: []
58
58
  require_paths:
59
59
  - lib
60
60
  required_ruby_version: !ruby/object:Gem::Requirement
61
- none: false
62
61
  requirements:
63
- - - ! '>='
62
+ - - ">="
64
63
  - !ruby/object:Gem::Version
65
64
  version: '0'
66
65
  required_rubygems_version: !ruby/object:Gem::Requirement
67
- none: false
68
66
  requirements:
69
- - - ! '>='
67
+ - - ">="
70
68
  - !ruby/object:Gem::Version
71
69
  version: '0'
72
70
  requirements: []
73
71
  rubyforge_project: jpcalendar
74
- rubygems_version: 1.8.24
72
+ rubygems_version: 2.2.2
75
73
  signing_key:
76
- specification_version: 3
74
+ specification_version: 4
77
75
  summary: japanese calendar
78
76
  test_files:
79
77
  - spec/format_spec.rb