octopress-filters 1.0.0 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +11 -0
- data/README.md +26 -5
- data/lib/octopress-filters/version.rb +1 -1
- data/lib/octopress-filters.rb +47 -37
- data/octopress-filters.gemspec +2 -0
- data/test/Gemfile +1 -0
- data/test/_expected/canonical.html +4 -0
- data/test/_expected/smartquotes.html +27 -0
- data/test/canonical.html +6 -0
- data/test/smartquotes.html +31 -0
- metadata +38 -2
- data/lib/octopress-filters/utils.rb +0 -42
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 01bc72327b02e3212f41ef3a045e85cc6c57311c
|
4
|
+
data.tar.gz: 7aea28624451226fab505cb081908e682aff8e9f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bbf8bd4f1fab1c633fbe03742b3f9a682e49eb42913b7a71f246d6aefb984aa3d365a3e85d1fa5301ab38d2d45338e3ca572492a72dd33c140b875396edc62df
|
7
|
+
data.tar.gz: a29c5f96babd2df342ca6f54a766d415c0985a64349c6db0f0baf10c47806d9e0a8f5b5e15d619fbd0e9659fed835e420e68379300e0bbf60f11673f287e4546
|
data/CHANGELOG.md
ADDED
data/README.md
CHANGED
@@ -2,8 +2,11 @@
|
|
2
2
|
|
3
3
|
A set of handy liquid filters used by Octopress.
|
4
4
|
|
5
|
-
- full_urls - Replace relative urls with absolute urls.
|
6
|
-
-
|
5
|
+
- full_urls - Replace relative urls with absolute urls (searches for `href` and `src` properties).
|
6
|
+
- full_url - Replace a relative url with an absolute url.
|
7
|
+
- canonical_url - Convert a url to the proper canonical version.
|
8
|
+
- titlecase - Properly capitalize titles with John Gruber’s [Title Case](http://daringfireball.net/2008/05/title_case).
|
9
|
+
- smartquotes - Smartly curl your quotation marks with John Gruber’s [Smarty Pants](http://daringfireball.net/projects/smartypants/).
|
7
10
|
- unorphan - Insert a non-breaking space between the last two words in a title.
|
8
11
|
- sluggify - Replaces all non-word characters in a string with dashes.
|
9
12
|
- classify - An alias for sluggify (seems appropriate when working with CSS class names).
|
@@ -37,17 +40,35 @@ Next add it to your gems list in Jekyll's `_config.yml`
|
|
37
40
|
|
38
41
|
### Full urls
|
39
42
|
|
40
|
-
|
41
|
-
|
43
|
+
Any relative links in your site will be expanded with the `url` configuration in Jekyll's `_config.yml`. This filter only affects urls
|
44
|
+
beginning with `/` inside of `href` or `src` attributes.
|
42
45
|
|
43
46
|
{{ post.content | full_urls }}
|
44
47
|
|
45
|
-
|
48
|
+
You might use this if you're working on an RSS feed, you'll need to be sure all relative urls in your content are expanded to full urls.
|
49
|
+
|
50
|
+
### Full url
|
51
|
+
|
52
|
+
This filter prepends input with the `url` configuration in Jekyll's `_config.yml`.
|
53
|
+
|
54
|
+
{{ post.url | full_url }}
|
55
|
+
|
56
|
+
### Canonical url
|
57
|
+
|
58
|
+
This filter expands the url to be a full url, then removes "index.html" if it is present. Here are some examples.
|
59
|
+
|
60
|
+
{{ "about/index.html" | canonical_url }} //=> http://example.com/about/
|
61
|
+
{{ "about.html" | canonical_url }} //=> http://example.com/about.html
|
62
|
+
{{ "/" | canonical_url }} //=> http://example.com/
|
46
63
|
|
47
64
|
### Titlecase
|
48
65
|
|
49
66
|
{{ post.title | titlecase }} //=> This Is a Properly Capitalized Title
|
50
67
|
|
68
|
+
### Smartquote
|
69
|
+
|
70
|
+
{{ post.content | smartquotes }}
|
71
|
+
|
51
72
|
### Unorphan
|
52
73
|
|
53
74
|
{{ post.title | unorphan }} //=> This Is a Properly Capitalized Title
|
data/lib/octopress-filters.rb
CHANGED
@@ -1,15 +1,23 @@
|
|
1
1
|
require "octopress-filters/version"
|
2
|
-
require "octopress-filters/utils"
|
3
2
|
|
4
3
|
unless defined? Octopress::Ink
|
5
4
|
require "octopress-filters/generator"
|
6
5
|
end
|
7
6
|
|
8
7
|
require "jekyll"
|
8
|
+
require "rubypants-unicode"
|
9
|
+
require "titlecase"
|
9
10
|
|
10
11
|
module Octopress
|
11
12
|
module Filters
|
12
13
|
|
14
|
+
# Returns the site's config root or '/' if the config isn't set
|
15
|
+
#
|
16
|
+
def root
|
17
|
+
root_url = Ink.site.config['root']
|
18
|
+
root_url.nil? ? '/' : File.join('/', root_url)
|
19
|
+
end
|
20
|
+
|
13
21
|
# Escapes HTML content for XML
|
14
22
|
def cdata_escape(input)
|
15
23
|
input.gsub(/<!\[CDATA\[/, '<![CDATA[').gsub(/\]\]>/, ']]>')
|
@@ -18,7 +26,11 @@ module Octopress
|
|
18
26
|
# Returns a title cased string based on John Gruber's title case
|
19
27
|
# Info: http://daringfireball.net/2008/08/title_case_update
|
20
28
|
def titlecase(input)
|
21
|
-
|
29
|
+
input.titlecase
|
30
|
+
end
|
31
|
+
|
32
|
+
def smartquotes(input)
|
33
|
+
RubyPants.new(input).to_html
|
22
34
|
end
|
23
35
|
|
24
36
|
# Formats a string for use as a css classname, removing illegal characters
|
@@ -43,34 +55,10 @@ module Octopress
|
|
43
55
|
input.sub(/\s+(\S+)\s*$/, ' \1')
|
44
56
|
end
|
45
57
|
|
46
|
-
#
|
58
|
+
# Convert url input into a standard canonical url
|
47
59
|
#
|
48
|
-
|
49
|
-
|
50
|
-
#
|
51
|
-
# Returns the modified url, e.g /blog
|
52
|
-
#
|
53
|
-
def expand_url(input, url=nil)
|
54
|
-
url ||= root
|
55
|
-
if input =~ /^#{url}/
|
56
|
-
input
|
57
|
-
else
|
58
|
-
File.join(url, input)
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
# Prepend all absolute urls with a url fragment
|
63
|
-
#
|
64
|
-
# input - The content of a page or post
|
65
|
-
# url - The fragment to prepend absolute urls
|
66
|
-
#
|
67
|
-
# Returns input with modified urls
|
68
|
-
#
|
69
|
-
def expand_urls(input, url=nil)
|
70
|
-
url ||= root
|
71
|
-
input.gsub /(\s+(href|src|rel)\s*=\s*["|']{1})(\/[^\/>]{1}[^\"'>]*)/ do
|
72
|
-
$1 + expand_url($3, url)
|
73
|
-
end
|
60
|
+
def canonical_url(input)
|
61
|
+
full_url(input).downcase.sub(/index\.html/, '')
|
74
62
|
end
|
75
63
|
|
76
64
|
# Prepend all urls with the full site url
|
@@ -105,17 +93,39 @@ module Octopress
|
|
105
93
|
end
|
106
94
|
end
|
107
95
|
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
96
|
+
# Prepends input with a url fragment
|
97
|
+
#
|
98
|
+
# input - An absolute url, e.g. /images/awesome.gif
|
99
|
+
# url - The fragment to prepend the input, e.g. /blog
|
100
|
+
#
|
101
|
+
# Returns the modified url, e.g /blog
|
102
|
+
#
|
103
|
+
def expand_url(input, url=nil)
|
104
|
+
url ||= root
|
105
|
+
if input =~ /^#{url}/
|
106
|
+
input
|
107
|
+
else
|
108
|
+
File.join(url, input)
|
109
|
+
end
|
110
|
+
end
|
112
111
|
|
113
|
-
#
|
112
|
+
# Prepend all absolute urls with a url fragment
|
114
113
|
#
|
115
|
-
|
116
|
-
|
117
|
-
|
114
|
+
# input - The content of a page or post
|
115
|
+
# url - The fragment to prepend absolute urls
|
116
|
+
#
|
117
|
+
# Returns input with modified urls
|
118
|
+
#
|
119
|
+
def expand_urls(input, url=nil)
|
120
|
+
url ||= root
|
121
|
+
input.gsub /(\s+(href|src)\s*=\s*["|']{1})(\/[^\/>]{1}[^\"'>]*)/ do
|
122
|
+
$1 + expand_url($3, url)
|
123
|
+
end
|
118
124
|
end
|
125
|
+
|
126
|
+
module_function *instance_methods
|
127
|
+
public *private_instance_methods.reject!{ |m| [:root].include?(m) }
|
128
|
+
|
119
129
|
end
|
120
130
|
end
|
121
131
|
|
data/octopress-filters.gemspec
CHANGED
@@ -19,6 +19,8 @@ Gem::Specification.new do |spec|
|
|
19
19
|
spec.require_paths = ["lib"]
|
20
20
|
|
21
21
|
spec.add_runtime_dependency "jekyll"
|
22
|
+
spec.add_runtime_dependency "rubypants-unicode"
|
23
|
+
spec.add_runtime_dependency "titlecase"
|
22
24
|
|
23
25
|
spec.add_development_dependency "bundler", "~> 1.6"
|
24
26
|
spec.add_development_dependency "rake"
|
data/test/Gemfile
CHANGED
@@ -0,0 +1,27 @@
|
|
1
|
+
“A first example”
|
2
|
+
“A first “nested” example”
|
3
|
+
”.
|
4
|
+
“a
|
5
|
+
’.
|
6
|
+
‘a
|
7
|
+
<p>He said, “‘Quoted’ words in a larger quote.”</p>
|
8
|
+
“I like the 70’s”
|
9
|
+
“I like the ’70s”
|
10
|
+
“I like the ‘70!”
|
11
|
+
|
12
|
+
pre”post
|
13
|
+
pre “post
|
14
|
+
pre “post
|
15
|
+
pre–“post
|
16
|
+
pre–”!
|
17
|
+
|
18
|
+
pre’post
|
19
|
+
pre ‘post
|
20
|
+
pre ‘post
|
21
|
+
pre–‘post
|
22
|
+
pre–’!
|
23
|
+
<b>‘</b>
|
24
|
+
foo<b>’</b>
|
25
|
+
|
26
|
+
<pre>"this shouldn't be curled"</pre>
|
27
|
+
<code>"this shouldn't be curled"</code>
|
data/test/canonical.html
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
---
|
2
|
+
---
|
3
|
+
{% filter smartquotes %}
|
4
|
+
"A first example"
|
5
|
+
"A first "nested" example"
|
6
|
+
".
|
7
|
+
"a
|
8
|
+
'.
|
9
|
+
'a
|
10
|
+
<p>He said, "'Quoted' words in a larger quote."</p>
|
11
|
+
"I like the 70's"
|
12
|
+
"I like the '70s"
|
13
|
+
"I like the '70!"
|
14
|
+
|
15
|
+
pre"post
|
16
|
+
pre "post
|
17
|
+
pre "post
|
18
|
+
pre--"post
|
19
|
+
pre--"!
|
20
|
+
|
21
|
+
pre'post
|
22
|
+
pre 'post
|
23
|
+
pre 'post
|
24
|
+
pre--'post
|
25
|
+
pre--'!
|
26
|
+
<b>'</b>
|
27
|
+
foo<b>'</b>
|
28
|
+
|
29
|
+
<pre>"this shouldn't be curled"</pre>
|
30
|
+
<code>"this shouldn't be curled"</code>
|
31
|
+
{% endfilter %}
|
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.
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brandon Mathis
|
@@ -24,6 +24,34 @@ dependencies:
|
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rubypants-unicode
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: titlecase
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
27
55
|
- !ruby/object:Gem::Dependency
|
28
56
|
name: bundler
|
29
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -89,28 +117,32 @@ extra_rdoc_files: []
|
|
89
117
|
files:
|
90
118
|
- ".gitignore"
|
91
119
|
- ".travis.yml"
|
120
|
+
- CHANGELOG.md
|
92
121
|
- Gemfile
|
93
122
|
- LICENSE.txt
|
94
123
|
- README.md
|
95
124
|
- Rakefile
|
96
125
|
- lib/octopress-filters.rb
|
97
126
|
- lib/octopress-filters/generator.rb
|
98
|
-
- lib/octopress-filters/utils.rb
|
99
127
|
- lib/octopress-filters/version.rb
|
100
128
|
- octopress-filters.gemspec
|
101
129
|
- test/.clash.yml
|
102
130
|
- test/Gemfile
|
103
131
|
- test/_config.yml
|
132
|
+
- test/_expected/canonical.html
|
104
133
|
- test/_expected/classify.html
|
105
134
|
- test/_expected/compact_newlines.html
|
106
135
|
- test/_expected/full_urls.html
|
107
136
|
- test/_expected/join_lines.html
|
137
|
+
- test/_expected/smartquotes.html
|
108
138
|
- test/_expected/titlecase.html
|
109
139
|
- test/_expected/unorphan.html
|
140
|
+
- test/canonical.html
|
110
141
|
- test/classify.html
|
111
142
|
- test/compact_newlines.html
|
112
143
|
- test/full_urls.html
|
113
144
|
- test/join_lines.html
|
145
|
+
- test/smartquotes.html
|
114
146
|
- test/titlecase.html
|
115
147
|
- test/unorphan.html
|
116
148
|
homepage: https://github.com/octopress/filters
|
@@ -141,15 +173,19 @@ test_files:
|
|
141
173
|
- test/.clash.yml
|
142
174
|
- test/Gemfile
|
143
175
|
- test/_config.yml
|
176
|
+
- test/_expected/canonical.html
|
144
177
|
- test/_expected/classify.html
|
145
178
|
- test/_expected/compact_newlines.html
|
146
179
|
- test/_expected/full_urls.html
|
147
180
|
- test/_expected/join_lines.html
|
181
|
+
- test/_expected/smartquotes.html
|
148
182
|
- test/_expected/titlecase.html
|
149
183
|
- test/_expected/unorphan.html
|
184
|
+
- test/canonical.html
|
150
185
|
- test/classify.html
|
151
186
|
- test/compact_newlines.html
|
152
187
|
- test/full_urls.html
|
153
188
|
- test/join_lines.html
|
189
|
+
- test/smartquotes.html
|
154
190
|
- test/titlecase.html
|
155
191
|
- test/unorphan.html
|
@@ -1,42 +0,0 @@
|
|
1
|
-
module Octopress
|
2
|
-
module Utils
|
3
|
-
# Smart capitalization for titles
|
4
|
-
#
|
5
|
-
def self.titlecase(input)
|
6
|
-
small_words = %w(a an and as at but by en for if in of on or the to v v. via vs vs.)
|
7
|
-
|
8
|
-
x = input.split(" ").map do |word|
|
9
|
-
# note: word could contain non-word characters!
|
10
|
-
# downcase all small_words, capitalize the rest
|
11
|
-
small_words.include?(word.gsub(/\W/, "").downcase) ? word.downcase! : smart_capitalize!(word)
|
12
|
-
word
|
13
|
-
end
|
14
|
-
# capitalize first and last words
|
15
|
-
smart_capitalize!(x.first)
|
16
|
-
smart_capitalize!(x.last)
|
17
|
-
# small words are capitalized after colon, period, exclamation mark, question mark
|
18
|
-
x.join(" ").gsub(/(:|\.|!|\?)\s?(\W*#{small_words.join("|")}\W*)\s/) { "#{$1} #{smart_capitalize($2)} " }
|
19
|
-
end
|
20
|
-
|
21
|
-
def self.titlecase!(input)
|
22
|
-
input.replace(titlecase(input))
|
23
|
-
end
|
24
|
-
|
25
|
-
def self.smart_capitalize(input)
|
26
|
-
target = input.dup
|
27
|
-
# ignore any leading crazy characters and capitalize the first real character
|
28
|
-
if target =~ /^['"\(\[']*([a-z])/
|
29
|
-
i = input.index($1)
|
30
|
-
x = target[i,target.length]
|
31
|
-
# word with capitals and periods mid-word are left alone
|
32
|
-
target[i,1] = target[i,1].upcase unless x =~ /[A-Z]/ or x =~ /\.\w+/
|
33
|
-
end
|
34
|
-
target
|
35
|
-
end
|
36
|
-
|
37
|
-
def self.smart_capitalize!(input)
|
38
|
-
input.replace(smart_capitalize(input))
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|