octopress-filters 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: d40675a0cd8630124d45612741f89126ae9a2cb0
4
+ data.tar.gz: 05aad8da4369126ecc078e1528507efc132a2392
5
+ SHA512:
6
+ metadata.gz: 09c6d4be84f20a2de65dff01847873fcf9d221aff3a89f58f46e27041d38fb21d7b3ac9ed751afc50b9552674fc22f68e5ad90ac8ea6fa799659dd9e1a4747f1
7
+ data.tar.gz: 0e736abdddd45f4f7292a634ab47dc87906f9368b531204390088f4a3436d487809708428e40b092fee90d21ccc0cb52325b1f8c7fad965297668ec7f1c02b85
data/.gitignore ADDED
@@ -0,0 +1,23 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ *.bundle
19
+ *.so
20
+ *.o
21
+ *.a
22
+ mkmf.log
23
+ _site
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.0.0
4
+ - 1.9.3
5
+ script: cd test && bundle exec clash
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in octopress_render_tag.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Brandon Mathis
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,81 @@
1
+ # Octopress Filters
2
+
3
+ A set of handy liquid filters used by Octopress.
4
+
5
+ - full_urls - Replace relative urls with absolute urls.
6
+ - titlecase - Properly capitalize titles based on John Gruber's [Title Case](http://daringfireball.net/2008/05/title_case).
7
+ - unorphan - Insert a non-breaking space between the last two words in a title.
8
+ - sluggify - Replaces all non-word characters in a string with dashes.
9
+ - classify - An alias for sluggify (seems appropriate when working with CSS class names).
10
+ - compact_newlines - Compact groups of empty lines into one, because Liquid templates have lots of whitespace.
11
+ - join_lines - Remove all new lines, joining each line with a separator. (defaults to a space).
12
+
13
+ [![Build Status](https://travis-ci.org/octopress/filters.svg)](https://travis-ci.org/octopress/filters)
14
+ [![Gem Version](http://img.shields.io/gem/v/octopress-filters.svg)](https://rubygems.org/gems/octopress-filters)
15
+ [![License](http://img.shields.io/:license-mit-blue.svg)](http://octopress.mit-license.org)
16
+
17
+ ## Installation
18
+
19
+ Add this line to your application's Gemfile:
20
+
21
+ gem 'octopress-filters'
22
+
23
+ And then execute:
24
+
25
+ $ bundle
26
+
27
+ Or install it yourself as:
28
+
29
+ $ gem install octopress-filters
30
+
31
+ Next add it to your gems list in Jekyll's `_config.yml`
32
+
33
+ gems:
34
+ - octopress-filters
35
+
36
+ ## Examples
37
+
38
+ ### Full urls
39
+
40
+ If you're working on an RSS feed, you'll need to be sure all of your relative urls are converted to full urls. In that case, when
41
+ rendering the content of a page, just do this:
42
+
43
+ {{ post.content | full_urls }}
44
+
45
+ Now any relative links in your site will be expanded with the `url` configuration in Jekyll's `_config.yml`.
46
+
47
+ ### Titlecase
48
+
49
+ {{ post.title | titlecase }} //=> This Is a Properly Capitalized Title
50
+
51
+ ### Unorphan
52
+
53
+ {{ post.title | unorphan }} //=> This Is a Properly Capitalized Title
54
+
55
+ ### Sluggify/Classify
56
+
57
+ <article class="{{ post.class | classify }}">
58
+
59
+ ### Compact newlines
60
+
61
+ {{ content | compact_newlines }}
62
+
63
+ ### Join lines
64
+
65
+ {% capture page_title %}
66
+ {{ page.title }}
67
+ {{ site.header.title }}
68
+ {% endcapture %}
69
+
70
+ <head>
71
+ <title>{{ page_title | join_lines: " - " }}</title>
72
+
73
+
74
+ ## Contributing
75
+
76
+ 1. Fork it ( https://github.com/octopress/filters/fork )
77
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
78
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
79
+ 4. Push to the branch (`git push origin my-new-feature`)
80
+ 5. Create a new Pull Request
81
+
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,124 @@
1
+ require "octopress-filters/version"
2
+ require "octopress-filters/utils"
3
+
4
+ unless defined? Octopress::Ink
5
+ require "octopress-filters/generator"
6
+ end
7
+
8
+ require "jekyll"
9
+
10
+ module Octopress
11
+ module Filters
12
+
13
+ # Escapes HTML content for XML
14
+ def cdata_escape(input)
15
+ input.gsub(/<!\[CDATA\[/, '&lt;![CDATA[').gsub(/\]\]>/, ']]&gt;')
16
+ end
17
+
18
+ # Returns a title cased string based on John Gruber's title case
19
+ # Info: http://daringfireball.net/2008/08/title_case_update
20
+ def titlecase(input)
21
+ Octopress::Utils.titlecase!(input)
22
+ end
23
+
24
+ # Formats a string for use as a css classname, removing illegal characters
25
+ def classify(input)
26
+ input.gsub(/ /,'-').gsub(/[^\w-]/,'').downcase
27
+ end
28
+
29
+ alias_method :sluggify, :classify
30
+
31
+ # Remove empty lines
32
+ def compact_newlines(input)
33
+ input.gsub(/\n{2,}/, "\n").gsub(/^ +\n/,"")
34
+ end
35
+
36
+ # Join newlines
37
+ def join_lines(input, separator='')
38
+ compact_newlines(input).strip.gsub(/\s*\n\s*/, separator)
39
+ end
40
+
41
+ # Prevent orphans in text by inserting a non-breaking space between the two last words of a string.
42
+ def unorphan(input)
43
+ input.sub(/\s+(\S+)\s*$/, '&nbsp;\1')
44
+ end
45
+
46
+ # Prepends input with a url fragment
47
+ #
48
+ # input - An absolute url, e.g. /images/awesome.gif
49
+ # url - The fragment to prepend the input, e.g. /blog
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
74
+ end
75
+
76
+ # Prepend all urls with the full site url
77
+ #
78
+ # input - The content of a page or post
79
+ #
80
+ # Returns input with all urls expanded to include the full site url
81
+ # e.g. /images/awesome.gif => http://example.com/images/awesome.gif
82
+ #
83
+ def full_urls(input)
84
+ url = Ink.site.config['url']
85
+ if url.nil?
86
+ raise IOError.new "Could not expand urls: Please add your published url to your _config.yml, eg url: http://example.com/"
87
+ else
88
+ expand_urls(input, url)
89
+ end
90
+ end
91
+
92
+ # Prepend a url with the full site url
93
+ #
94
+ # input - a url
95
+ #
96
+ # Returns input with all urls expanded to include the full site url
97
+ # e.g. /images/awesome.gif => http://example.com/images/awesome.gif
98
+ #
99
+ def full_url(input)
100
+ url = Ink.site.config['url']
101
+ if url.nil?
102
+ raise IOError.new "Could not expand url in #{input}: Please add your site's published url to your _config.yml, eg url: http://example.com/"
103
+ else
104
+ expand_url(input, url)
105
+ end
106
+ end
107
+
108
+ module_function *instance_methods
109
+ public *private_instance_methods
110
+
111
+ private
112
+
113
+ # Returns the site's config root or '/' if the config isn't set
114
+ #
115
+ def root
116
+ root_url = Ink.site.config['root']
117
+ root_url.nil? ? '/' : File.join('/', root_url)
118
+ end
119
+ end
120
+ end
121
+
122
+
123
+
124
+ Liquid::Template.register_filter Octopress::Filters
@@ -0,0 +1,17 @@
1
+ module Octopress
2
+ module Ink
3
+ def self.site
4
+ @site
5
+ end
6
+
7
+ def self.site=(site)
8
+ @site = site
9
+ end
10
+
11
+ class SiteGrabber < Jekyll::Generator
12
+ def generate(site)
13
+ Octopress::Ink.site = site
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,42 @@
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
+
@@ -0,0 +1,7 @@
1
+ module Octopress
2
+ module Tags
3
+ module Filters
4
+ VERSION = "1.0.0"
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'octopress-filters/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "octopress-filters"
8
+ spec.version = Octopress::Tags::Filters::VERSION
9
+ spec.authors = ["Brandon Mathis"]
10
+ spec.email = ["brandon@imathis.com"]
11
+ spec.summary = %q{Return tag renders a variable with some nice features}
12
+ spec.description = %q{Return tag renders a variable with some nice features}
13
+ spec.homepage = "https://github.com/octopress/filters"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_runtime_dependency "jekyll"
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.6"
24
+ spec.add_development_dependency "rake"
25
+ spec.add_development_dependency "clash"
26
+ spec.add_development_dependency "octopress-filter-tag", "~> 1.0"
27
+ end
data/test/.clash.yml ADDED
@@ -0,0 +1,2 @@
1
+ build: true
2
+ compare: _expected _site
data/test/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'octopress-filters', path: '../'
4
+ gem 'pry-debugger'
5
+ gem 'octopress-filter-tag'
6
+ gem 'clash'
data/test/_config.yml ADDED
@@ -0,0 +1,15 @@
1
+ # Site settings
2
+ title: Your awesome title
3
+ email: your-email@domain.com
4
+ baseurl: ""
5
+ url: "http://yourdomain.com"
6
+ timezone: UTC
7
+
8
+ exclude:
9
+ - Gemfile*
10
+
11
+ # Build settings
12
+ markdown: kramdown
13
+ gems:
14
+ - octopress-filters
15
+ - octopress-filter-tag
@@ -0,0 +1,5 @@
1
+
2
+
3
+ <div class="this-is-a-silly-classname"></div>
4
+ <div class="this-is-a-silly-classname"></div>
5
+
@@ -0,0 +1,6 @@
1
+ There
2
+ Is
3
+ A
4
+ Lot
5
+ Of
6
+ Whitespace
@@ -0,0 +1,2 @@
1
+ <a href="http://yourdomain.com/about">About</a>
2
+ <script src="http://yourdomain.com/javascripts/foo.js"></script>
@@ -0,0 +1,2 @@
1
+ this,has,commas,man
2
+
@@ -0,0 +1 @@
1
+ This Title Could Use Some Capitals
@@ -0,0 +1 @@
1
+ This title is long so it might&nbsp;wrap
@@ -0,0 +1,7 @@
1
+ ---
2
+ ---
3
+ {% assign class = "this is a silly classname" %}
4
+
5
+ <div class="{{ class | classify }}"></div>
6
+ <div class="{{ class | sluggify }}"></div>
7
+
@@ -0,0 +1,15 @@
1
+ ---
2
+ ---
3
+ {% filter compact_newlines %}
4
+ There
5
+
6
+ Is
7
+
8
+ A
9
+
10
+ Lot
11
+
12
+ Of
13
+
14
+ Whitespace
15
+ {% endfilter %}
@@ -0,0 +1,6 @@
1
+ ---
2
+ ---
3
+ {% filter full_urls %}
4
+ <a href="/about">About</a>
5
+ <script src="/javascripts/foo.js"></script>
6
+ {% endfilter %}
@@ -0,0 +1,9 @@
1
+ ---
2
+ ---
3
+ {% filter join_lines: ',' %}
4
+ this
5
+ has
6
+ commas
7
+ man
8
+ {% endfilter %}
9
+
@@ -0,0 +1,5 @@
1
+ ---
2
+ title: this title could use some capitals
3
+ ---
4
+
5
+ {{ page.title | titlecase }}
@@ -0,0 +1,5 @@
1
+ ---
2
+ title: This title is long so it might wrap
3
+ ---
4
+
5
+ {{ page.title | unorphan }}
metadata ADDED
@@ -0,0 +1,155 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: octopress-filters
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Brandon Mathis
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-07-21 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: jekyll
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.6'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.6'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: clash
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: octopress-filter-tag
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '1.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '1.0'
83
+ description: Return tag renders a variable with some nice features
84
+ email:
85
+ - brandon@imathis.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".gitignore"
91
+ - ".travis.yml"
92
+ - Gemfile
93
+ - LICENSE.txt
94
+ - README.md
95
+ - Rakefile
96
+ - lib/octopress-filters.rb
97
+ - lib/octopress-filters/generator.rb
98
+ - lib/octopress-filters/utils.rb
99
+ - lib/octopress-filters/version.rb
100
+ - octopress-filters.gemspec
101
+ - test/.clash.yml
102
+ - test/Gemfile
103
+ - test/_config.yml
104
+ - test/_expected/classify.html
105
+ - test/_expected/compact_newlines.html
106
+ - test/_expected/full_urls.html
107
+ - test/_expected/join_lines.html
108
+ - test/_expected/titlecase.html
109
+ - test/_expected/unorphan.html
110
+ - test/classify.html
111
+ - test/compact_newlines.html
112
+ - test/full_urls.html
113
+ - test/join_lines.html
114
+ - test/titlecase.html
115
+ - test/unorphan.html
116
+ homepage: https://github.com/octopress/filters
117
+ licenses:
118
+ - MIT
119
+ metadata: {}
120
+ post_install_message:
121
+ rdoc_options: []
122
+ require_paths:
123
+ - lib
124
+ required_ruby_version: !ruby/object:Gem::Requirement
125
+ requirements:
126
+ - - ">="
127
+ - !ruby/object:Gem::Version
128
+ version: '0'
129
+ required_rubygems_version: !ruby/object:Gem::Requirement
130
+ requirements:
131
+ - - ">="
132
+ - !ruby/object:Gem::Version
133
+ version: '0'
134
+ requirements: []
135
+ rubyforge_project:
136
+ rubygems_version: 2.2.2
137
+ signing_key:
138
+ specification_version: 4
139
+ summary: Return tag renders a variable with some nice features
140
+ test_files:
141
+ - test/.clash.yml
142
+ - test/Gemfile
143
+ - test/_config.yml
144
+ - test/_expected/classify.html
145
+ - test/_expected/compact_newlines.html
146
+ - test/_expected/full_urls.html
147
+ - test/_expected/join_lines.html
148
+ - test/_expected/titlecase.html
149
+ - test/_expected/unorphan.html
150
+ - test/classify.html
151
+ - test/compact_newlines.html
152
+ - test/full_urls.html
153
+ - test/join_lines.html
154
+ - test/titlecase.html
155
+ - test/unorphan.html