frozen-filters 0.2.0 → 0.3.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 +4 -4
- data/CHANGELOG.md +12 -0
- data/README.md +32 -5
- data/lib/frozen-filters.rb +47 -6
- metadata +4 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8619a0aad345f04850e48755327aee77ad2bdd17de3c70892e63d194cb8dba5f
|
4
|
+
data.tar.gz: 9d4b9ee1ad4f26fb203bf15c7e3595be63d44c1435e9eeaf1f5206cbab84834a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4e582ec706d6c57202234cdf800e12e222a6391504f84fbff99b6c059f1cb45c7118da178c3a2d32f64a84d6beb8826c516c01477320529368510359580c7fc8
|
7
|
+
data.tar.gz: 127075375c03b4d710d3513d6a757cd34baf048a541859dcc8527f3a4671f0a97f1b9a8c2665f24fa293f7da3e63c79fa0f8b67b6955098d00f57e1797706ea0
|
data/CHANGELOG.md
CHANGED
@@ -4,6 +4,18 @@ All notable changes to this project will be documented in this file.
|
|
4
4
|
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
|
5
5
|
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
|
6
6
|
|
7
|
+
## [0.3.0] -
|
8
|
+
### Added
|
9
|
+
- (DEV) Add test script.
|
10
|
+
- (DEV) Add trevis support.
|
11
|
+
- (DEV) Add support for `enabled:false` in a test case.
|
12
|
+
- Add `extract_path` and `extract_qs` filters.
|
13
|
+
- Add `array_head`, `array_tail` and `array_to_taglist` filters.
|
14
|
+
|
15
|
+
### Fixed
|
16
|
+
- Fix `extract_dirname` when it's only `/index.html`.
|
17
|
+
|
18
|
+
|
7
19
|
## [0.2.0] -
|
8
20
|
### Added
|
9
21
|
- Add jekyllrb and installation information to README.md.
|
data/README.md
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
## Description
|
2
|
-
[](https://badge.fury.io/rb/frozen-filters)
|
2
|
+
[](https://badge.fury.io/rb/frozen-filters)
|
3
|
+
[](https://travis-ci.org/a-bentofreire/frozen-filters)
|
3
4
|
|
4
5
|
Liquid filters for shopify [liquid](https://github.com/shopify/liquid) template engine.
|
5
6
|
This ruby gem is a port of [frozen-filters-js](https://github.com/a-bentofreire/frozen-filters-js).
|
@@ -27,7 +28,7 @@ Usage within `jekyllrb`:
|
|
27
28
|
|
28
29
|
- Add to blog `Gemfile`:
|
29
30
|
```ruby
|
30
|
-
gem "frozen-filters", "~> 0.
|
31
|
+
gem "frozen-filters", "~> 0.3.0"
|
31
32
|
```
|
32
33
|
- Add to `plugins` section of blog `_config.yml`:
|
33
34
|
```ruby
|
@@ -40,19 +41,45 @@ e.g.
|
|
40
41
|
```
|
41
42
|
|
42
43
|
## Filters
|
44
|
+
### Url Filters
|
43
45
|
|
44
46
|
- `remove_ext` - Removes the extension part of an url.
|
45
47
|
e.g. `http://www.example.com/first/second/index?param1=value1¶m2=value2`.
|
46
48
|
|
47
49
|
- `remove_qs` - Removes the query string part of an url. e.g. `http://www.example.com/first/second/index.html`.
|
48
50
|
- `extract_basename` - Returns the basename of an url. e.g. `index.html`.
|
49
|
-
- `extract_dirname` - Returns the dirname of an url. e.g.
|
51
|
+
- `extract_dirname` - Returns the dirname of an url. e.g. `/first/second`.
|
52
|
+
- `extract_path` - Returns the path of an url. e.g. `/first/second/index.html`.
|
50
53
|
- `extract_protocol` - Returns the protocol. e.g. `http`.
|
54
|
+
- `extract_qs` - Returns the query string. e.g. `param1=value1¶m2=value2`.
|
55
|
+
|
56
|
+
### Array Filters
|
57
|
+
|
58
|
+
- `array_head` - Returns the first `N` elements of an array.
|
59
|
+
e.g. `{{ ["first","second","third"] | array_head: 2 }}` =~ `["first","second"]`.
|
60
|
+
If the number of parameters is negative it returns an empty array.
|
61
|
+
The the input isn't an array it returns the untouched input.
|
62
|
+
|
63
|
+
- `array_tail` - Returns the last `N` elements of an array.
|
64
|
+
e.g. `{{ ["first","second","third"] | array_tail: 2 }}` =~ `["first","second"]`.
|
65
|
+
If the number of parameters is negative it returns an empty array.
|
66
|
+
The the input isn't an array it returns the untouched input.
|
67
|
+
- `array_to_taglist` - Transforms an array into an enclosed html tag list separated by newline.
|
68
|
+
e.g. `{{ ["first","second" | array_to_taglist: "li" }}` returns:
|
69
|
+
```html
|
70
|
+
<li>first</li>
|
71
|
+
<li>second</li>
|
72
|
+
```
|
73
|
+
|
74
|
+
If the input isn't an array, it returns the untouched input.
|
51
75
|
|
52
76
|
## Internationalization
|
53
77
|
|
54
|
-
The url filters support domains and paths with
|
55
|
-
|
78
|
+
The url filters support domains and paths with:
|
79
|
+
- non-latin characters.
|
80
|
+
e.g. `http://吃.高雄/第一/第二/首頁.html?param1=value1¶m2=value2`.
|
81
|
+
- punycodes:
|
82
|
+
e.g. `https://xn--jp-cd2fp15c.xn--fsq.jp/abc/index.html?param1=value1¶m2=value2`.
|
56
83
|
|
57
84
|
## Copyrights
|
58
85
|
|
data/lib/frozen-filters.rb
CHANGED
@@ -25,25 +25,66 @@ module FrozenFilters
|
|
25
25
|
input.to_s.gsub(/^.*\/([^\/\?]+).*$/, '\1')
|
26
26
|
end
|
27
27
|
|
28
|
-
# Returns the dirname of an url. e.g.
|
28
|
+
# Returns the dirname of an url. e.g. `/first/second`.
|
29
29
|
def extract_dirname(input)
|
30
|
+
result = extract_path(input).gsub(/\/[^\/]+$/, '')
|
31
|
+
result != "" ? result : "/"
|
32
|
+
end
|
33
|
+
|
34
|
+
# Returns the path of an url. e.g. `/first/second/index.html`.
|
35
|
+
def extract_path(input)
|
30
36
|
input_s = input.to_s
|
31
37
|
if /^(\w+):/.match(input_s)
|
32
|
-
input_s.gsub(/^\w+:[^\/]*\/\/[^\/]+(\/[^\?]+)
|
38
|
+
input_s.gsub(/^\w+:[^\/]*\/\/[^\/]+(\/[^\?]+)(?:\?.*)?$/, '\1')
|
33
39
|
else
|
34
|
-
input_s.gsub(
|
40
|
+
input_s.gsub(/(?:\?.*)$/, '')
|
35
41
|
end
|
36
42
|
end
|
37
43
|
|
38
44
|
# Returns the protocol. e.g. `http`.
|
39
45
|
def extract_protocol(input)
|
40
46
|
matches = input.to_s.match(/^(\w+):/)
|
41
|
-
|
42
|
-
|
47
|
+
matches ? matches[1] : ""
|
48
|
+
end
|
49
|
+
|
50
|
+
# Returns the query string part. e.g. `param1=value1¶m2=value2`.
|
51
|
+
def extract_qs(input)
|
52
|
+
input.to_s.gsub(/^[^\?]*\??/, '\1')
|
53
|
+
end
|
54
|
+
|
55
|
+
# Returns the first N elements of an array.
|
56
|
+
# e.g. `{{ ["first","second","third"] | array_head: 2 }}` =~ `["first","second"]`.
|
57
|
+
# If the number of parameters is negative it returns an empty array.
|
58
|
+
# The the input isn't an array it returns the untouched input.
|
59
|
+
def array_head(input, p)
|
60
|
+
input.kind_of?(Array) ? input.take([0, p.to_i].max) : input
|
61
|
+
end
|
62
|
+
|
63
|
+
# Returns the last N elements of an array.
|
64
|
+
# e.g. `{{ ["first","second","third"] | array_tail: 2 }}` =~ `["second","third"]`.
|
65
|
+
# If the number of parameters is negative it returns an empty array.
|
66
|
+
# The the input isn't an array it returns the untouched input.
|
67
|
+
def array_tail(input, p)
|
68
|
+
input.kind_of?(Array) ? input.drop([0, input.length - p.to_i].max) : input
|
69
|
+
end
|
70
|
+
|
71
|
+
# Transforms an array into an enclose html tag list separated by newline.
|
72
|
+
# e.g. `{{ ["first","second" | array_to_taglist: "li" }}` =~
|
73
|
+
# ```html
|
74
|
+
# <li>first</li>
|
75
|
+
# <li>second</li>
|
76
|
+
# ```
|
77
|
+
# The the input isn't an array it returns the untouched input.
|
78
|
+
def array_to_taglist(input, p)
|
79
|
+
if input.kind_of?(Array) && p.kind_of?(String)
|
80
|
+
startTag = "<" + p + ">"
|
81
|
+
endTag = "</" + p + ">"
|
82
|
+
input.length != 0 ? startTag + input.join(endTag + "\n" + startTag) + endTag : ""
|
43
83
|
else
|
44
|
-
|
84
|
+
input
|
45
85
|
end
|
46
86
|
end
|
87
|
+
|
47
88
|
end
|
48
89
|
|
49
90
|
Liquid::Template.register_filter(FrozenFilters)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: frozen-filters
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alexandre Bento Freire
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-09-
|
11
|
+
date: 2018-09-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: liquid
|
@@ -24,9 +24,8 @@ dependencies:
|
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '4.0'
|
27
|
-
description:
|
28
|
-
|
29
|
-
Designed to be used with jekyll.
|
27
|
+
description: " Liquid filters for shopify template engine. Designed to be used with
|
28
|
+
jekyll.\n"
|
30
29
|
email: devpieces@a-bentofreire.com
|
31
30
|
executables: []
|
32
31
|
extensions: []
|