octopress-filters 1.2.4 → 1.2.5

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: b2357cb37590cb64fbeaaecd05376b426165491d
4
- data.tar.gz: 7c1ae0b31902592000b63670e4e6d1bac628e391
3
+ metadata.gz: 11cba7cb5a1ea7328d01334b1f6e9e17dced1c10
4
+ data.tar.gz: 7fbcb1e3b70bb1dd1cff8f510552921163611e44
5
5
  SHA512:
6
- metadata.gz: 6bf6d18153c2c0033253f8615065cf292cdc463efcae779a3a32c9f87570d3cdef703996b59bb77a9d46c0eacb6aaf7e4680b305ae9331b631c7eed89db3b8f1
7
- data.tar.gz: f7c237f990bb7c18c6e33443d5c848c2c97aed282476cfbb874864cfeb293cb71d8a9b869c182f0600751c9c1a9b317149f466b020cc9df30d71320199dc557e
6
+ metadata.gz: 7e649ed873418aafb09229b1336d5da8b618dee985e279be8ca49ad094ec77e1f062aff617cfe3c98625f66212ff3cccddf89aae54cd78c8fe1fe9080b5b5c78
7
+ data.tar.gz: 6c856e68115ed7ed6efe595876838f0a23e8d6c15f5e0f7369ee6a7af0ce28359d618e6a1af1a28755c4607725d9a0fa7cf0005a218d4be41a6a556cfe9793b7
data/CHANGELOG.md CHANGED
@@ -1,12 +1,18 @@
1
1
  # Changelog
2
2
 
3
+ ### 1.2.5 - 2015-01-24
4
+
5
+ - New: join_url filter, works like File.join.
6
+ - New: smart_slash filter. Appends trailing slashes to URLs when appropriate.
7
+ - Fix: Ensure a baseurl isn't added twice when expanding URLs.
8
+
3
9
  ### 1.2.4 - 2015-01-23
4
10
 
5
11
  - Simple domains won't end in trailing slashes (eg: http://example.com doesn't need a trailing slash).
6
12
 
7
13
  ### 1.2.3 - 2015-01-23
8
14
 
9
- - Full urls will end with trailing slashes when appropriate
15
+ - Full URLs will end with trailing slashes when appropriate
10
16
 
11
17
  ### 1.2.2 - 2015-01-23
12
18
 
@@ -10,13 +10,16 @@ require "titlecase"
10
10
  module Octopress
11
11
  module Filters
12
12
 
13
- # Returns the site's config root or '/' if the config isn't set
13
+ # Returns the site's baseurl or '/' if the config isn't set
14
14
  #
15
15
  def root
16
- baseurl = Octopress.site.config['baseurl'] || Octopress.site.config['root']
17
16
  baseurl.nil? ? '/' : File.join('/', baseurl)
18
17
  end
19
18
 
19
+ def baseurl
20
+ Octopress.site.config['baseurl'] || Octopress.site.config['root']
21
+ end
22
+
20
23
  def site_url
21
24
  @url ||= begin
22
25
  File.join(Octopress.site.config['url'], root)
@@ -52,6 +55,11 @@ module Octopress
52
55
  input.gsub(/\n{2,}/, "\n").gsub(/^ +\n/,"")
53
56
  end
54
57
 
58
+ # Join url fragments
59
+ def join_url(*input)
60
+ smart_slash(File.join(input))
61
+ end
62
+
55
63
  # Join newlines
56
64
  def join_lines(input, separator='')
57
65
  compact_newlines(input).strip.gsub(/\s*\n\s*/, separator)
@@ -76,7 +84,17 @@ module Octopress
76
84
  # e.g. /images/awesome.gif => http://example.com/images/awesome.gif
77
85
  #
78
86
  def full_urls(input)
79
- expand_urls(input, site_url)
87
+ expand_urls(strip_baseurls(input), site_url)
88
+ end
89
+
90
+ # If a baseurl has been manually added to a url,
91
+ # this ensures it isn't added twice
92
+ def strip_baseurls(input)
93
+ if baseurl
94
+ input.gsub /(\s+(href|src|poster)\s*=\s*["|'])(\/#{baseurl})/, '\1'
95
+ else
96
+ input
97
+ end
80
98
  end
81
99
 
82
100
  # Prepend a url with the full site url
@@ -99,18 +117,22 @@ module Octopress
99
117
  #
100
118
  def expand_url(input, url=nil)
101
119
  url ||= root
120
+
102
121
  url = if input.start_with?("http", url)
103
122
  input
104
123
  else
105
124
  File.join(url, input)
106
125
  end
107
126
 
108
- # Ensure a trailing slash if a url ends with a directory
109
- if !(url =~ /\.\w+$/)
110
- url = File.join(url, '/')
111
- end
127
+ smart_slash(url)
128
+ end
112
129
 
113
- url
130
+ # Ensure a trailing slash if a url ends with a directory
131
+ def smart_slash(input)
132
+ if !(input =~ /\.\w+$/)
133
+ input = File.join(input, '/')
134
+ end
135
+ input
114
136
  end
115
137
 
116
138
  # Prepend all absolute urls with a url fragment
@@ -122,7 +144,7 @@ module Octopress
122
144
  #
123
145
  def expand_urls(input, url=nil)
124
146
  url ||= root
125
- input.gsub /(\s+(href|src|poster)\s*=\s*["|']{1})(\/[^\/>]{1}[^\"'>]*)/ do
147
+ input.gsub /(\s+(href|src|poster)\s*=\s*["|'])(\/[^\/][^"'>]*)/ do
126
148
  $1 + expand_url($3, url)
127
149
  end
128
150
  end
@@ -1,5 +1,5 @@
1
1
  module Octopress
2
2
  module Filters
3
- VERSION = "1.2.4"
3
+ VERSION = "1.2.5"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: octopress-filters
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.4
4
+ version: 1.2.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brandon Mathis