├── .gitignore ├── .travis.yml ├── Gemfile ├── LICENSE.txt ├── README.md ├── Rakefile ├── jekyll-conrefifier.gemspec ├── lib ├── jekyll-conrefifier.rb └── version.rb ├── script └── cibuild └── spec ├── conrefifier_spec.rb ├── fixtures ├── _articles │ ├── filtered_frontmatter.md │ ├── markdown_frontmatter.md │ └── simple_frontmatter.md ├── _config.yml ├── _data │ ├── categories.yml │ ├── conrefs.yml │ ├── enterprise_filtered_categories.yml │ ├── filtered_categories.yml │ └── warnings.yml ├── _layouts │ ├── article.html │ └── filtering_layout.html ├── enterprise_filtered_index.html ├── filtered_index.html ├── filtering_layout.html ├── index.html └── warnings.html └── spec_helper.rb /.gitignore: -------------------------------------------------------------------------------- 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 19 | .jekyll_metadata 20 | .DS_Store 21 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: ruby 2 | rvm: 3 | - 2.1 4 | - 2.0 5 | script: "script/cibuild" 6 | -------------------------------------------------------------------------------- /Gemfile: -------------------------------------------------------------------------------- 1 | source 'https://rubygems.org' 2 | 3 | # Specify your gem's dependencies in jekyll-html-pipeline.gemspec 4 | gemspec 5 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 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. 21 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 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 | Note that Markdown rendering is enabled for this content. 20 | 21 | ## Per-audience filtering 22 | 23 | You can scope your variables to an audience value. For example, given a conref file that looks like this: 24 | 25 | ``` yaml 26 | product_name: 27 | dotcom: GitHub 28 | 2.0: GitHub Enterprise 29 | 11.10.340: GitHub Enterprise 30 | ``` 31 | 32 | And a file that looks like this: 33 | 34 | ``` markdown 35 | --- 36 | title: Welcome to {{ site.data.conrefs.product_name[site.audience] }} 37 | --- 38 | 39 | Some other page. 40 | ``` 41 | 42 | The title renders through `product_name`, then the value of `site.audience` to become "Welcome to GitHub". 43 | 44 | ## Substitutions within data files 45 | 46 | Your data files can also rely on Liquid substitution. For example, given a data file called *categories.yml* that looks like this: 47 | 48 | ``` yaml 49 | Bootcamp: 50 | - Set Up Git 51 | - Create A Repo 52 | - Fork A Repo 53 | - Be Social 54 | - '{{ site.data.conrefs.product_name[site.audience] }} Glossary' 55 | - Good Resources for Learning Git and GitHub 56 | ``` 57 | 58 | The value renders out to "GitHub Glossary", just like above. 59 | 60 | ## Liquid filtering within data files 61 | 62 | You can add filters within data files, to show or hide content depending on certain variable criteria. 63 | 64 | For example, given a data file that looks like this: 65 | 66 | ``` yaml 67 | Listing: 68 | {% if page.version == '2.0' %} 69 | - Article v2.0 70 | {% endif %} 71 | {% if page.version != '2.0' %} 72 | - Article v2.1 73 | {% endif %} 74 | 75 | {% unless page.version == '2.0' %} 76 | Ignored: 77 | - Item1 78 | - Item 2 79 | {% endunless %} 80 | ``` 81 | 82 | If `page.version` is equal to `'2.0'`, only `Listing: - Artivle v2.0` will render. 83 | 84 | To support such a syntax, you'll need to add a new entry in your `config.yml` that defines your variables, like this: 85 | 86 | ``` yaml 87 | 88 | data_file_variables: 89 | - 90 | scope: 91 | path: "" 92 | values: 93 | version: "2.0" 94 | 95 | ``` 96 | 97 | `data_file_variables` is an array of hashes. The `scope` key defines which data files are affected by the variables; the data file must match the path define in `path`. Regular expression syntaxes are supported in `path`, and a blank `path` refers to every data file. The `values` key specifies every key you want to support in your data file. 98 | 99 | Here's a more complex example: 100 | 101 | ``` yaml 102 | data_file_variables: 103 | - 104 | scope: 105 | path: "" 106 | values: 107 | version: "2.0" 108 | - 109 | scope: 110 | path: "ent\\w+_" 111 | values: 112 | version: "2.1" 113 | 114 | ``` 115 | 116 | In this case, every data file has a `page.version` of `2.0`. However, only data files prefixed with `ent`, containing one or more word characters (`\w+`), and followed by an underscore (`_`), have a value of `2.1`. 117 | 118 | ## Rendering filtered data files in layouts 119 | 120 | As an addition to the above, a new tag, `data_render`, can be used to iterate over filtered data files. 121 | 122 | You can call this filter by: 123 | 124 | * Passing a data file name to `data_render` 125 | * Passing any optional variables to this filter 126 | * The YAML information will be temporarily stored within `site.data.data_render` 127 | * You can iterate over `site.data.data_render` to walk along the data 128 | * Multiple calls to `data_render` rewrite to `site.data.data_render` 129 | 130 | Here's an example: 131 | 132 | ``` liquid 133 | {% data_render site.data.filtered_categories(:version => 2.0.to_s) %} 134 | 135 | {% for category_hash in site.data.data_render %} 136 | {% assign category_title = category_hash[0] %} 137 | {% assign category_articles = category_hash[1] %} 138 | {{ category_title }} 139 | {{ category_articles }} 140 | {% endfor %} 141 | ``` 142 | 143 | Note that data files are read *once*, to improve performance. The variables passed in are evaluated for each call. 144 | -------------------------------------------------------------------------------- /Rakefile: -------------------------------------------------------------------------------- 1 | require "bundler/gem_tasks" 2 | require 'rspec/core/rake_task' 3 | 4 | RSpec::Core::RakeTask.new(:spec) 5 | 6 | task :default => :spec 7 | -------------------------------------------------------------------------------- /jekyll-conrefifier.gemspec: -------------------------------------------------------------------------------- 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 | 22 | spec.add_development_dependency 'rake' 23 | spec.add_development_dependency 'rspec' 24 | end 25 | -------------------------------------------------------------------------------- /lib/jekyll-conrefifier.rb: -------------------------------------------------------------------------------- 1 | module Jekyll 2 | module ConrefifierUtils 3 | class << self; attr_accessor :og_paths; end 4 | 5 | # fetch the custom scope vars, as defined in _config.yml 6 | def self.data_file_variables(config, path) 7 | data_vars = {} 8 | scopes = config['data_file_variables'].select { |v| v['scope']['path'].empty? || Regexp.new(v['scope']['path']) =~ path } 9 | scopes.each do |scope| 10 | data_vars = data_vars.merge(scope['values']) 11 | end 12 | data_vars 13 | end 14 | 15 | def self.setup_config(site, opts, path) 16 | data_vars = path.nil? ? {} : ConrefifierUtils.data_file_variables(site.config, opts[:actual_path] || path) 17 | config = { 'page' => data_vars } 18 | { 'site' => { 'data' => site.data, 'config' => site.config } }.merge(config) 19 | end 20 | 21 | def self.convert(content, data_vars) 22 | value = Liquid::Template.parse(content).render(data_vars) 23 | # protects against situations where [page.version] prevented a conversion 24 | value = Liquid::Template.parse(value).render(data_vars) if value =~ /\{\{/ 25 | value.gsub('"', '\"') 26 | end 27 | end 28 | 29 | class Document 30 | # remove when on a moderner Jekyll 31 | FRONT_REGEXP = /\A(---\s*\n.*?\n?)^((---|\.\.\.)\s*$\n?)/m 32 | 33 | # allow us to use any variable within Jekyll Frontmatter; for example: 34 | # title: What are {{ site.data.conrefs.product_name[site.audience] }} Pages? 35 | # renders as "GitHub Pages?" for dotcom, but "GitHub Enterprise Pages?" for Enterprise 36 | def read(opts = {}) 37 | if yaml_file? 38 | @data = SafeYAML.load_file(path) 39 | else 40 | begin 41 | defaults = @site.frontmatter_defaults.all(url, collection.label.to_sym) 42 | @data = defaults unless defaults.empty? 43 | @content = File.read(path, merged_file_read_opts(opts)) 44 | if content =~ FRONT_REGEXP 45 | @content = $POSTMATCH 46 | prev_match = $1 47 | prev_match = prev_match.gsub(/\{\{.+?\}\}/) do |match| 48 | data_vars = ConrefifierUtils.setup_config(@site, opts, path) 49 | value = ConrefifierUtils.convert(match, data_vars) 50 | value = Jekyll::Renderer.new(@site, self).convert(value) 51 | value = value.gsub(/:/, ':') 52 | value = value.gsub(/\\"/, '"') 53 | value.sub(/^
/, '').sub(%r{
$}, '').strip 54 | end 55 | 56 | data_file = SafeYAML.load(prev_match) 57 | unless data_file.nil? 58 | @data = Utils.deep_merge_hashes(defaults, data_file) 59 | end 60 | end 61 | rescue SyntaxError => e 62 | puts "YAML Exception reading #{path}: #{e.message}" 63 | rescue Exception => e 64 | puts "Error reading file #{path}: #{e.message}" 65 | end 66 | end 67 | 68 | @data.each_pair do |key, value| 69 | next unless value =~ /(\{% (?:if|unless).+? %\}.*?\{% end(?:if|unless) %\})/ 70 | 71 | data_vars = ConrefifierUtils.setup_config(@site, opts, path) 72 | value = ConrefifierUtils.convert(value, data_vars) 73 | value = Jekyll::Renderer.new(@site, self).convert(value) 74 | @data[key] = value.sub(/^/, '').sub(%r{
$}, '').strip 75 | end 76 | end 77 | end 78 | 79 | class Site 80 | alias_method :old_read_collections, :read_collections 81 | 82 | def in_source_dir(*paths) 83 | paths.reduce(source) do |base, path| 84 | Jekyll.sanitized_path(base, path) 85 | end 86 | end 87 | 88 | # allows us to filter data file contents via conditionals, eg. `{% if page.version == ... %}` 89 | def read_data_to(dir, data) 90 | return unless File.directory?(dir) && (!safe || !File.symlink?(dir)) 91 | 92 | entries = Dir.chdir(dir) do 93 | Dir['*.{yaml,yml,json,csv}'] + Dir['*'].select { |fn| File.directory?(fn) } 94 | end 95 | 96 | ConrefifierUtils.og_paths = [] if ConrefifierUtils.og_paths.nil? 97 | 98 | # all of this is copied from the Jekyll source, except... 99 | entries.each do |entry| 100 | path = self.in_source_dir(dir, entry) 101 | next if File.symlink?(path) && safe 102 | 103 | key = sanitize_filename(File.basename(entry, '.*')) 104 | if File.directory?(path) 105 | read_data_to(path, data[key] = {}) 106 | else 107 | case File.extname(path).downcase 108 | when '.csv' 109 | data[key] = CSV.read(path, :headers => true).map(&:to_hash) 110 | else 111 | src = config['data_source'] 112 | ConrefifierUtils.og_paths << path.slice(dir.index(src) + src.length + 1..-1).sub(/\.[^.]+\z/, '') 113 | # if we hit upon if/unless conditionals, we'll need to pause and render them 114 | contents = File.read(path) 115 | if (matches = contents.scan /(\s*\{% (?:if|unless).+? %\}.*?\{% end(?:if|unless) %\})/m) 116 | unless ConrefifierUtils.data_file_variables(config, path).nil? 117 | contents = apply_vars_to_datafile(contents, matches, path, { preserve_all: true } ) 118 | end 119 | end 120 | 121 | begin 122 | data[key] = SafeYAML.load(contents) 123 | rescue StandardError => e 124 | puts "Load error in \n#{contents}: #{e}" 125 | raise e 126 | end 127 | end 128 | end 129 | end 130 | end 131 | 132 | def read_collections 133 | # once we're done reading in the data, we need to iterate once more to parse out `{{ }}` blocks. 134 | # two reasons for this: one, we need to collect every data file before attempting to 135 | # parse these vars; two, the Liquid parse above obliterates these tags, so we 136 | # first need to convert them into `[[ }}`, and *then* continue with the parse 137 | ConrefifierUtils.og_paths.each do |path| 138 | keys = path.split('/') 139 | value = keys.inject(data, :fetch) 140 | yaml_dump = YAML::dump value 141 | 142 | keys[0...-1].inject(data, :fetch)[keys.last] = SafeYAML.load transform_liquid_variables(yaml_dump, path) 143 | end 144 | old_read_collections 145 | end 146 | 147 | # apply the custom scope plus the rest of the `site.data` information 148 | def apply_vars_to_datafile(contents, matches, path, preserve_all: true, preserve_non_vars: false) 149 | return contents if matches.empty? 150 | 151 | data_vars = path.nil? ? {} : ConrefifierUtils.data_file_variables(config, path) 152 | 153 | config = { 'page' => data_vars } 154 | config = { 'site' => { 'data' => self.data, 'config' => self.config } }.merge(config) 155 | 156 | matches.each do |match| 157 | match = match.is_a?(Array) ? match.first : match 158 | safe_match = if preserve_all 159 | match.gsub(/\{\{/, '[[\1') 160 | elsif preserve_non_vars 161 | match.gsub(/\{\{(\s*)(?!\s*(site|page))/, '[[\1') 162 | end 163 | 164 | parsed_content = begin 165 | parsed = Liquid::Template.parse(safe_match).render(config) 166 | parsed.gsub(/\[\[/, '{{\1') if preserve_all || preserve_non_vars 167 | rescue StandardError => e 168 | puts "Parse error in \n#{matches}: #{e}" 169 | match 170 | end 171 | next if parsed_content.nil? 172 | contents = contents.sub(match, parsed_content) 173 | end 174 | contents 175 | end 176 | 177 | # allow us to use any variable within Jekyll data files; for example: 178 | # - '{{ site.data.conrefs.product_name[site.audience] }} Glossary' 179 | # renders as "GitHub Glossary" for dotcom, but "GitHub Enterprise Glossary" for Enterprise 180 | def transform_liquid_variables(contents, path = nil) 181 | if (matches = contents.scan /(\{\{.+?\}\})/) 182 | contents = apply_vars_to_datafile(contents, matches, path, preserve_all: false, preserve_non_vars: true) 183 | end 184 | 185 | contents 186 | end 187 | end 188 | 189 | class DataRenderTag < Liquid::Tag 190 | def initialize(tag_name, text, tokens) 191 | super 192 | 193 | keys = text.strip.split('.', 3) 194 | keys.shift(2) # this is just site.data 195 | paren_arg = keys.last.match(/\((.+?)\)/) 196 | unless paren_arg.nil? 197 | last_key = keys.last.sub(paren_arg[0], '') 198 | keys.pop 199 | keys << last_key 200 | @hash_args = paren_arg[1].gsub(/[{}:]/,'').split(', ').map{|h| h1,h2 = h.split('=>'); {h1.strip => eval(h2.strip)}}.reduce(:merge) 201 | end 202 | @keys = keys 203 | @id = keys.join('-') 204 | end 205 | 206 | def fetch_datafile(context, keys) 207 | data_file = context.registers[:site].data["data_render_#{@id}"] 208 | return data_file unless data_file.nil? 209 | 210 | path = @id.tr('.', '/') 211 | data_source = File.join(context.registers[:site].source, context.registers[:site].config['data_source']) 212 | data_file = File.read("#{data_source}/#{path}.yml") 213 | context.registers[:site].data["data_render_#{@id}"] = data_file 214 | end 215 | 216 | def render(context) 217 | datafile = fetch_datafile(context, @keys) 218 | 219 | config = { 'page' => @hash_args } 220 | config = { 'site' => { 'data' => context.registers[:site].data } }.merge(config) 221 | versioned_yaml = SafeYAML.load(Liquid::Template.parse(datafile).render(config)) 222 | context.registers[:site].data['data_render'] = versioned_yaml 223 | nil 224 | end 225 | end 226 | 227 | Liquid::Template.register_tag('data_render', Jekyll::DataRenderTag) 228 | end 229 | -------------------------------------------------------------------------------- /lib/version.rb: -------------------------------------------------------------------------------- 1 | module JekyllConrefifier 2 | VERSION = '0.5.1' 3 | end 4 | -------------------------------------------------------------------------------- /script/cibuild: -------------------------------------------------------------------------------- 1 | #! /bin/bash 2 | 3 | script/bootstrap > /dev/null 2>&1 4 | bundle exec rake spec 5 | -------------------------------------------------------------------------------- /spec/conrefifier_spec.rb: -------------------------------------------------------------------------------- 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 for values 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 | 19 | it "writes the proper content for keys after fetching info from a data file" do 20 | index_file = @dest.join("index.html") 21 | expect(index_file).to exist 22 | index_contents = File.read(index_file) 23 | expect(index_contents).to include("Amazing") 24 | end 25 | 26 | it "writes the proper content for values with Markdown" do 27 | index_file = @dest.join("articles", "this-is-strong-wow-strong", "index.html") 28 | expect(index_file).to exist 29 | index_contents = File.read(index_file) 30 | expect(index_contents).to include("wow!") 31 | end 32 | 33 | it 'filters simple items' do 34 | filtered_index_file = @dest.join("filtered_index.html") 35 | expect(filtered_index_file).to exist 36 | filtered_index_contents = File.read(filtered_index_file) 37 | expect(filtered_index_contents).to include("GitHub Enterprise Glossary") 38 | expect(filtered_index_contents).to include("Fork A Repo") 39 | expect(filtered_index_contents).to include("Article v2.0") 40 | expect(filtered_index_contents).to include("Still show") 41 | expect(filtered_index_contents).to_not include("Article v2.1") 42 | expect(filtered_index_contents).to_not include("Ignored") 43 | end 44 | 45 | it 'filters items when a prefix is provided' do 46 | enterprise_filtered_index = @dest.join("enterprise_filtered_index.html") 47 | expect(enterprise_filtered_index).to exist 48 | filtered_index_contents = File.read(enterprise_filtered_index) 49 | expect(filtered_index_contents).to include("GitHub Enterprise Glossary") 50 | expect(filtered_index_contents).to include("Fork A Repo") 51 | expect(filtered_index_contents).to include("Article v2.1") 52 | expect(filtered_index_contents).to include("Still show") 53 | expect(filtered_index_contents).to_not include("Article v2.0") 54 | expect(filtered_index_contents).to_not include("Ignored") 55 | end 56 | 57 | it 'uses the data_render tag to provide filtered data in a layout' do 58 | filtering_layout = @dest.join("filtering_layout.html") 59 | expect(filtering_layout).to exist 60 | filtering_layout_contents = File.read(filtering_layout) 61 | expect(filtering_layout_contents).to include('GitHub Enterprise Glossary') 62 | expect(filtering_layout_contents.scan(/Bootcamp/).count).to eq(2) 63 | expect(filtering_layout_contents.scan(/Article v2.1/).count).to eq(1) 64 | expect(filtering_layout_contents.scan(/Article v2.0/).count).to eq(1) 65 | expect(filtering_layout_contents.scan(/Ignored/).count).to eq(1) 66 | end 67 | 68 | it 'filters items even if they have other curlies' do 69 | warnings = @dest.join("warnings.html") 70 | expect(warnings).to exist 71 | warnings_contents = File.read(warnings) 72 | expect(warnings_contents.scan(/- A dotcom Article/).count).to eq(1) 73 | expect(warnings_contents.scan(/Article v2.0/).count).to eq(0) 74 | end 75 | end 76 | -------------------------------------------------------------------------------- /spec/fixtures/_articles/filtered_frontmatter.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Welcome to {{ site.data.conrefs.product_name[site.config.audience] }} 3 | --- 4 | 5 | Some other page. 6 | -------------------------------------------------------------------------------- /spec/fixtures/_articles/markdown_frontmatter.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: This is {{ site.data.conrefs.bold_title }} 3 | layout: article 4 | --- 5 | 6 | Oh my my. 7 | -------------------------------------------------------------------------------- /spec/fixtures/_articles/simple_frontmatter.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: This is very {{ site.data.conrefs.product_type }} 3 | --- 4 | 5 | Some page. 6 | -------------------------------------------------------------------------------- /spec/fixtures/_config.yml: -------------------------------------------------------------------------------- 1 | gems: 2 | - jekyll-conrefifier 3 | 4 | collections: 5 | articles: 6 | output: true 7 | permalink: /articles/:title/ 8 | 9 | defaults: 10 | - 11 | scope: 12 | path: "" 13 | type: "_articles" 14 | values: 15 | layout: "article" 16 | 17 | audience: 'dotcom' 18 | 19 | data_file_variables: 20 | - 21 | scope: 22 | path: "" 23 | values: 24 | version: "2.0" 25 | - 26 | scope: 27 | path: "^warn" 28 | values: 29 | version: "dotcom" 30 | - 31 | scope: 32 | path: "^categories" 33 | values: 34 | version: "dotcom" 35 | - 36 | scope: 37 | path: "ent\\w+_" 38 | values: 39 | version: "2.1" 40 | -------------------------------------------------------------------------------- /spec/fixtures/_data/categories.yml: -------------------------------------------------------------------------------- 1 | Bootcamp: 2 | - Set Up Git 3 | - Create A Repo 4 | - Fork A Repo 5 | - Be Social 6 | - '{{ site.data.conrefs.product_name[page.version] }} Glossary' 7 | - Good Resources for Learning Git and GitHub 8 | 9 | '{{ site.data.conrefs.product_type }}': 10 | - Something something 11 | -------------------------------------------------------------------------------- /spec/fixtures/_data/conrefs.yml: -------------------------------------------------------------------------------- 1 | product_name: 2 | dotcom: GitHub 3 | '2.0': 'GitHub Enterprise' 4 | '2.1': 'GitHub Enterprise' 5 | 11.10.340: 'GitHub Enterprise' 6 | 7 | product_type: 'Amazing' 8 | 9 | bold_title: '**wow!**' 10 | -------------------------------------------------------------------------------- /spec/fixtures/_data/enterprise_filtered_categories.yml: -------------------------------------------------------------------------------- 1 | Bootcamp: 2 | - Set Up Git 3 | - Create A Repo 4 | - Fork A Repo 5 | - Be Social 6 | - '{{ site.data.conrefs.product_name[page.version] }} Glossary' 7 | - Good Resources for Learning Git and GitHub 8 | 9 | Listing: 10 | {% if page.version == '2.0' %} 11 | - Article v2.0 12 | {% endif %} 13 | {% if page.version != '2.0' %} 14 | - Article v2.1 15 | {% endif %} 16 | - Wow 17 | {% if page.version == '2.0' or page.version == '2.1' %} 18 | - Still show 19 | {% endif %} 20 | 21 | {% unless page.version == '2.1' %} 22 | Ignored: 23 | - Item1 24 | - Item 2 25 | {% endunless %} 26 | -------------------------------------------------------------------------------- /spec/fixtures/_data/filtered_categories.yml: -------------------------------------------------------------------------------- 1 | Bootcamp: 2 | - Set Up Git 3 | - Create A Repo 4 | - Fork A Repo 5 | - Be Social 6 | - '{{ site.data.conrefs.product_name[page.version] }} Glossary' 7 | - Good Resources for Learning Git and GitHub 8 | 9 | Listing: 10 | {% if page.version == '2.0' %} 11 | - Article v2.0 12 | {% endif %} 13 | {% if page.version != '2.0' %} 14 | - Article v2.1 15 | {% endif %} 16 | - Wow 17 | {% if page.version == '2.0' or page.version == '2.1' %} 18 | - Still show 19 | {% endif %} 20 | 21 | {% unless page.version == '2.0' %} 22 | Ignored: 23 | - Item1 24 | - Item 2 25 | {% endunless %} 26 | -------------------------------------------------------------------------------- /spec/fixtures/_data/warnings.yml: -------------------------------------------------------------------------------- 1 | article_name: | 2 | {% if page.version == '2.1' %} 3 | - Article v2.0 4 | {% else %} 5 | - A {{ page.version }} Article 6 | {% endif %} 7 | -------------------------------------------------------------------------------- /spec/fixtures/_layouts/article.html: -------------------------------------------------------------------------------- 1 | 2 | {{ page.title }} 3 | 4 | {{ content }} 5 | -------------------------------------------------------------------------------- /spec/fixtures/_layouts/filtering_layout.html: -------------------------------------------------------------------------------- 1 | 2 | {% data_render site.data.filtered_categories(:version => 2.0.to_s) %} 3 | 4 | {% for category_hash in site.data.data_render %} 5 | {% assign category_title = category_hash[0] %} 6 | {% assign category_articles = category_hash[1] %} 7 | {{ category_title }} 8 | {{ category_articles }} 9 | {% endfor %} 10 | 11 | {{ content }} 12 | 13 | {% data_render site.data.filtered_categories(:version => 2.1.to_s) %} 14 | 15 | {% for category_hash in site.data.data_render %} 16 | {% assign category_title = category_hash[0] %} 17 | {% assign category_articles = category_hash[1] %} 18 | {{ category_title }} 19 | {{ category_articles }} 20 | {% endfor %} 21 | -------------------------------------------------------------------------------- /spec/fixtures/enterprise_filtered_index.html: -------------------------------------------------------------------------------- 1 | --- 2 | --- 3 |