Security News
Oracle Drags Its Feet in the JavaScript Trademark Dispute
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
jekyll_from_to_until
Advanced tools
jekyll_from_to_until
This module provides 3 filters that return portions of a multiline string. It can be used as a Jekyll plugin, or it can be called from any Ruby program.
Matches are specified by regular expressions; the simplest regular expression is a string.
from
— returns the portion beginning with the line that satisfies a regular expression to the end of the multiline string.to
— returns the portion from the first line to the line that satisfies a regular expression, including the matched line.until
— returns the portion from the first line to the line that satisfies a regular expression, excluding the matched line.Rubular is a handy online tool to try out regular expressions.
More information is available on the jekyll_from_to_until
gem web page.
If you want to use this Ruby gem in a Jekyll application,
add the following line to your application's Gemfile
:
group :jekyll_plugins do
gem 'jekyll_from_to_until'
end
And then install in the usual fashion:
$ bundle
Add the following line to your application's .gemspec
:
spec.add_dependency 'jekyll_from_to_until'
And then install the dependencies in the usual fashion:
$ bundle
Add the following line to your application's Gemfile
:
gem 'jekyll_from_to_until'
And then install the dependencies in the usual fashion:
$ bundle
The regular expression may be enclosed in single quotes, double quotes, or nothing.
from
All of these examples perform identically.
{{ sourceOfLines | from: 'regex' }}
{{ sourceOfLines | from: "regex" }}
{{ sourceOfLines | from: regex }}
to
All of these examples perform identically.
{{ sourceOfLines | to: 'regex' }}
{{ sourceOfLines | to: "regex" }}
{{ sourceOfLines | to: regex }}
until
All of these examples perform identically.
{{ sourceOfLines | until: 'regex' }}
{{ sourceOfLines | until: "regex" }}
{{ sourceOfLines | until: regex }}
:warning: Important: the name of the filter must be followed by a colon (:).
If you fail to do that an error will be generated and the Jekyll site building process will halt.
The error message looks something like this:
Liquid Warning: Liquid syntax error (line 285): Expected end_of_string but found string in "{{ lines | from '2' | until: '4' | xml_escape }}" in /some_directory/some_files.html Liquid Exception: Liquid error (line 285): wrong number of arguments (given 1, expected 2) in /some_directory/some_file. html Error: Liquid error (line 285): wrong number of arguments (given 1, expected 2)
Some of the following examples use a multiline string called lines
that contains 5 lines, which was created this way:
{% capture lines %}line 1
line 2
line 3
line 4
line 5
{% endcapture %}
Other examples use a multiline string called gitignore
that contains the contents of a mythical .gitignore
file,
which looks like this:
.bsp/
project/
target/
*.gz
*.sublime*
*.swp
*.out
*.Identifier
*.log
.idea*
*.iml
*.tmp
*~
~*
.DS_Store
.idea
.jekyll-cache/
.jekyll-metadata
.sass-cache/
.yardoc/
__pycache__/
__MACOSX
_build/
_package/
_site/
bin/*.class
doc/
jekyll/doc/
node_modules/
Notepad++/
out/
package/
instances.json
rescue_ubuntu2010
rescue_ubuntu2010.b64
landingPageShortName.md
test.html
RUNNING_PID
mslinn_jekyll_plugins.zip
cloud9.tar
cloud9.zip
mslinn_aws.tar
These examples return the lines of the file from the beginning of the until a line with the string "3" is found, including the matched line. The only difference between the examples is the delimiter around the regular expression.
{{ lines | from: '3' }}
{{ lines | from: "3" }}
{{ lines | from: 3 }}
The above all generate:
line 3
line 4
line 5
{% capture gitignore %}{% flexible_include '.gitignore' %}{% endcapture %}
{{ gitignore | from: 'PID' | xml_escape }}
The above generates:
RUNNING_PID
mslinn_jekyll_plugins.zip
cloud9.tar
cloud9.zip
mslinn_aws.tar
These examples return the lines of the file from the first line until a line with the string "3"
is found,
including the matched line.
The only difference between the examples is the delimiter around the regular expression.
{{ lines | to: '3' }}
{{ lines | to: "3" }}
{{ lines | to: 3 }}
The above all generate:
line 1
line 2
line 3
{{ gitignore | to: 'idea' }}
The above generates:
.bsp/
project/
target/
*.gz
*.sublime*
*.swp
*.out
*.Identifier
*.log
.idea*
These examples return the lines of the file until a line with the string "3"
is found, excluding the matched line.
The only difference between the examples is the delimiter around the regular expression.
{{ lines | until: '3' }}
{{ lines | until: "3" }}
{{ lines | until: 3 }}
The above all generate:
line 1
line 2
{{ gitignore | until: 'idea' }}
The above generates:
.bsp/
project/
target/
*.gz
*.sublime*
*.swp
*.out
*.Identifier
*.log
These examples return the lines of the file until a line with the string "3"
is found, excluding the matched line.
The only difference between the examples is the delimiter around the regular expression.
{{ lines | from: '2' | until: '4' }}
{{ lines | from: "2" | until: "4" }}
{{ lines | from: 2 | until: 4 }}
The above all generate:
line 2
line 3
The .gitignore
file does not contain the string xx
.
If we attempt to match against that string the remainder of the file is returned for the to and until filter.
{{ gitignore | from: 'PID' | until: 'xx' }}
The above generates:
RUNNING_PID
mslinn_jekyll_plugins.zip
cloud9.tar
cloud9.zip
mslinn_aws.tar
The from
, to
and until
filters can all accept regular expressions.
The regular expression matches lines that have either the string sun
or cloud
at the beginning of the line.
{{ gitignore | from: '^(cloud|sun)' }}
The above generates:
cloud9.tar
cloud9.zip
mslinn_aws.tar
Special characters can be specified as HTML entities.
For example, }
is Open parenthesis. Belle par. A parent. 5 Resulting. OK. OK, so now what }
.
{{ css | from: '.error' | to: '}' | strip }}
demo/special.html
demonstrates this.
After checking out the repo, run bin/setup
to install dependencies.
You can also run bin/console
for an interactive prompt that will allow you to experiment.
To build and install this gem onto your local machine, run:
$ bundle exec rake install
Examine the newly built gem:
$ gem info jekyll_from_to_until
*** LOCAL GEMS ***
jekyll_from_to_until (1.0.0)
Author: Mike Slinn
Homepage:
https://github.com/mslinn/jekyll_from_to_until
License: MIT
Installed at: /home/mslinn/.gems
Generates Jekyll logger with colored output.
A test/demo website is provided in the demo
directory.
You can run it under a debugger, or let it run free.
The demo/_bin/debug
script can set various parameters for the demo.
View the help information with the -h
option:
$ demo/_bin/debug -h
debug - Run the demo Jekyll website.
By default the demo Jekyll website runs without restriction under ruby-debug-ide and debase.
View it at http://localhost:4444
Options:
-h Show this error message
-r Run freely, without a debugger
To run under a debugger, for example Visual Studio Code:
Set breakpoints.
Initiate a debug session from the command line:
$ demo/bin/debug
Once the Fast Debugger
signon appears, launch the Visual Studio Code launch configuration called Attach rdebug-ide
.
View the generated website at http://localhost:4444
.
To release a new version,
Update the version number in version.rb
.
Commit all changes to git; if you don't the next step might fail with an unexplainable error message.
Run the following:
$ bundle exec rake release
The above creates a git tag for the version, commits the created tag,
and pushes the new .gem
file to RubyGems.org.
The gem is available as open source under the terms of the MIT License.
FAQs
Unknown package
We found that jekyll_from_to_until demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.