acos_jekyll_openapi_helper 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/acos_jekyll_openapi.rb +207 -0
- metadata +43 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 2f031059c47d7e93635b131c00549a5cd0c0808c18ab62374f03643316cbee4e
|
4
|
+
data.tar.gz: 73382a34bbd3de1d7fc6efcec7a27c98443cef7a755c955a9cef97b2a961a8a0
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: df841fbebdabdf441f26c23ca11fc6611f38547b9119c10e6c58dd7a3c1a066e5ec6d98c3a1dab31a0b33ed220b8c7a853bbdc699437eb396ebd12dd1ba0b6fc
|
7
|
+
data.tar.gz: e4d1b2c48d89eeca46630df996b2018f11f304d2ef83de03362f77abd2e7c27a41c7a03e2d2a6d599acfd7eb18bfb6f6b8b0552a131d3e08697b507f52487989
|
@@ -0,0 +1,207 @@
|
|
1
|
+
require 'json'
|
2
|
+
|
3
|
+
class AcosOpenApiHelper
|
4
|
+
def self.generate_pages(json_file, basePath, output_path)
|
5
|
+
|
6
|
+
puts "Loading json file: %s" % [json_file]
|
7
|
+
fileHelper = JsonFileHelper.new(json_file)
|
8
|
+
fileHelper.load
|
9
|
+
|
10
|
+
engine = PageEngine.new(fileHelper.json_data, basePath, output_path, json_file)
|
11
|
+
engine.generate
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.generate_pages_from_data(datafolder, basePath, output_path)
|
15
|
+
json_files = Dir["%s/*.json" % datafolder]
|
16
|
+
json_files.each do | jf |
|
17
|
+
puts "Generating pages based on: %s" % jf
|
18
|
+
generate_pages(jf, basePath, output_path)
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
class AcosOpenApiHelper::JsonFileHelper
|
25
|
+
include JSON
|
26
|
+
def initialize(path)
|
27
|
+
@path = path
|
28
|
+
end
|
29
|
+
|
30
|
+
def path
|
31
|
+
@path
|
32
|
+
end
|
33
|
+
|
34
|
+
def json_data
|
35
|
+
@json_data
|
36
|
+
end
|
37
|
+
|
38
|
+
|
39
|
+
def load
|
40
|
+
file = File.read(@path)
|
41
|
+
@json_data = JSON.parse(file)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
class AcosOpenApiHelper::PageEngine
|
46
|
+
def initialize(data, basePath, output_path, swaggerfile)
|
47
|
+
@data = data
|
48
|
+
@output_path = output_path
|
49
|
+
#@sidebar = sidebar
|
50
|
+
@swaggerfile = swaggerfile
|
51
|
+
@basePath = basePath
|
52
|
+
end
|
53
|
+
|
54
|
+
def generate
|
55
|
+
puts "generating pages..."
|
56
|
+
cnt = 0
|
57
|
+
puts "Open API version %s" % @data['openapi']
|
58
|
+
docTitle = @data["info"]["title"]
|
59
|
+
sidebar = "%s_sidebar" % docTitle
|
60
|
+
menu = AcosOpenApiHelper::SidebarMenu.new()
|
61
|
+
@data['paths'].each do |path|
|
62
|
+
#puts "Prop: %s at counter %s" % [path, cnt]
|
63
|
+
_path = path[0] #path of swagger method
|
64
|
+
_methods = @data['paths'][_path]
|
65
|
+
#puts "Path: %s has methods: %s " % [_path, _methods]
|
66
|
+
puts "Methods: %s" % _methods
|
67
|
+
puts "Path: %s" % [_path]
|
68
|
+
#Should not need this. yet...
|
69
|
+
# _methods.each do | _method |
|
70
|
+
# puts "Method: %s " % _method
|
71
|
+
# _md = _methods[_method]
|
72
|
+
# puts "Method description: %s" % [_md]
|
73
|
+
# end
|
74
|
+
#@prop = @data['paths'][cnt]
|
75
|
+
#puts "Found property %s" [@prop]
|
76
|
+
#puts "Constants: %s, %s, %s, %s" % [_path, @output_path, @swaggerfile, @sidebar]
|
77
|
+
writer = AcosOpenApiHelper::PageCreator.new(_path, @basePath, @output_path, @swaggerfile, sidebar)
|
78
|
+
writer.write
|
79
|
+
_permalink =AcosOpenApiHelper::PermalinkGenerator.create(_path, @swaggerfile)
|
80
|
+
_menuItem = AcosOpenApiHelper::MenuItem.new(_path, _permalink)
|
81
|
+
menu.add(_menuItem)
|
82
|
+
cnt = cnt + 1
|
83
|
+
|
84
|
+
end
|
85
|
+
puts "Done generating %s pages..." % cnt
|
86
|
+
puts "Writing menu"
|
87
|
+
menu.write("%s/_data/sidebars" % @basePath, sidebar, docTitle)
|
88
|
+
end
|
89
|
+
|
90
|
+
end
|
91
|
+
|
92
|
+
class AcosOpenApiHelper::SidebarMenu
|
93
|
+
@@entries = Array.new
|
94
|
+
#attr_accessor :title, :url
|
95
|
+
|
96
|
+
def self.all_entries
|
97
|
+
@@entries
|
98
|
+
end
|
99
|
+
|
100
|
+
def add(entry)
|
101
|
+
@@entries.push(entry)
|
102
|
+
end
|
103
|
+
|
104
|
+
|
105
|
+
def initialize()
|
106
|
+
# @title = title
|
107
|
+
# @url = url
|
108
|
+
#@@entries << self
|
109
|
+
end
|
110
|
+
|
111
|
+
def write (output_path, name, menuTitle)
|
112
|
+
_standardLines = [
|
113
|
+
"# This is your sidebar TOC. The sidebar code loops through sections here and provides the appropriate formatting.",
|
114
|
+
"entries:",
|
115
|
+
"- title: sidebar",
|
116
|
+
" # product: Documentation",
|
117
|
+
" # version: 1.0",
|
118
|
+
" folders:",
|
119
|
+
" - title: %s" % menuTitle,
|
120
|
+
" output: web",
|
121
|
+
" type: frontmatter",
|
122
|
+
" folderitems: "
|
123
|
+
]
|
124
|
+
puts "Writing menu with length: %s" % @@entries.length
|
125
|
+
@@entries.each do | item |
|
126
|
+
puts "Entry: %s, url: %s" % [item.title, item.url]
|
127
|
+
_standardLines << " - title: %s" % item.title
|
128
|
+
_standardLines << " url: /%s.html" % item.url
|
129
|
+
_standardLines << " output: web, pdf"
|
130
|
+
end
|
131
|
+
|
132
|
+
_standardLines << " - title: %s" % "Models"
|
133
|
+
_standardLines << " url: /%s.html" % "userapi_components"
|
134
|
+
_standardLines << " output: web, pdf"
|
135
|
+
# File.open("%s/%s/%s/%s.%s" % [@basePath, "pages", "swagger", @permalink, "md"], "w+") do |f|
|
136
|
+
# f.puts(@lines)
|
137
|
+
# end
|
138
|
+
puts "Writing menu file for %s at %s" % [name, output_path]
|
139
|
+
File.open("%s/%s.%s" % [output_path, name, "yml"], "w+") do | f |
|
140
|
+
f.puts(_standardLines)
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
144
|
+
end
|
145
|
+
|
146
|
+
class AcosOpenApiHelper::MenuItem
|
147
|
+
def initialize(title, url)
|
148
|
+
@title = title
|
149
|
+
@url = url
|
150
|
+
end
|
151
|
+
|
152
|
+
def title
|
153
|
+
@title
|
154
|
+
end
|
155
|
+
def url
|
156
|
+
@url
|
157
|
+
end
|
158
|
+
end
|
159
|
+
|
160
|
+
class AcosOpenApiHelper::PermalinkGenerator
|
161
|
+
def self.create(path, swaggerfile)
|
162
|
+
@swaggerfileBase = File.basename(swaggerfile, ".*")
|
163
|
+
@permalinkBase = "%s_%s" % [@swaggerfileBase, path]
|
164
|
+
@permalink = @permalinkBase.gsub(/\s+|{|}|\//, "_").downcase
|
165
|
+
return @permalink
|
166
|
+
end
|
167
|
+
|
168
|
+
def permalink
|
169
|
+
@permalink
|
170
|
+
end
|
171
|
+
|
172
|
+
end
|
173
|
+
|
174
|
+
class AcosOpenApiHelper::PageCreator
|
175
|
+
def initialize(path, basePath, output_path, swaggerfile, sidebar)
|
176
|
+
puts "Initialize intput %s, %s, %s, %s" % [path, output_path, swaggerfile, sidebar]
|
177
|
+
@path = path
|
178
|
+
@output_path = output_path
|
179
|
+
@swaggerfile = swaggerfile
|
180
|
+
@sidebar = sidebar
|
181
|
+
@basePath = basePath
|
182
|
+
@swaggerfileBase = File.basename(@swaggerfile, ".*")
|
183
|
+
@permalink = AcosOpenApiHelper::PermalinkGenerator.create(path, @swaggerfile)
|
184
|
+
@lines = [
|
185
|
+
"---",
|
186
|
+
"title: User API %s" % path,
|
187
|
+
"keywords: json, openapi",
|
188
|
+
"# summary: test med json fil",
|
189
|
+
"sidebar: %s" % @sidebar,
|
190
|
+
"permalink: %s.html" % @permalink,
|
191
|
+
"folder: swagger",
|
192
|
+
"toc: false",
|
193
|
+
"swaggerfile: %s" % @swaggerfileBase,
|
194
|
+
"swaggerpath: paths",
|
195
|
+
"swaggerkey: %s" % @path,
|
196
|
+
"---",
|
197
|
+
"{\% include swagger_json/get_path.md \%}"
|
198
|
+
]
|
199
|
+
end
|
200
|
+
|
201
|
+
def write
|
202
|
+
File.open("%s/%s/%s/%s.%s" % [@basePath, "pages", "swagger", @permalink, "md"], "w+") do |f|
|
203
|
+
f.puts(@lines)
|
204
|
+
end
|
205
|
+
end
|
206
|
+
end
|
207
|
+
|
metadata
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: acos_jekyll_openapi_helper
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Acos AS
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-05-23 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: A gem to generate page entries for jekyll sites
|
14
|
+
email: utvikling@acos.no
|
15
|
+
executables: []
|
16
|
+
extensions: []
|
17
|
+
extra_rdoc_files: []
|
18
|
+
files:
|
19
|
+
- lib/acos_jekyll_openapi.rb
|
20
|
+
homepage: https://rubygems.org/gems/acos_jekyll_openapi_helper
|
21
|
+
licenses:
|
22
|
+
- MIT
|
23
|
+
metadata: {}
|
24
|
+
post_install_message:
|
25
|
+
rdoc_options: []
|
26
|
+
require_paths:
|
27
|
+
- lib
|
28
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
29
|
+
requirements:
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
34
|
+
requirements:
|
35
|
+
- - ">="
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
requirements: []
|
39
|
+
rubygems_version: 3.0.3
|
40
|
+
signing_key:
|
41
|
+
specification_version: 4
|
42
|
+
summary: Open API json file helper
|
43
|
+
test_files: []
|