jpcalendar 0.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,6 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
5
+ .rvmrc
6
+ tags
data/Gemfile ADDED
@@ -0,0 +1,15 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in jpcalendar.gemspec
4
+ gemspec
5
+
6
+ gem 'holiday_jp', :git => 'git://github.com/komagata/holiday_jp.git'
7
+
8
+ group :development, :test do
9
+ gem 'jeweler'
10
+ gem 'rails'
11
+ gem 'rspec'
12
+ gem 'rspec-rails'
13
+ gem 'ruby-debug19'
14
+ end
15
+
data/LICENSE.md ADDED
@@ -0,0 +1,7 @@
1
+ Copyright (c) 2013 yoshitsugu fujii
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
+
5
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
+
7
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,321 @@
1
+ Jpcalendar
2
+ ======================
3
+ 日本の祝日に対応したカレンダーを出力します。
4
+
5
+ install
6
+ ------
7
+ ダウンロード後、ディレクトリに移動して以下を実行
8
+ ```zsh
9
+ gem install jpcalendar
10
+ ```
11
+
12
+ usage
13
+ ------
14
+
15
+ ###Class methods
16
+ `calendar_table(date = Date.today, options ={})`
17
+ table形式のカレンダーを生成します。
18
+
19
+ `calendar_div(date = Date.today, options ={})`
20
+ div形式でカレンダーを生成します。
21
+
22
+ `calendar(date = Date.today, options ={})`
23
+ 任意の形式でカレンダーを生成します。
24
+
25
+ ###example
26
+ 出力例 その1
27
+ カレンダー出力(table形式)
28
+ ```ruby
29
+ Jpcalendar.calendar_table(Date.new(2013,1,1))
30
+ ```
31
+ ```html
32
+ <table>
33
+ <tr class='header'> <th class='header header_0 sun'>日</th>
34
+ <th class='header header_1 mon'>月</th>
35
+ <th class='header header_2 tue'>火</th>
36
+ <th class='header header_3 wed'>水</th>
37
+ <th class='header header_4 thu'>木</th>
38
+ <th class='header header_5 fri'>金</th>
39
+ <th class='header header_6 sat'>土</th>
40
+ </tr>
41
+ <tr class='row_0'>
42
+ <td>
43
+ <span class='day'></span>
44
+ </td>
45
+ <td>
46
+ <span class='day'></span>
47
+ </td>
48
+ <td class='row_1 col_2 tue holiday day_1'>
49
+ <span class='day'>01</span>
50
+ <span class='holiday_name'>元日</span>
51
+ </td>
52
+ <td class='row_1 col_3 wed day_2'>
53
+ <span class='day'>02</span>
54
+ </td>
55
+ <td class='row_1 col_4 thu day_3'>
56
+ <span class='day'>03</span>
57
+ </td>
58
+ <td class='row_1 col_5 fri day_4'>
59
+ <span class='day'>04</span>
60
+ </td>
61
+ <td class='row_1 col_6 sat day_5'>
62
+ <span class='day'>05</span>
63
+ </td>
64
+ </tr>
65
+ <tr class='row_1'>
66
+ <td class='row_2 col_0 sun holiday day_6'>
67
+ <span class='day'>06</span>
68
+ </td>
69
+ <td class='row_2 col_1 mon day_7'>
70
+ <span class='day'>07</span>
71
+ </td>
72
+ <td class='row_2 col_2 tue day_8'>
73
+ <span class='day'>08</span>
74
+ </td>
75
+ <td id='today' class='row_2 col_3 wed day_9'>
76
+ <span class='day'>09</span>
77
+ </td>
78
+ <td class='row_2 col_4 thu day_10'>
79
+ <span class='day'>10</span>
80
+ </td>
81
+ <td class='row_2 col_5 fri day_11'>
82
+ <span class='day'>11</span>
83
+ </td>
84
+ <td class='row_2 col_6 sat day_12'>
85
+ <span class='day'>12</span>
86
+ </td>
87
+ </tr>
88
+ <tr class='row_2'>
89
+ <td class='row_3 col_0 sun holiday day_13'>
90
+ <span class='day'>13</span>
91
+ </td>
92
+ <td class='row_3 col_1 mon holiday day_14'>
93
+ <span class='day'>14</span>
94
+ <span class='holiday_name'>成人の日</span>
95
+ </td>
96
+ <td class='row_3 col_2 tue day_15'>
97
+ <span class='day'>15</span>
98
+ </td>
99
+ <td class='row_3 col_3 wed day_16'>
100
+ <span class='day'>16</span>
101
+ </td>
102
+ <td class='row_3 col_4 thu day_17'>
103
+ <span class='day'>17</span>
104
+ </td>
105
+ <td class='row_3 col_5 fri day_18'>
106
+ <span class='day'>18</span>
107
+ </td>
108
+ <td class='row_3 col_6 sat day_19'>
109
+ <span class='day'>19</span>
110
+ </td>
111
+ </tr>
112
+ <tr class='row_3'>
113
+ <td class='row_4 col_0 sun holiday day_20'>
114
+ <span class='day'>20</span>
115
+ </td>
116
+ <td class='row_4 col_1 mon day_21'>
117
+ <span class='day'>21</span>
118
+ </td>
119
+ <td class='row_4 col_2 tue day_22'>
120
+ <span class='day'>22</span>
121
+ </td>
122
+ <td class='row_4 col_3 wed day_23'>
123
+ <span class='day'>23</span>
124
+ </td>
125
+ <td class='row_4 col_4 thu day_24'>
126
+ <span class='day'>24</span>
127
+ </td>
128
+ <td class='row_4 col_5 fri day_25'>
129
+ <span class='day'>25</span>
130
+ </td>
131
+ <td class='row_4 col_6 sat day_26'>
132
+ <span class='day'>26</span>
133
+ </td>
134
+ </tr>
135
+ <tr class='row_4'>
136
+ <td class='row_5 col_0 sun holiday day_27'>
137
+ <span class='day'>27</span>
138
+ </td>
139
+ <td class='row_5 col_1 mon day_28'>
140
+ <span class='day'>28</span>
141
+ </td>
142
+ <td class='row_5 col_2 tue day_29'>
143
+ <span class='day'>29</span>
144
+ </td>
145
+ <td class='row_5 col_3 wed day_30'>
146
+ <span class='day'>30</span>
147
+ </td>
148
+ <td class='row_5 col_4 thu day_31'>
149
+ <span class='day'>31</span>
150
+ </td>
151
+ </tr>
152
+ </table>
153
+ ```
154
+
155
+ 出力例 その2
156
+ カレンダー出力(div形式/optionをたくさん指定)
157
+ ```ruby
158
+ date_event = JSON.generate({"1" => "定例会", "9" => "ディズニーランド", "14" => "サーフィン", "23" => "小梅と遊ぶ", "24" => "クリスマスパーティー"})
159
+ Jpcalendar.calendar_div(Date.new(2012, 12, 1),holiday_off: true, padding: " ", start_with_monday: true, date_event: @date_event )
160
+ ```
161
+ ```html
162
+ <html>
163
+ <div class='header'>
164
+ <span class='header header_0 mon'>月</span>
165
+ <span class='header header_1 tue'>火</span>
166
+ <span class='header header_2 wed'>水</span>
167
+ <span class='header header_3 thu'>木</span>
168
+ <span class='header header_4 fri'>金</span>
169
+ <span class='header header_5 sat'>土</span>
170
+ <span class='header header_6 sun'>日</span>
171
+ </div>
172
+ <div class='row_0'>
173
+ <span>
174
+ <span class='day'></span>
175
+ </span>
176
+ <span>
177
+ <span class='day'></span>
178
+ </span>
179
+ <span>
180
+ <span class='day'></span>
181
+ </span>
182
+ <span>
183
+ <span class='day'></span>
184
+ </span>
185
+ <span>
186
+ <span class='day'></span>
187
+ </span>
188
+ <span class='row_1 col_5 sat day_1'>
189
+ <span class='day'>&nbsp;1</span>定例会
190
+ </span>
191
+ <span class='row_1 col_6 sun holiday day_2'>
192
+ <span class='day'>&nbsp;2</span>
193
+ </span>
194
+ </div>
195
+ <div class='row_1'>
196
+ <span class='row_2 col_0 mon day_3'>
197
+ <span class='day'>&nbsp;3</span>
198
+ </span>
199
+ <span class='row_2 col_1 tue day_4'>
200
+ <span class='day'>&nbsp;4</span>
201
+ </span>
202
+ <span class='row_2 col_2 wed day_5'>
203
+ <span class='day'>&nbsp;5</span>
204
+ </span>
205
+ <span class='row_2 col_3 thu day_6'>
206
+ <span class='day'>&nbsp;6</span>
207
+ </span>
208
+ <span class='row_2 col_4 fri day_7'>
209
+ <span class='day'>&nbsp;7</span>
210
+ </span>
211
+ <span class='row_2 col_5 sat day_8'>
212
+ <span class='day'>&nbsp;8</span>
213
+ </span>
214
+ <span class='row_2 col_6 sun holiday day_9'>
215
+ <span class='day'>&nbsp;9</span>ディズニーランド
216
+ </span>
217
+ </div>
218
+ <div class='row_2'>
219
+ <span class='row_3 col_0 mon day_10'>
220
+ <span class='day'>10</span>
221
+ </span>
222
+ <span class='row_3 col_1 tue day_11'>
223
+ <span class='day'>11</span>
224
+ </span>
225
+ <span class='row_3 col_2 wed day_12'>
226
+ <span class='day'>12</span>
227
+ </span>
228
+ <span class='row_3 col_3 thu day_13'>
229
+ <span class='day'>13</span>
230
+ </span>
231
+ <span class='row_3 col_4 fri day_14'>
232
+ <span class='day'>14</span>サーフィン
233
+ </span>
234
+ <span class='row_3 col_5 sat day_15'>
235
+ <span class='day'>15</span>
236
+ </span>
237
+ <span class='row_3 col_6 sun holiday day_16'>
238
+ <span class='day'>16</span>
239
+ </span>
240
+ </div>
241
+ <div class='row_3'>
242
+ <span class='row_4 col_0 mon day_17'>
243
+ <span class='day'>17</span>
244
+ </span>
245
+ <span class='row_4 col_1 tue day_18'>
246
+ <span class='day'>18</span>
247
+ </span>
248
+ <span class='row_4 col_2 wed day_19'>
249
+ <span class='day'>19</span>
250
+ </span>
251
+ <span class='row_4 col_3 thu day_20'>
252
+ <span class='day'>20</span>
253
+ </span>
254
+ <span class='row_4 col_4 fri day_21'>
255
+ <span class='day'>21</span>
256
+ </span>
257
+ <span class='row_4 col_5 sat day_22'>
258
+ <span class='day'>22</span>
259
+ </span>
260
+ <span class='row_4 col_6 sun holiday day_23'>
261
+ <span class='day'>23</span>小梅と遊ぶ
262
+ </span>
263
+ </div>
264
+ <div class='row_4'>
265
+ <span class='row_5 col_0 mon holiday day_24'>
266
+ <span class='day'>24</span>クリスマスパーティー
267
+ </span>
268
+ <span class='row_5 col_1 tue day_25'>
269
+ <span class='day'>25</span>
270
+ </span>
271
+ <span class='row_5 col_2 wed day_26'>
272
+ <span class='day'>26</span>
273
+ </span>
274
+ <span class='row_5 col_3 thu day_27'>
275
+ <span class='day'>27</span>
276
+ </span>
277
+ <span class='row_5 col_4 fri day_28'>
278
+ <span class='day'>28</span>
279
+ </span>
280
+ <span class='row_5 col_5 sat day_29'>
281
+ <span class='day'>29</span>
282
+ </span>
283
+ <span class='row_5 col_6 sun holiday day_30'>
284
+ <span class='day'>30</span>
285
+ </span>
286
+ </div>
287
+ <div class='row_5'>
288
+ <span class='row_6 col_0 mon day_31'>
289
+ <span class='day'>31</span>
290
+ </span>
291
+ </div>
292
+ </html>
293
+ ```
294
+
295
+ Options
296
+ ------
297
+ * 月曜はじまり
298
+ `start_with_monday: ( true または false )`
299
+
300
+ * 休日を含まない
301
+ `holiday_off: (true または false)`
302
+
303
+ * 一桁の日付を何でパディングするか
304
+ `padding: 任意の文字列`
305
+
306
+ * カスタムイベント
307
+ `date_event: json形式の文字列 または hash`
308
+
309
+ * 任意のタグ
310
+
311
+ * 全体を覆うタグ
312
+ `wrap_tag: タグのシンボル (例) :section`
313
+
314
+ * 行を覆うタグ
315
+ `row_tag: タグのシンボル (例) :ul`
316
+
317
+ * ヘッダ(月~日)までの各セルを覆うタグ
318
+ `header_cell_tag: タグのシンボル (例) :li`
319
+
320
+ * 日付の各セルを覆うタグ
321
+ `body_cell_tag: タグのシンボル (例) :li`
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
@@ -0,0 +1,23 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "jpcalendar/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "jpcalendar"
7
+ s.version = Jpcalendar::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["yoshitsugu fujii"]
10
+ s.email = ["ishikurasakura@gmail.com"]
11
+ s.homepage = "https://github.com/YoshitsuguFujii/jpcalendar"
12
+ s.summary = %q{japanese calendar}
13
+ s.description = %q{日本の祝祭日に対応したカレンダー}
14
+
15
+ s.rubyforge_project = "jpcalendar"
16
+
17
+ s.files = `git ls-files`.split("\n")
18
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
+ s.require_paths = ["lib"]
21
+
22
+ s.add_dependency "holiday_jp", "~>0.3.1"
23
+ end
data/lib/jpcalendar.rb ADDED
@@ -0,0 +1,19 @@
1
+ # coding: utf-8
2
+
3
+ #
4
+ # カレンダークラス
5
+ #
6
+ module Jpcalendar
7
+ require 'active_support/core_ext/date/calculations'
8
+ require 'active_support/core_ext/time/calculations'
9
+
10
+ require 'jpcalendar/generator'
11
+ require 'jpcalendar/format'
12
+ require 'jpcalendar/util'
13
+
14
+ require 'jpcalendar/weekday_scale'
15
+
16
+ require 'holiday_jp'
17
+
18
+ extend Format
19
+ end
@@ -0,0 +1,105 @@
1
+ # coding: utf-8
2
+
3
+ module Jpcalendar
4
+
5
+ extend Generator
6
+
7
+ #
8
+ # 出力用整形クラス
9
+ #
10
+ module Format
11
+
12
+ ##
13
+ # テーブル版
14
+ # options: padding 一桁の日付を何で埋めるか。デフォルトは0 => 01とか
15
+ # start_with_monday 月曜ではじめるかどうか。 デフォルトはfalse
16
+ # @holiday_off trueの場合は休日を出力しない
17
+ # date_event 日付に対応するイベント情報(hash、またはjsonでparseできる文字列)
18
+ #
19
+ def calendar_table(_date = Date.today,options = {})
20
+ options.merge!(wrap_tag: :table, row_tag: :tr, header_cell_tag: :th, body_cell_tag: :td)
21
+ calendar(_date, options)
22
+ end
23
+
24
+ ##
25
+ # div版
26
+ # options: padding 一桁の日付を何で埋めるか。デフォルトは0 => 01とか
27
+ # start_with_monday 月曜ではじめるかどうか。 デフォルトはfalse
28
+ # @holiday_off trueの場合は休日を出力しない
29
+ # date_event 日付に対応するイベント情報(hash、またはjsonでparseできる文字列)
30
+ #
31
+ def calendar_div(_date = Date.today,options = {})
32
+ options.merge!(wrap_tag: :html, row_tag: :div, header_cell_tag: :span, body_cell_tag: :span)
33
+ calendar(_date, options)
34
+ end
35
+
36
+ ##
37
+ # カレンダー出力
38
+ # options: padding 一桁の日付を何で埋めるか。デフォルトは0 => 01とか
39
+ # start_with_monday 月曜ではじめるかどうか。 デフォルトはfalse
40
+ # @holiday_off trueの場合は休日を出力しない
41
+ # date_event 日付に対応するイベント情報(hash、またはjsonでparseできる文字列)
42
+ #
43
+ def calendar(_date = Date.today,options = {})
44
+ print(_date, options)
45
+ end
46
+
47
+ private
48
+
49
+ def print(_date, options) #{{{
50
+ set_options(options)
51
+ feeds = generator_feed(_date, options)
52
+
53
+ table = ""
54
+ table << to_header(feeds)
55
+ table << to_body(feeds)
56
+
57
+ Util.tag_wrap(@wrap_tag){table}
58
+ end #}}}
59
+
60
+ def set_options(options) #{{{
61
+ @holiday_off = options.delete(:holiday_off) || false
62
+ @wrap_tag = options.delete(:wrap_tag) || :table
63
+ @row_tag = options.delete(:row_tag) || :tr
64
+ @header_cell_tag = options.delete(:header_cell_tag) || :th
65
+ @body_cell_tag = options.delete(:body_cell_tag) || :td
66
+ end #}}}
67
+
68
+ def to_header(feeds) #{{{
69
+ weekdays = feeds.shift
70
+
71
+ Util.tag_wrap(@row_tag, class: "header") do
72
+ table_header = ""
73
+ weekdays.each do | weekday |
74
+ table_header << Util.tag_wrap(@header_cell_tag, {class: weekday.attributes[:class] } ){weekday.text}
75
+ end
76
+ table_header
77
+ end
78
+ end #}}}
79
+
80
+ def to_body(feeds) #{{{
81
+ table = ""
82
+ feeds.each_with_index do |days, idx|
83
+ table << Util.tag_wrap(@row_tag, class: "row_#{idx}" ) do
84
+ table_data = ""
85
+
86
+ days.each do |day|
87
+ if @holiday_off
88
+ table_data << Util.tag_wrap(@body_cell_tag, id: day.attributes[:id], class: day.attributes[:class]){ [output_day(day.text) , day.event].compact.join }
89
+ else
90
+ table_data << Util.tag_wrap(@body_cell_tag, id: day.attributes[:id], class: day.attributes[:class]){ [output_day(day.text), Util.expr_not_nil(day.jp_holiday){ Util.tag_wrap(:span, class: "holiday_name"){day.jp_holiday} }, day.event].compact.join }
91
+ end
92
+ end
93
+ table_data
94
+ end
95
+ end
96
+ table
97
+ end #}}}
98
+
99
+ def output_day(day) #{{{
100
+ Util.tag_wrap(:span, class: "day" ){ day }
101
+ end #}}}
102
+ # end private
103
+
104
+ end
105
+ end