jekyll_constant_values 0.1.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 +11 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +65 -0
- data/Rakefile +1 -0
- data/jekyll_constant_values.gemspec +21 -0
- data/lib/jekyll_constant_values.rb +66 -0
- data/lib/jekyll_constant_values/version.rb +3 -0
- metadata +80 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 055e551e09e53e64092e17f340952638a02e5bb4
|
4
|
+
data.tar.gz: eb2f1b9272b843b2c8536bdd1ae34feec3ec9b4c
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 5ec326b003849b13a66517717a43c2dfc03e8a7fee1d2414c2be40a1570f2b17fffe8e12d947fb85aaa78bd63d6f0ac6d0134667b794b81f9e2866e56e0690d4
|
7
|
+
data.tar.gz: cb5e385336f453e44a5f77bea5bc6de1bc9c03df7b84624e492fd7cfe600ed08ad6eae785ce5cbe8568e6f404b9fb923a4b2e6689caf4cd8910c29c42454a9e9
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2017 unabris
|
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,65 @@
|
|
1
|
+
# Jekyll Constant Values
|
2
|
+
|
3
|
+
__Jekyll Constant Values__ plugin allows you to render constant values in the `.html` files of your [Jekyll][jekyll-web] project. This way, if you have words that you repeat a lot or words that are susceptible to changes (like the number of workers in your company), this plugin helps you to only have to modify the value in a single file.
|
4
|
+
|
5
|
+
## 1. Installation
|
6
|
+
|
7
|
+
1. Add the following to your site's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'jekyll_constant_values', group: :jekyll_plugins
|
11
|
+
```
|
12
|
+
|
13
|
+
2. Run `bundle install` in your command line:
|
14
|
+
|
15
|
+
```bash
|
16
|
+
$ bundle install
|
17
|
+
```
|
18
|
+
|
19
|
+
3. Create a new YAML file called `constants.yml` under your `_data/` folder. If you prefer, you can customize the name of the file (must be also under `_data/`) and put the name of your custom file without the extension in your `_config.yml` file this way:
|
20
|
+
|
21
|
+
```yaml
|
22
|
+
constants: your-custom-name
|
23
|
+
```
|
24
|
+
|
25
|
+
## 2. Usage
|
26
|
+
|
27
|
+
1. Fill your constants YAML file with the content you need:
|
28
|
+
|
29
|
+
```yaml
|
30
|
+
company_name: Group Hirthe-Ritchie
|
31
|
+
contact:
|
32
|
+
phone: (186)285-7925
|
33
|
+
address: 282 Kevin Brook
|
34
|
+
workers: 150
|
35
|
+
```
|
36
|
+
|
37
|
+
2. Use `{% const [key] %}` Jekyll tag to render the content you need in the `.html` files:
|
38
|
+
|
39
|
+
```html
|
40
|
+
<h3>{% const company_name %}</h3>
|
41
|
+
<p>We are more than {% const workers %} workers in our company located in {% const contact.address %}.</p>
|
42
|
+
<a href="tel:{% const contact.phone %}">Call us</a>
|
43
|
+
```
|
44
|
+
|
45
|
+
3. After rendering the previous example, you will see the following code in the `.html` file:
|
46
|
+
|
47
|
+
```html
|
48
|
+
<h3>Group Hirthe-Ritchie</h3>
|
49
|
+
<p>We are more than 150 workers in our company located in 282 Kevin Brook.</p>
|
50
|
+
<a href="tel:(186)285-7925">Call us</a>
|
51
|
+
```
|
52
|
+
|
53
|
+
## 3. Contributing
|
54
|
+
|
55
|
+
1. Fork it
|
56
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
57
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
58
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
59
|
+
5. Create a new Pull Request
|
60
|
+
|
61
|
+
## 4. License
|
62
|
+
|
63
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
64
|
+
|
65
|
+
[jekyll-web]: https://jekyllrb.com/
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'bundler/gem_tasks'
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'jekyll_constant_values/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'jekyll_constant_values'
|
8
|
+
spec.version = JekyllConstantValues::VERSION
|
9
|
+
spec.authors = ['Unai Abrisketa']
|
10
|
+
spec.email = ['unai.abrisqueta@gmail.com']
|
11
|
+
|
12
|
+
spec.summary = %q{Jekyll plugin to render constant values}
|
13
|
+
spec.homepage = 'https://github.com/unabris/jekyll_constant_values'
|
14
|
+
spec.license = 'MIT'
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.require_paths = ['lib']
|
18
|
+
|
19
|
+
spec.add_development_dependency 'bundler', '~> 1.13'
|
20
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
21
|
+
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
require 'jekyll_constant_values/version'
|
2
|
+
|
3
|
+
module Jekyll
|
4
|
+
class Site
|
5
|
+
attr_accessor :constants_file
|
6
|
+
alias :process_constants :process
|
7
|
+
|
8
|
+
def process
|
9
|
+
# Get the constants file path
|
10
|
+
const_file = constants_file_path
|
11
|
+
# Exit the process if not valid file
|
12
|
+
exit unless valid_file?(const_file)
|
13
|
+
# Assign the path if valid
|
14
|
+
self.constants_file ||= const_file
|
15
|
+
# Show info message
|
16
|
+
puts "Using file #{const_file} for constant values"
|
17
|
+
|
18
|
+
process_constants
|
19
|
+
end
|
20
|
+
|
21
|
+
def constants_file_path
|
22
|
+
# Check if a custom name for constants file is defined
|
23
|
+
if config['constants'].nil?
|
24
|
+
'_data/constants.yml' # Default constants file
|
25
|
+
else
|
26
|
+
'_data/' + config['constants'] + '.yml' # Custom constants file
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def valid_file?(const_file)
|
31
|
+
# Check if the constants file exist
|
32
|
+
unless File.exist?(const_file)
|
33
|
+
puts "No such file or directory #{const_file}"
|
34
|
+
return false
|
35
|
+
end
|
36
|
+
true
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
class ConstantValues < Liquid::Tag
|
41
|
+
def initialize(tag_name, key, tokens)
|
42
|
+
super
|
43
|
+
@key = key.strip
|
44
|
+
end
|
45
|
+
|
46
|
+
def render(context)
|
47
|
+
# Load Jekyll site object
|
48
|
+
site = context.registers[:site]
|
49
|
+
# Load constants file
|
50
|
+
c_file = YAML.load_file(site.constants_file)
|
51
|
+
# Get constant value
|
52
|
+
c_value = @key.to_s.split('.').inject(c_file) { |h, k| h[k.to_s] }
|
53
|
+
# Check if constant value is empty
|
54
|
+
if c_value.nil?
|
55
|
+
# Get the path of the file where is failing
|
56
|
+
page_path = context.registers[:page]['path']
|
57
|
+
# Show info message
|
58
|
+
puts "No constant value for key '#{@key}' in file '#{page_path}'"
|
59
|
+
end
|
60
|
+
# Return the constant value
|
61
|
+
c_value
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
Liquid::Template.register_tag('const', Jekyll::ConstantValues)
|
metadata
ADDED
@@ -0,0 +1,80 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: jekyll_constant_values
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Unai Abrisketa
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-05-02 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.13'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.13'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
description:
|
42
|
+
email:
|
43
|
+
- unai.abrisqueta@gmail.com
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- ".gitignore"
|
49
|
+
- Gemfile
|
50
|
+
- LICENSE.txt
|
51
|
+
- README.md
|
52
|
+
- Rakefile
|
53
|
+
- jekyll_constant_values.gemspec
|
54
|
+
- lib/jekyll_constant_values.rb
|
55
|
+
- lib/jekyll_constant_values/version.rb
|
56
|
+
homepage: https://github.com/unabris/jekyll_constant_values
|
57
|
+
licenses:
|
58
|
+
- MIT
|
59
|
+
metadata: {}
|
60
|
+
post_install_message:
|
61
|
+
rdoc_options: []
|
62
|
+
require_paths:
|
63
|
+
- lib
|
64
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
70
|
+
requirements:
|
71
|
+
- - ">="
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
version: '0'
|
74
|
+
requirements: []
|
75
|
+
rubyforge_project:
|
76
|
+
rubygems_version: 2.5.1
|
77
|
+
signing_key:
|
78
|
+
specification_version: 4
|
79
|
+
summary: Jekyll plugin to render constant values
|
80
|
+
test_files: []
|