middleman-blog 4.0.2 → 4.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (68) hide show
  1. checksums.yaml +5 -5
  2. data/.rubocop.yml +69 -0
  3. data/.travis.yml +20 -28
  4. data/CHANGELOG.md +4 -4
  5. data/Gemfile +20 -21
  6. data/Gemfile-4.x +38 -0
  7. data/README.md +0 -6
  8. data/Rakefile +14 -12
  9. data/features/summary.feature +3 -6
  10. data/features/support/env.rb +7 -10
  11. data/features/support/time_steps.rb +7 -10
  12. data/features/tags.feature +1 -1
  13. data/fixtures/article-dirs-app/config-directory-indexes.rb +2 -2
  14. data/fixtures/article-dirs-app/config-permalink-with-dot.rb +2 -2
  15. data/fixtures/article-dirs-app/config.rb +2 -2
  16. data/fixtures/blog-sources-app/config.rb +2 -5
  17. data/fixtures/blog-sources-no-date-app/config.rb +2 -5
  18. data/fixtures/blog-sources-no-day-app/config.rb +2 -5
  19. data/fixtures/blog-sources-no-title-app/config.rb +1 -4
  20. data/fixtures/blog-sources-subdirs-app/config.rb +3 -6
  21. data/fixtures/calendar-and-tag-app/config-directory-indexes.rb +3 -3
  22. data/fixtures/calendar-and-tag-app/config.rb +4 -4
  23. data/fixtures/calendar-app/config-directory-indexes.rb +5 -7
  24. data/fixtures/calendar-app/config-only-year.rb +7 -9
  25. data/fixtures/calendar-app/config.rb +5 -7
  26. data/fixtures/calendar-multiblog-app/config.rb +12 -12
  27. data/fixtures/custom-collections-app/config-blog-prefix.rb +7 -7
  28. data/fixtures/custom-collections-app/config-directory-indexes.rb +6 -6
  29. data/fixtures/custom-collections-app/config.rb +6 -6
  30. data/fixtures/custom-collections-multiblog-app/config.rb +14 -14
  31. data/fixtures/custom-collections-sources-app/config.rb +5 -5
  32. data/fixtures/custom-permalinks-app/config-directory-indexes.rb +3 -3
  33. data/fixtures/custom-permalinks-app/config.rb +3 -3
  34. data/fixtures/default-template-app/Gemfile +5 -5
  35. data/fixtures/default-template-app/config.rb +11 -11
  36. data/fixtures/filename-date-app/config.rb +1 -1
  37. data/fixtures/future-date-app/config.rb +2 -2
  38. data/fixtures/indexes-app/config.rb +2 -2
  39. data/fixtures/lang-path-app/config.rb +2 -2
  40. data/fixtures/layouts-app/config.rb +1 -1
  41. data/fixtures/paginate-app/config-directory-indexes.rb +12 -14
  42. data/fixtures/paginate-app/config-paginate-off.rb +12 -14
  43. data/fixtures/paginate-app/config.rb +12 -14
  44. data/fixtures/paginate-multiblog-app/config.rb +13 -13
  45. data/fixtures/permalink-app/config.rb +3 -6
  46. data/fixtures/preview-app/config.rb +2 -2
  47. data/fixtures/published-app/config.rb +2 -2
  48. data/fixtures/tags-app/config-directory-indexes.rb +5 -5
  49. data/fixtures/tags-app/config.rb +5 -5
  50. data/fixtures/tags-multiblog-app/config.rb +10 -10
  51. data/lib/middleman-blog.rb +6 -8
  52. data/lib/middleman-blog/blog_article.rb +20 -40
  53. data/lib/middleman-blog/blog_data.rb +20 -27
  54. data/lib/middleman-blog/calendar_pages.rb +8 -14
  55. data/lib/middleman-blog/commands/article.rb +54 -63
  56. data/lib/middleman-blog/custom_pages.rb +8 -9
  57. data/lib/middleman-blog/extension.rb +7 -8
  58. data/lib/middleman-blog/helpers.rb +17 -26
  59. data/lib/middleman-blog/paginator.rb +5 -4
  60. data/lib/middleman-blog/tag_pages.rb +11 -23
  61. data/lib/middleman-blog/truncate_html.rb +8 -7
  62. data/lib/middleman-blog/uri_templates.rb +31 -17
  63. data/lib/middleman-blog/version.rb +1 -3
  64. data/lib/middleman_extension.rb +1 -1
  65. data/middleman-blog.gemspec +15 -15
  66. data/spec/spec_helper.rb +1 -4
  67. data/spec/uri_templates_spec.rb +23 -30
  68. metadata +10 -9
@@ -1,15 +1,12 @@
1
1
  require 'middleman-blog/uri_templates'
2
2
 
3
3
  module Middleman
4
-
5
4
  module Blog
6
-
7
5
  ##
8
6
  # A sitemap resource manipulator that adds a tag page to the sitemap for
9
7
  # each tag in the associated blog
10
8
  ##
11
9
  class TagPages
12
-
13
10
  include UriTemplates
14
11
 
15
12
  ##
@@ -18,7 +15,7 @@ module Middleman
18
15
  # @param app [Object] Middleman app
19
16
  # @param blog_controller [Object] Blog controller
20
17
  ##
21
- def initialize( app, blog_controller )
18
+ def initialize(app, blog_controller)
22
19
  @sitemap = app.sitemap
23
20
  @blog_controller = blog_controller
24
21
  @tag_link_template = uri_template blog_controller.options.taglink
@@ -33,8 +30,8 @@ module Middleman
33
30
  # @param tag [String] Tag name
34
31
  # @return [String] Safe Tag URL
35
32
  ##
36
- def link( tag )
37
- apply_uri_template @tag_link_template, tag: safe_parameterize( tag )
33
+ def link(tag)
34
+ apply_uri_template @tag_link_template, tag: safe_parameterize(tag)
38
35
  end
39
36
 
40
37
  ##
@@ -43,14 +40,12 @@ module Middleman
43
40
  # @param resources [Object] Tag name
44
41
  # @return [void]
45
42
  ##
46
- def manipulate_resource_list( resources )
47
-
43
+ def manipulate_resource_list(resources)
48
44
  return resources unless @generate_tag_pages
49
45
 
50
- resources + @blog_data.tags.map do | tag, articles |
51
- tag_page_resource( tag, articles )
46
+ resources + @blog_data.tags.map do |tag, articles|
47
+ tag_page_resource(tag, articles)
52
48
  end
53
-
54
49
  end
55
50
 
56
51
  private
@@ -64,27 +59,20 @@ module Middleman
64
59
  #
65
60
  # @todo Can we inject the correct locale into the metadata here
66
61
  ##
67
- def tag_page_resource( tag, articles )
68
-
69
- Sitemap::ProxyResource.new( @sitemap, link( tag ), @tag_template ).tap do | p |
70
-
62
+ def tag_page_resource(tag, articles)
63
+ Sitemap::ProxyResource.new(@sitemap, link(tag), @tag_template).tap do |p|
71
64
  # Detect "formatted" tag in first article - trying to guess the correct format to show
72
65
  # tagname = articles.first.tags.detect { |article_tag| safe_parameterize(article_tag) == tag }
73
66
 
74
67
  # Add metadata in local variables so it's accessible to later extensions
75
68
  p.add_metadata locals: {
76
- 'page_type' => 'tag',
77
- 'tagname' => tag,
78
- 'articles' => articles,
69
+ 'page_type' => 'tag',
70
+ 'tagname' => tag,
71
+ 'articles' => articles,
79
72
  'blog_controller' => @blog_controller
80
73
  }
81
-
82
74
  end
83
-
84
75
  end
85
-
86
76
  end
87
-
88
77
  end
89
-
90
78
  end
@@ -1,5 +1,5 @@
1
1
  begin
2
- require "nokogiri"
2
+ require 'nokogiri'
3
3
  rescue LoadError
4
4
  raise "Nokogiri is required for blog post summaries. Add 'nokogiri' to your Gemfile."
5
5
  end
@@ -13,7 +13,7 @@ module TruncateHTML
13
13
  doc.inner_html
14
14
  end
15
15
 
16
- def self.truncate_at_length(text, max_length, ellipsis = "...")
16
+ def self.truncate_at_length(text, max_length, ellipsis = '...')
17
17
  ellipsis_length = ellipsis.length
18
18
  text = text.encode('UTF-8') if text.respond_to?(:encode)
19
19
  doc = Nokogiri::HTML::DocumentFragment.parse text
@@ -31,12 +31,14 @@ module NokogiriTruncator
31
31
  module NodeWithChildren
32
32
  def truncate(max_length, ellipsis)
33
33
  return self if inner_text.length <= max_length
34
- truncated_node = self.dup
34
+
35
+ truncated_node = dup
35
36
  truncated_node.children.remove
36
37
 
37
- self.children.each do |node|
38
+ children.each do |node|
38
39
  remaining_length = max_length - truncated_node.inner_text.length
39
40
  break if remaining_length <= 0
41
+
40
42
  truncated_node.add_child node.truncate(remaining_length, ellipsis)
41
43
  end
42
44
  truncated_node
@@ -54,15 +56,14 @@ module NokogiriTruncator
54
56
  end
55
57
 
56
58
  module CommentNode
57
- def truncate(*args)
59
+ def truncate(*_args)
58
60
  # Don't truncate comments, since they aren't visible
59
61
  self
60
62
  end
61
63
  end
62
-
63
64
  end
64
65
 
65
66
  Nokogiri::HTML::DocumentFragment.send(:include, NokogiriTruncator::NodeWithChildren)
66
67
  Nokogiri::XML::Element.send(:include, NokogiriTruncator::NodeWithChildren)
67
68
  Nokogiri::XML::Text.send(:include, NokogiriTruncator::TextNode)
68
- Nokogiri::XML::Comment.send(:include, NokogiriTruncator::CommentNode)
69
+ Nokogiri::XML::Comment.send(:include, NokogiriTruncator::CommentNode)
@@ -4,12 +4,9 @@ require 'active_support/inflector'
4
4
  require 'active_support/inflector/transliterate'
5
5
 
6
6
  module Middleman
7
-
8
7
  module Blog
9
-
10
8
  # Handy methods for dealing with URI templates. Mix into whatever class.
11
9
  module UriTemplates
12
-
13
10
  module_function
14
11
 
15
12
  ##
@@ -22,9 +19,7 @@ module Middleman
22
19
  ##
23
20
  def uri_template(tmpl_src)
24
21
  # Support the RFC6470 templates directly if people use them
25
- if tmpl_src.include?(':')
26
- tmpl_src = tmpl_src.gsub(/:([A-Za-z0-9]+)/, '{\1}')
27
- end
22
+ tmpl_src = tmpl_src.gsub(/:([A-Za-z0-9]+)/, '{\1}') if tmpl_src.include?(':')
28
23
 
29
24
  Addressable::Template.new ::Middleman::Util.normalize_path(tmpl_src)
30
25
  end
@@ -52,15 +47,37 @@ module Middleman
52
47
  template.extract(path, BlogTemplateProcessor)
53
48
  end
54
49
 
55
- ##
56
50
  # Parametrize a string preserving any multi-byte characters
57
51
  # Reimplementation of this, preserves un-transliterate-able multibyte chars.
58
52
  #
59
53
  # @see http://api.rubyonrails.org/classes/ActiveSupport/Inflector.html#method-i-parameterize
60
- ##
61
- def safe_parameterize(str)
62
- parameterized_string = ::ActiveSupport::Inflector.transliterate(str.to_s)
63
- parameterized_string.parameterize
54
+ def safe_parameterize(str, sep = '-')
55
+ # Remove ending ?
56
+ str = str.to_s.gsub(/\?$/, '')
57
+
58
+ # Reimplementation of http://api.rubyonrails.org/classes/ActiveSupport/Inflector.html#method-i-parameterize that preserves un-transliterate-able multibyte chars.
59
+ parameterized_string = ::ActiveSupport::Inflector.transliterate(str.to_s).downcase
60
+ parameterized_string.gsub!(/[^a-z0-9\-_\?]+/, sep)
61
+
62
+ # Check for multibytes and sub back in
63
+ parameterized_string.chars.to_a.each_with_index do |char, i|
64
+ next unless char == '?' && str[i].bytes.count != 1
65
+
66
+ parameterized_string[i] = str[i]
67
+ end
68
+
69
+ re_sep = ::Regexp.escape(sep)
70
+
71
+ # No more than one of the separator in a row.
72
+ parameterized_string.gsub!(/#{re_sep}{2,}/, sep)
73
+
74
+ # Remove leading/trailing separator.
75
+ parameterized_string.gsub!(/^#{re_sep}|#{re_sep}$/, '')
76
+ parameterized_string.tr!('_', '-')
77
+ parameterized_string.delete!('?')
78
+
79
+ # Replace all ?
80
+ parameterized_string
64
81
  end
65
82
 
66
83
  ##
@@ -71,7 +88,7 @@ module Middleman
71
88
  # @return [Hash] parameters
72
89
  ##
73
90
  def date_to_params(date)
74
- return {
91
+ {
75
92
  year: date.year.to_s,
76
93
  month: date.month.to_s.rjust(2, '0'),
77
94
  day: date.day.to_s.rjust(2, '0')
@@ -81,13 +98,12 @@ module Middleman
81
98
  ##
82
99
  #
83
100
  ##
84
- def extract_directory_path( article_path )
101
+ def extract_directory_path(article_path)
85
102
  uri = Addressable::URI.parse article_path
86
103
 
87
104
  # Remove file extension from the article path
88
- directory_path = uri.path.gsub( uri.extname, '' )
105
+ uri.path.gsub(uri.extname, '')
89
106
  end
90
-
91
107
  end
92
108
 
93
109
  ##
@@ -106,7 +122,5 @@ module Middleman
106
122
  end
107
123
  end
108
124
  end
109
-
110
125
  end
111
-
112
126
  end
@@ -1,7 +1,5 @@
1
1
  module Middleman
2
-
3
2
  module Blog
4
- VERSION = '4.0.2'
3
+ VERSION = '4.0.3'.freeze
5
4
  end
6
-
7
5
  end
@@ -1 +1 @@
1
- require "middleman-blog"
1
+ require 'middleman-blog'
@@ -1,25 +1,25 @@
1
1
  # -*- encoding: utf-8 -*-
2
- $:.push File.expand_path('../lib', __FILE__)
3
- require 'middleman-blog/version'
2
+ $:.push File.expand_path( "../lib", __FILE__ )
3
+ require "middleman-blog/version"
4
4
 
5
- Gem::Specification.new do |s|
5
+ Gem::Specification.new do | s |
6
6
 
7
- s.name = 'middleman-blog'
7
+ s.name = "middleman-blog"
8
8
  s.version = Middleman::Blog::VERSION
9
9
  s.platform = Gem::Platform::RUBY
10
- s.authors = ['Thomas Reynolds', 'Ben Hollis', 'Ian Warner']
11
- s.email = ['me@tdreyno.com', 'ben@benhollis.net', 'ian.warner@drykiss.com']
12
- s.homepage = 'https://github.com/middleman/middleman-blog'
10
+ s.authors = [ "Thomas Reynolds", "Ben Hollis", "Ian Warner" ]
11
+ s.email = [ "me@tdreyno.com", "ben@benhollis.net", "ian.warner@drykiss.com" ]
12
+ s.homepage = "https://github.com/middleman/middleman-blog"
13
13
  s.summary = %q{ Blog engine for Middleman }
14
14
  s.description = %q{ Blog engine for Middleman }
15
- s.license = 'MIT'
16
- s.files = `git ls-files -z`.split("\0")
17
- s.test_files = `git ls-files -z -- {fixtures,features}/*`.split("\0")
18
- s.require_paths = ['lib']
19
- s.required_ruby_version = '>= 2.0.0'
15
+ s.license = "MIT"
16
+ s.files = `git ls-files -z`.split( "\0" )
17
+ s.test_files = `git ls-files -z -- {fixtures,features}/*`.split( "\0" )
18
+ s.require_paths = [ "lib" ]
19
+ s.required_ruby_version = '>= 2.3.0'
20
20
 
21
- s.add_dependency('middleman-core', ['~> 4.0'])
22
- s.add_dependency('tzinfo', ['>= 0.3.0'])
23
- s.add_dependency('addressable', ['~> 2.3'])
21
+ s.add_dependency( "middleman-core", [ ">= 4.0.0" ] )
22
+ s.add_dependency( "tzinfo", [ ">= 0.3.0" ] )
23
+ s.add_dependency( "addressable", [ "~> 2.3" ] )
24
24
 
25
25
  end
@@ -1,5 +1,2 @@
1
1
  require 'simplecov'
2
- SimpleCov.root( File.expand_path( File.dirname( __FILE__ ) + '/..' ) )
3
-
4
- require 'coveralls'
5
- Coveralls.wear!
2
+ SimpleCov.root(File.expand_path(File.dirname(__FILE__) + '/..'))
@@ -1,5 +1,3 @@
1
- # -*- coding: utf-8 -*-
2
-
3
1
  require 'middleman-blog/uri_templates'
4
2
 
5
3
  describe 'Middleman::Blog::UriTemplates' do
@@ -7,24 +5,24 @@ describe 'Middleman::Blog::UriTemplates' do
7
5
 
8
6
  describe 'safe_parameterize' do
9
7
  it 'can parameterize normal strings' do
10
- expect(safe_parameterize('Some FUN stuff!')) == 'some-fun-stuff'
8
+ expect(safe_parameterize('Some FUN stuff!')).to eq 'some-fun-stuff'
11
9
  end
12
10
 
13
11
  it "doesn't mangle unicode strings" do
14
- expect(safe_parameterize('☆☆☆')) == '☆☆☆'
15
- expect(safe_parameterize('明日がある')) == '明日がある'
12
+ expect(safe_parameterize('☆☆☆')).to eq '☆☆☆'
13
+ expect(safe_parameterize('明日がある')).to eq '明日がある'
16
14
  end
17
15
 
18
16
  it "still transliterates when it's safe" do
19
- expect(safe_parameterize('Schlagwörter')) == 'schlagworter'
17
+ expect(safe_parameterize('Schlagwörter')).to eq 'schlagworter'
20
18
  end
21
19
 
22
- it "can handle mixed strings" do
23
- expect(safe_parameterize('What ☆☆☆!')) == 'what-☆☆☆'
20
+ it 'can handle mixed strings' do
21
+ expect(safe_parameterize('What ☆☆☆!')).to eq 'what-☆☆☆'
24
22
  end
25
23
 
26
- it "can handle numbers" do
27
- expect(safe_parameterize(1)) == '1'
24
+ it 'can handle numbers' do
25
+ expect(safe_parameterize(1)).to eq '1'
28
26
  end
29
27
  end
30
28
 
@@ -33,47 +31,42 @@ describe 'Middleman::Blog::UriTemplates' do
33
31
  template = uri_template('{year}/{month}/{day}/{title}/{+path}')
34
32
  params = extract_params(template, '2013/12/13/foo-bar/foo/bar.html')
35
33
 
36
- expect(params['year']) == '2013'
37
- expect(params['month']) == '12'
38
- expect(params['day']) == '13'
39
- expect(params['title']) == 'foo-bar'
40
- expect(params['path']) == 'foo/bar.html'
34
+ expect(params['year']).to eq '2013'
35
+ expect(params['month']).to eq '12'
36
+ expect(params['day']).to eq '13'
37
+ expect(params['title']).to eq 'foo-bar'
38
+ expect(params['path']).to eq 'foo/bar.html'
41
39
  end
42
40
 
43
41
  it 'returns nil if there is no match' do
44
42
  template = uri_template('{year}/{month}/{day}/{title}/{+path}')
45
- expect(extract_params(template, 'foo/bar.html')) == nil
43
+ expect(extract_params(template, 'foo/bar.html')).nil?
46
44
  end
47
45
 
48
46
  it 'returns nil if there is no match in the date bits' do
49
47
  template = uri_template('{year}/{month}/{day}/{title}/{+path}')
50
- params = extract_params(template, '2a13/1a2/1s3/foo-bar/foo/bar.html')
48
+ extract_params(template, '2a13/1a2/1s3/foo-bar/foo/bar.html')
51
49
  end
52
50
 
53
51
  it 'matches even when the path contains spaces' do
54
52
  template = uri_template('{year}/{month}/{day}/{title}/{+path}')
55
53
  params = extract_params(template, '2013/12/13/foo - bar/foo/bar.html')
56
54
 
57
- expect(params['year']) == '2013'
58
- expect(params['month']) == '12'
59
- expect(params['day']) == '13'
60
- expect(params['title']) == 'foo - bar'
61
- expect(params['path']) == 'foo/bar.html'
55
+ expect(params['year']).to eq '2013'
56
+ expect(params['month']).to eq '12'
57
+ expect(params['day']).to eq '13'
58
+ expect(params['title']).to eq 'foo - bar'
59
+ expect(params['path']).to eq 'foo/bar.html'
62
60
  end
63
61
  end
64
62
 
65
63
  describe 'extract_directory_path' do
66
-
67
64
  it 'can extract a directory path' do
68
-
69
- template = uri_template( '{year}/{month}/{day}/{title}/{+path}' )
70
- params = extract_params( template, '2013/12/13/foo-bar/foo/bar.html' )
65
+ template = uri_template('{year}/{month}/{day}/{title}/{+path}')
66
+ params = extract_params(template, '2013/12/13/foo-bar/foo/bar.html')
71
67
  article_path = apply_uri_template template, params
72
68
 
73
- expect( extract_directory_path( article_path ) ) == '2013-12-13-foo-bar-foo-bar'
74
-
69
+ expect(extract_directory_path(article_path)).to eq '2013/12/13/foo-bar/foo/bar'
75
70
  end
76
-
77
71
  end
78
-
79
72
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: middleman-blog
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.0.2
4
+ version: 4.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Thomas Reynolds
@@ -10,22 +10,22 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2017-05-22 00:00:00.000000000 Z
13
+ date: 2018-12-27 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: middleman-core
17
17
  requirement: !ruby/object:Gem::Requirement
18
18
  requirements:
19
- - - "~>"
19
+ - - ">="
20
20
  - !ruby/object:Gem::Version
21
- version: '4.0'
21
+ version: 4.0.0
22
22
  type: :runtime
23
23
  prerelease: false
24
24
  version_requirements: !ruby/object:Gem::Requirement
25
25
  requirements:
26
- - - "~>"
26
+ - - ">="
27
27
  - !ruby/object:Gem::Version
28
- version: '4.0'
28
+ version: 4.0.0
29
29
  - !ruby/object:Gem::Dependency
30
30
  name: tzinfo
31
31
  requirement: !ruby/object:Gem::Requirement
@@ -65,11 +65,13 @@ extra_rdoc_files: []
65
65
  files:
66
66
  - ".editorconfig"
67
67
  - ".gitignore"
68
+ - ".rubocop.yml"
68
69
  - ".travis.yml"
69
70
  - ".yardopts"
70
71
  - CHANGELOG.md
71
72
  - CONTRIBUTING.md
72
73
  - Gemfile
74
+ - Gemfile-4.x
73
75
  - ISSUE_TEMPLATE.md
74
76
  - LICENSE.md
75
77
  - README.md
@@ -371,15 +373,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
371
373
  requirements:
372
374
  - - ">="
373
375
  - !ruby/object:Gem::Version
374
- version: 2.0.0
376
+ version: 2.3.0
375
377
  required_rubygems_version: !ruby/object:Gem::Requirement
376
378
  requirements:
377
379
  - - ">="
378
380
  - !ruby/object:Gem::Version
379
381
  version: '0'
380
382
  requirements: []
381
- rubyforge_project:
382
- rubygems_version: 2.6.11
383
+ rubygems_version: 3.0.1
383
384
  signing_key:
384
385
  specification_version: 4
385
386
  summary: Blog engine for Middleman