-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
examples.html.haml
91 lines (72 loc) · 2.52 KB
/
examples.html.haml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
---
layout: simplepage
title: Pipeline Examples
section: doc
---
:ruby
require 'rouge'
formatter = Rouge::Formatters::HTML.new
lexer = Rouge::Lexers::Groovy.new
examples_dir = File.expand_path(File.dirname(__FILE__) + '/../../_tmp/examples/pipeline-examples-master')
pipeline_examples = File.join(examples_dir, 'pipeline-examples')
# we must have a pipeline-examples directory, otherwise fail
unless File.directory?(pipeline_examples)
raise "Could not find directory file #{pipeline_examples}."
end
examples = []
Dir.entries(pipeline_examples).sort.each do |dir|
next if dir.start_with?('.')
full_path = File.join(pipeline_examples, dir)
readme = File.join(full_path, 'README.md')
# We must have a readme for each directory otherwise we won't use it
next unless File.directory?(full_path)
next unless File.exist?(readme)
readme = File.open(readme).read
# Titlecase based off the directory name
title = dir.gsub('-', ' ').split(' ').map { |w| w.capitalize }.join(' ')
# Collect whatever groovy files, which represent the examples, into the array
codes = Dir.glob("#{full_path}/*.groovy")
examples << [dir, title, readme, codes]
end
%div
%p
The following examples are sourced from the the
%a{:href => 'https://github.com/jenkinsci/pipeline-examples', :target => '_blank', :rel => 'noreferrer noopener'}
pipeline-examples
repository on GitHub and contributed to by various members of the Jenkins
project. If you are interested in contributing your own example, please consult the
%a{:href => 'https://github.com/jenkinsci/pipeline-examples#introduction', :target => '_blank', :rel => 'noreferrer noopener'}
README
in the repository.
%div.toc#toc
%div.toctitle
Table of Contents
%ul.sectlevel1
- examples.each do |dir, title, y, z|
%li
%a{:href => ['#', dir].join('')}
= title
%div.examples
- examples.each do |dir, title, readme, codes|
%div.example
:ruby
# Replacing markdown headers with ones one level further indented
readme.gsub!(/^#/, '#####')
%div.title
%a{:name => dir}
%h3
= title
%div.readme
:plain
<!--
#{readme}
-->
:markdown
#{readme}
%div.code
- codes.each do |code|
:plain
<!-- syntax highlighting #{File.basename(code)} -->
%div.listingblock
%pre.highlight
= formatter.format(lexer.lex(File.read(code)))