Skip to content

Commit bbdd835

Browse files
committed
Docs - update TOML generation
1 parent 3072afd commit bbdd835

File tree

10 files changed

+97
-58
lines changed

10 files changed

+97
-58
lines changed

app/server/ruby/bin/qt-doc2.rb

Lines changed: 69 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -36,72 +36,108 @@ class QtDocs
3636
include SonicPi::Util
3737
include GetText
3838

39-
def doc_collections
40-
synths = SonicPi::Synths::SynthInfo.get_all.select do |k, v|
41-
v.is_a?(SonicPi::Synths::SynthInfo) && v.user_facing?
42-
end
43-
[
44-
{
45-
items: synths,
46-
template_path: synth_and_fx_template_path,
47-
interpolated_path: synths_interpolated_path,
48-
output_path: synths_toml_path,
49-
klass: SonicPi::Synths::SynthInfo
50-
},
51-
{
52-
items: @@docs,
53-
template_path: lang_template_path,
54-
interpolated_path: lang_interpolated_path,
55-
output_path: lang_toml_path
56-
}
57-
]
58-
end
59-
6039
def run
61-
_generate_docs
40+
generate_docs
41+
sync_to_documentation_app
6242
end
6343

6444
def t_(arg)
45+
# this didn't work on docstrings containing "blah"
46+
arg = arg.tr('"', "\"") if arg.is_a?(String)
6547
"<%= _(\"#{arg}\") %>"
6648
end
6749

6850
private
69-
def _generate_docs
70-
interpolated_file_paths = doc_collections.each_with_object([]) do |collection, paths|
51+
def generate_docs
52+
interpolated_file_paths = [synths, fx, samples, lang].each_with_object([]) do |collection, paths|
7153
original_template = File.read(collection[:template_path])
7254
collection[:items].to_a.take(2).each do |key, item|
55+
# this really needs a more elegant way of reading arg/slide data from the object for
56+
# all types (synths/fx/samples)
57+
data_object = collection[:data_object] || item
58+
key = key.to_s[3..-1] if collection[:klass] == SonicPi::Synths::FXInfo
7359
interpolated_file_path = "#{collection[:interpolated_path]}/#{key}.toml.erb"
74-
template = ERB.new(original_template).result(binding)
60+
template = ERB.new(original_template, nil, '-').result(binding)
7561
File.open(interpolated_file_path, 'w') do |f|
7662
f.write template
7763
end
7864
paths << interpolated_file_path
7965
end
80-
end
81-
_generate_pot_file(interpolated_file_paths)
82-
_generate_toml_files
8366

67+
end
68+
generate_pot_file(interpolated_file_paths)
69+
generate_toml_files
8470
end
8571

86-
87-
def _generate_pot_file(interpolated_file_paths)
72+
def generate_pot_file(interpolated_file_paths)
8873
GetText::Tools::XGetText.run(
8974
*interpolated_file_paths,
9075
"-o ../../../../../../etc/doc/generated/toml/synths/test.pot"
9176
)
9277
end
9378

94-
def _generate_toml_files
95-
doc_collections.each do |collection|
79+
def generate_toml_files
80+
[synths, fx, samples, lang].each do |collection|
9681
collection[:items].to_a.take(2).each do |key, item|
82+
key = key.to_s[3..-1] if collection[:klass] == SonicPi::Synths::FXInfo
9783
interpolated_file = File.read("#{collection[:interpolated_path]}/#{key}.toml.erb")
98-
output = ERB.new(interpolated_file).result(binding)
84+
output = ERB.new(interpolated_file, nil, '-').result(binding)
9985
File.open("#{collection[:output_path]}/#{key}.toml", 'w') do |f|
10086
f.write output
10187
end
10288
end
10389
end
10490
end
91+
92+
def sync_to_documentation_app
93+
FileUtils.cp_r(doc_toml_path, documentation_app_priv_path, remove_destination: true)
94+
end
95+
96+
def synths
97+
items = SonicPi::Synths::SynthInfo.get_all.select do |k, v|
98+
v.is_a?(SonicPi::Synths::SynthInfo) && v.user_facing?
99+
end
100+
{
101+
items: items,
102+
template_path: synth_and_fx_template_path,
103+
interpolated_path: synths_interpolated_path,
104+
output_path: synths_toml_path,
105+
klass: SonicPi::Synths::SynthInfo
106+
}
107+
end
108+
109+
def fx
110+
items = SonicPi::Synths::SynthInfo.get_all.select do |k, v|
111+
v.is_a?(SonicPi::Synths::FXInfo) && v.user_facing? && !(k.to_s.include? 'replace_')
112+
end
113+
{
114+
items: items,
115+
template_path: synth_and_fx_template_path,
116+
interpolated_path: fx_interpolated_path,
117+
output_path: fx_toml_path,
118+
klass: SonicPi::Synths::FXInfo
119+
}
120+
end
121+
122+
def samples
123+
{
124+
items: SonicPi::Synths::SynthInfo.grouped_samples,
125+
template_path: samples_template_path,
126+
interpolated_path: samples_interpolated_path,
127+
output_path: samples_toml_path,
128+
data_object: SonicPi::Synths::StereoPlayer.new
129+
}
130+
end
131+
132+
def lang
133+
{
134+
items: @@docs,
135+
template_path: lang_template_path,
136+
interpolated_path: lang_interpolated_path,
137+
output_path: lang_toml_path
138+
}
139+
end
140+
105141
end
106142

107143
QtDocs.new.run

app/server/ruby/lib/sonicpi/synths/synthinfo.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3819,7 +3819,7 @@ def specific_arg_info
38193819

38203820
:pitch_dis =>
38213821
{
3822-
:doc => "Pitch dispersion - how much random variation in pitch to add. Using a low value like 0.001 can help to \"soften up\" the metallic sounds, especially on drum loops. To be really technical, pitch_dispersion is the maximum random deviation of the pitch from the pitch ratio (which is set by the pitch param)",
3822+
:doc => "Pitch dispersion - how much random variation in pitch to add. Using a low value like 0.001 can help to 'soften up' the metallic sounds, especially on drum loops. To be really technical, pitch_dispersion is the maximum random deviation of the pitch from the pitch ratio (which is set by the pitch param)",
38233823
:validations => [v_greater_than_oet(:pitch_dis, 0)],
38243824
:modulatable => true
38253825
},

etc/doc/templates/lang.toml.erb

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<%=
2-
t_(<<~TEXT
2+
t_(<<~TEXT.chomp
33
# This is a data file that contains information describing the text that is
44
# displayed on pages in the Lang section of Sonic Pi's help panel.
55
TEXT
@@ -12,7 +12,7 @@ TEXT
1212
[<%= item[:name] %>]
1313

1414
<%=
15-
t_(<<~TEXT
15+
t_(<<~TEXT.chomp
1616
# A short phrase describing this Sonic Pi function. (Eg the 'chord' function has
1717
# a summary phrase: 'Create chord').
1818
TEXT
@@ -21,14 +21,14 @@ TEXT
2121
summary = "<%= t_(summary) %>"
2222

2323
<%=
24-
t_(<<~TEXT
24+
t_(<<~TEXT.chomp
2525
# Args are the required parameters for the function. Each arg has two documented
2626
# properties:
2727
# - the arg's name
2828
# - the arg's type (number, integer, symbol, ...).
2929
TEXT
3030
)
31-
%>
31+
-%>
3232
<% item[:args].each do |name, type| %>
3333
[[<%= item[:name] %>.args]]
3434
name = "<%= name %>"
@@ -40,7 +40,7 @@ doc = '''
4040
'''
4141

4242
<%=
43-
t_(<<~TEXT
43+
t_(<<~TEXT.chomp
4444
# The label describing the version of Sonic Pi in which this function first
4545
# appeared.
4646
TEXT
@@ -51,7 +51,7 @@ label = "<%= t_("Introduced in #{item[:introduced].to_s}") %>"
5151
<% if item[:opts] && !item[:opts].empty? %>
5252

5353
<%=
54-
t_(<<~TEXT
54+
t_(<<~TEXT.chomp
5555
# The options are the optional parameters of this function.
5656
# Each option has two documented properties:
5757
# - the option's name
@@ -68,7 +68,7 @@ doc = "<%= t_(doc) %>"
6868
<% end %>
6969
<% end %>
7070
<%=
71-
t_(<<~TEXT
71+
t_(<<~TEXT.chomp
7272
# Each function may have one or more examples. If it has any, they are listed
7373
# under an overall 'Example' or 'Examples' label (heading), and each example has
7474
# a numbered sub-heading, such as 'Example 1'.

etc/doc/templates/slides.toml.erb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
slide_label = "<%= t_('Slide Options') %>"
33
slide_description = '''
44
<%=
5-
t_(<<~TEXT
5+
t_(<<~TEXT.chomp
66
Any parameter that is slidable has three additional options named _slide,
77
slide_curve, and _slide_shape. For example, 'amp' is slidable, so you can also
88
set amp_slide, amp_slide_curve, and amp_slide_shape with the following effects:
@@ -12,11 +12,11 @@ TEXT
1212
'''
1313
<%
1414
slide_opts = {
15-
:_slide => {:default => 0, :doc=>item.generic_slide_doc('parameter')},
16-
:_slide_shape => {:default=>5, :doc=>item.generic_slide_shape_doc('parameter')},
17-
:_slide_curve => {:default=>0, :doc=>item.generic_slide_curve_doc('parameter')}
15+
:_slide => {:default => 0, :doc=>data_object.generic_slide_doc('parameter')},
16+
:_slide_shape => {:default=>5, :doc=>data_object.generic_slide_shape_doc('parameter')},
17+
:_slide_curve => {:default=>0, :doc=>data_object.generic_slide_curve_doc('parameter')}
1818
}
19-
%>
19+
-%>
2020
<% slide_opts.each do |name, attributes| %>
2121
[[sliding.slide_opts]]
2222
name = "<%= name %>"

etc/doc/templates/synth_and_fx.toml.erb

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<%=
2-
t_(<<~TEXT
2+
t_(<<~TEXT.chomp
33
# This is a data file that contains information describing the text that is
44
# displayed on pages in the Synths section of Sonic Pi's help panel.
55

@@ -12,7 +12,7 @@ TEXT
1212
[<%= key %>]
1313

1414
<%=
15-
t_(<<~TEXT
15+
t_(<<~TEXT.chomp
1616
# A word or short phrase that is used as a label for the synth or fx.
1717
# (For example: Pretty Bell).
1818
TEXT
@@ -26,8 +26,8 @@ usage = '''
2626
if collection[:klass] == SonicPi::Synths::SynthInfo
2727
"use_synth :#{key}"
2828
elsif collection[:klass] == SonicPi::Synths::FXInfo
29-
fx_string = <<~TEXT
30-
with_fx :#{key.to_s[3..-1]} do
29+
fx_string = <<~TEXT.chomp
30+
with_fx :#{key} do
3131
play 50
3232
end
3333
TEXT
@@ -41,7 +41,7 @@ doc = '''
4141
'''
4242

4343
<%=
44-
t_(<<~TEXT
44+
t_(<<~TEXT.chomp
4545
# The label describing the version of Sonic Pi in which this synth or fx first
4646
# appeared.
4747
TEXT
@@ -51,7 +51,7 @@ TEXT
5151
label = "<%= t_("Introduced in #{item.introduced.to_s}") %>"
5252

5353
<%=
54-
t_(<<~TEXT
54+
t_(<<~TEXT.chomp
5555
# The options are the opts of this synth or fx.
5656
# In the documentation, we currently display two tables of opts:
5757
# - one listing the name of each opt and its default value for easy reference
@@ -93,6 +93,6 @@ t_(
9393
<% end %>
9494
<%=
9595
if item.arg_info.any? { |name, arg| arg[:slidable] }
96-
ERB.new(File.read(slides_template_path), eoutvar: '_slide01').result(binding)
96+
ERB.new(File.read(slides_template_path), nil, '-', eoutvar: '_slide01').result(binding)
9797
end
9898
%>

etc/docs/lib/docs/application.ex

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ defmodule Docs.Application do
1717
# {Docs.Worker, arg}
1818
]
1919

20+
:ets.new(:session, [:set, :public, :named_table, read_concurrency: true])
2021
# See https://hexdocs.pm/elixir/Supervisor.html
2122
# for other strategies and supported options
2223
opts = [strategy: :one_for_one, name: Docs.Supervisor]

etc/docs/lib/docs_web/endpoint.ex

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@ defmodule DocsWeb.Endpoint do
55
# this means its contents can be read but not tampered with.
66
# Set :encryption_salt if you would also like to encrypt it.
77
@session_options [
8-
store: :cookie,
9-
key: "_docs_key",
8+
store: :ets,
9+
key: "sid",
10+
table: :session,
1011
signing_salt: "lVcj/WFu"
1112
]
1213

etc/docs/lib/docs_web/live/page_live.ex

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ defmodule DocsWeb.PageLive do
22
use DocsWeb, :live_view
33

44
@impl true
5-
def mount(_params, _session, socket) do
6-
{:ok, assign(socket, query: "", results: %{})}
5+
def mount(_params, %{"metadata" => metadata}, socket) do
6+
{:ok, assign(socket, query: "", results: %{}, metadata: metadata)}
77
end
88

99
@impl true

etc/docs/lib/docs_web/live/page_live.html.leex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
<button type="submit" phx-disable-with="Searching...">Go to Hexdocs</button>
1313
</form>
1414
</section>
15-
15+
<p><%= inspect @metadata %></p>
1616
<section class="row">
1717
<article class="column">
1818
<h2>Resources</h2>

etc/docs/lib/docs_web/router.ex

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ defmodule DocsWeb.Router do
88
plug :put_root_layout, {DocsWeb.LayoutView, :root}
99
plug :protect_from_forgery
1010
plug :put_secure_browser_headers
11+
plug DocsWeb.Plug.InjectToml
1112
end
1213

1314
pipeline :api do

0 commit comments

Comments
 (0)