mirror of
https://github.com/inspec/inspec
synced 2024-11-10 07:04:15 +00:00
render resource docs
This commit is contained in:
parent
dba8638e3a
commit
f9248033c3
3 changed files with 53 additions and 4836 deletions
1
Gemfile
1
Gemfile
|
@ -46,6 +46,7 @@ group :tools do
|
|||
gem 'rb-readline'
|
||||
gem 'license_finder'
|
||||
gem 'github_changelog_generator', '~> 1'
|
||||
gem 'ruby-progressbar', '~> 1.8'
|
||||
end
|
||||
|
||||
# gems for Maintainers.md generation
|
||||
|
|
4836
docs/resources.rst
4836
docs/resources.rst
File diff suppressed because it is too large
Load diff
|
@ -15,6 +15,10 @@
|
|||
# limitations under the License.
|
||||
#
|
||||
|
||||
require 'erb'
|
||||
require 'ruby-progressbar'
|
||||
require 'fileutils'
|
||||
|
||||
class Markdown
|
||||
class << self
|
||||
def h1(msg)
|
||||
|
@ -103,6 +107,30 @@ class RST
|
|||
end
|
||||
end
|
||||
|
||||
class ResourceDocs
|
||||
def initialize(root)
|
||||
@paths = {} # cache of paths
|
||||
@root = root # relative root path for all docs
|
||||
end
|
||||
|
||||
def render(path)
|
||||
@paths[path] ||= render_path(path)
|
||||
end
|
||||
|
||||
def partial(x)
|
||||
render(x + '.md.erb')
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def render_path(path)
|
||||
abs = File.join(@root, path)
|
||||
fail "Can't find file to render in #{abs}" unless File.file?(abs)
|
||||
|
||||
ERB.new(File.read(abs)).result(binding)
|
||||
end
|
||||
end
|
||||
|
||||
namespace :docs do
|
||||
desc 'Create cli docs'
|
||||
task :cli do
|
||||
|
@ -154,6 +182,30 @@ namespace :docs do
|
|||
File.write(dst, res)
|
||||
puts "Documentation generated in #{dst.inspect}"
|
||||
end
|
||||
|
||||
desc 'Create resources docs'
|
||||
task :resources do
|
||||
src = 'docs'
|
||||
dst = 'www/source/docs/resources'
|
||||
docs = ResourceDocs.new(src)
|
||||
resources = Dir[File.join(src, 'resources/*.md.erb')]
|
||||
.map { |x| x.sub(/^#{src}/, '') }
|
||||
puts "Found #{src.length} resource docs"
|
||||
puts "Clean up #{dst}"
|
||||
FileUtils.rm_rf(dst) if File.exist?(dst)
|
||||
FileUtils.mkdir_p(dst)
|
||||
puts "Rendering docs to #{dst}/"
|
||||
|
||||
progressbar = ProgressBar.create(total: resources.length, title: 'Rendering')
|
||||
resources.each do |file|
|
||||
progressbar.log(' '+file)
|
||||
dst_name = File.basename(file).sub(/\.erb$/, '')
|
||||
res = docs.render(file)
|
||||
File.write(File.join(dst, dst_name), res)
|
||||
progressbar.increment
|
||||
end
|
||||
progressbar.finish
|
||||
end
|
||||
end
|
||||
|
||||
def run_tasks_in_namespace(ns)
|
||||
|
|
Loading…
Reference in a new issue