jekyll-config-variables 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: d0f6eec0587832e96bb779767ba7935725ad1c3b
4
+ data.tar.gz: d4f0647fad2b6680469043478abcfc3d9a259323
5
+ SHA512:
6
+ metadata.gz: 62540a9382ed0ecbd0a4d48f4565f16e96d27de58172078221492c87189d6140dc4592d925fd73a4f866f107981801a7d70eeb4606d34a30594849b79bc18037
7
+ data.tar.gz: b3e72f3f8f25d18c9032be5724b2fd1466c55c1e0be9395456cf48cac810845c5af7d1861e6a21e24a04322a33b1bdb63534922717ec8b608393caa9c166c157
@@ -0,0 +1,18 @@
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
+ spec/fixtures/_site
@@ -0,0 +1,6 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.1
4
+ - 2.0
5
+ - 1.9.3
6
+ script: "script/cibuild"
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in jekyll-alt-urls.gemspec
4
+ gemspec
@@ -0,0 +1,25 @@
1
+ jekyll-verison-helper
2
+ =======================
3
+
4
+ This gem lets you define variables within a *_config.yml* file and refer to it through the same file.
5
+
6
+ To do that, first, create a key called `variables`, and populate it with any set of variable names you like:
7
+
8
+ ``` yaml
9
+ variables:
10
+ latest_version: "2.0"
11
+ ```
12
+
13
+ In this case, a new variable called `latest_version` is available to use, and it's defined a `"2.0"`. You can use this variable throughout your YAML file with the `%{...}` notation. For example:
14
+
15
+ ``` yaml
16
+ defaults:
17
+ -
18
+ scope:
19
+ path: ""
20
+ type: "source"
21
+ values:
22
+ version: "%{latest_version}"
23
+ ```
24
+
25
+ This sets a frontmatter of `version` on all the files in the `source` collection. It uses whatever value is defined in `latest_version` to set that up.
@@ -0,0 +1,6 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task default: :spec
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in jekyll-alt-urls.gemspec
4
+ gemspec
File without changes
@@ -0,0 +1,6 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task default: :spec
@@ -0,0 +1,24 @@
1
+ lib = File.expand_path('../lib', __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+
4
+ Gem::Specification.new do |spec|
5
+ spec.name = 'jekyll-version-helper'
6
+ spec.version = '0.0.1'
7
+ spec.authors = ['Garen Torikian']
8
+ spec.email = ['gjtorikian@gmail.com']
9
+ spec.summary = 'A set of monkey-patching plugins to help Jekyll when building versioned sites'
10
+ spec.description = ''
11
+ spec.homepage = ''
12
+ spec.license = 'MIT'
13
+
14
+ spec.files = `git ls-files`.split($/)
15
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
16
+ spec.test_files = spec.files.grep(%r{^(test)/})
17
+ spec.require_paths = ['lib']
18
+
19
+ spec.add_runtime_dependency 'jekyll', '~> 2.0'
20
+
21
+ spec.add_development_dependency 'bundler', '~> 1.3'
22
+ spec.add_development_dependency 'rake'
23
+ spec.add_development_dependency 'rspec'
24
+ end
@@ -0,0 +1,33 @@
1
+ # encoding: UTF-8
2
+
3
+ def iterate(h, variables)
4
+ h.each do |k, v|
5
+ # If v is nil, an array is being iterated and the value is k.
6
+ # If v is not nil, a hash is being iterated and the value is v.
7
+ #
8
+ value = v || k
9
+
10
+ if value.is_a?(Hash) || value.is_a?(Array)
11
+ iterate(value, variables)
12
+ else
13
+ variables.each_pair { |var, val| v.gsub!(/\%\{#{var}\}/, val) } if v.is_a? String
14
+ end
15
+ end
16
+ end
17
+
18
+ module Jekyll
19
+ class Site
20
+
21
+ alias_method :old_process, :process
22
+
23
+ def process
24
+ variables = self.config['variables']
25
+ return old_process if variables.nil?
26
+
27
+ iterate(self.config, variables)
28
+
29
+ old_process
30
+ end
31
+
32
+ end
33
+ end
@@ -0,0 +1,4 @@
1
+ module JekyllVersionHelper
2
+ require 'configurer'
3
+ require 'permalinker'
4
+ end
@@ -0,0 +1,29 @@
1
+ # encoding: UTF-8
2
+
3
+ module Jekyll
4
+ class Document
5
+ alias_method :old_url_placeholders, :url_placeholders
6
+
7
+ PROTECTED_NAMES = %w(index search)
8
+
9
+ def url_placeholders
10
+ additional_placeholders = site.config['placeholders'] || {}
11
+ split_path = cleaned_relative_path.split('/')
12
+ filename = split_path.pop # last value is the filename
13
+
14
+ if !PROTECTED_NAMES.include? filename
15
+ if split_path.last == 'hidden'
16
+ split_path.pop
17
+ path = (split_path << filename).join('/')
18
+ else
19
+ path = old_url_placeholders[:path]
20
+ end
21
+ additional_placeholders[:dirpath] = File.join(path, "index#{old_url_placeholders[:output_ext]}")
22
+ else
23
+ additional_placeholders[:dirpath] = File.join(*split_path, "#{filename}#{old_url_placeholders[:output_ext]}")
24
+ end
25
+
26
+ old_url_placeholders.merge(additional_placeholders)
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,12 @@
1
+ require 'spec_helper'
2
+
3
+ describe('Configurer') do
4
+ let(:file1) { setup_doc('file1.md') }
5
+ let(:file2) { setup_doc('file2.md') }
6
+
7
+ it "writes the default frontmatter using a variable" do
8
+ require 'pp'
9
+ pp file1
10
+ expect(1).to eql(3)
11
+ end
12
+ end
@@ -0,0 +1,41 @@
1
+ require 'jekyll'
2
+ require 'yaml'
3
+ require File.expand_path('lib/jekyll-config-variables.rb')
4
+
5
+ RSpec.configure do |config|
6
+
7
+ config.run_all_when_everything_filtered = true
8
+ config.filter_run :focus
9
+ config.order = 'random'
10
+
11
+ config.expect_with :rspec do |c|
12
+ c.syntax = :expect
13
+ end
14
+
15
+ config.before(:each) do
16
+ Jekyll.logger.log_level = :error
17
+
18
+ @fixtures_path = Pathname.new(__FILE__).parent.join('fixtures')
19
+ @dest = @fixtures_path.join('_site')
20
+ @config_src = @fixtures_path.join('_config.yml')
21
+ # @posts_src = @fixtures_path.join('_posts')
22
+ # @layouts_src = @fixtures_path.join('_layouts')
23
+ # @plugins_src = @fixtures_path.join('_plugins')
24
+
25
+ @site = Jekyll::Site.new(Jekyll.configuration(
26
+ YAML.load_file(@config_src)
27
+ ))
28
+
29
+ @dest.rmtree if @dest.exist?
30
+ @site.process
31
+ end
32
+
33
+ config.after(:each) do
34
+ # @dest.rmtree if @dest.exist?
35
+ end
36
+
37
+ def setup_doc(doc_filename)
38
+ puts @site.collections['source'].docs
39
+ @site.collections['source'].docs.find { |d| d.relative_path.match(doc_filename) }
40
+ end
41
+ end
@@ -0,0 +1,24 @@
1
+ lib = File.expand_path('../lib', __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+
4
+ Gem::Specification.new do |spec|
5
+ spec.name = 'jekyll-config-variables'
6
+ spec.version = '0.1.0'
7
+ spec.authors = ['Garen Torikian']
8
+ spec.email = ['gjtorikian@gmail.com']
9
+ spec.summary = 'A Jekyll monkey-patch to allow you to use variables within your _config.yml file'
10
+ spec.description = ''
11
+ spec.homepage = 'https://github.com/gjtorikian/jekyll-config-variables'
12
+ spec.license = 'MIT'
13
+
14
+ spec.files = `git ls-files`.split($/)
15
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
16
+ spec.test_files = spec.files.grep(%r{^(test)/})
17
+ spec.require_paths = ['lib']
18
+
19
+ spec.add_runtime_dependency 'jekyll', '~> 2.0'
20
+
21
+ spec.add_development_dependency 'bundler', '~> 1.3'
22
+ spec.add_development_dependency 'rake'
23
+ spec.add_development_dependency 'rspec'
24
+ end
@@ -0,0 +1,33 @@
1
+ # encoding: UTF-8
2
+
3
+ def iterate(h, variables)
4
+ h.each do |k, v|
5
+ # If v is nil, an array is being iterated and the value is k.
6
+ # If v is not nil, a hash is being iterated and the value is v.
7
+ #
8
+ value = v || k
9
+
10
+ if value.is_a?(Hash) || value.is_a?(Array)
11
+ iterate(value, variables)
12
+ else
13
+ variables.each_pair { |var, val| v.gsub!(/\%\{#{var}\}/, val) } if v.is_a? String
14
+ end
15
+ end
16
+ end
17
+
18
+ module Jekyll
19
+ class Site
20
+
21
+ alias_method :old_process, :process
22
+
23
+ def process
24
+ variables = self.config['variables']
25
+ return old_process if variables.nil?
26
+
27
+ iterate(self.config, variables)
28
+
29
+ old_process
30
+ end
31
+
32
+ end
33
+ end
@@ -0,0 +1,3 @@
1
+ module JekyllConfigVariables
2
+ require 'configurer'
3
+ end
@@ -0,0 +1,3 @@
1
+ #! /bin/bash
2
+
3
+ bundle install
@@ -0,0 +1,4 @@
1
+ #! /bin/bash
2
+
3
+ script/bootstrap > /dev/null 2>&1
4
+ bundle exec rake spec
@@ -0,0 +1,15 @@
1
+ variables:
2
+ latest_version: "2.0"
3
+
4
+ collections:
5
+ source:
6
+ output: true
7
+ permalink: '/output/%{latest_version}/:dirpath'
8
+
9
+ defaults:
10
+ -
11
+ scope:
12
+ path: ""
13
+ type: "source"
14
+ values:
15
+ version: "%{latest_version}"
@@ -0,0 +1,5 @@
1
+ ---
2
+ title: A file
3
+ ---
4
+
5
+ I am a file.
@@ -0,0 +1,5 @@
1
+ ---
2
+ title: Another file
3
+ ---
4
+
5
+ I am another file.
@@ -0,0 +1,5 @@
1
+ ---
2
+ title: Another index!
3
+ ---
4
+
5
+ I am an md index.
@@ -0,0 +1,5 @@
1
+ ---
2
+ title: Search page
3
+ ---
4
+
5
+ I search and stuff.
@@ -0,0 +1,5 @@
1
+ ---
2
+ title: The index.
3
+ ---
4
+
5
+ Hello, I am an index.
@@ -0,0 +1,5 @@
1
+ ---
2
+ title: A page
3
+ ---
4
+
5
+ I am a page.
File without changes
@@ -0,0 +1,13 @@
1
+ require 'spec_helper'
2
+
3
+ describe('Configurer') do
4
+ let(:index) { setup_doc('index.html') }
5
+ let(:file1) { setup_doc('file1.md') }
6
+ let(:file2) { setup_doc('file2.md') }
7
+
8
+ it 'writes the default frontmatter using a variable' do
9
+ expect(file1.data['version']).to eql('2.0')
10
+ expect(file2.data['version']).to eql('2.0')
11
+ expect(index.data['version']).to eql('2.0')
12
+ end
13
+ end
@@ -0,0 +1,49 @@
1
+ require 'jekyll'
2
+ require 'yaml'
3
+ require File.expand_path('lib/jekyll-config-variables.rb')
4
+
5
+ RSpec.configure do |config|
6
+
7
+ config.run_all_when_everything_filtered = true
8
+ config.filter_run :focus
9
+ config.order = 'random'
10
+
11
+ config.expect_with :rspec do |c|
12
+ c.syntax = :expect
13
+ end
14
+
15
+ config.before(:each) do
16
+ Jekyll.logger.log_level = :error
17
+
18
+ @fixtures_path = Pathname.new(__FILE__).parent.join('fixtures')
19
+ @dest = @fixtures_path.join('_site')
20
+ @config_src = @fixtures_path.join('_config.yml')
21
+ @posts_src = @fixtures_path.join('_posts')
22
+ @layouts_src = @fixtures_path.join('_layouts')
23
+ @plugins_src = @fixtures_path.join('_plugins')
24
+
25
+ @site = Jekyll::Site.new(Jekyll.configuration(
26
+ 'source' => @fixtures_path.to_s,
27
+ 'destination' => @dest.to_s,
28
+ 'plugins' => @plugins_src.to_s,
29
+ 'collections' => {
30
+ 'source' => {'output' => true}
31
+ }
32
+ ))
33
+
34
+ @dest.rmtree if @dest.exist?
35
+ @site.process
36
+ end
37
+
38
+ # config.after(:each) do
39
+ # @dest.rmtree if @dest.exist?
40
+ # end
41
+
42
+ def setup_doc(doc_filename)
43
+ @site.collections['source'].docs.find { |d| d.relative_path.match(doc_filename) }
44
+ end
45
+
46
+ def destination_file_exists?(file)
47
+ File.exist?(File.join(@dest.to_s, file))
48
+ end
49
+ end
metadata ADDED
@@ -0,0 +1,130 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jekyll-config-variables
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Garen Torikian
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-12-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.3'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.3'
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
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
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
+ email:
71
+ - gjtorikian@gmail.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - ".travis.yml"
78
+ - Gemfile
79
+ - README.md
80
+ - Rakefile
81
+ - _site/Gemfile
82
+ - _site/README.md
83
+ - _site/Rakefile
84
+ - _site/jekyll-version-helper.gemspec
85
+ - _site/lib/configurer.rb
86
+ - _site/lib/jekyll-version-helper.rb
87
+ - _site/lib/permalinker.rb
88
+ - _site/spec/jekyll-version-helper/configurer_spec.rb
89
+ - _site/spec/spec_helper.rb
90
+ - jekyll-config-variables.gemspec
91
+ - lib/configurer.rb
92
+ - lib/jekyll-config-variables.rb
93
+ - script/bootstrap
94
+ - script/cibuild
95
+ - spec/fixtures/_config.yml
96
+ - spec/fixtures/_source/folder/file1.md
97
+ - spec/fixtures/_source/folder/file2.md
98
+ - spec/fixtures/_source/folder/index.md
99
+ - spec/fixtures/_source/folder/search/search.html
100
+ - spec/fixtures/_source/index.html
101
+ - spec/fixtures/_source/page1.md
102
+ - spec/fixtures/_source/search.html
103
+ - spec/jekyll-config-variables/configurer_spec.rb
104
+ - spec/spec_helper.rb
105
+ homepage: https://github.com/gjtorikian/jekyll-config-variables
106
+ licenses:
107
+ - MIT
108
+ metadata: {}
109
+ post_install_message:
110
+ rdoc_options: []
111
+ require_paths:
112
+ - lib
113
+ required_ruby_version: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ required_rubygems_version: !ruby/object:Gem::Requirement
119
+ requirements:
120
+ - - ">="
121
+ - !ruby/object:Gem::Version
122
+ version: '0'
123
+ requirements: []
124
+ rubyforge_project:
125
+ rubygems_version: 2.2.2
126
+ signing_key:
127
+ specification_version: 4
128
+ summary: A Jekyll monkey-patch to allow you to use variables within your _config.yml
129
+ file
130
+ test_files: []