jekyll_begin_end 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
+ SHA256:
3
+ metadata.gz: 777a1dfd0a686d88f77246edf2b1239393012bbd90891b98f5b5efdaf28d36bc
4
+ data.tar.gz: 89f839d3a222a55f9d821204fcecc7a4dc1e42c9db029ca0bddb5d03dec0788e
5
+ SHA512:
6
+ metadata.gz: 65c59361becd2b4436d7aab8c8c006be52d1588c27e2a388436cf6b941d33e6c1dd81eeb8b83732f682b00188d57ff308fe6b045c7ed060ce5563ed1009803ef
7
+ data.tar.gz: b09eb2adb187174af0824dfc71d79fe786322c0a2f7a80568624041d8ea9a8566198ee003b2e7da4d2ee67732413c7026802a64609a6b696f916bf7fc29407d5
data/.rubocop.yml ADDED
@@ -0,0 +1,34 @@
1
+ require: rubocop-jekyll
2
+ inherit_gem:
3
+ rubocop-jekyll: .rubocop.yml
4
+
5
+ AllCops:
6
+ Exclude:
7
+ - vendor/**/*
8
+ - Gemfile*
9
+ NewCops: enable
10
+ TargetRubyVersion: 2.6
11
+
12
+ Layout/LineLength:
13
+ Max: 150
14
+
15
+ Layout/MultilineMethodCallIndentation:
16
+ Enabled: false
17
+
18
+ Layout/MultilineOperationIndentation:
19
+ Enabled: false
20
+
21
+ Metrics/BlockLength:
22
+ Enabled: false
23
+
24
+ Style/PercentLiteralDelimiters:
25
+ Enabled: false
26
+
27
+ Style/RegexpLiteral:
28
+ Enabled: false
29
+
30
+ Style/StringLiterals:
31
+ Enabled: false
32
+
33
+ Style/StringLiteralsInInterpolation:
34
+ Enabled: false
data/CHANGELOG.md ADDED
@@ -0,0 +1,8 @@
1
+ ## 1.0.0 / 2022-03-14
2
+ * Made into a Ruby gem and published on RubyGems.org as [jekyll_begin_end](https://rubygems.org/gems/jekyll_begin_end).
3
+ * `bin/attach` script added for debugging
4
+ * Rubocop standards added
5
+ * Proper versioning and CHANGELOG.md added
6
+
7
+ ## 0.1.0 / 2020-12-29
8
+ * Initial version published
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2020 Mike Slinn
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,195 @@
1
+ `jekyll_begin_end`
2
+ [![Gem Version](https://badge.fury.io/rb/jekyll_begin_end.svg)](https://badge.fury.io/rb/jekyll_begin_end)
3
+ ===========
4
+
5
+ Defines the following Jekyll filters:
6
+
7
+ * `begins_with` — returns `true` if a string starts with a given substring.
8
+ * `does_not_begin_with` — returns `false` if a string starts with a given substring.
9
+ * `ends_with` — returns `true` if a string end with a given substring.
10
+ * `does_not_end_with` — returns `false` if a string end with a given substring.
11
+ * `append_suffix_if_does_not_start_with` — appends a suffix to the string if the string does not start with a substring.
12
+
13
+ ## Syntax
14
+
15
+ :warning: Important: the name of each of these filters 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 | begins_with 'blah' | 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)`
16
+
17
+ ### `begins_with`
18
+ First example:
19
+ ```
20
+ {% assign url = "https:/asdf.com" %}
21
+ {% assign isAbsolute = url | begins_with: 'http' %}
22
+ ```
23
+
24
+ Second example:
25
+ ```
26
+ {% assign url = "https:/asdf.com" %}
27
+ {% if url | begins_with: 'http' %}
28
+ <p>Absolute</p>
29
+ {% else %}
30
+ <p>Relative</p>
31
+ {% endif %}
32
+ ```
33
+
34
+ ### `does_not_begin_with`
35
+ First example:
36
+ ```
37
+ {% assign url = "https:/asdf.com" %}
38
+ {% assign isRelative = url | does_not_begin_with: 'http' %}
39
+ ```
40
+
41
+ Second example
42
+ ```
43
+ {% assign url = "https:/asdf.com" %}
44
+ {% if url | does_not_begin_with: 'http' %}
45
+ <p>Relative</p>
46
+ {% else %}
47
+ <p>Absolute</p>
48
+ {% endif %}
49
+ ```
50
+
51
+ ### `ends_with`
52
+ First example:
53
+ ```
54
+ {% assign url = "https:/asdf.com" %}
55
+ {% assign isDotCom = url | ends_with: '.com' %}
56
+ ```
57
+
58
+ Second example:
59
+ ```
60
+ {% assign url = "https:/asdf.com" %}
61
+ {% if url | ends_with: '.com' %}
62
+ <p>.com found</p>
63
+ {% else %}
64
+ <p>Not a .com</p>
65
+ {% endif %}
66
+ ```
67
+
68
+ ### `does_not_end_with`
69
+ First example:
70
+ ```
71
+ {% assign url = "https:/asdf.com" %}
72
+ {% assign isNotDotCom = url | does_not_end_with: '.com' %}
73
+ ```
74
+
75
+ Second example:
76
+ ```
77
+ {% assign url = "https:/asdf.com" %}
78
+ {% if url | does_not_end_with: '.com' %}
79
+ <p>Not a .com</p>
80
+ {% else %}
81
+ <p>.com found</p>
82
+ {% endif %}
83
+ ```
84
+
85
+
86
+ ### `append_suffix_if_does_not_start_with`
87
+ This filter was created to make asset reloading work better.
88
+
89
+ Given a portion of `_layouts/default.html` that looks like this:
90
+ ```
91
+ {% assign csses = page.css | default: layout.css %}
92
+ {% assign nowMillis = site.time | date: '%s' %}
93
+ {% assign suffix = '?v=' | append: nowMillis %}
94
+ {% for css in csses %}
95
+ <link rel="stylesheet" href="{{ css | append_suffix_if_does_not_start_with: 'http', suffix }}" type="text/css">
96
+ {% endfor %}
97
+ ```
98
+ And given `index.html` with front matter that looks like this:
99
+ ```
100
+ ---
101
+ css: [
102
+ https://cdnjs.cloudflare.com/ajax/libs/jquery-modal/0.9.1/jquery.modal.min.css,
103
+ /order/order.css
104
+ ]
105
+ ---
106
+ ```
107
+
108
+ The following is generated. Note that the suffix s?v=1612879301 in only applied to the relative URL for `order.css`.
109
+ ```
110
+ <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/jquery-modal/0.9.1/jquery.modal.min.css" type="text/css">
111
+ <link rel="stylesheet" href="/order/order.css?v=1612879301" type="text/css">
112
+ ```
113
+
114
+
115
+ ### Additional Information
116
+ More information is available on my web site about [my Jekyll plugins](https://www.mslinn.com/blog/2020/10/03/jekyll-plugins.html).
117
+
118
+
119
+ ## Installation
120
+
121
+ Add this line to your application's Gemfile:
122
+
123
+ ```ruby
124
+ group :jekyll_plugins do
125
+ gem 'jekyll_begin_end'
126
+ end
127
+ ```
128
+
129
+ And then execute:
130
+
131
+ $ bundle install
132
+
133
+ Or install it yourself as:
134
+
135
+ $ gem install jekyll_begin_end
136
+
137
+
138
+ ## Development
139
+
140
+ After checking out the repo, run `bin/setup` to install dependencies.
141
+
142
+ You can also run `bin/console` for an interactive prompt that will allow you to experiment.
143
+
144
+
145
+ ### Build and Install Locally
146
+ To build and install this gem onto your local machine, run:
147
+ ```shell
148
+ $ rake install:local
149
+ ```
150
+
151
+ The following also does the same thing:
152
+ ```shell
153
+ $ bundle exec rake install
154
+ ```
155
+
156
+ Examine the newly built gem:
157
+ ```shell
158
+ $ gem info jekyll_begin_end
159
+
160
+ *** LOCAL GEMS ***
161
+
162
+ jekyll_begin_end (1.0.0)
163
+ Author: Mike Slinn
164
+ Homepage:
165
+ https://github.com/mslinn/jekyll_begin_end
166
+ License: MIT
167
+ Installed at: /home/mslinn/.gems
168
+
169
+ Generates Jekyll logger with colored output.
170
+ ```
171
+
172
+
173
+ ### Build and Push to RubyGems
174
+ To release a new version,
175
+ 1. Update the version number in `version.rb`.
176
+ 2. Commit all changes to git; if you don't the next step might fail with an unexplainable error message.
177
+ 3. Run the following:
178
+ ```shell
179
+ $ bundle exec rake release
180
+ ```
181
+ The above creates a git tag for the version, commits the created tag,
182
+ and pushes the new `.gem` file to [RubyGems.org](https://rubygems.org).
183
+
184
+
185
+ ## Contributing
186
+
187
+ 1. Fork the project
188
+ 2. Create a descriptively named feature branch
189
+ 3. Add your feature
190
+ 4. Submit a pull request
191
+
192
+
193
+ ## License
194
+
195
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+ task :default => :spec
@@ -0,0 +1,45 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/jekyll_begin_end/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ github = "https://github.com/mslinn/jekyll_begin_end"
7
+
8
+ spec.authors = ["Mike Slinn"]
9
+ spec.bindir = "exe"
10
+ spec.description = <<~END_DESC
11
+ This Jekyll plugin defines the following Jekyll filters that return portions of a string:
12
+ begins_with — returns true if a string starts with a given substring.
13
+ does_not_begin_with — returns false if a string starts with a given substring.
14
+ ends_with — returns true if a string end with a given substring.
15
+ does_not_end_with — returns false if a string end with a given substring.
16
+ append_suffix_if_does_not_start_with — appends a suffix to the string if the string does not start with a substring.
17
+ END_DESC
18
+ spec.email = ["mslinn@mslinn.com"]
19
+ spec.files = Dir[".rubocop.yml", "LICENSE.*", "Rakefile", "{lib,spec}/**/*", "*.gemspec", "*.md"]
20
+ spec.homepage = "https://www.mslinn.com/blog/2020/10/03/jekyll-plugins.html#begin_end"
21
+ spec.license = "MIT"
22
+ spec.metadata = {
23
+ "allowed_push_host" => "https://rubygems.org",
24
+ "bug_tracker_uri" => "#{github}/issues",
25
+ "changelog_uri" => "#{github}/CHANGELOG.md",
26
+ "homepage_uri" => spec.homepage,
27
+ "source_code_uri" => github,
28
+ }
29
+ spec.name = "jekyll_begin_end"
30
+ spec.require_paths = ["lib"]
31
+ spec.required_ruby_version = ">= 2.6.0"
32
+ spec.summary = "This Jekyll plugin provides 5 filters that return portions of a string: begins_with, " \
33
+ "does_not_begin_with, ends_with, does_not_end_with and append_suffix_if_does_not_start_with."
34
+ spec.test_files = spec.files.grep(%r!^(test|spec|features)/!)
35
+ spec.version = JekyllFromToUntil::VERSION
36
+
37
+ spec.add_dependency "jekyll", ">= 3.5.0"
38
+ spec.add_dependency "jekyll_plugin_logger"
39
+
40
+ spec.add_development_dependency "debase"
41
+ # spec.add_development_dependency "rubocop-jekyll"
42
+ # spec.add_development_dependency "rubocop-rake"
43
+ # spec.add_development_dependency "rubocop-rspec"
44
+ spec.add_development_dependency "ruby-debug-ide"
45
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module JekyllFromToUntil
4
+ VERSION = "1.0.0"
5
+ end
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "jekyll_plugin_logger"
4
+ require_relative "jekyll_begin_end/version"
5
+
6
+ # Jekyll filters for working with strings.
7
+
8
+ module StringFilter
9
+ @logger = PluginMetaLogger.instance.new_logger(self)
10
+
11
+ def does_not_begin_with(text, query)
12
+ !text.start_with? query
13
+ end
14
+
15
+ def begins_with(text, query)
16
+ @logger.debug { "text=#{text} query=#{query} result: #{text.start_with? query}" }
17
+ text.start_with? query
18
+ end
19
+
20
+ def does_not_end_with(text, query)
21
+ !text.end_with? query
22
+ end
23
+
24
+ def ends_with(text, query)
25
+ text.end_with? query
26
+ end
27
+
28
+ def append_suffix_if_does_not_start_with(text, query, suffix)
29
+ text.start_with? query ? text : "#{text}#{suffix}"
30
+ end
31
+ end
32
+
33
+ PluginMetaLogger.instance.info { "Loaded jekyll_begin_end v#{JekyllFromToUntil::VERSION} plugin." }
34
+ Liquid::Template.register_filter(Jekyll::StringFilter)
@@ -0,0 +1,90 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'liquid'
4
+ require 'fileutils'
5
+ require "jekyll_plugin_logger"
6
+ require_relative '../lib/jekyll_begin_end'
7
+
8
+ RSpec.describe(JekyllFromToUntil) do
9
+ include JekyllFromToUntil
10
+
11
+ _logger = PluginMetaLogger.new_logger(self)
12
+
13
+ let(:lines) do
14
+ <<~END_OF_LINES
15
+ line 1
16
+ line 2
17
+ line 3
18
+ line 4
19
+ line 5
20
+ END_OF_LINES
21
+ end
22
+
23
+ let(:gitignore) do
24
+ <<~END_OF_LINES
25
+ .bsp/
26
+ project/
27
+ target/
28
+ *.gz
29
+ *.sublime*
30
+ *.swp
31
+ *.out
32
+ *.Identifier
33
+ *.log
34
+ .idea*
35
+ *.iml
36
+ *.tmp
37
+ *~
38
+ ~*
39
+ .DS_Store
40
+ .idea
41
+ .jekyll-cache/
42
+ .jekyll-metadata
43
+ .makeAwsBucketAndDistribution.log
44
+ .sass-cache/
45
+ .yardoc/
46
+ __pycache__/
47
+ __MACOSX
48
+ _build/
49
+ _package/
50
+ _site/
51
+ bin/*.class
52
+ doc/
53
+ jekyll/doc/
54
+ node_modules/
55
+ Notepad++/
56
+ out/
57
+ package/
58
+ instances.json
59
+ rescue_ubuntu2010
60
+ rescue_ubuntu2010.b64
61
+ landingPageShortName.md
62
+ test.html
63
+ RUNNING_PID
64
+ mslinn_jekyll_plugins.zip
65
+ cloud9.tar
66
+ cloud9.zip
67
+ mslinn_aws.tar
68
+ END_OF_LINES
69
+ end
70
+
71
+ it 'verifies from' do
72
+ expect(from(lines, '3')).to eq("line 3\nline 4\nline 5\n")
73
+ expect(from(gitignore, 'PID')).to eq("RUNNING_PID\nmslinn_jekyll_plugins.zip\ncloud9.tar\ncloud9.zip\nmslinn_aws.tar\n")
74
+ end
75
+
76
+ it 'verifies to' do
77
+ expect(to(lines, '3')).to eq("line 1\nline 2\nline 3\n")
78
+ expect(to(gitignore, 'idea')).to eq(".bsp/\nproject/\ntarget/\n*.gz\n*.sublime*\n*.swp\n*.out\n*.Identifier\n*.log\n.idea*\n")
79
+ end
80
+
81
+ it 'verifies until' do
82
+ # until is a Ruby keyword
83
+ expect(method(:until).call(lines, '3')).to eq("line 1\nline 2\n")
84
+ expect(method(:until).call(gitignore, 'idea')).to eq(".bsp/\nproject/\ntarget/\n*.gz\n*.sublime*\n*.swp\n*.out\n*.Identifier\n*.log\n")
85
+ end
86
+
87
+ it 'verifies from regex' do
88
+ expect(from(gitignore, '^(cloud|sun)')).to eq("cloud9.tar\ncloud9.zip\nmslinn_aws.tar\n")
89
+ end
90
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'liquid'
4
+ require 'fileutils'
5
+ require_relative '../lib/jekyll_begin_end'
6
+
7
+ RSpec.configure do |config|
8
+ config.run_all_when_everything_filtered = true
9
+ config.filter_run :focus
10
+ config.order = 'random'
11
+ end
metadata ADDED
@@ -0,0 +1,123 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jekyll_begin_end
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Mike Slinn
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2022-03-25 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: 3.5.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 3.5.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: jekyll_plugin_logger
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: debase
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: ruby-debug-ide
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
+ description: |
70
+ This Jekyll plugin defines the following Jekyll filters that return portions of a string:
71
+ begins_with — returns true if a string starts with a given substring.
72
+ does_not_begin_with — returns false if a string starts with a given substring.
73
+ ends_with — returns true if a string end with a given substring.
74
+ does_not_end_with — returns false if a string end with a given substring.
75
+ append_suffix_if_does_not_start_with — appends a suffix to the string if the string does not start with a substring.
76
+ email:
77
+ - mslinn@mslinn.com
78
+ executables: []
79
+ extensions: []
80
+ extra_rdoc_files: []
81
+ files:
82
+ - ".rubocop.yml"
83
+ - CHANGELOG.md
84
+ - LICENSE.txt
85
+ - README.md
86
+ - Rakefile
87
+ - jekyll_begin_end.gemspec
88
+ - lib/jekyll_begin_end.rb
89
+ - lib/jekyll_begin_end/version.rb
90
+ - spec/jekyll_begin_end.rb
91
+ - spec/spec_helper.rb
92
+ homepage: https://www.mslinn.com/blog/2020/10/03/jekyll-plugins.html#begin_end
93
+ licenses:
94
+ - MIT
95
+ metadata:
96
+ allowed_push_host: https://rubygems.org
97
+ bug_tracker_uri: https://github.com/mslinn/jekyll_begin_end/issues
98
+ changelog_uri: https://github.com/mslinn/jekyll_begin_end/CHANGELOG.md
99
+ homepage_uri: https://www.mslinn.com/blog/2020/10/03/jekyll-plugins.html#begin_end
100
+ source_code_uri: https://github.com/mslinn/jekyll_begin_end
101
+ post_install_message:
102
+ rdoc_options: []
103
+ require_paths:
104
+ - lib
105
+ required_ruby_version: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - ">="
108
+ - !ruby/object:Gem::Version
109
+ version: 2.6.0
110
+ required_rubygems_version: !ruby/object:Gem::Requirement
111
+ requirements:
112
+ - - ">="
113
+ - !ruby/object:Gem::Version
114
+ version: '0'
115
+ requirements: []
116
+ rubygems_version: 3.1.4
117
+ signing_key:
118
+ specification_version: 4
119
+ summary: 'This Jekyll plugin provides 5 filters that return portions of a string:
120
+ begins_with, does_not_begin_with, ends_with, does_not_end_with and append_suffix_if_does_not_start_with.'
121
+ test_files:
122
+ - spec/jekyll_begin_end.rb
123
+ - spec/spec_helper.rb