middleman-blog-ymd 0.0.3 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 22ab466f43a9c4c9d062a75c02f5ee57f8865491
4
- data.tar.gz: fd29f7c7dd01345c2bb08a603571ca795cb58064
3
+ metadata.gz: 94a804d71fd425d4b9fbd81138238effe524b21e
4
+ data.tar.gz: 7e329cdac3c041d5adc381bee25a01fec32a1fb2
5
5
  SHA512:
6
- metadata.gz: f93ad4966af5ba0fc9cea6e4d1994f535666ae45a3ffabc2839d31d4cd9ba047f68ff85d8385ad899b670b761c26f8854bd72479c4e2337858370e7e49b332d5
7
- data.tar.gz: e9a75018c27a4b9d349991eeb0762b4a364be5d1910cae63d21d62061433b1d25c61c0ab7eede799bef6d993e208c9e05d67423bff07d40ab7cb1ac888cfa306
6
+ metadata.gz: 111a0027b391015916040c68d22cf5a424567dabcb936adaefd01a86601fbece866fc2f6ff08c6d007fd8652a7e4137e077287ebd499c46e039a6a672389722b
7
+ data.tar.gz: 9ffe86d5c5414f9814089cb3d18f164ef2733145dcade6b25ace13ddb22b75cf3613b4fb4ab7f976a7a05b3e4f8a4f4e93b1935b5cd1452db16deb7c873c4772
data/README.md CHANGED
@@ -1,6 +1,13 @@
1
- # Middleman::Blog::Ymd
1
+ # Middleman-Blog-YMD Extension
2
+
3
+ This is an extension for Middleman blog.
4
+
5
+ ## Introduction & Motivation
6
+
7
+ This extension provides helper methods of middleman-blog. These methods enables you to collect years and months data of your blog articles. These years and months data mean only years and months WHICH HAVE ARTICLES.
8
+
9
+ The motivation of this gem came from my own blog based on middleman-blog. I couldn't easily get months having articles of specific year. I couldn't get next month which have article.
2
10
 
3
- TODO: Write a gem description
4
11
 
5
12
  ## Installation
6
13
 
@@ -16,14 +23,53 @@ Or install it yourself as:
16
23
 
17
24
  $ gem install middleman-blog-ymd
18
25
 
26
+
27
+ ## Configuration
28
+
29
+ In config.rb file, add the next line. This line should come after "activate :blog"
30
+
31
+ activate :ymd_extension
32
+
33
+
19
34
  ## Usage
20
35
 
21
- TODO: Write usage instructions here
36
+ All the helper methods' names begin with "ymd". This avoids method name confliction. In view of Middleman-blog, "blog" helper mothod returns BlogData. YMD methods get years and methods data from this BlogData object.
37
+
38
+
39
+ * ymd_years_of(blog)
40
+ + returns years having articles in Array.
41
+
42
+ * ymd_year_months_hash_of(blog)
43
+ + returns pairs of year and month"S" having articles in Hash.
44
+ + The returned hash is like this,
45
+
46
+ ~~~ Ruby
47
+ { 2013 => [1,2,3,4,5,6,7,8,9], 2014 => [1,2,3,4,5,6,7,8,9] } )
48
+ ~~~
49
+
50
+ * ymd_next_month_of(blog, current_year, current_month)
51
+ * ymd_prev_month_of(blog, current_year, current_month)
52
+ + These methods return next month or previous month WHICH HAVE ARTICLES. Current year and month should be specified in argument by integer.
53
+
54
+ ~~~ Ruby
55
+ # Example
56
+ ymd_next_month_of(blog, 2014, 1 ) # returns next month having articles of 2014 Jan.
57
+ ~~~
58
+
59
+ This returns a month number (e.g. 1, 2, 3, 4, ... 9, 10, 11,12 ).
60
+ If you want to get a two digit value, use ruby method
61
+ ~~~~ Ruby
62
+ "%02d".%( integer )
63
+ ~~~~
64
+
65
+ which converts integer into two digits.
66
+
67
+ If you want to get short name of the month from the number
68
+ ~~~~ Ruby
69
+ Date::MONTHNAMES[ integer ]
70
+ ~~~~
71
+
72
+ ## ToDo
22
73
 
23
- ## Contributing
74
+ In version 0.5, every time the ymd methods is called, Ymdtree is regenerated. This makes the build process slow. But good for Live Preview. I'd like to change this behavior based on "during build" or "live preview". My idea now is to make an option in this gem and change the option value in Rspec.
24
75
 
25
- 1. Fork it ( https://github.com/[my-github-username]/middleman-blog-ymd/fork )
26
- 2. Create your feature branch (`git checkout -b my-new-feature`)
27
- 3. Commit your changes (`git commit -am 'Add some feature'`)
28
- 4. Push to the branch (`git push origin my-new-feature`)
29
- 5. Create a new Pull Request
@@ -1,3 +1,3 @@
1
1
  module MiddlemanBlogYmd
2
- VERSION = "0.0.3"
2
+ VERSION = "0.5.0"
3
3
  end
@@ -1,7 +1,15 @@
1
1
  class Ymdtree
2
2
  @hash = Hash.new{|h, k| h[k] = Hash.new(&h.default_proc) }
3
-
3
+
4
4
  class << self
5
+ def init(blog_data)
6
+ blog_data.articles.each{|article|
7
+ year_value = article.date.gmtime.year
8
+ month_value =article.date.gmtime.month
9
+ day_value =article.date.gmtime.day
10
+ add(year_value, month_value, day_value)
11
+ }
12
+ end
5
13
  def hash
6
14
  return @hash
7
15
  end
@@ -17,20 +25,23 @@ class Ymdtree
17
25
  def days_of( y, m )
18
26
  @hash[y][m].keys
19
27
  end
20
- def next_month( y , m)
28
+ def previous_month( y , m)
21
29
  month_array = @hash[y].to_a
30
+ month_array = month_array.collect{|month|
31
+ month[0]
32
+ }
22
33
  m_idx = month_array.index(m)
23
- if m_idx == ( m_idx.length - 1 )
34
+ if m_idx == ( month_array.length - 1 )
24
35
  return false
25
36
  else
26
37
  return month_array[ m_idx + 1 ]
27
38
  end
28
39
  end
29
- def previous_month( y , m)
30
- p @hash
31
- p y
40
+ def next_month( y , m)
32
41
  month_array = @hash[y].to_a
33
- p month_array
42
+ month_array = month_array.collect{|month|
43
+ month[0]
44
+ }
34
45
  m_idx = month_array.index(m)
35
46
  if m_idx == 0
36
47
  return false
@@ -1,16 +1,6 @@
1
1
  require "middleman-blog"
2
- require "middleman-blog-ymd/version"
3
- require "middleman-blog-ymd/ymdtree"
4
-
5
- def collect_articles_ymds
6
- blog.articles.each{|article|
7
- if article.path =~ /^(\d+)\/(\d+)\/(\d+)_/
8
- year_value = $1
9
- month_value = $2
10
- day_value = $3.to_s[4..5].to_i
11
- Ymdtree.add(year_value, month_value, day_value)
12
- }
13
- end
2
+ require File.expand_path("../middleman-blog-ymd/version", __FILE__)
3
+ require File.expand_path("../middleman-blog-ymd/ymdtree", __FILE__)
14
4
 
15
5
  class YmdExtension < ::Middleman::Extension
16
6
  def initialize(app, options_hash={}, &block)
@@ -18,26 +8,36 @@ class YmdExtension < ::Middleman::Extension
18
8
  super
19
9
  end
20
10
 
21
- def manipulate_resource_list(resources)
22
- p ::Middleman:BlogExtension.data
23
- end
24
-
25
11
  helpers do
26
- def ymdtree
27
- return YMDTree
12
+ def ymdtree_of(blog)
13
+ Ymdtree.init(blog)
14
+ return Ymdtree
28
15
  end
29
16
 
30
- def blog_years
31
- return YMDTree.years
17
+ def ymd_years_of(blog)
18
+ Ymdtree.init(blog)
19
+ return Ymdtree.years
32
20
  end
33
21
 
34
- def blog_year_month_hash
22
+ def ymd_year_months_hash_of(blog)
23
+ Ymdtree.init(blog)
35
24
  ymhash = Hash.new
36
- YMDTree.hash.each{ |k, v|
25
+ Ymdtree.hash.each{ |k, v|
37
26
  ymhash[k] = v.keys
38
27
  }
39
28
  return ymhash
40
29
  end
30
+
31
+ def ymd_next_month_of( blog, year, month)
32
+ Ymdtree.init(blog)
33
+ return Ymdtree.next_month(year, month)
34
+ end
35
+
36
+ def ymd_prev_month_of( blog, year, month)
37
+ Ymdtree.init(blog)
38
+ return Ymdtree.previous_month(year, month)
39
+ end
40
+
41
41
  end
42
42
  end
43
43
 
@@ -10,7 +10,7 @@ Gem::Specification.new do |spec|
10
10
  spec.email = ["toshi@niceume.com"]
11
11
  spec.summary = %q{years months days (for middleman-blog).}
12
12
  spec.description = %q{years months days support for middleman-blog.}
13
- spec.homepage = ""
13
+ spec.homepage = "https://github.com/niceume/middleman-blog-ymd"
14
14
  spec.license = "MIT"
15
15
 
16
16
  spec.files = `git ls-files -z`.split("\x0")
@@ -21,6 +21,8 @@ Gem::Specification.new do |spec|
21
21
  spec.add_development_dependency "bundler", "~> 1.6"
22
22
  spec.add_development_dependency "rake"
23
23
  spec.add_development_dependency "rspec", "~> 3.0"
24
+
25
+ spec.add_runtime_dependency "middleman-blog"
24
26
  end
25
27
 
26
28
 
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.0.3
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - niceume
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-07-13 00:00:00.000000000 Z
11
+ date: 2014-12-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -52,6 +52,20 @@ dependencies:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: middleman-blog
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
55
69
  description: years months days support for middleman-blog.
56
70
  email:
57
71
  - toshi@niceume.com
@@ -67,9 +81,8 @@ files:
67
81
  - lib/middleman-blog-ymd.rb
68
82
  - lib/middleman-blog-ymd/version.rb
69
83
  - lib/middleman-blog-ymd/ymdtree.rb
70
- - lib/middleman-extension.rb
71
84
  - middleman-blog-ymd.gemspec
72
- homepage: ''
85
+ homepage: https://github.com/niceume/middleman-blog-ymd
73
86
  licenses:
74
87
  - MIT
75
88
  metadata: {}
@@ -1 +0,0 @@
1
- require "middleman-blog-ymd"