octopress-tag-helpers 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +22 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +27 -0
- data/Rakefile +2 -0
- data/lib/octopress-tag-helpers/conditional.rb +23 -0
- data/lib/octopress-tag-helpers/content_for.rb +30 -0
- data/lib/octopress-tag-helpers/hooks.rb +12 -0
- data/lib/octopress-tag-helpers/path.rb +47 -0
- data/lib/octopress-tag-helpers/var.rb +103 -0
- data/lib/octopress-tag-helpers/version.rb +5 -0
- data/lib/octopress-tag-helpers.rb +11 -0
- data/octopress-tag-helpers.gemspec +25 -0
- metadata +99 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 0e6606d7dc37bf5dc130e0919411b41f34441e03
|
4
|
+
data.tar.gz: cea488d88d622bf07273e153e65c0369c02e1d3f
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 68213ec81a1b24ac4b9f511f4e07998dd062128f9e86ee9d8ab302b2b730c4e4e4afe2c1843a8a5a165a97ea9ead517f35b841c32ec34c635b8c5f4c52ddca15
|
7
|
+
data.tar.gz: 6b2e8d01438c4ac28d1f9f13140c2439f981d3edc90a60e2fdb1f490362b61f72c7c5612340620d70cd5ed21ca03889c1d04179861fc81f46839abbae9c013c5
|
data/.gitignore
ADDED
@@ -0,0 +1,22 @@
|
|
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
|
data/Gemfile
ADDED
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,27 @@
|
|
1
|
+
# Octopress Tag Helpers
|
2
|
+
|
3
|
+
This allows other Octopress tags to share helpful utility
|
4
|
+
methods and evaluate conditionals, determine paths and evaluate
|
5
|
+
vars in the context of a Jekyll site.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
gem 'octopress-tag-helpers'
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install octopress-tag-helpers
|
20
|
+
|
21
|
+
## Contributing
|
22
|
+
|
23
|
+
1. Fork it ( https://github.com/octopress/tag-helpers/fork )
|
24
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
25
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
26
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
27
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
module Octopress
|
2
|
+
module TagHelpers
|
3
|
+
module Conditional
|
4
|
+
SYNTAX = /(.*)\s(if|unless)\s(.+)/
|
5
|
+
|
6
|
+
def self.parse(markup, context)
|
7
|
+
if markup =~ SYNTAX
|
8
|
+
case $2
|
9
|
+
when 'if'
|
10
|
+
tag = Liquid::If.new('if', $3, ["true","{% endif %}"])
|
11
|
+
when 'unless'
|
12
|
+
tag = Liquid::Unless.new('unless', $3, ["true","{% endunless %}"])
|
13
|
+
end
|
14
|
+
tag.render(context) != '' ? $1 : false
|
15
|
+
else
|
16
|
+
markup
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module Octopress
|
2
|
+
module TagHelpers
|
3
|
+
module ContentFor
|
4
|
+
def self.get_block_name(tag_name, markup)
|
5
|
+
if markup.strip == ''
|
6
|
+
raise IOError.new "Syntax Error: #{tag_name} requires a name, eg. {% #{tag_name} sidebar %}"
|
7
|
+
else
|
8
|
+
markup.strip
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
# Gets the storage space for the content block
|
13
|
+
def self.get_block(context, block)
|
14
|
+
context.environments.first['content_for'] ||= {}
|
15
|
+
context.environments.first['content_for'][block] ||= []
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.render(context, block)
|
19
|
+
content = get_block(context, block).map { |b| b }.join
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.append_to_block(context, block, content)
|
23
|
+
converter = context.environments.first['converter']
|
24
|
+
content = converter.convert(content).sub(/\n$/,'')
|
25
|
+
get_block(context, block) << content
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
@@ -0,0 +1,12 @@
|
|
1
|
+
module Jekyll
|
2
|
+
module Convertible
|
3
|
+
alias_method :jekyll_do_layout, :do_layout
|
4
|
+
|
5
|
+
def do_layout(payload, layouts)
|
6
|
+
# The tags needs access to the converter to process it while rendering.
|
7
|
+
payload['converter'] = self.converter
|
8
|
+
|
9
|
+
jekyll_do_layout(payload, layouts)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
module Octopress
|
2
|
+
module TagHelpers
|
3
|
+
module Path
|
4
|
+
FILE = /(\S+)(\s?)(.*)/
|
5
|
+
def self.parse(markup, context)
|
6
|
+
if markup =~ FILE
|
7
|
+
(context[$1].nil? ? $1 : context[$1]) + ' ' + ($3 || '')
|
8
|
+
else
|
9
|
+
markup
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
# Allow paths to begin from the directory of the context page or
|
14
|
+
# have absolute paths
|
15
|
+
#
|
16
|
+
# Input:
|
17
|
+
# - file: "file.html"
|
18
|
+
# - context: A Jekyll context object
|
19
|
+
#
|
20
|
+
# Returns the full path to a file
|
21
|
+
#
|
22
|
+
def self.expand(file, context)
|
23
|
+
root = context.registers[:site].source
|
24
|
+
|
25
|
+
# If relative path, e.g. ./somefile, ../somefile
|
26
|
+
if file =~ /^\.+\//
|
27
|
+
page = context['page']
|
28
|
+
if local_dir = page['dir']
|
29
|
+
File.expand_path(File.join(root, local_dir, file))
|
30
|
+
else
|
31
|
+
local_dir = File.dirname(page['path'])
|
32
|
+
File.expand_path(File.join(root, local_dir, file))
|
33
|
+
end
|
34
|
+
|
35
|
+
# If absolute or relative to a user directory, e.g. /Users/Bob/somefile or ~/somefile
|
36
|
+
elsif file =~ /^[\/~]/
|
37
|
+
File.expand_path(file)
|
38
|
+
|
39
|
+
# Otherwise, assume relative to site root
|
40
|
+
else
|
41
|
+
File.join(root, file)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
@@ -0,0 +1,103 @@
|
|
1
|
+
module Octopress
|
2
|
+
module TagHelpers
|
3
|
+
module Var
|
4
|
+
TERNARY = /(.*?)\(\s*(.+?)\s+\?\s+(.+?)\s+:\s+(.+?)\s*\)(.+)?/
|
5
|
+
HAS_FILTERS = /(.*?)(\s+\|\s+.+)/
|
6
|
+
|
7
|
+
def self.set_var(var, operator, value, context)
|
8
|
+
case operator
|
9
|
+
when '||='
|
10
|
+
context.scopes.last[var] = value if context.scopes.last[var].nil?
|
11
|
+
when '+='
|
12
|
+
if context.scopes.last[var].nil?
|
13
|
+
context.scopes.last[var] = value
|
14
|
+
else
|
15
|
+
context.scopes.last[var] += value
|
16
|
+
end
|
17
|
+
else
|
18
|
+
context.scopes.last[var] = value
|
19
|
+
end
|
20
|
+
context
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.get_value(vars, context)
|
24
|
+
vars = evaluate_ternary(vars, context)
|
25
|
+
vars = vars.strip.gsub(/ or /, ' || ')
|
26
|
+
filters = false
|
27
|
+
if vars =~ HAS_FILTERS
|
28
|
+
vars = $1
|
29
|
+
filters = $2
|
30
|
+
end
|
31
|
+
vars = vars.split(/ \|\| /).map { |v|
|
32
|
+
context[v.strip]
|
33
|
+
}.compact
|
34
|
+
|
35
|
+
var = vars.first
|
36
|
+
if filters
|
37
|
+
var = Liquid::Variable.new("'#{var}'"+ filters).render(context)
|
38
|
+
end
|
39
|
+
var
|
40
|
+
end
|
41
|
+
|
42
|
+
def self.evaluate_ternary(markup, context)
|
43
|
+
if markup =~ TERNARY
|
44
|
+
$1 + (Conditional.parse(" if #{$2}", context) ? $3 : $4) + $5
|
45
|
+
else
|
46
|
+
markup
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
# Parses filters into arrays
|
51
|
+
#
|
52
|
+
# input - a string of one or more filters, e.g. "| upcase | replace:'a','b'"
|
53
|
+
#
|
54
|
+
# Returns nested arrays of filters and arguments
|
55
|
+
#
|
56
|
+
def self.parse_filters(input)
|
57
|
+
output = []
|
58
|
+
if input.match(/#{Liquid::FilterSeparator}\s*(.*)/o)
|
59
|
+
filters = Regexp.last_match(1).scan(Liquid::Variable::FilterParser)
|
60
|
+
filters.each do |f|
|
61
|
+
if matches = f.match(/\s*(\w+)/)
|
62
|
+
filtername = matches[1]
|
63
|
+
filterargs = f.scan(/(?:#{Liquid::FilterArgumentSeparator}|#{Liquid::ArgumentSeparator})\s*((?:\w+\s*\:\s*)?#{Liquid::QuotedFragment})/o).flatten
|
64
|
+
output << [filtername, filterargs]
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
output
|
69
|
+
end
|
70
|
+
|
71
|
+
# Passes input through Liquid filters
|
72
|
+
#
|
73
|
+
# content - a string to be parsed
|
74
|
+
# filters - a series of liquid filters e.g. "| upcase | replace:'a','b'"
|
75
|
+
# context - the current Liquid context object
|
76
|
+
#
|
77
|
+
# Returns a filtered string
|
78
|
+
#
|
79
|
+
def self.render_filters(content, filters, context)
|
80
|
+
filters = parse_filters(filters)
|
81
|
+
return '' if content.nil?
|
82
|
+
filters.inject(content) do |output, filter|
|
83
|
+
filterargs = []
|
84
|
+
keyword_args = {}
|
85
|
+
filter[1].to_a.each do |a|
|
86
|
+
if matches = a.match(/\A#{Liquid::TagAttributes}\z/o)
|
87
|
+
keyword_args[matches[1]] = context[matches[2]]
|
88
|
+
else
|
89
|
+
filterargs << context[a]
|
90
|
+
end
|
91
|
+
end
|
92
|
+
filterargs << keyword_args unless keyword_args.empty?
|
93
|
+
begin
|
94
|
+
output = context.invoke(filter[0], output, *filterargs)
|
95
|
+
rescue
|
96
|
+
raise "Error - filter '#{filter[0]}' could not be found."
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
@@ -0,0 +1,11 @@
|
|
1
|
+
require "octopress-tag-helpers/version"
|
2
|
+
require "octopress-tag-helpers/hooks"
|
3
|
+
|
4
|
+
module Octopress
|
5
|
+
module TagHelpers
|
6
|
+
autoload :Conditional, 'octopress-tag-helpers/conditional'
|
7
|
+
autoload :ContentFor, 'octopress-tag-helpers/content_for'
|
8
|
+
autoload :Path, 'octopress-tag-helpers/path'
|
9
|
+
autoload :Var, 'octopress-tag-helpers/var'
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'octopress-tag-helpers/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "octopress-tag-helpers"
|
8
|
+
spec.version = Octopress::TagHelpers::VERSION
|
9
|
+
spec.authors = ["Brandon Mathis"]
|
10
|
+
spec.email = ["brandon@imathis.com"]
|
11
|
+
spec.summary = %q{Making it easier to build smart Jekyll/Octopress Liquid tags.}
|
12
|
+
spec.description = %q{Making it easier to build smart Jekyll/Octopress Liquid tags.}
|
13
|
+
spec.homepage = "https://github.com/octopress/tag-helpers"
|
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", "~> 2.0"
|
22
|
+
|
23
|
+
spec.add_development_dependency "bundler", "~> 1.6"
|
24
|
+
spec.add_development_dependency "rake"
|
25
|
+
end
|
metadata
ADDED
@@ -0,0 +1,99 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: octopress-tag-helpers
|
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-06-29 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: '2.0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '2.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
|
+
description: Making it easier to build smart Jekyll/Octopress Liquid tags.
|
56
|
+
email:
|
57
|
+
- brandon@imathis.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- ".gitignore"
|
63
|
+
- Gemfile
|
64
|
+
- LICENSE.txt
|
65
|
+
- README.md
|
66
|
+
- Rakefile
|
67
|
+
- lib/octopress-tag-helpers.rb
|
68
|
+
- lib/octopress-tag-helpers/conditional.rb
|
69
|
+
- lib/octopress-tag-helpers/content_for.rb
|
70
|
+
- lib/octopress-tag-helpers/hooks.rb
|
71
|
+
- lib/octopress-tag-helpers/path.rb
|
72
|
+
- lib/octopress-tag-helpers/var.rb
|
73
|
+
- lib/octopress-tag-helpers/version.rb
|
74
|
+
- octopress-tag-helpers.gemspec
|
75
|
+
homepage: https://github.com/octopress/tag-helpers
|
76
|
+
licenses:
|
77
|
+
- MIT
|
78
|
+
metadata: {}
|
79
|
+
post_install_message:
|
80
|
+
rdoc_options: []
|
81
|
+
require_paths:
|
82
|
+
- lib
|
83
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
84
|
+
requirements:
|
85
|
+
- - ">="
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: '0'
|
88
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
89
|
+
requirements:
|
90
|
+
- - ">="
|
91
|
+
- !ruby/object:Gem::Version
|
92
|
+
version: '0'
|
93
|
+
requirements: []
|
94
|
+
rubyforge_project:
|
95
|
+
rubygems_version: 2.2.2
|
96
|
+
signing_key:
|
97
|
+
specification_version: 4
|
98
|
+
summary: Making it easier to build smart Jekyll/Octopress Liquid tags.
|
99
|
+
test_files: []
|