middleman-blog 3.5.0 → 3.5.1

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: 08ba0a40e858e3199220173897c437db62c6513e
4
- data.tar.gz: 9d38d7176eb91b89ad0c8f125a2271553d3dbacc
3
+ metadata.gz: 9607656cf709f1ad3a4cc7ec060e3c3cd5e73ae3
4
+ data.tar.gz: 169bd0122267d51e7768885fdfa3a782d6a7f9af
5
5
  SHA512:
6
- metadata.gz: 888e2bf9c611950366eeb2c65d2cee9f08914d0e0ceec9acdb65f42a940f581b23aedcf38cacf5108005f19009263f607b39a0ae6308c899d391be8aa6d5da50
7
- data.tar.gz: 18a3c29946fc65bf638b736a8fde6873ebc67eb9e9c99491e2dbd11598d37e0705795ec0e16a21d2bd50b99ff70d5acf3a273e4fa1807d36ac33a01fe640888d
6
+ metadata.gz: 0bacecc695f007c53ba6df3b8dd259768b151b2b783f16a19762dad8fe5a90014c62c453e3c26c31614ebac8c58feb79cdaf85eeecc2eed8daeff8ec48ebe5cb
7
+ data.tar.gz: fbc3ce009ad08ccce6c644b4741dde9e36cdb1d4a00ca10514d4bd9afd1fa0218af78ad70f788a3d6d7eb783e2136c6f37d6ff08e5150a509a09b9719ec5351a
data/CHANGELOG.md CHANGED
@@ -1,4 +1,12 @@
1
- master
1
+ 3.5.1
2
+ ===
3
+
4
+ * Remove a broken bracket in the blog template. #181
5
+ * Fix transliteration of strings into URL slugs to still transliterate when it can but not smash multibyte chars. #183
6
+ * Only match source URI templates if the date components match what a date would look like, and avoid throwing when companion files do not have an article. #184
7
+ * Re-support spaces in blog article source paths. #185
8
+
9
+ 3.5.0
2
10
  ===
3
11
 
4
12
  * Add support for internationalization and locale-specific articles. #156
data/README.md CHANGED
@@ -21,7 +21,7 @@ activate :blog
21
21
 
22
22
  ## Learn More
23
23
 
24
- See [the blog extension guide](http://middlemanapp.com/blogging/) for detailed information on configuring and using the blog extension.
24
+ See [the blog extension guide](http://middlemanapp.com/basics/blogging/) for detailed information on configuring and using the blog extension.
25
25
 
26
26
  Additionally, up-to-date generated code documentation is available on [RubyDoc].
27
27
 
data/Rakefile CHANGED
@@ -17,7 +17,15 @@ end
17
17
 
18
18
  require 'rake/clean'
19
19
 
20
- task :test => ["cucumber"]
20
+ desc "Run tests, both RSpec and Cucumber"
21
+ task :test => [:spec, :cucumber]
22
+
23
+ require 'rspec/core/rake_task'
24
+ desc "Run RSpec"
25
+ RSpec::Core::RakeTask.new do |spec|
26
+ spec.pattern = 'spec/**/*_spec.rb'
27
+ spec.rspec_opts = ['--color', '--format nested']
28
+ end
21
29
 
22
30
  begin
23
31
  require 'cane/rake_task'
@@ -78,7 +78,7 @@ module Middleman
78
78
  used_resources = []
79
79
 
80
80
  resources.each do |resource|
81
- if (params = @source_template.extract(resource.path))
81
+ if (params = extract_params(@source_template, resource.path))
82
82
  article = convert_to_article(resource)
83
83
  next unless publishable?(article)
84
84
 
@@ -92,26 +92,25 @@ module Middleman
92
92
 
93
93
  @_articles << article
94
94
 
95
- elsif (params = @subdir_template.extract(resource.path))
95
+ elsif (params = extract_params(@subdir_template, resource.path))
96
96
  # It's not an article, but it's thhe companion files for an article
97
97
  # (in a subdirectory named after the article)
98
98
  # figure out the matching article for this subdirectory file
99
99
 
100
100
  article_path = @source_template.expand(params).to_s
101
101
 
102
- article = @app.sitemap.find_resource_by_path(article_path)
103
- raise "Article for #{resource.path} not found" if article.nil?
102
+ if article = @app.sitemap.find_resource_by_path(article_path)
103
+ # The article may not yet have been processed, so convert it here.
104
+ article = convert_to_article(article)
105
+ next unless publishable?(article)
104
106
 
105
- # The article may not yet have been processed, so convert it here.
106
- article = convert_to_article(article)
107
- next unless publishable?(article)
108
-
109
- # The subdir path is the article path with the index file name
110
- # or file extension stripped off.
111
- path = params.fetch('path')
112
- new_destination_path = template_path @subdir_permalink_template, article, path: path
107
+ # The subdir path is the article path with the index file name
108
+ # or file extension stripped off.
109
+ path = params.fetch('path')
110
+ new_destination_path = template_path @subdir_permalink_template, article, path: path
113
111
 
114
- resource.destination_path = Middleman::Util.normalize_path(new_destination_path)
112
+ resource.destination_path = Middleman::Util.normalize_path(new_destination_path)
113
+ end
115
114
  end
116
115
 
117
116
  used_resources << resource
@@ -4,7 +4,7 @@
4
4
  <meta charset="utf-8" />
5
5
  <meta http-equiv='X-UA-Compatible' content='IE=edge;chrome=1' />
6
6
  <title>Blog Title<%= ' - ' + current_article.title unless current_article.nil? %></title>
7
- <%= feed_tag :atom, "#{blog.options.prefix.to_s}/feed.xml"), title: "Atom Feed" %>
7
+ <%= feed_tag :atom, "#{blog.options.prefix.to_s}/feed.xml", title: "Atom Feed" %>
8
8
  </head>
9
9
  <body>
10
10
 
@@ -1,4 +1,7 @@
1
1
  require 'addressable/template'
2
+ require 'middleman-core/util'
3
+ require 'active_support/inflector'
4
+ require 'active_support/inflector/transliterate'
2
5
 
3
6
  module Middleman
4
7
  module Blog
@@ -32,14 +35,36 @@ module Middleman
32
35
  ::Middleman::Util.normalize_path Addressable::URI.unencode(template.expand(data)).to_s
33
36
  end
34
37
 
35
- # Parameterize a string only if it does not contain UTF-8 characters
38
+ # Use a template to extract parameters from a path, and validate some special (date)
39
+ # keys. Returns nil if the special keys don't match.
40
+ #
41
+ # @param [Addressable::Template] template
42
+ # @param [String] path
43
+ def extract_params(template, path)
44
+ params = template.extract(path, BlogTemplateProcessor)
45
+ end
46
+
47
+ # Parameterize a string preserving any multibyte characters
36
48
  def safe_parameterize(str)
37
- if str.chars.all? { |c| c.bytes.count == 1 }
38
- str.parameterize
39
- else
40
- # At least change spaces to dashes
41
- str.gsub(/\s+/, '-')
49
+ sep = '-'
50
+
51
+ # Reimplementation of http://api.rubyonrails.org/classes/ActiveSupport/Inflector.html#method-i-parameterize that preserves un-transliterate-able multibyte chars.
52
+ parameterized_string = ActiveSupport::Inflector.transliterate(str).downcase
53
+ parameterized_string.gsub!(/[^a-z0-9\-_\?]+/, sep)
54
+
55
+ parameterized_string.chars.to_a.each_with_index do |char, i|
56
+ if char == '?' && str[i].bytes.count != 1
57
+ parameterized_string[i] = str[i]
58
+ end
42
59
  end
60
+
61
+ re_sep = Regexp.escape(sep)
62
+ # No more than one of the separator in a row.
63
+ parameterized_string.gsub!(/#{re_sep}{2,}/, sep)
64
+ # Remove leading/trailing separator.
65
+ parameterized_string.gsub!(/^#{re_sep}|#{re_sep}$/, '')
66
+
67
+ parameterized_string
43
68
  end
44
69
 
45
70
  # Convert a date into a hash of components to strings
@@ -54,5 +79,20 @@ module Middleman
54
79
  }
55
80
  end
56
81
  end
82
+
83
+ # A special template processor that validates date fields
84
+ # and has an extra-permissive default regex.
85
+ #
86
+ # See https://github.com/sporkmonger/addressable/blob/master/lib/addressable/template.rb#L279
87
+ class BlogTemplateProcessor
88
+ def self.match(name)
89
+ case name
90
+ when 'year' then '\d{4}'
91
+ when 'month' then '\d{2}'
92
+ when 'day' then '\d{2}'
93
+ else '.*?'
94
+ end
95
+ end
96
+ end
57
97
  end
58
98
  end
@@ -1,5 +1,5 @@
1
1
  module Middleman
2
2
  module Blog
3
- VERSION = "3.5.0"
3
+ VERSION = "3.5.1"
4
4
  end
5
5
  end
@@ -0,0 +1,5 @@
1
+ require 'simplecov'
2
+ SimpleCov.root(File.expand_path(File.dirname(__FILE__) + '/..'))
3
+
4
+ require 'coveralls'
5
+ Coveralls.wear!
@@ -0,0 +1,60 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ require 'middleman-blog/uri_templates'
4
+
5
+ describe 'Middleman::Blog::UriTemplates' do
6
+ include Middleman::Blog::UriTemplates
7
+
8
+ describe 'safe_parameterize' do
9
+ it 'can parameterize normal strings' do
10
+ safe_parameterize('Some FUN stuff!').should == 'some-fun-stuff'
11
+ end
12
+
13
+ it "doesn't mangle unicode strings" do
14
+ safe_parameterize('☆☆☆').should == '☆☆☆'
15
+ safe_parameterize('明日がある').should == '明日がある'
16
+ end
17
+
18
+ it "still transliterates when it's safe" do
19
+ safe_parameterize('Schlagwörter').should == 'schlagworter'
20
+ end
21
+
22
+ it "can handle mixed strings" do
23
+ safe_parameterize('What ☆☆☆!').should == 'what-☆☆☆'
24
+ end
25
+ end
26
+
27
+ describe 'extract_params' do
28
+ it 'matches correctly' do
29
+ template = uri_template('{year}/{month}/{day}/{title}/{+path}')
30
+ params = extract_params(template, '2013/12/13/foo-bar/foo/bar.html')
31
+
32
+ params['year'].should == '2013'
33
+ params['month'].should == '12'
34
+ params['day'].should == '13'
35
+ params['title'].should == 'foo-bar'
36
+ params['path'].should == 'foo/bar.html'
37
+ end
38
+
39
+ it 'returns nil if there is no match' do
40
+ template = uri_template('{year}/{month}/{day}/{title}/{+path}')
41
+ extract_params(template, 'foo/bar.html').should == nil
42
+ end
43
+
44
+ it 'returns nil if there is no match in the date bits' do
45
+ template = uri_template('{year}/{month}/{day}/{title}/{+path}')
46
+ params = extract_params(template, '2a13/1a2/1s3/foo-bar/foo/bar.html')
47
+ end
48
+
49
+ it 'matches even when the path contains spaces' do
50
+ template = uri_template('{year}/{month}/{day}/{title}/{+path}')
51
+ params = extract_params(template, '2013/12/13/foo - bar/foo/bar.html')
52
+
53
+ params['year'].should == '2013'
54
+ params['month'].should == '12'
55
+ params['day'].should == '13'
56
+ params['title'].should == 'foo - bar'
57
+ params['path'].should == 'foo/bar.html'
58
+ end
59
+ end
60
+ 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: 3.5.0
4
+ version: 3.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Thomas Reynolds
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-11-29 00:00:00.000000000 Z
12
+ date: 2013-12-16 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: middleman-core
@@ -341,6 +341,8 @@ files:
341
341
  - lib/middleman-blog/version.rb
342
342
  - lib/middleman_extension.rb
343
343
  - middleman-blog.gemspec
344
+ - spec/spec_helper.rb
345
+ - spec/uri_templates_spec.rb
344
346
  homepage: https://github.com/middleman/middleman-blog
345
347
  licenses:
346
348
  - MIT