middleman-blog-ymd 0.5.0 → 0.5.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 94a804d71fd425d4b9fbd81138238effe524b21e
4
- data.tar.gz: 7e329cdac3c041d5adc381bee25a01fec32a1fb2
3
+ metadata.gz: 0b6d49237649298b234244213720f9b464f77477
4
+ data.tar.gz: 9f1e10c52f9af84c44bb5fd726b3aa4c5d347798
5
5
  SHA512:
6
- metadata.gz: 111a0027b391015916040c68d22cf5a424567dabcb936adaefd01a86601fbece866fc2f6ff08c6d007fd8652a7e4137e077287ebd499c46e039a6a672389722b
7
- data.tar.gz: 9ffe86d5c5414f9814089cb3d18f164ef2733145dcade6b25ace13ddb22b75cf3613b4fb4ab7f976a7a05b3e4f8a4f4e93b1935b5cd1452db16deb7c873c4772
6
+ metadata.gz: 131eb522cad4eb99e449ff8b6570614c474858b654c52f0c8c67ffaa4b86b7e1a83c305d28a5c44e0b2883fdcb707676bc3b8f8a78d77d374248e1ccd635d82d
7
+ data.tar.gz: 117b8886e47988ed39e37c0a2ab02641fe1fb7a770b48192a5fe5f01abc44cb591d9ffca5a4d131dd38c4adc16166db8a6f9a14d51bfe349c68cc03c09cf9d94
data/README.md CHANGED
@@ -56,10 +56,19 @@ All the helper methods' names begin with "ymd". This avoids method name conflic
56
56
  ymd_next_month_of(blog, 2014, 1 ) # returns next month having articles of 2014 Jan.
57
57
  ~~~
58
58
 
59
- This returns a month number (e.g. 1, 2, 3, 4, ... 9, 10, 11,12 ).
59
+ This returns a pair of year and month number in Array (e.g. [ 2014, 1 ] [2015, 2] ). If you want to access its year its index is 0, the month, its index 1.
60
+
61
+ ~~~ HAML
62
+ # HAML View Example
63
+ - previous_month = ymd_prev_month_of(blog, article_date.year, article_date.month)
64
+ - if previous_month
65
+ = link_to( "Prev Month", "/#{previous_month[0]}/#{sprintf("%02d", previous_month[1])}.html" )
66
+
67
+ ~~~
68
+
60
69
  If you want to get a two digit value, use ruby method
61
70
  ~~~~ Ruby
62
- "%02d".%( integer )
71
+ "%02d".%( integer ) # or use sprintf method
63
72
  ~~~~
64
73
 
65
74
  which converts integer into two digits.
@@ -1,3 +1,3 @@
1
1
  module MiddlemanBlogYmd
2
- VERSION = "0.5.0"
2
+ VERSION = "0.5.1"
3
3
  end
@@ -25,6 +25,47 @@ class Ymdtree
25
25
  def days_of( y, m )
26
26
  @hash[y][m].keys
27
27
  end
28
+
29
+ def previous_year(y)
30
+ ys = years
31
+ sorted_ys = ys.sort
32
+ yidx = sorted_ys.index(y)
33
+ case yidx
34
+ when 0
35
+ return nil
36
+ when nil
37
+ raise Error , "argument year doesn't exist"
38
+ else
39
+ return sorted_ys[yidx - 1]
40
+ end
41
+ end
42
+
43
+ def next_year(y)
44
+ ys = years
45
+ sorted_ys = ys.sort
46
+ yidx = sorted_ys.index(y)
47
+ case yidx
48
+ when (sorted_ys.length - 1)
49
+ return nil
50
+ when nil
51
+ raise Error , "argument year doesn't exist"
52
+ else
53
+ return sorted_ys[yidx + 1]
54
+ end
55
+ end
56
+
57
+ def last_month_of_year(y)
58
+ ms = @hash[y].keys
59
+ sorted_ms = ms.sort
60
+ sorted_ms.last
61
+ end
62
+
63
+ def first_month_of_year(y)
64
+ ms = @hash[y].keys
65
+ sorted_ms = ms.sort
66
+ sorted_ms.first
67
+ end
68
+
28
69
  def previous_month( y , m)
29
70
  month_array = @hash[y].to_a
30
71
  month_array = month_array.collect{|month|
@@ -32,11 +73,17 @@ class Ymdtree
32
73
  }
33
74
  m_idx = month_array.index(m)
34
75
  if m_idx == ( month_array.length - 1 )
35
- return false
76
+ if previous_year(y)
77
+ return [ previous_year(y), last_month_of_year( previous_year(y) )]
78
+ # preious year of last month
79
+ else
80
+ return nil
81
+ end
36
82
  else
37
- return month_array[ m_idx + 1 ]
83
+ return [ y, month_array[ m_idx + 1 ] ]
38
84
  end
39
85
  end
86
+
40
87
  def next_month( y , m)
41
88
  month_array = @hash[y].to_a
42
89
  month_array = month_array.collect{|month|
@@ -44,9 +91,14 @@ class Ymdtree
44
91
  }
45
92
  m_idx = month_array.index(m)
46
93
  if m_idx == 0
47
- return false
94
+ if next_year(y)
95
+ return [ next_year(y), first_month_of_year( next_year(y) ) ]
96
+ # preious year of last month
97
+ else
98
+ return nil
99
+ end
48
100
  else
49
- return month_array[ m_idx - 1 ]
101
+ return [y , month_array[ m_idx - 1 ] ]
50
102
  end
51
103
  end
52
104
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: middleman-blog-ymd
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - niceume
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-12-31 00:00:00.000000000 Z
11
+ date: 2015-01-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler