middleman-blog-ymd 0.5.0 → 0.5.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +11 -2
- data/lib/middleman-blog-ymd/version.rb +1 -1
- data/lib/middleman-blog-ymd/ymdtree.rb +56 -4
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0b6d49237649298b234244213720f9b464f77477
|
4
|
+
data.tar.gz: 9f1e10c52f9af84c44bb5fd726b3aa4c5d347798
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
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.
|
@@ -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
|
-
|
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
|
-
|
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.
|
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:
|
11
|
+
date: 2015-01-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|