bunto-optional-front-matter 0.2.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 6ee5606d18fa268f587a7bc476ce9cf283ba0168
4
+ data.tar.gz: da94660a90797ae09398894ba2d857e09b7e5e7a
5
+ SHA512:
6
+ metadata.gz: 63e5fc4d9a550cb1848ed36b89fdbc592b3c21b01e1ea8d70c0380910c3b07f6265242c4984cca3894b9eae49eeeed12c04d521760ec92746ca8deb7c742768b
7
+ data.tar.gz: 87df35adc4601bd78bb79504921239af92136e3f3e5912ddea36526abbaf8078e12d8fabd888c13ff07047f737bb6acc19f86d4d3b8be6433e4e812671c4bb24
@@ -0,0 +1,18 @@
1
+ require "bunto"
2
+ require "bunto-optional-front-matter/generator"
3
+
4
+ module BuntoOptionalFrontMatter
5
+ # Case-insensitive array of filenames to exclude. All files must first
6
+ # match the config-defined list of markdown extensions. If you'd like one
7
+ # of these files included in your site, simply add YAML front matter to it.
8
+ FILENAME_BLACKLIST = %w(
9
+ README
10
+ LICENSE
11
+ LICENCE
12
+ COPYING
13
+ CODE_OF_CONDUCT
14
+ CONTRIBUTING
15
+ ISSUE_TEMPLATE
16
+ PULL_REQUEST_TEMPLATE
17
+ ).freeze
18
+ end
@@ -0,0 +1,62 @@
1
+ module BuntoOptionalFrontMatter
2
+ class Generator < Bunto::Generator
3
+ attr_accessor :site
4
+
5
+ safe true
6
+ priority :normal
7
+
8
+ def initialize(site)
9
+ @site = site
10
+ end
11
+
12
+ def generate(site)
13
+ @site = site
14
+ return if site.config["require_front_matter"]
15
+ site.pages.concat(pages_to_add)
16
+ end
17
+
18
+ private
19
+
20
+ # An array of Bunto::Pages to add, *excluding* blacklisted files
21
+ def pages_to_add
22
+ pages.reject { |page| blacklisted?(page) }
23
+ end
24
+
25
+ # An array of potential Bunto::Pages to add, *including* blacklisted files
26
+ def pages
27
+ markdown_files.map { |static_file| page_from_static_file(static_file) }
28
+ end
29
+
30
+ # An array of Bunto::StaticFile's with a site-defined markdown extension
31
+ def markdown_files
32
+ site.static_files.select { |file| markdown_converter.matches(file.extname) }
33
+ end
34
+
35
+ # Given a Bunto::StaticFile, returns the file as a Bunto::Page
36
+ def page_from_static_file(static_file)
37
+ base = static_file.instance_variable_get("@base")
38
+ dir = static_file.instance_variable_get("@dir")
39
+ name = static_file.instance_variable_get("@name")
40
+ Bunto::Page.new(site, base, dir, name)
41
+ end
42
+
43
+ # Does the given Bunto::Page match our filename blacklist?
44
+ def blacklisted?(page)
45
+ return false if whitelisted?(page)
46
+ FILENAME_BLACKLIST.include?(page.basename.upcase)
47
+ end
48
+
49
+ def whitelisted?(page)
50
+ return false unless site.config["include"].is_a? Array
51
+ entry_filter.included?(page.path)
52
+ end
53
+
54
+ def markdown_converter
55
+ @markdown_converter ||= site.find_converter_instance(Bunto::Converters::Markdown)
56
+ end
57
+
58
+ def entry_filter
59
+ @entry_filter ||= Bunto::EntryFilter.new(site)
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,3 @@
1
+ module BuntoOptionalFrontMatter
2
+ VERSION = "0.2.0".freeze
3
+ end
metadata ADDED
@@ -0,0 +1,91 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: bunto-optional-front-matter
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.0
5
+ platform: ruby
6
+ authors:
7
+ - Ben Balter
8
+ - Suriyaa Kudo
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2017-08-07 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bunto
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - "~>"
19
+ - !ruby/object:Gem::Version
20
+ version: '3.4'
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - "~>"
26
+ - !ruby/object:Gem::Version
27
+ version: '3.4'
28
+ - !ruby/object:Gem::Dependency
29
+ name: rspec
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - "~>"
33
+ - !ruby/object:Gem::Version
34
+ version: '3.5'
35
+ type: :development
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - "~>"
40
+ - !ruby/object:Gem::Version
41
+ version: '3.5'
42
+ - !ruby/object:Gem::Dependency
43
+ name: rubocop
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - "~>"
47
+ - !ruby/object:Gem::Version
48
+ version: '0.40'
49
+ type: :development
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - "~>"
54
+ - !ruby/object:Gem::Version
55
+ version: '0.40'
56
+ description:
57
+ email:
58
+ - ben.balter@github.com
59
+ - github@suriyaa.tk
60
+ executables: []
61
+ extensions: []
62
+ extra_rdoc_files: []
63
+ files:
64
+ - lib/bunto-optional-front-matter.rb
65
+ - lib/bunto-optional-front-matter/generator.rb
66
+ - lib/bunto-optional-front-matter/version.rb
67
+ homepage: https://github.com/bunto/bunto-optional-front-matter
68
+ licenses:
69
+ - MIT
70
+ metadata: {}
71
+ post_install_message:
72
+ rdoc_options: []
73
+ require_paths:
74
+ - lib
75
+ required_ruby_version: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - ">="
78
+ - !ruby/object:Gem::Version
79
+ version: '0'
80
+ required_rubygems_version: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ version: '0'
85
+ requirements: []
86
+ rubyforge_project:
87
+ rubygems_version: 2.6.12
88
+ signing_key:
89
+ specification_version: 4
90
+ summary: A Bunto plugin to make front matter optional for Markdown files
91
+ test_files: []