sleeping_king_studios-docs 0.1.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 +7 -0
- data/CHANGELOG.md +5 -0
- data/CODE_OF_CONDUCT.md +132 -0
- data/LICENSE +22 -0
- data/README.md +101 -0
- data/lib/sleeping_king_studios/docs/commands/generate.rb +268 -0
- data/lib/sleeping_king_studios/docs/commands/generators/base.rb +97 -0
- data/lib/sleeping_king_studios/docs/commands/generators/data_generator.rb +68 -0
- data/lib/sleeping_king_studios/docs/commands/generators/reference_generator.rb +59 -0
- data/lib/sleeping_king_studios/docs/commands/generators.rb +15 -0
- data/lib/sleeping_king_studios/docs/commands/installation/install_jekyll.rb +273 -0
- data/lib/sleeping_king_studios/docs/commands/installation/install_templates.rb +125 -0
- data/lib/sleeping_king_studios/docs/commands/installation/install_workflow.rb +121 -0
- data/lib/sleeping_king_studios/docs/commands/installation.rb +15 -0
- data/lib/sleeping_king_studios/docs/commands/parse.rb +51 -0
- data/lib/sleeping_king_studios/docs/commands/write_file.rb +89 -0
- data/lib/sleeping_king_studios/docs/commands.rb +14 -0
- data/lib/sleeping_king_studios/docs/data/base.rb +48 -0
- data/lib/sleeping_king_studios/docs/data/class_object.rb +119 -0
- data/lib/sleeping_king_studios/docs/data/constant_object.rb +161 -0
- data/lib/sleeping_king_studios/docs/data/metadata.rb +196 -0
- data/lib/sleeping_king_studios/docs/data/method_object.rb +555 -0
- data/lib/sleeping_king_studios/docs/data/module_object.rb +234 -0
- data/lib/sleeping_king_studios/docs/data/namespace_object.rb +375 -0
- data/lib/sleeping_king_studios/docs/data/root_object.rb +40 -0
- data/lib/sleeping_king_studios/docs/data/see_tags/base.rb +35 -0
- data/lib/sleeping_king_studios/docs/data/see_tags/class_method_tag.rb +99 -0
- data/lib/sleeping_king_studios/docs/data/see_tags/constant_tag.rb +60 -0
- data/lib/sleeping_king_studios/docs/data/see_tags/definition_tag.rb +52 -0
- data/lib/sleeping_king_studios/docs/data/see_tags/instance_method_tag.rb +69 -0
- data/lib/sleeping_king_studios/docs/data/see_tags/link_tag.rb +53 -0
- data/lib/sleeping_king_studios/docs/data/see_tags/namespace_item_tag.rb +56 -0
- data/lib/sleeping_king_studios/docs/data/see_tags/reference_tag.rb +92 -0
- data/lib/sleeping_king_studios/docs/data/see_tags/text_tag.rb +30 -0
- data/lib/sleeping_king_studios/docs/data/see_tags/unstructured_tag.rb +37 -0
- data/lib/sleeping_king_studios/docs/data/see_tags.rb +101 -0
- data/lib/sleeping_king_studios/docs/data/types/grammar.treetop +49 -0
- data/lib/sleeping_king_studios/docs/data/types/key_value_type.rb +54 -0
- data/lib/sleeping_king_studios/docs/data/types/parameterized_type.rb +57 -0
- data/lib/sleeping_king_studios/docs/data/types/parser.rb +143 -0
- data/lib/sleeping_king_studios/docs/data/types/type.rb +100 -0
- data/lib/sleeping_king_studios/docs/data/types.rb +19 -0
- data/lib/sleeping_king_studios/docs/data.rb +29 -0
- data/lib/sleeping_king_studios/docs/errors/file_already_exists.rb +22 -0
- data/lib/sleeping_king_studios/docs/errors/file_error.rb +30 -0
- data/lib/sleeping_king_studios/docs/errors/file_not_found.rb +22 -0
- data/lib/sleeping_king_studios/docs/errors/invalid_directory.rb +22 -0
- data/lib/sleeping_king_studios/docs/errors/invalid_file.rb +22 -0
- data/lib/sleeping_king_studios/docs/errors.rb +19 -0
- data/lib/sleeping_king_studios/docs/registry.rb +22 -0
- data/lib/sleeping_king_studios/docs/registry_query.rb +93 -0
- data/lib/sleeping_king_studios/docs/tasks/base.rb +20 -0
- data/lib/sleeping_king_studios/docs/tasks/generate.rb +39 -0
- data/lib/sleeping_king_studios/docs/tasks/installation/install_jekyll.rb +67 -0
- data/lib/sleeping_king_studios/docs/tasks/installation/install_templates.rb +39 -0
- data/lib/sleeping_king_studios/docs/tasks/installation/install_workflow.rb +53 -0
- data/lib/sleeping_king_studios/docs/tasks/installation.rb +8 -0
- data/lib/sleeping_king_studios/docs/tasks/update.rb +35 -0
- data/lib/sleeping_king_studios/docs/tasks.rb +14 -0
- data/lib/sleeping_king_studios/docs/templates/config.yml.erb +22 -0
- data/lib/sleeping_king_studios/docs/templates/deploy-pages.yml.erb +67 -0
- data/lib/sleeping_king_studios/docs/templates/includes/breadcrumbs.md +7 -0
- data/lib/sleeping_king_studios/docs/templates/includes/reference/attribute.md +23 -0
- data/lib/sleeping_king_studios/docs/templates/includes/reference/attributes/heading.md +15 -0
- data/lib/sleeping_king_studios/docs/templates/includes/reference/class.md +27 -0
- data/lib/sleeping_king_studios/docs/templates/includes/reference/constant.md +8 -0
- data/lib/sleeping_king_studios/docs/templates/includes/reference/constants/heading.md +6 -0
- data/lib/sleeping_king_studios/docs/templates/includes/reference/constants/inherited.md +4 -0
- data/lib/sleeping_king_studios/docs/templates/includes/reference/constants/overview.md +60 -0
- data/lib/sleeping_king_studios/docs/templates/includes/reference/definitions/breadcrumbs.md +21 -0
- data/lib/sleeping_king_studios/docs/templates/includes/reference/definitions/class_attributes.md +9 -0
- data/lib/sleeping_king_studios/docs/templates/includes/reference/definitions/class_methods.md +9 -0
- data/lib/sleeping_king_studios/docs/templates/includes/reference/definitions/constants.md +9 -0
- data/lib/sleeping_king_studios/docs/templates/includes/reference/definitions/constructor.md +12 -0
- data/lib/sleeping_king_studios/docs/templates/includes/reference/definitions/definitions.md +23 -0
- data/lib/sleeping_king_studios/docs/templates/includes/reference/definitions/details.md +34 -0
- data/lib/sleeping_king_studios/docs/templates/includes/reference/definitions/instance_attributes.md +9 -0
- data/lib/sleeping_king_studios/docs/templates/includes/reference/definitions/instance_methods.md +17 -0
- data/lib/sleeping_king_studios/docs/templates/includes/reference/definitions/overview.md +74 -0
- data/lib/sleeping_king_studios/docs/templates/includes/reference/definitions/subclasses.md +10 -0
- data/lib/sleeping_king_studios/docs/templates/includes/reference/definitions/table-of-contents/class_attributes.md +10 -0
- data/lib/sleeping_king_studios/docs/templates/includes/reference/definitions/table-of-contents/class_methods.md +10 -0
- data/lib/sleeping_king_studios/docs/templates/includes/reference/definitions/table-of-contents/constants.md +10 -0
- data/lib/sleeping_king_studios/docs/templates/includes/reference/definitions/table-of-contents/instance_attributes.md +10 -0
- data/lib/sleeping_king_studios/docs/templates/includes/reference/definitions/table-of-contents/instance_methods.md +10 -0
- data/lib/sleeping_king_studios/docs/templates/includes/reference/definitions/table-of-contents/overview.md +41 -0
- data/lib/sleeping_king_studios/docs/templates/includes/reference/definitions/table-of-contents.md +27 -0
- data/lib/sleeping_king_studios/docs/templates/includes/reference/method.md +27 -0
- data/lib/sleeping_king_studios/docs/templates/includes/reference/methods/aliases.md +4 -0
- data/lib/sleeping_king_studios/docs/templates/includes/reference/methods/heading.md +14 -0
- data/lib/sleeping_king_studios/docs/templates/includes/reference/methods/inherited.md +4 -0
- data/lib/sleeping_king_studios/docs/templates/includes/reference/methods/overload.md +18 -0
- data/lib/sleeping_king_studios/docs/templates/includes/reference/methods/overloads.md +12 -0
- data/lib/sleeping_king_studios/docs/templates/includes/reference/methods/overview.md +41 -0
- data/lib/sleeping_king_studios/docs/templates/includes/reference/methods/parameters.md +31 -0
- data/lib/sleeping_king_studios/docs/templates/includes/reference/methods/post_overview.md +51 -0
- data/lib/sleeping_king_studios/docs/templates/includes/reference/methods/raises.md +14 -0
- data/lib/sleeping_king_studios/docs/templates/includes/reference/methods/return_types.md +9 -0
- data/lib/sleeping_king_studios/docs/templates/includes/reference/methods/returns.md +14 -0
- data/lib/sleeping_king_studios/docs/templates/includes/reference/methods/yields.md +42 -0
- data/lib/sleeping_king_studios/docs/templates/includes/reference/module.md +23 -0
- data/lib/sleeping_king_studios/docs/templates/includes/reference/namespace.md +33 -0
- data/lib/sleeping_king_studios/docs/templates/includes/reference/parent_link.md +6 -0
- data/lib/sleeping_king_studios/docs/templates/includes/reference/reference_link.md +7 -0
- data/lib/sleeping_king_studios/docs/templates/includes/reference/see_link.md +7 -0
- data/lib/sleeping_king_studios/docs/templates/includes/reference/type.md +14 -0
- data/lib/sleeping_king_studios/docs/templates/includes/reference/type_list.md +4 -0
- data/lib/sleeping_king_studios/docs/templates/includes/reference/types/array_type.md +1 -0
- data/lib/sleeping_king_studios/docs/templates/includes/reference/types/hash_type.md +1 -0
- data/lib/sleeping_king_studios/docs/templates/includes/reference/types/ordered_type.md +1 -0
- data/lib/sleeping_king_studios/docs/templates/pages/index.md.erb +22 -0
- data/lib/sleeping_king_studios/docs/templates/pages/reference.md.erb +14 -0
- data/lib/sleeping_king_studios/docs/templates/pages/versions.md.erb +13 -0
- data/lib/sleeping_king_studios/docs/version.rb +59 -0
- data/lib/sleeping_king_studios/docs.rb +27 -0
- metadata +243 -0
@@ -0,0 +1,59 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'sleeping_king_studios/docs/commands/generators'
|
4
|
+
|
5
|
+
module SleepingKingStudios::Docs::Commands::Generators
|
6
|
+
# Generator for writing reference files.
|
7
|
+
class ReferenceGenerator <
|
8
|
+
SleepingKingStudios::Docs::Commands::Generators::Base
|
9
|
+
# @overload file_path(data_object:)
|
10
|
+
# Determines the generated file path for the given data object.
|
11
|
+
#
|
12
|
+
# @param data_object [SleepingKingStudios::Docs::Data::Base] the data
|
13
|
+
# object for which the file is generated.
|
14
|
+
#
|
15
|
+
# @return [String] the qualified path to the generated file.
|
16
|
+
def file_path(data_object:, data_type: nil) # rubocop:disable Lint/UnusedMethodArgument
|
17
|
+
File.join(dir_path, "#{data_object.data_path}.md")
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
def dir_path
|
23
|
+
if version
|
24
|
+
File.join(docs_path, 'versions', version, 'reference')
|
25
|
+
else
|
26
|
+
File.join(docs_path, 'reference')
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def process(data_object:, data_type: nil)
|
31
|
+
data_type ||= data_object_type(data_object:)
|
32
|
+
contents = template(data_object:, data_type:)
|
33
|
+
|
34
|
+
return success(nil) if dry_run?
|
35
|
+
|
36
|
+
write_command.call(
|
37
|
+
contents:,
|
38
|
+
file_path: file_path(data_object:)
|
39
|
+
)
|
40
|
+
end
|
41
|
+
|
42
|
+
def template(data_object:, data_type:)
|
43
|
+
<<~MARKDOWN
|
44
|
+
---
|
45
|
+
data_path: "#{data_object.data_path}"
|
46
|
+
version: "#{version_string}"
|
47
|
+
---
|
48
|
+
|
49
|
+
{% include #{template_path}/#{data_type}.md %}
|
50
|
+
MARKDOWN
|
51
|
+
end
|
52
|
+
|
53
|
+
def write_command
|
54
|
+
@write_command ||=
|
55
|
+
SleepingKingStudios::Docs::Commands::WriteFile
|
56
|
+
.new(force: force?)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'sleeping_king_studios/docs/commands'
|
4
|
+
|
5
|
+
module SleepingKingStudios::Docs::Commands
|
6
|
+
# Namespace for generator commands, which write docs to the filesystem.
|
7
|
+
module Generators
|
8
|
+
autoload :Base,
|
9
|
+
'sleeping_king_studios/docs/commands/generators/base'
|
10
|
+
autoload :DataGenerator,
|
11
|
+
'sleeping_king_studios/docs/commands/generators/data_generator'
|
12
|
+
autoload :ReferenceGenerator,
|
13
|
+
'sleeping_king_studios/docs/commands/generators/reference_generator'
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,273 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'fileutils'
|
4
|
+
|
5
|
+
require 'erubi'
|
6
|
+
|
7
|
+
require 'sleeping_king_studios/docs/commands/installation'
|
8
|
+
require 'sleeping_king_studios/docs/commands/installation/install_templates'
|
9
|
+
|
10
|
+
module SleepingKingStudios::Docs::Commands::Installation
|
11
|
+
# Installs the Jekyll application.
|
12
|
+
class InstallJekyll < Cuprum::Command # rubocop:disable Metrics/ClassLength
|
13
|
+
# @overload initialize(**options)
|
14
|
+
# @param options [Hash] additional options for the command.
|
15
|
+
#
|
16
|
+
# @option options description [String] a short description of the
|
17
|
+
# documented library.
|
18
|
+
# @option options dry_run [Boolean] if true, does not apply filesystem
|
19
|
+
# changes. Defaults to false.
|
20
|
+
# @option options name [String] the name of the documented library.
|
21
|
+
# @option options repository [String] the URL of the library repository.
|
22
|
+
# @option options verbose [Boolean] if true, prints updates to STDOUT.
|
23
|
+
# Defaults to true.
|
24
|
+
def initialize(error_stream: $stderr, output_stream: $stdout, **options)
|
25
|
+
super()
|
26
|
+
|
27
|
+
@error_stream = error_stream
|
28
|
+
@output_stream = output_stream
|
29
|
+
@options = options
|
30
|
+
end
|
31
|
+
|
32
|
+
# @return [String] a short description of the documented library.
|
33
|
+
def description
|
34
|
+
@options.fetch(:description, 'A Ruby library.')
|
35
|
+
end
|
36
|
+
|
37
|
+
# @return [Boolean] if true, does not apply filesystem changes.
|
38
|
+
def dry_run?
|
39
|
+
@options.fetch(:dry_run, false)
|
40
|
+
end
|
41
|
+
|
42
|
+
# @return [String] the name of the documented library.
|
43
|
+
def name
|
44
|
+
@options.fetch(:name, 'Library Name')
|
45
|
+
end
|
46
|
+
|
47
|
+
# @return [String] the URL of the library repository.
|
48
|
+
def repository
|
49
|
+
@options.fetch(:repository, 'www.example.com')
|
50
|
+
end
|
51
|
+
|
52
|
+
# @return [Boolean] if true, prints updates to STDOUT.
|
53
|
+
def verbose?
|
54
|
+
@options.fetch(:verbose, true)
|
55
|
+
end
|
56
|
+
|
57
|
+
private
|
58
|
+
|
59
|
+
attr_reader :docs_path
|
60
|
+
|
61
|
+
attr_reader :error_stream
|
62
|
+
|
63
|
+
attr_reader :output_stream
|
64
|
+
|
65
|
+
attr_reader :project_path
|
66
|
+
|
67
|
+
def create_configuration
|
68
|
+
file_path = File.join(docs_path, '_config.yml')
|
69
|
+
|
70
|
+
return if File.exist?(file_path)
|
71
|
+
|
72
|
+
output ' - Generating Jekyll configuration'
|
73
|
+
|
74
|
+
return if dry_run?
|
75
|
+
|
76
|
+
File.write(
|
77
|
+
file_path,
|
78
|
+
evaluate_template(File.join(templates_path, 'config.yml.erb'))
|
79
|
+
)
|
80
|
+
end
|
81
|
+
|
82
|
+
def create_directory
|
83
|
+
return if Dir.exist?(docs_path)
|
84
|
+
|
85
|
+
output " - Creating Jekyll directory at #{docs_path}"
|
86
|
+
|
87
|
+
return if dry_run?
|
88
|
+
|
89
|
+
FileUtils.mkdir_p docs_path
|
90
|
+
end
|
91
|
+
|
92
|
+
def create_index_page
|
93
|
+
file_path = File.join(docs_path, 'index.md')
|
94
|
+
|
95
|
+
return if File.exist?(file_path)
|
96
|
+
|
97
|
+
output ' - Generating index page'
|
98
|
+
|
99
|
+
return if dry_run?
|
100
|
+
|
101
|
+
File.write(
|
102
|
+
file_path,
|
103
|
+
evaluate_template(File.join(templates_path, 'pages', 'index.md.erb'))
|
104
|
+
)
|
105
|
+
end
|
106
|
+
|
107
|
+
def create_pages
|
108
|
+
step { create_index_page }
|
109
|
+
step { create_reference_page }
|
110
|
+
step { create_versions_page }
|
111
|
+
end
|
112
|
+
|
113
|
+
def create_reference_page # rubocop:disable Metrics/MethodLength
|
114
|
+
dir_path = File.join(docs_path, 'reference')
|
115
|
+
|
116
|
+
FileUtils.mkdir_p(dir_path) unless dry_run?
|
117
|
+
|
118
|
+
file_path = File.join(dir_path, 'index.md')
|
119
|
+
|
120
|
+
return if File.exist?(file_path)
|
121
|
+
|
122
|
+
output ' - Generating reference page'
|
123
|
+
|
124
|
+
return if dry_run?
|
125
|
+
|
126
|
+
File.write(
|
127
|
+
file_path,
|
128
|
+
evaluate_template(
|
129
|
+
File.join(templates_path, 'pages', 'reference.md.erb')
|
130
|
+
)
|
131
|
+
)
|
132
|
+
end
|
133
|
+
|
134
|
+
def create_versions_page # rubocop:disable Metrics/MethodLength
|
135
|
+
dir_path = File.join(docs_path, 'versions')
|
136
|
+
|
137
|
+
FileUtils.mkdir_p(dir_path) unless dry_run?
|
138
|
+
|
139
|
+
file_path = File.join(dir_path, 'index.md')
|
140
|
+
|
141
|
+
return if File.exist?(file_path)
|
142
|
+
|
143
|
+
output ' - Generating versions page'
|
144
|
+
|
145
|
+
return if dry_run?
|
146
|
+
|
147
|
+
File.write(
|
148
|
+
file_path,
|
149
|
+
evaluate_template(
|
150
|
+
File.join(templates_path, 'pages', 'versions.md.erb')
|
151
|
+
)
|
152
|
+
)
|
153
|
+
end
|
154
|
+
|
155
|
+
def evaluate_template(template_path)
|
156
|
+
template = File.read(template_path)
|
157
|
+
engine = Erubi::Engine.new(template).src
|
158
|
+
|
159
|
+
eval(engine, local_binding) # rubocop:disable Security/Eval
|
160
|
+
end
|
161
|
+
|
162
|
+
def install_templates
|
163
|
+
includes_path = File.join(docs_path, '_includes')
|
164
|
+
|
165
|
+
FileUtils.mkdir_p(includes_path) unless dry_run?
|
166
|
+
|
167
|
+
output ' - Installing Jekyll templates'
|
168
|
+
|
169
|
+
file_path = File.join(includes_path, 'breadcrumbs.md')
|
170
|
+
|
171
|
+
unless File.exist?(file_path)
|
172
|
+
template_path = File.join(templates_path, 'includes', 'breadcrumbs.md')
|
173
|
+
|
174
|
+
File.write(file_path, File.read(template_path)) unless dry_run?
|
175
|
+
end
|
176
|
+
|
177
|
+
install_reference_templates
|
178
|
+
end
|
179
|
+
|
180
|
+
def install_reference_templates
|
181
|
+
SleepingKingStudios::Docs::Commands::Installation::InstallTemplates
|
182
|
+
.new(
|
183
|
+
dry_run: dry_run?,
|
184
|
+
force: false,
|
185
|
+
ignore_existing: true,
|
186
|
+
verbose: false
|
187
|
+
)
|
188
|
+
.call(docs_path:)
|
189
|
+
end
|
190
|
+
|
191
|
+
def jekyll_cache_path
|
192
|
+
File.join(docs_path, '.jekyll-cache').sub(/\A\./, '')
|
193
|
+
end
|
194
|
+
|
195
|
+
def jekyll_site_path
|
196
|
+
File.join(docs_path, '_site').sub(/\A\./, '')
|
197
|
+
end
|
198
|
+
|
199
|
+
def local_binding
|
200
|
+
return @local_binding if @local_binding
|
201
|
+
|
202
|
+
description = self.description
|
203
|
+
name = self.name
|
204
|
+
repository = self.repository
|
205
|
+
|
206
|
+
@local_binding = binding
|
207
|
+
end
|
208
|
+
|
209
|
+
def output(string)
|
210
|
+
return unless verbose?
|
211
|
+
|
212
|
+
output_stream.puts(string)
|
213
|
+
end
|
214
|
+
|
215
|
+
def process(docs_path:, project_path: Dir.pwd)
|
216
|
+
@docs_path = docs_path
|
217
|
+
@project_path = project_path
|
218
|
+
|
219
|
+
output "Installing SleepingKingStudios::YARD to #{docs_path}..."
|
220
|
+
|
221
|
+
step { update_gitignore }
|
222
|
+
step { create_directory }
|
223
|
+
step { create_configuration }
|
224
|
+
step { create_pages }
|
225
|
+
step { install_templates }
|
226
|
+
|
227
|
+
output 'Done!'
|
228
|
+
end
|
229
|
+
|
230
|
+
def templates_path
|
231
|
+
@templates_path ||=
|
232
|
+
File.join(
|
233
|
+
SleepingKingStudios::Docs.gem_path,
|
234
|
+
'lib',
|
235
|
+
'sleeping_king_studios',
|
236
|
+
'docs',
|
237
|
+
'templates'
|
238
|
+
)
|
239
|
+
end
|
240
|
+
|
241
|
+
def update_gitignore
|
242
|
+
file_path = File.join(project_path, '.gitignore')
|
243
|
+
|
244
|
+
FileUtils.touch(file_path) unless dry_run?
|
245
|
+
|
246
|
+
original_contents = File.read(file_path)
|
247
|
+
updated_contents = update_gitignore_contents(original_contents:)
|
248
|
+
|
249
|
+
return if updated_contents == original_contents
|
250
|
+
|
251
|
+
output ' - Updating .gitignore'
|
252
|
+
|
253
|
+
File.write(file_path, updated_contents) unless dry_run?
|
254
|
+
end
|
255
|
+
|
256
|
+
def update_gitignore_contents(original_contents:) # rubocop:disable Metrics/MethodLength
|
257
|
+
updated = original_contents
|
258
|
+
ignored = original_contents.each_line.map(&:strip)
|
259
|
+
|
260
|
+
unless ignored.include?(jekyll_cache_path)
|
261
|
+
updated += "\n" unless updated.empty? || updated.end_with?("\n")
|
262
|
+
updated += "#{jekyll_cache_path}\n"
|
263
|
+
end
|
264
|
+
|
265
|
+
unless ignored.include?(jekyll_site_path)
|
266
|
+
updated += "\n" unless updated.end_with?("\n")
|
267
|
+
updated += "#{jekyll_site_path}\n"
|
268
|
+
end
|
269
|
+
|
270
|
+
updated
|
271
|
+
end
|
272
|
+
end
|
273
|
+
end
|
@@ -0,0 +1,125 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'fileutils'
|
4
|
+
|
5
|
+
require 'sleeping_king_studios/docs/commands/installation'
|
6
|
+
require 'sleeping_king_studios/docs/errors/file_already_exists'
|
7
|
+
|
8
|
+
module SleepingKingStudios::Docs::Commands::Installation
|
9
|
+
# Installs the Liquid template files.
|
10
|
+
class InstallTemplates < Cuprum::Command
|
11
|
+
# @overload initialize(**options)
|
12
|
+
# @param options [Hash] additional options for the command.
|
13
|
+
#
|
14
|
+
# @option options dry_run [Boolean] if true, does not apply filesystem
|
15
|
+
# changes. Defaults to false.
|
16
|
+
# @option options force [Boolean] if true, replaces existing template
|
17
|
+
# files.
|
18
|
+
# @option options ignore_existing [Boolean] if true, does not attempt to
|
19
|
+
# copy over existing files.
|
20
|
+
# @option options verbose [Boolean] if true, prints updates to STDOUT.
|
21
|
+
# Defaults to true.
|
22
|
+
def initialize(error_stream: $stderr, output_stream: $stdout, **options)
|
23
|
+
super()
|
24
|
+
|
25
|
+
@error_stream = error_stream
|
26
|
+
@output_stream = output_stream
|
27
|
+
@options = options
|
28
|
+
end
|
29
|
+
|
30
|
+
# @return [Boolean] if true, does not apply filesystem changes.
|
31
|
+
def dry_run?
|
32
|
+
@options.fetch(:dry_run, false)
|
33
|
+
end
|
34
|
+
|
35
|
+
# @return [Boolean] if true, overwrites existing template files.
|
36
|
+
def force?
|
37
|
+
@options.fetch(:force, false)
|
38
|
+
end
|
39
|
+
|
40
|
+
# @return [Boolean] if true, does not attempt to copy over existing files.
|
41
|
+
def ignore_existing?
|
42
|
+
@options.fetch(:ignore_existing, false)
|
43
|
+
end
|
44
|
+
|
45
|
+
# @return [Boolean] if true, prints updates to STDOUT.
|
46
|
+
def verbose?
|
47
|
+
@options.fetch(:verbose, true)
|
48
|
+
end
|
49
|
+
|
50
|
+
private
|
51
|
+
|
52
|
+
attr_reader :docs_path
|
53
|
+
|
54
|
+
attr_reader :error_stream
|
55
|
+
|
56
|
+
attr_reader :output_stream
|
57
|
+
|
58
|
+
def check_for_existing_file(filename)
|
59
|
+
return if force?
|
60
|
+
return unless File.exist?(filename)
|
61
|
+
|
62
|
+
error =
|
63
|
+
SleepingKingStudios::Docs::Errors::FileAlreadyExists
|
64
|
+
.new(path: filename)
|
65
|
+
|
66
|
+
error_stream.puts("Error: #{error.message}")
|
67
|
+
|
68
|
+
failure(error)
|
69
|
+
end
|
70
|
+
|
71
|
+
def copy_template(template_path)
|
72
|
+
install_path = File.join(docs_path, '_includes', 'reference')
|
73
|
+
relative_path = template_path.sub("#{templates_path}/", '')
|
74
|
+
absolute_path = File.join(install_path, relative_path)
|
75
|
+
|
76
|
+
return if ignore_existing? && File.exist?(absolute_path)
|
77
|
+
|
78
|
+
output " - Copying template #{relative_path}"
|
79
|
+
|
80
|
+
step { check_for_existing_file(absolute_path) }
|
81
|
+
|
82
|
+
FileUtils.mkdir_p(File.dirname(absolute_path)) unless dry_run?
|
83
|
+
FileUtils.copy(template_path, absolute_path) unless dry_run?
|
84
|
+
end
|
85
|
+
|
86
|
+
def each_template(&)
|
87
|
+
return enum_for(:each_template) unless block_given?
|
88
|
+
|
89
|
+
Dir[templates_pattern].each(&)
|
90
|
+
end
|
91
|
+
|
92
|
+
def output(string)
|
93
|
+
return unless verbose?
|
94
|
+
|
95
|
+
output_stream.puts(string)
|
96
|
+
end
|
97
|
+
|
98
|
+
def process(docs_path:)
|
99
|
+
@docs_path = docs_path
|
100
|
+
|
101
|
+
output "Copying template files (force=#{force?})..."
|
102
|
+
|
103
|
+
each_template { |template_path| step { copy_template(template_path) } }
|
104
|
+
|
105
|
+
output 'Done!'
|
106
|
+
end
|
107
|
+
|
108
|
+
def templates_path
|
109
|
+
@templates_path ||=
|
110
|
+
File.join(
|
111
|
+
SleepingKingStudios::Docs.gem_path,
|
112
|
+
'lib',
|
113
|
+
'sleeping_king_studios',
|
114
|
+
'docs',
|
115
|
+
'templates',
|
116
|
+
'includes',
|
117
|
+
'reference'
|
118
|
+
)
|
119
|
+
end
|
120
|
+
|
121
|
+
def templates_pattern
|
122
|
+
@templates_pattern ||= File.join(templates_path, '**', '*.md')
|
123
|
+
end
|
124
|
+
end
|
125
|
+
end
|
@@ -0,0 +1,121 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'fileutils'
|
4
|
+
|
5
|
+
require 'erubi'
|
6
|
+
|
7
|
+
require 'sleeping_king_studios/docs/commands/installation'
|
8
|
+
require 'sleeping_king_studios/docs/errors/file_already_exists'
|
9
|
+
|
10
|
+
module SleepingKingStudios::Docs::Commands::Installation
|
11
|
+
# Installs the GitHub pages CI workflow.
|
12
|
+
class InstallWorkflow < Cuprum::Command
|
13
|
+
# @overload initialize(**options)
|
14
|
+
# @param options [Hash] additional options for the command.
|
15
|
+
#
|
16
|
+
# @option options dry_run [Boolean] if true, does not apply filesystem
|
17
|
+
# changes. Defaults to false.
|
18
|
+
# @option options force [Boolean] if true, replaces existing template
|
19
|
+
# files.
|
20
|
+
# @option options verbose [Boolean] if true, prints updates to STDOUT.
|
21
|
+
# Defaults to true.
|
22
|
+
def initialize(error_stream: $stderr, output_stream: $stdout, **options)
|
23
|
+
super()
|
24
|
+
|
25
|
+
@error_stream = error_stream
|
26
|
+
@output_stream = output_stream
|
27
|
+
@options = options
|
28
|
+
end
|
29
|
+
|
30
|
+
# @return [Boolean] if true, does not apply filesystem changes.
|
31
|
+
def dry_run?
|
32
|
+
@options.fetch(:dry_run, false)
|
33
|
+
end
|
34
|
+
|
35
|
+
# @return [Boolean] if true, overwrites existing template files.
|
36
|
+
def force?
|
37
|
+
@options.fetch(:force, false)
|
38
|
+
end
|
39
|
+
|
40
|
+
# @return [Boolean] if true, prints updates to STDOUT.
|
41
|
+
def verbose?
|
42
|
+
@options.fetch(:verbose, true)
|
43
|
+
end
|
44
|
+
|
45
|
+
private
|
46
|
+
|
47
|
+
attr_reader :error_stream
|
48
|
+
|
49
|
+
attr_reader :output_stream
|
50
|
+
|
51
|
+
def check_for_existing_file(filename)
|
52
|
+
return if force?
|
53
|
+
return unless File.exist?(filename)
|
54
|
+
|
55
|
+
error =
|
56
|
+
SleepingKingStudios::Docs::Errors::FileAlreadyExists
|
57
|
+
.new(path: filename)
|
58
|
+
|
59
|
+
error_stream.puts("Error: #{error.message}")
|
60
|
+
|
61
|
+
failure(error)
|
62
|
+
end
|
63
|
+
|
64
|
+
def create_workflow(workflow_path)
|
65
|
+
file_path = File.join(workflow_path, 'deploy-pages.yml')
|
66
|
+
|
67
|
+
step { check_for_existing_file(file_path) }
|
68
|
+
|
69
|
+
return if dry_run?
|
70
|
+
|
71
|
+
File.write(
|
72
|
+
file_path,
|
73
|
+
evaluate_template(File.join(templates_path, 'deploy-pages.yml.erb'))
|
74
|
+
)
|
75
|
+
end
|
76
|
+
|
77
|
+
def evaluate_template(template_path)
|
78
|
+
template = File.read(template_path)
|
79
|
+
engine = Erubi::Engine.new(template).src
|
80
|
+
|
81
|
+
eval(engine, local_binding) # rubocop:disable Security/Eval
|
82
|
+
end
|
83
|
+
|
84
|
+
def local_binding
|
85
|
+
return @local_binding if @local_binding
|
86
|
+
|
87
|
+
ruby_version = RUBY_VERSION.split('.')[0..1].join('.')
|
88
|
+
|
89
|
+
@local_binding = binding
|
90
|
+
end
|
91
|
+
|
92
|
+
def output(string)
|
93
|
+
return unless verbose?
|
94
|
+
|
95
|
+
output_stream.puts(string)
|
96
|
+
end
|
97
|
+
|
98
|
+
def process(root_path: Dir.pwd)
|
99
|
+
workflow_path = File.join(root_path, '.github', 'workflows')
|
100
|
+
|
101
|
+
output 'Adding GitHub pages workflow...'
|
102
|
+
|
103
|
+
FileUtils.mkdir_p(workflow_path) unless dry_run?
|
104
|
+
|
105
|
+
step { create_workflow(workflow_path) }
|
106
|
+
|
107
|
+
output 'Done!'
|
108
|
+
end
|
109
|
+
|
110
|
+
def templates_path
|
111
|
+
@templates_path ||=
|
112
|
+
File.join(
|
113
|
+
SleepingKingStudios::Docs.gem_path,
|
114
|
+
'lib',
|
115
|
+
'sleeping_king_studios',
|
116
|
+
'docs',
|
117
|
+
'templates'
|
118
|
+
)
|
119
|
+
end
|
120
|
+
end
|
121
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'sleeping_king_studios/docs/commands'
|
4
|
+
|
5
|
+
module SleepingKingStudios::Docs::Commands
|
6
|
+
# Namespace for installation commands, which set up an application with docs.
|
7
|
+
module Installation
|
8
|
+
autoload :InstallJekyll,
|
9
|
+
'sleeping_king_studios/docs/commands/installation/install_jekyll'
|
10
|
+
autoload :InstallTemplates,
|
11
|
+
'sleeping_king_studios/docs/commands/installation/install_templates'
|
12
|
+
autoload :InstallWorkflow,
|
13
|
+
'sleeping_king_studios/docs/commands/installation/install_workflow'
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'cuprum/command'
|
4
|
+
require 'yard'
|
5
|
+
|
6
|
+
require 'sleeping_king_studios/docs/commands'
|
7
|
+
|
8
|
+
module SleepingKingStudios::Docs::Commands
|
9
|
+
# Adds the specified data to the YARD Registry.
|
10
|
+
class Parse < Cuprum::Command
|
11
|
+
# @!method call
|
12
|
+
# @overload call
|
13
|
+
# Parses the working directory per YARD defaults.
|
14
|
+
#
|
15
|
+
# @return [Cuprum::Result<Module>] an empty result.
|
16
|
+
#
|
17
|
+
# @overload call(path)
|
18
|
+
# Parses the given file or directory.
|
19
|
+
#
|
20
|
+
# @return [Cuprum::Result<nil>] an empty result if the parse is
|
21
|
+
# successful.
|
22
|
+
# @return [Cuprum::Result<Cuprum::Error>] a failing result if the file
|
23
|
+
# or directory path is invalid.
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def file_not_found_error(path)
|
28
|
+
SleepingKingStudios::Docs::Errors::FileNotFound.new(path:)
|
29
|
+
end
|
30
|
+
|
31
|
+
def process(path = nil)
|
32
|
+
if path.nil?
|
33
|
+
::YARD.parse
|
34
|
+
|
35
|
+
return success(nil)
|
36
|
+
end
|
37
|
+
|
38
|
+
step { validate_file_path(path) }
|
39
|
+
|
40
|
+
::YARD.parse(path)
|
41
|
+
|
42
|
+
success(nil)
|
43
|
+
end
|
44
|
+
|
45
|
+
def validate_file_path(path)
|
46
|
+
return if File.exist?(path)
|
47
|
+
|
48
|
+
failure(file_not_found_error(path))
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|