jekyll-conrefifier 0.0.1

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 7fd6a5071f7e5ace52c45ef3f8847acac7aae9db
4
+ data.tar.gz: 64f0ce2548156487bfa205675ed0e54fbec2a387
5
+ SHA512:
6
+ metadata.gz: a08a27b34f9ad08e591294f0eebb97ca1ac2f0b855925dfec43a1bfdb0cbaaa7e933b31e794c5b5ccbe35f85e4d6c5b1fc043a1e27ba59a2c99170134ee17869
7
+ data.tar.gz: 79b585769a377eae919f873c0c48e71cd50a8f4141477cadc39de9a5397a3c00de531e6cbdeffef345a37e100302999fa6f961f90755bca6a9cc886d81979db7
data/.gitignore ADDED
@@ -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
data/.travis.yml ADDED
@@ -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-html-pipeline.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2014 Garen J. Torikian
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
6
+ this software and associated documentation files (the "Software"), to deal in
7
+ the Software without restriction, including without limitation the rights to
8
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9
+ the Software, and to permit persons to whom the Software is furnished to do so,
10
+ subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ 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, FITNESS
17
+ FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18
+ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19
+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,56 @@
1
+ # jekyll-conrefifier
2
+
3
+ A set of monkey patches that allows you to use Liquid variables in a variety of places in Jekyll.
4
+
5
+ ## Substitutions within frontmatter
6
+
7
+ You can include Liquid variables in your frontmatter, like this:
8
+
9
+ ``` markdown
10
+ ---
11
+ title: This is very {{ site.data.conrefs.product_type }}
12
+ ---
13
+
14
+ Some page.
15
+ ```
16
+
17
+ In this case, title would equals the value of `product_type` in [a data file](http://jekyllrb.com/docs/datafiles/) called *conrefs*.
18
+
19
+ ## Per-audience filtering
20
+
21
+ You can scope your variables to an audience value. For example, given a conref file that looks like this:
22
+
23
+ ``` yaml
24
+ product_name:
25
+ dotcom: GitHub
26
+ 2.0: GitHub Enterprise
27
+ 11.10.340: GitHub Enterprise
28
+ ```
29
+
30
+ And a file that looks like this:
31
+
32
+ ``` markdown
33
+ ---
34
+ title: Welcome to {{ site.data.conrefs.product_name[site.audience] }}
35
+ ---
36
+
37
+ Some other page.
38
+ ```
39
+
40
+ The title renders through `product_name`, then the value of `site.audience` to become "Welcome to GitHub".
41
+
42
+ ## Substitutions within data files
43
+
44
+ Your data files can also rely on Liquid substitution. For example, given a data file called *categories.yml* that looks like this:
45
+
46
+ ``` yaml
47
+ Bootcamp:
48
+ - Set Up Git
49
+ - Create A Repo
50
+ - Fork A Repo
51
+ - Be Social
52
+ - '{{ site.data.conrefs.product_name[site.audience] }} Glossary'
53
+ - Good Resources for Learning Git and GitHub
54
+ ```
55
+
56
+ The value renders out to "GitHub Glossary", just like above.
data/Rakefile ADDED
@@ -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,23 @@
1
+ lib = File.expand_path('../lib', __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require 'version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "jekyll-conrefifier"
7
+ spec.version = JekyllConrefifier::VERSION
8
+ spec.authors = ["Garen J. Torikian"]
9
+ spec.email = ["gjtorikian@gmail.com"]
10
+ spec.summary = %q{Allows you to use Liquid variables in various places in Jekyll}
11
+ spec.description = %q{A set of monkey patches that allows you to use Liquid variables in a variety of places in Jekyll, like frontmatter or data files.}
12
+ spec.homepage = ""
13
+ spec.license = "MIT"
14
+
15
+ spec.files = `git ls-files`.split($/)
16
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
+ spec.test_files = spec.files.grep(%r{^(test)/})
18
+ spec.require_paths = ["lib"]
19
+
20
+ spec.add_development_dependency "jekyll", "~> 2.0"
21
+ spec.add_development_dependency "rake"
22
+ spec.add_development_dependency "rspec"
23
+ end
@@ -0,0 +1,43 @@
1
+ module Jekyll
2
+ class Document
3
+ alias_method :old_read, :read
4
+
5
+ # allow us to use any variable within Jekyll Frontmatter; for example:
6
+ # title: What are {{ site.data.conrefs.product_name[site.audience] }} Pages?
7
+ # renders as "GitHub Pages?" for dotcom, but "GitHub Enterprise Pages?" for Enterprise
8
+ def read(opts = {})
9
+ old_read(opts)
10
+ @data.each_pair do |key, value|
11
+ if value =~ /\{\{.+?\}\}/
12
+ value = Liquid::Template.parse(value).render({ "site" => { "data" => @site.data }.merge(@site.config) })
13
+ @data[key] = value
14
+ end
15
+ end
16
+ end
17
+ end
18
+
19
+ class Site
20
+ alias_method :old_read, :read
21
+
22
+ # allow us to use any variable within Jekyll data files; for example:
23
+ # - '{{ site.data.conrefs.product_name[site.audience] }} Glossary'
24
+ # renders as "GitHub Glossary" for dotcom, but "GitHub Enterprise Glossary" for Enterprise
25
+ def read
26
+ old_read
27
+ data.each_pair do |data_file, data_set|
28
+ if data_set.is_a? Hash
29
+ data_set.each_pair do |key, values|
30
+ if values.is_a? Array
31
+ values.each_with_index do |value, i|
32
+ if value =~ /\{\{.+?\}\}/
33
+ value = Liquid::Template.parse(value).render({ "site" => { "data" => data }.merge(config) })
34
+ data[data_file][key][i] = value
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
data/lib/version.rb ADDED
@@ -0,0 +1,3 @@
1
+ module JekyllConrefifier
2
+ VERSION = "0.0.1"
3
+ end
data/script/cibuild ADDED
@@ -0,0 +1,4 @@
1
+ #! /bin/bash
2
+
3
+ script/bootstrap > /dev/null 2>&1
4
+ bundle exec rake spec
@@ -0,0 +1,18 @@
1
+ require 'spec_helper'
2
+
3
+ describe("Conrefifier") do
4
+ it "writes the proper page for simple substitutions" do
5
+ expect(@dest.join("articles", "this-is-very-amazing", "index.html")).to exist
6
+ end
7
+
8
+ it "writes the proper page for compicated substitutions" do
9
+ expect(@dest.join("articles", "welcome-to-github", "index.html")).to exist
10
+ end
11
+
12
+ it "writes the proper content after fetching info from a data file" do
13
+ index_file = @dest.join("index.html")
14
+ expect(index_file).to exist
15
+ index_contents = File.read(index_file)
16
+ expect(index_contents).to include("GitHub Glossary")
17
+ end
18
+ end
@@ -0,0 +1,5 @@
1
+ ---
2
+ title: Welcome to {{ site.data.conrefs.product_name[site.audience] }}
3
+ ---
4
+
5
+ Some other page.
@@ -0,0 +1,5 @@
1
+ ---
2
+ title: This is very {{ site.data.conrefs.product_type }}
3
+ ---
4
+
5
+ Some page.
@@ -0,0 +1,9 @@
1
+ gems:
2
+ - jekyll-conrefifier
3
+
4
+ collections:
5
+ articles:
6
+ output: true
7
+ permalink: /articles/:title/
8
+
9
+ audience: 'dotcom'
@@ -0,0 +1,7 @@
1
+ Bootcamp:
2
+ - Set Up Git
3
+ - Create A Repo
4
+ - Fork A Repo
5
+ - Be Social
6
+ - '{{ site.data.conrefs.product_name[site.audience] }} Glossary'
7
+ - Good Resources for Learning Git and GitHub
@@ -0,0 +1,6 @@
1
+ product_name:
2
+ dotcom: GitHub
3
+ 2.0: GitHub Enterprise
4
+ 11.10.340: GitHub Enterprise
5
+
6
+ product_type: 'Amazing'
@@ -0,0 +1,26 @@
1
+ ---
2
+ ---
3
+ <ul id="categories">
4
+ {% for category_hash in site.data.categories %}
5
+ {% assign category_title = category_hash[0] %}
6
+ {% assign category_articles = category_hash[1] %}
7
+
8
+ <li class="category">
9
+
10
+ <h5>
11
+ <span class="handle"></span>
12
+ <a href="{{ site.baseurl }}/categories/{{ category_title | slugify }}">{{ category_title }}</a>
13
+ </h5>
14
+
15
+ <ul class="chevron list">
16
+ {% for title in category_articles %}
17
+ <li class="article">
18
+ <a href="{{ site.baseurl }}/articles/{{ title | slugify }}" class="km-article-link">{{ title }}</a>
19
+ </li>
20
+ {% endfor %}
21
+ </ul>
22
+
23
+ </li>
24
+
25
+ {% endfor %}
26
+ </ul>
@@ -0,0 +1,73 @@
1
+ require "jekyll"
2
+ require File.expand_path("lib/jekyll-conrefifier.rb")
3
+
4
+ RSpec.configure do |config|
5
+ config.run_all_when_everything_filtered = true
6
+ config.filter_run :focus
7
+ config.order = 'random'
8
+
9
+ config.expect_with :rspec do |c|
10
+ c.syntax = :expect
11
+ end
12
+
13
+ config.before(:each) do
14
+ Jekyll.logger.log_level = :error
15
+
16
+ @fixtures_path = Pathname.new(__FILE__).parent.join("fixtures")
17
+ @dest = @fixtures_path.join("_site")
18
+ @posts_src = @fixtures_path.join("_posts")
19
+ @layouts_src = @fixtures_path.join("_layouts")
20
+ @plugins_src = @fixtures_path.join("_plugins")
21
+
22
+ @site = Jekyll::Site.new(Jekyll.configuration({
23
+ "source" => @fixtures_path.to_s,
24
+ "destination" => @dest.to_s,
25
+ "plugins" => @plugins_src.to_s,
26
+ "collections" => {
27
+ "articles" => {"output" => true},
28
+ "authors" => {}
29
+ }
30
+ }))
31
+
32
+ @dest.rmtree if @dest.exist?
33
+ @site.process
34
+ end
35
+
36
+ # config.after(:each) do
37
+ # @dest.rmtree if @dest.exist?
38
+ # end
39
+
40
+ def unpublished_doc
41
+ @site.collections["authors"].docs.first
42
+ end
43
+
44
+ def setup_doc(doc_filename)
45
+ @site.collections["articles"].docs.find { |d| d.relative_path.match(doc_filename) }
46
+ end
47
+
48
+ def setup_post(file)
49
+ Jekyll::Post.new(@site, @fixtures_path.to_s, '', file)
50
+ end
51
+
52
+ def setup_page(file)
53
+ Jekyll::Page.new(@site, @fixtures_path.to_s, File.dirname(file), File.basename(file))
54
+ end
55
+
56
+ def destination_file_exists?(file)
57
+ File.exists?(File.join(@dest.to_s, file))
58
+ end
59
+
60
+ def destination_file_contents(file)
61
+ File.read(File.join(@dest.to_s, file))
62
+ end
63
+
64
+ def destination_doc_contents(collection, file)
65
+ File.read(File.join(@dest.to_s, collection, file))
66
+ end
67
+
68
+ def new_redirect_page(permalink)
69
+ page = JekyllRedirectFrom::RedirectPage.new(@site, @site.source, "", "")
70
+ page.data['permalink'] = permalink
71
+ page
72
+ end
73
+ end
metadata ADDED
@@ -0,0 +1,105 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jekyll-conrefifier
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Garen J. Torikian
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-11-02 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: :development
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: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
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: rspec
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
+ description: A set of monkey patches that allows you to use Liquid variables in a
56
+ variety of places in Jekyll, like frontmatter or data files.
57
+ email:
58
+ - gjtorikian@gmail.com
59
+ executables: []
60
+ extensions: []
61
+ extra_rdoc_files: []
62
+ files:
63
+ - ".gitignore"
64
+ - ".travis.yml"
65
+ - Gemfile
66
+ - LICENSE.txt
67
+ - README.md
68
+ - Rakefile
69
+ - jekyll-conrefifier.gemspec
70
+ - lib/jekyll-conrefifier.rb
71
+ - lib/version.rb
72
+ - script/cibuild
73
+ - spec/conrefifier_spec.rb
74
+ - spec/fixtures/_articles/filtered_frontmatter.md
75
+ - spec/fixtures/_articles/simple_frontmatter.md
76
+ - spec/fixtures/_config.yml
77
+ - spec/fixtures/_data/categories.yml
78
+ - spec/fixtures/_data/conrefs.yml
79
+ - spec/fixtures/index.html
80
+ - spec/spec_helper.rb
81
+ homepage: ''
82
+ licenses:
83
+ - MIT
84
+ metadata: {}
85
+ post_install_message:
86
+ rdoc_options: []
87
+ require_paths:
88
+ - lib
89
+ required_ruby_version: !ruby/object:Gem::Requirement
90
+ requirements:
91
+ - - ">="
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ required_rubygems_version: !ruby/object:Gem::Requirement
95
+ requirements:
96
+ - - ">="
97
+ - !ruby/object:Gem::Version
98
+ version: '0'
99
+ requirements: []
100
+ rubyforge_project:
101
+ rubygems_version: 2.2.2
102
+ signing_key:
103
+ specification_version: 4
104
+ summary: Allows you to use Liquid variables in various places in Jekyll
105
+ test_files: []