nanoc-conref-fs 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (39) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +29 -0
  3. data/.travis.yml +12 -0
  4. data/Gemfile +11 -0
  5. data/LICENSE.txt +22 -0
  6. data/README.md +64 -0
  7. data/Rakefile +11 -0
  8. data/lib/nanoc-conref-fs.rb +3 -0
  9. data/lib/nanoc-conref-fs/conref-fs.rb +103 -0
  10. data/lib/nanoc-conref-fs/conrefifier.rb +18 -0
  11. data/lib/nanoc-conref-fs/datafiles.rb +48 -0
  12. data/nanoc-conref-fs.gemspec +24 -0
  13. data/script/bootstrap +5 -0
  14. data/test/conref_fs_test.rb +100 -0
  15. data/test/datafiles_test.rb +41 -0
  16. data/test/fixtures/Rules +23 -0
  17. data/test/fixtures/content/datafiles/deep.html +18 -0
  18. data/test/fixtures/content/datafiles/deep.md +6 -0
  19. data/test/fixtures/content/frontmatter/audience.html +18 -0
  20. data/test/fixtures/content/frontmatter/audience.md +5 -0
  21. data/test/fixtures/content/frontmatter/different.html +18 -0
  22. data/test/fixtures/content/frontmatter/different.md +5 -0
  23. data/test/fixtures/content/frontmatter/title.html +18 -0
  24. data/test/fixtures/content/frontmatter/title.md +6 -0
  25. data/test/fixtures/content/parents/missing_title.html +18 -0
  26. data/test/fixtures/content/parents/missing_title.md +5 -0
  27. data/test/fixtures/content/parents/single_parent.html +18 -0
  28. data/test/fixtures/content/parents/single_parent.md +5 -0
  29. data/test/fixtures/content/parents/two_parents.html +18 -0
  30. data/test/fixtures/content/parents/two_parents.md +5 -0
  31. data/test/fixtures/data/categories/category.yml +9 -0
  32. data/test/fixtures/data/reusables/intro.yml +14 -0
  33. data/test/fixtures/data/reusables/names.yml +1 -0
  34. data/test/fixtures/data/variables/empty.yml +0 -0
  35. data/test/fixtures/data/variables/product.yml +14 -0
  36. data/test/fixtures/layouts/default.html +16 -0
  37. data/test/fixtures/nanoc.yaml +51 -0
  38. data/test/test_helper.rb +75 -0
  39. metadata +176 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: c521a9f295c33c7aa6f4dc47ca92045539c467e5
4
+ data.tar.gz: 42ac9a18696599fd0f298899f48b7f6b4484bd3f
5
+ SHA512:
6
+ metadata.gz: 3fad6cd16943d5e3b4cbda7579d7c0cc6b3b30b0ddf7194a9a198d2d2f01138ed564c3b353d510e78076f7b5c11fe35a088e06cf1332c7d0e1f883fb2525dd12
7
+ data.tar.gz: ca660bcfaf0287c737ff8a50186d61196cae39b39861fffbb4925f62a2539e1cfa0a56d79c2ccd0bd71815a125a4c41e143e2dde2c9314cf52cb314e3221c7f5
data/.gitignore ADDED
@@ -0,0 +1,29 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ coverage
6
+ InstalledFiles
7
+ lib/bundler/man
8
+ pkg
9
+ rdoc
10
+ spec/reports
11
+ test/tmp
12
+ test/version_tmp
13
+ tmp
14
+
15
+ Gemfile.lock
16
+ out/
17
+ sample.rb
18
+ run_sample.rb
19
+ src/
20
+ docs/
21
+
22
+ # YARD artifacts
23
+ .yardoc
24
+ _yardoc
25
+ doc/
26
+ .DS_Store
27
+
28
+ test/fixtures/output
29
+ test/fixtures/tmp
data/.travis.yml ADDED
@@ -0,0 +1,12 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2
4
+ env:
5
+ global:
6
+ - NOKOGIRI_USE_SYSTEM_LIBRARIES=true
7
+
8
+ sudo: false
9
+ cache: bundler
10
+
11
+ git:
12
+ depth: 10
data/Gemfile ADDED
@@ -0,0 +1,11 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'nanoc', '~> 4.0.0rc3'
4
+ gem 'liquid'
5
+ gem 'kramdown'
6
+ gem 'activesupport'
7
+
8
+ gem 'rake'
9
+ gem 'minitest'
10
+ gem 'awesome_print'
11
+ gem 'safe_yaml'
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 Garen J. Torikian
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,64 @@
1
+ # nanoc-conref-fs
2
+
3
+ This gem adds a new Filesystem type called `ConrefFS` to nanoc.
4
+
5
+ The idea is that you have a set of YAML files in a data folder which act as your reusables. You can apply thse reusables throughout your content and layout.
6
+
7
+ [![Build Status](https://travis-ci.org/gjtorikian/nanoc-conref-fs.svg)](https://travis-ci.org/gjtorikian/nanoc-conref-fs)
8
+
9
+ ## Usage
10
+
11
+ Nearly all the usage of this gem relies on a *data* folder, sibling to your *content* and *layouts* folders. See [the test fixture](test/fixtures/data) for an example.
12
+
13
+ You'll also need some relevant keys added to your *nanoc.yaml* file:
14
+
15
+ * The `data_variables` key applies additional/dynamic values to your data files, based on their path. For example, the following `data_variables` configuration adds a `version` attribute to every data file, whose value is `dotcom`:
16
+
17
+ ``` yaml
18
+ data_variables:
19
+ -
20
+ scope:
21
+ path: ""
22
+ values:
23
+ version: "dotcom"
24
+ ```
25
+
26
+ You could add to this key to indicate that any data file called *changed* instead has a version of `something_different`:
27
+
28
+ ``` yaml
29
+ data_variables:
30
+ -
31
+ scope:
32
+ path: ""
33
+ values:
34
+ version: "dotcom"
35
+ -
36
+ scope:
37
+ path: "changed"
38
+ values:
39
+ version: "2.0"
40
+ ```
41
+
42
+ * Similarly, the `page_variables` also use `scope`s and `value`s to determine variables:
43
+
44
+ ``` yaml
45
+ page_variables:
46
+ -
47
+ scope:
48
+ path: ""
49
+ values:
50
+ version: "dotcom"
51
+ -
52
+ scope:
53
+ path: "different"
54
+ values:
55
+ version: "2.0"
56
+ ```
57
+
58
+ In this case, every file path will get a `version` of `dotcom`, but any file matching `different` will get a version of 2.0.
59
+
60
+ See the tests for further usage of these conditionals. In both cases, `path` is converted into a Ruby regular expression before being matched against a filename.
61
+
62
+ ### Associating files with data
63
+
64
+ If you have a special `data_association` value, additional metadata to items will be applied. Right now, this only adds a `parent` type to each item.
data/Rakefile ADDED
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/env rake
2
+ require 'bundler/gem_tasks'
3
+ require 'rake/testtask'
4
+
5
+ Rake::TestTask.new do |t|
6
+ t.libs << 'test'
7
+ t.test_files = FileList['test/**/*_test.rb']
8
+ t.verbose = true
9
+ end
10
+
11
+ task default: [:test]
@@ -0,0 +1,3 @@
1
+ require 'nanoc-conref-fs/conref-fs'
2
+ require 'nanoc-conref-fs/conrefifier'
3
+ require 'nanoc-conref-fs/datafiles'
@@ -0,0 +1,103 @@
1
+ require_relative 'conrefifier'
2
+
3
+ class ConrefFS < Nanoc::DataSource
4
+ include Nanoc::DataSources::Filesystem
5
+
6
+ identifier :conref_fs
7
+
8
+ # Before iterating over the file objects, this method loads the data folder
9
+ # and applies to to an ivar for later usage.
10
+ def load_objects(dir_name, kind, klass)
11
+ data = Datafiles.process(@site_config)
12
+ @vars = { 'site' => { 'config' => @site_config.to_h, 'data' => data } }
13
+ super
14
+ end
15
+
16
+ # This function calls the parent super, then adds additional metadata to the item.
17
+ def parse(content_filename, meta_filename, _kind)
18
+ meta, content = super
19
+ page_vars = Conrefifier.file_variables(@site_config[:page_variables], content_filename)
20
+ unless page_vars[:data_association].nil?
21
+ association = page_vars[:data_association]
22
+ reference = association.split('.')
23
+ toc = @vars['site']['data']
24
+ while key = reference.shift
25
+ toc = toc[key]
26
+ end
27
+ meta['parents'] = find_parents(toc, meta['title'])
28
+ end
29
+ [meta, content]
30
+ end
31
+
32
+ # Given a category file, this method finds its parent.
33
+ def find_parents(toc, title)
34
+ parents = ''
35
+ toc.keys.each do |key|
36
+ toc[key].each do |item|
37
+ if item.is_a?(Hash)
38
+ if item.keys.include?(title)
39
+ parents = key
40
+ break
41
+ else
42
+ if item[item.keys.first].include?(title)
43
+ parents = key
44
+ break
45
+ end
46
+ end
47
+ elsif title == item
48
+ parents = key
49
+ break
50
+ end
51
+ end
52
+ break unless parents.empty?
53
+ end
54
+ parents
55
+ end
56
+
57
+ # This file reads each piece of content as it comes in. It also applies the conref variables
58
+ # (demarcated by Liquid's {{ }} tags) using both the data/ folder and any variables defined
59
+ # within the nanoc.yaml config file
60
+ def read(filename)
61
+ begin
62
+ page_vars = Conrefifier.file_variables(@site_config[:page_variables], filename)
63
+ page_vars = { :page => page_vars }.merge(@vars)
64
+
65
+ data = File.read(filename)
66
+ return data unless filename.start_with?('content')
67
+
68
+ # This first pass converts the frontmatter variables,
69
+ # and inserts data variables into the body
70
+ result = Conrefifier.apply_liquid(data, page_vars)
71
+ # This second application renders the previously inserted
72
+ # data conditionals within the body
73
+ result = Conrefifier.apply_liquid(result, page_vars)
74
+ rescue => e
75
+ raise RuntimeError.new("Could not read #{filename}: #{e.inspect}")
76
+ end
77
+ end
78
+
79
+ # This method is extracted from the Nanoc default FS
80
+ def filename_for(base_filename, ext)
81
+ if ext.nil?
82
+ nil
83
+ elsif ext.empty?
84
+ base_filename
85
+ else
86
+ base_filename + '.' + ext
87
+ end
88
+ end
89
+
90
+ # This method is extracted from the Nanoc default FS
91
+ def identifier_for_filename(filename)
92
+ if config[:identifier_type] == 'full'
93
+ return Nanoc::Identifier.new(filename)
94
+ end
95
+
96
+ if filename =~ /(^|\/)index(\.[^\/]+)?$/
97
+ regex = @config && @config[:allow_periods_in_identifiers] ? /\/?(index)?(\.[^\/\.]+)?$/ : /\/?index(\.[^\/]+)?$/
98
+ else
99
+ regex = @config && @config[:allow_periods_in_identifiers] ? /\.[^\/\.]+$/ : /\.[^\/]+$/
100
+ end
101
+ Nanoc::Identifier.new(filename.sub(regex, ''), type: :legacy)
102
+ end
103
+ end
@@ -0,0 +1,18 @@
1
+ require 'liquid'
2
+
3
+ module Conrefifier
4
+ def self.file_variables(variables, path)
5
+ return {} if variables.nil?
6
+
7
+ data_vars = {}
8
+ scopes = 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.apply_liquid(content, data_vars)
16
+ ::Liquid::Template.parse(content).render(data_vars.deep_stringify_keys)
17
+ end
18
+ end
@@ -0,0 +1,48 @@
1
+ require 'yaml'
2
+ require 'active_support'
3
+ require 'active_support/core_ext/hash'
4
+
5
+ require_relative 'conrefifier'
6
+
7
+ module Datafiles
8
+
9
+ def self.apply_conditionals(config, path, content)
10
+ data_vars = Conrefifier.file_variables(config[:data_variables], path)
11
+ data_vars = { :page => data_vars, :site => { :config => config } }
12
+
13
+ content = content.gsub(/(\s*\{% (?:if|unless).+? %\}.*?\{% end(?:if|unless) %\})/m) do |match|
14
+ # We must obfuscate Liquid variables while replacing conditionals
15
+ match = match.gsub(/{{/, '~~#~~')
16
+ match = Conrefifier.apply_liquid(match, data_vars)
17
+ match.gsub('~~#~~', '{{')
18
+ end
19
+
20
+ doc = YAML.load(content)
21
+ data_keys = "#{path}".gsub(%r{^data/}, '').gsub(%r{/}, '.').gsub(/\.yml/, '').split('.')
22
+ create_nested_hash(data_keys, doc)
23
+ end
24
+
25
+ def self.create_nested_hash(keys, final)
26
+ keys.reverse.inject do |mem, var|
27
+ if mem == keys.last
28
+ { var => { mem => final } }
29
+ else
30
+ { var => mem }
31
+ end
32
+ end
33
+ end
34
+
35
+ def self.collect_data(dir)
36
+ Dir["#{dir}/**/*.{yaml,yml}"]
37
+ end
38
+
39
+ def self.process(config)
40
+ data = {}
41
+ files = collect_data('data')
42
+ files.each do |file|
43
+ content = File.read(file)
44
+ data = data.deep_merge apply_conditionals(config, file, content)
45
+ end
46
+ data
47
+ end
48
+ 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 = 'nanoc-conref-fs'
6
+ spec.version = '0.0.1'
7
+ spec.authors = ['Garen Torikian']
8
+ spec.email = ['gjtorikian@gmail.com']
9
+ spec.summary = 'A Nanoc filesystem to permit using conrefs/reusables in your content.'
10
+ spec.homepage = 'https://github.com/gjtorikian/nanoc-conref-fs'
11
+ spec.license = 'MIT'
12
+
13
+ spec.files = `git ls-files`.split($/)
14
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
15
+ spec.test_files = spec.files.grep(%r{^(test)/})
16
+ spec.require_paths = ['lib']
17
+
18
+ spec.add_runtime_dependency 'nanoc', '>= 3.1.6'
19
+ spec.add_runtime_dependency 'activesupport', '~> 4.2'
20
+ spec.add_runtime_dependency 'liquid', '~> 3.0'
21
+
22
+ spec.add_development_dependency 'rake'
23
+ spec.add_development_dependency 'minitest', '~> 5.8'
24
+ end
data/script/bootstrap ADDED
@@ -0,0 +1,5 @@
1
+ #!/bin/sh
2
+
3
+ set -e
4
+
5
+ bundle install "$@"
@@ -0,0 +1,100 @@
1
+ require 'test_helper'
2
+
3
+ class DatafilesTest < MiniTest::Test
4
+
5
+ def test_it_renders_conrefs_in_frontmatter
6
+ with_site(name: FIXTURES_DIR) do |site|
7
+
8
+ site = Nanoc::Int::SiteLoader.new.new_from_cwd
9
+ site.compile
10
+
11
+ output_file = read_output_file('frontmatter', 'title')
12
+ test_file = read_test_file('frontmatter', 'title')
13
+ assert_equal output_file, test_file
14
+ end
15
+ end
16
+
17
+ def test_it_renders_conrefs_in_frontmatter_at_different_path
18
+ with_site(name: FIXTURES_DIR) do |site|
19
+
20
+ site = Nanoc::Int::SiteLoader.new.new_from_cwd
21
+ site.compile
22
+
23
+ output_file = read_output_file('frontmatter', 'different')
24
+ test_file = read_test_file('frontmatter', 'different')
25
+ assert_equal output_file, test_file
26
+ end
27
+ end
28
+
29
+ def test_it_renders_conrefs_in_frontmatter_with_audience
30
+ with_site(name: FIXTURES_DIR) do |site|
31
+
32
+ site = Nanoc::Int::SiteLoader.new.new_from_cwd
33
+ site.compile
34
+
35
+ output_file = read_output_file('frontmatter', 'audience')
36
+ test_file = read_test_file('frontmatter', 'audience')
37
+ assert_equal output_file, test_file
38
+ end
39
+ end
40
+
41
+ def test_it_renders_nested_conrefs
42
+ with_site(name: FIXTURES_DIR) do |site|
43
+
44
+ site = Nanoc::Int::SiteLoader.new.new_from_cwd
45
+ site.compile
46
+
47
+ output_file = read_output_file('datafiles', 'deep')
48
+ test_file = read_test_file('datafiles', 'deep')
49
+ assert_equal output_file, test_file
50
+ end
51
+ end
52
+
53
+ def test_it_renders_nested_conrefs
54
+ with_site(name: FIXTURES_DIR) do |site|
55
+
56
+ site = Nanoc::Int::SiteLoader.new.new_from_cwd
57
+ site.compile
58
+
59
+ output_file = read_output_file('datafiles', 'deep')
60
+ test_file = read_test_file('datafiles', 'deep')
61
+ assert_equal output_file, test_file
62
+ end
63
+ end
64
+
65
+ def test_it_renders_single_parents
66
+ with_site(name: FIXTURES_DIR) do |site|
67
+
68
+ site = Nanoc::Int::SiteLoader.new.new_from_cwd
69
+ site.compile
70
+
71
+ output_file = read_output_file('parents', 'single_parent')
72
+ test_file = read_test_file('parents', 'single_parent')
73
+ assert_equal output_file, test_file
74
+ end
75
+ end
76
+
77
+ def test_it_renders_two_parents
78
+ with_site(name: FIXTURES_DIR) do |site|
79
+
80
+ site = Nanoc::Int::SiteLoader.new.new_from_cwd
81
+ site.compile
82
+
83
+ output_file = read_output_file('parents', 'two_parents')
84
+ test_file = read_test_file('parents', 'two_parents')
85
+ assert_equal output_file, test_file
86
+ end
87
+ end
88
+
89
+ def test_missing_cateogory_title_does_not_blow_up_parents
90
+ with_site(name: FIXTURES_DIR) do |site|
91
+
92
+ site = Nanoc::Int::SiteLoader.new.new_from_cwd
93
+ site.compile
94
+
95
+ output_file = read_output_file('parents', 'missing_title')
96
+ test_file = read_test_file('parents', 'missing_title')
97
+ assert_equal output_file, test_file
98
+ end
99
+ end
100
+ end
@@ -0,0 +1,41 @@
1
+ require 'test_helper'
2
+
3
+ class DatafilesTest < MiniTest::Test
4
+ def setup
5
+ @config = YAML.load_file(File.join(FIXTURES_DIR, 'nanoc.yaml')).deep_symbolize_keys
6
+ end
7
+
8
+ def test_it_collects_the_files
9
+ files = Datafiles.collect_data(File.join(FIXTURES_DIR, 'data'))
10
+ names = %w(categories/category reusables/intro reusables/names variables/empty variables/product)
11
+ names.map! { |name| File.join(FIXTURES_DIR, 'data', "#{name}.yml") }
12
+ assert_equal files, names
13
+ end
14
+
15
+ def test_it_creates_nested_hash
16
+ string = %w(this is deep)
17
+ value = 42
18
+ hash = Datafiles.create_nested_hash(string, value)
19
+ value = { 'this' => { 'is' => { 'deep' => 42 } } }
20
+ assert_equal value, hash
21
+ end
22
+
23
+ def test_it_applies_conref_conditionals
24
+ file = File.join(FIXTURES_DIR, 'data', 'variables', 'product.yml')
25
+ content = File.read(file)
26
+ result = Datafiles.apply_conditionals(@config, file, content)
27
+ assert_includes result.to_s, 'No caveats!'
28
+
29
+ @config[:data_variables][0][:values][:version] = 'foof'
30
+ result = Datafiles.apply_conditionals(@config, file, content)
31
+ assert_includes result.to_s, 'Well.....there is one.'
32
+ end
33
+
34
+ def test_it_leaves_liquid_substitutions_alone
35
+ file = File.join(FIXTURES_DIR, 'data', 'reusables', 'intro.yml')
36
+ content = File.read(file)
37
+ result = Datafiles.apply_conditionals(@config, file, content)
38
+ assert_includes result.to_s, 'We use {{ site.data.reusables.names.new_name }}'
39
+ assert_includes result.to_s, '{{ site.data.variables.product.product_name }} is great'
40
+ end
41
+ end
@@ -0,0 +1,23 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ compile '/**/*.html' do
4
+ layout '/default.*'
5
+ end
6
+
7
+ compile '/**/*.md' do
8
+ layout '/default.*'
9
+ end
10
+
11
+ route '/**/*.md' do
12
+ item.identifier.without_ext + '/index.html'
13
+ end
14
+
15
+ route '/**/*.html}' do
16
+
17
+ end
18
+
19
+ route '/**/*' do
20
+ item.identifier.to_s
21
+ end
22
+
23
+ layout '/**/*', :erb
@@ -0,0 +1,18 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>
5
+ Deep
6
+ </title>
7
+ </head>
8
+
9
+ <body>
10
+
11
+ We use SVNHub
12
+
13
+
14
+ Inception
15
+
16
+
17
+ </body>
18
+ </html>
@@ -0,0 +1,6 @@
1
+ ---
2
+ title: Deep
3
+ intro: {{ site.data.reusables.intro.svn_intro }}
4
+ ---
5
+
6
+ Inception
@@ -0,0 +1,18 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>
5
+ Welcome to GitHub
6
+ </title>
7
+ </head>
8
+
9
+ <body>
10
+
11
+
12
+
13
+
14
+ Some other page.
15
+
16
+
17
+ </body>
18
+ </html>
@@ -0,0 +1,5 @@
1
+ ---
2
+ title: Welcome to {{ site.data.variables.product.product_name[page.version] }}
3
+ ---
4
+
5
+ Some other page.
@@ -0,0 +1,18 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>
5
+ Welcome to GitHub Enterprise
6
+ </title>
7
+ </head>
8
+
9
+ <body>
10
+
11
+
12
+
13
+
14
+ Some other page.
15
+
16
+
17
+ </body>
18
+ </html>
@@ -0,0 +1,5 @@
1
+ ---
2
+ title: Welcome to {{ site.data.variables.product.product_name[page.version] }}
3
+ ---
4
+
5
+ Some other page.
@@ -0,0 +1,18 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>
5
+ Substitution
6
+ </title>
7
+ </head>
8
+
9
+ <body>
10
+
11
+ Here I am, in the front.
12
+
13
+
14
+ Some words.
15
+
16
+
17
+ </body>
18
+ </html>
@@ -0,0 +1,6 @@
1
+ ---
2
+ title: Substitution
3
+ intro: {{ site.data.reusables.intro.frontmatter_intro }}
4
+ ---
5
+
6
+ Some words.
@@ -0,0 +1,18 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>
5
+ OH WOW THIS IS NO WHERE
6
+ </title>
7
+ </head>
8
+
9
+ <body>
10
+
11
+
12
+
13
+
14
+ Little Orphan Annie.
15
+
16
+
17
+ </body>
18
+ </html>
@@ -0,0 +1,5 @@
1
+ ---
2
+ title: OH WOW THIS IS NO WHERE
3
+ ---
4
+
5
+ Little Orphan Annie.
@@ -0,0 +1,18 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>
5
+ Using keyboard shortcuts
6
+ </title>
7
+ </head>
8
+
9
+ <body>
10
+
11
+
12
+ Keyboard Shortcuts
13
+
14
+ Something something
15
+
16
+
17
+ </body>
18
+ </html>
@@ -0,0 +1,5 @@
1
+ ---
2
+ title: Using keyboard shortcuts
3
+ ---
4
+
5
+ Something something
@@ -0,0 +1,18 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>
5
+ Setting the default branch
6
+ </title>
7
+ </head>
8
+
9
+ <body>
10
+
11
+
12
+ Collaborating
13
+
14
+ Two parents!
15
+
16
+
17
+ </body>
18
+ </html>
@@ -0,0 +1,5 @@
1
+ ---
2
+ title: Setting the default branch
3
+ ---
4
+
5
+ Two parents!
@@ -0,0 +1,9 @@
1
+ Keyboard Shortcuts:
2
+ - Using keyboard shortcuts
3
+
4
+ Collaborating:
5
+ - Managing branches in your repository:
6
+ - About branches
7
+ - Setting the default branch
8
+ - Viewing branches in your repository
9
+ - Creating and deleting branches within your repository
@@ -0,0 +1,14 @@
1
+ frontmatter_intro: Here I am, in the front.
2
+
3
+ svn_intro: "We use {{ site.data.reusables.names.new_name }}"
4
+
5
+ conditional_with_subs: |
6
+ {% if page.version == 'dotcom' %}
7
+
8
+ {{ site.data.variables.product.product_name }} is great for open source.
9
+
10
+ {% else %}
11
+
12
+ {{ site.data.variables.product.product_name }} is great for businesses.
13
+
14
+ {% endif %}
@@ -0,0 +1 @@
1
+ new_name: 'SVNHub'
File without changes
@@ -0,0 +1,14 @@
1
+ product_name:
2
+ dotcom: 'GitHub'
3
+ '2.0': 'GitHub Enterprise'
4
+
5
+ caveat: |
6
+ {% if page.version == 'dotcom' %}
7
+
8
+ No caveats!
9
+
10
+ {% else %}
11
+
12
+ Well.....there is one.
13
+
14
+ {% endif %}
@@ -0,0 +1,16 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>
5
+ <%= @item[:title] %>
6
+ </title>
7
+ </head>
8
+
9
+ <body>
10
+
11
+ <%= @item[:intro] %>
12
+ <%= @item[:parents] %>
13
+ <%= yield %>
14
+
15
+ </body>
16
+ </html>
@@ -0,0 +1,51 @@
1
+
2
+ data_variables:
3
+ -
4
+ scope:
5
+ path: ""
6
+ values:
7
+ version: "dotcom"
8
+
9
+ page_variables:
10
+ -
11
+ scope:
12
+ path: ""
13
+ values:
14
+ version: "dotcom"
15
+ data_association: "categories.category"
16
+ -
17
+ scope:
18
+ path: "different"
19
+ values:
20
+ version: "2.0"
21
+
22
+ string_pattern_type: glob
23
+
24
+ text_extensions: [ 'coffee', 'css', 'erb', 'haml', 'handlebars', 'hb', 'htm', 'html', 'js', 'less', 'markdown', 'md', 'ms', 'mustache', 'php', 'rb', 'rdoc', 'sass', 'scss', 'slim', 'txt', 'xhtml', 'xml' ]
25
+
26
+ output_dir: output
27
+
28
+ index_filenames: [ 'index.html' ]
29
+
30
+ enable_output_diff: false
31
+
32
+ prune:
33
+ auto_prune: true
34
+
35
+ exclude: [ '.git', '.hg', '.svn', 'CVS' ]
36
+
37
+ data_sources:
38
+ -
39
+ # The type is the identifier of the data source.
40
+ type: conref_fs
41
+
42
+ items_root: /
43
+ layouts_root: /
44
+
45
+ encoding: utf-8
46
+
47
+ identifier_type: full
48
+
49
+ checks:
50
+ internal_links:
51
+ exclude: []
@@ -0,0 +1,75 @@
1
+ require 'bundler/setup'
2
+ require 'nanoc'
3
+ require_relative '../lib/nanoc-conref-fs'
4
+ require 'minitest/autorun'
5
+ require 'minitest/pride'
6
+ require 'active_support'
7
+
8
+ FIXTURES_DIR = File.join(Dir.pwd, 'test', 'fixtures')
9
+
10
+ def read_output_file(dir, name)
11
+ File.read(File.join('output', dir, name, 'index.html')).gsub(/^\s*$/, '')
12
+ end
13
+
14
+ def read_test_file(dir, name)
15
+ File.read(File.join(FIXTURES_DIR, 'content', dir, "#{name}.html")).gsub(/^\s*$/, '')
16
+ end
17
+
18
+ def with_site(params = {})
19
+ # Build site name
20
+ site_name = params[:name]
21
+ if site_name.nil?
22
+ @site_num ||= 0
23
+ site_name = "site-#{@site_num}"
24
+ @site_num += 1
25
+ end
26
+
27
+ # Build rules
28
+ rules_content = <<EOS
29
+ compile '*' do
30
+ {{compilation_rule_content}}
31
+ end
32
+
33
+ route '*' do
34
+ if item.binary?
35
+ item.identifier.chop + (item[:extension] ? '.' + item[:extension] : '')
36
+ else
37
+ item.identifier + 'index.html'
38
+ end
39
+ end
40
+
41
+ layout '*', :erb
42
+ EOS
43
+ rules_content.gsub!('{{compilation_rule_content}}', params[:compilation_rule_content] || '')
44
+
45
+ # Create site
46
+ unless File.directory?(site_name)
47
+ FileUtils.mkdir_p(site_name)
48
+ FileUtils.cd(site_name) do
49
+ FileUtils.mkdir_p('content')
50
+ FileUtils.mkdir_p('layouts')
51
+ FileUtils.mkdir_p('lib')
52
+ FileUtils.mkdir_p('output')
53
+
54
+ if params[:has_layout]
55
+ File.open('layouts/default.html', 'w') do |io|
56
+ io.write('... <%= @yield %> ...')
57
+ end
58
+ end
59
+
60
+ File.open('nanoc.yaml', 'w') do |io|
61
+ io << 'string_pattern_type: legacy' << "\n"
62
+ io << 'data_sources:' << "\n"
63
+ io << ' -' << "\n"
64
+ io << ' type: filesystem' << "\n"
65
+ io << ' identifier_type: legacy' << "\n"
66
+ end
67
+ File.open('Rules', 'w') { |io| io.write(rules_content) }
68
+ end
69
+ end
70
+
71
+ # Yield site
72
+ FileUtils.cd(site_name) do
73
+ yield Nanoc::Int::SiteLoader.new.new_from_cwd
74
+ end
75
+ end
metadata ADDED
@@ -0,0 +1,176 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: nanoc-conref-fs
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Garen Torikian
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-10-19 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: nanoc
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 3.1.6
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 3.1.6
27
+ - !ruby/object:Gem::Dependency
28
+ name: activesupport
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '4.2'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '4.2'
41
+ - !ruby/object:Gem::Dependency
42
+ name: liquid
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
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
+ - !ruby/object:Gem::Dependency
70
+ name: minitest
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '5.8'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '5.8'
83
+ description:
84
+ email:
85
+ - gjtorikian@gmail.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".gitignore"
91
+ - ".travis.yml"
92
+ - Gemfile
93
+ - LICENSE.txt
94
+ - README.md
95
+ - Rakefile
96
+ - lib/nanoc-conref-fs.rb
97
+ - lib/nanoc-conref-fs/conref-fs.rb
98
+ - lib/nanoc-conref-fs/conrefifier.rb
99
+ - lib/nanoc-conref-fs/datafiles.rb
100
+ - nanoc-conref-fs.gemspec
101
+ - script/bootstrap
102
+ - test/conref_fs_test.rb
103
+ - test/datafiles_test.rb
104
+ - test/fixtures/Rules
105
+ - test/fixtures/content/datafiles/deep.html
106
+ - test/fixtures/content/datafiles/deep.md
107
+ - test/fixtures/content/frontmatter/audience.html
108
+ - test/fixtures/content/frontmatter/audience.md
109
+ - test/fixtures/content/frontmatter/different.html
110
+ - test/fixtures/content/frontmatter/different.md
111
+ - test/fixtures/content/frontmatter/title.html
112
+ - test/fixtures/content/frontmatter/title.md
113
+ - test/fixtures/content/parents/missing_title.html
114
+ - test/fixtures/content/parents/missing_title.md
115
+ - test/fixtures/content/parents/single_parent.html
116
+ - test/fixtures/content/parents/single_parent.md
117
+ - test/fixtures/content/parents/two_parents.html
118
+ - test/fixtures/content/parents/two_parents.md
119
+ - test/fixtures/data/categories/category.yml
120
+ - test/fixtures/data/reusables/intro.yml
121
+ - test/fixtures/data/reusables/names.yml
122
+ - test/fixtures/data/variables/empty.yml
123
+ - test/fixtures/data/variables/product.yml
124
+ - test/fixtures/layouts/default.html
125
+ - test/fixtures/nanoc.yaml
126
+ - test/test_helper.rb
127
+ homepage: https://github.com/gjtorikian/nanoc-conref-fs
128
+ licenses:
129
+ - MIT
130
+ metadata: {}
131
+ post_install_message:
132
+ rdoc_options: []
133
+ require_paths:
134
+ - lib
135
+ required_ruby_version: !ruby/object:Gem::Requirement
136
+ requirements:
137
+ - - ">="
138
+ - !ruby/object:Gem::Version
139
+ version: '0'
140
+ required_rubygems_version: !ruby/object:Gem::Requirement
141
+ requirements:
142
+ - - ">="
143
+ - !ruby/object:Gem::Version
144
+ version: '0'
145
+ requirements: []
146
+ rubyforge_project:
147
+ rubygems_version: 2.4.5
148
+ signing_key:
149
+ specification_version: 4
150
+ summary: A Nanoc filesystem to permit using conrefs/reusables in your content.
151
+ test_files:
152
+ - test/conref_fs_test.rb
153
+ - test/datafiles_test.rb
154
+ - test/fixtures/Rules
155
+ - test/fixtures/content/datafiles/deep.html
156
+ - test/fixtures/content/datafiles/deep.md
157
+ - test/fixtures/content/frontmatter/audience.html
158
+ - test/fixtures/content/frontmatter/audience.md
159
+ - test/fixtures/content/frontmatter/different.html
160
+ - test/fixtures/content/frontmatter/different.md
161
+ - test/fixtures/content/frontmatter/title.html
162
+ - test/fixtures/content/frontmatter/title.md
163
+ - test/fixtures/content/parents/missing_title.html
164
+ - test/fixtures/content/parents/missing_title.md
165
+ - test/fixtures/content/parents/single_parent.html
166
+ - test/fixtures/content/parents/single_parent.md
167
+ - test/fixtures/content/parents/two_parents.html
168
+ - test/fixtures/content/parents/two_parents.md
169
+ - test/fixtures/data/categories/category.yml
170
+ - test/fixtures/data/reusables/intro.yml
171
+ - test/fixtures/data/reusables/names.yml
172
+ - test/fixtures/data/variables/empty.yml
173
+ - test/fixtures/data/variables/product.yml
174
+ - test/fixtures/layouts/default.html
175
+ - test/fixtures/nanoc.yaml
176
+ - test/test_helper.rb