]> git.sesse.net Git - mlt/blob - src/swig/ruby/metadata.rb
596bcce65272dc16974147cc9bfff29943c0ec4f
[mlt] / src / swig / ruby / metadata.rb
1 #!/usr/bin/env ruby
2 require 'erb'
3 require 'yaml'
4 require 'mlt'
5
6 $repo = Mlt::Factory::init
7
8 $optional_params = [
9   'minimum',
10   'maximum',
11   'default',
12   'unit',
13   'scale',
14   'format',
15   'widget'
16 ]
17 template = %q{%%META:TOPICPARENT{name="Plugins<%= type_title %>s"}%
18 <noautolink>
19 ---+ <%= type_title %>: <%= yml['identifier'] %> 
20 %%TOC%
21 ---++ Plugin Information
22 title: <%= yml['title'] %> %BR%
23 % if yml['tags']
24 media types:
25 %   yml['tags'].each do |x|
26 <%= x %> 
27 %   end
28 %%BR%
29 % end
30 description: <%= yml['description'] %> %BR%
31 version: <%= yml['version'] %> %BR%
32 creator: <%= yml['creator'] %> %BR%
33 % yml['contributor'] and yml['contributor'].each do |x|
34 contributor: <%= x %> %BR%
35 % end 
36 <%= "license: #{yml['license']} %BR%\n" if yml['license'] %>
37 <%= "URL: [[#{yml['url']}]] %BR%\n" if yml['url'] %>
38
39 % if yml['notes']
40 ---++ Notes
41 %   yml['notes'].each do |x|
42 <%= x %>
43 %   end
44 % end
45
46 % if yml['bugs']
47 ---++ Bugs
48 %   yml['bugs'].each do |x|
49    * <%= x %>
50 %   end
51 % end
52
53 % if yml['parameters']
54 ---++ Parameters
55 %   yml['parameters'].each do |param|
56 ---+++ <%= param['identifier'] %>
57 <%= "title: #{param['title']} %BR%\n" if param['title'] %>
58 <%= "description: #{param['description']} %BR%\n" if param['description'] %>
59 type: <%= param['type'] %> %BR%
60 readonly: <%= param['readonly'] or 'no' %> %BR%
61 required: <%= param['required'] or 'no' %> %BR%
62 %     $optional_params.each do |key|
63 <%= "#{key}: #{param[key]} %BR%\n" if param[key] %>
64 %     end
65 %     if param['values']
66 values:
67 %       param['values'].each do |value|
68    * <%= value %>
69 %       end
70 %     end 
71
72 %   end
73 % end
74 </noautolink>
75 }
76
77 $processor = ERB.new(template, 0, "%<>")
78
79
80 def output(mlt_type, services, type_title)
81   index = File.open("Plugins#{type_title}s.txt", 'w')
82   index.puts '%META:TOPICPARENT{name="Documentation"}%'
83   index.puts '<noautolink>'
84   index.puts "---+ #{type_title} Plugins"
85   unsorted = []
86   (0..(services.count - 1)).each do |i|
87     unsorted << services.get_name(i)
88   end
89   unsorted.sort().each do |name|
90     meta = $repo.metadata(mlt_type, name)
91     if meta.is_valid
92       filename = type_title + name.capitalize.gsub('.', '-')
93       puts "Processing #{filename}"
94       begin
95         yml = YAML.load(meta.serialise_yaml)
96         if yml
97           File.open(filename + '.txt', 'w') do |f|
98             f.puts $processor.result(binding)
99           end
100         else
101           puts "Failed to write file for #{filename}"
102         end
103         index.puts "   * [[#{filename}][#{name}]]: #{meta.get('title')}\n"
104       rescue ArgumentError
105           puts "Failed to parse YAML for #{filename}"
106       end
107     end
108   end 
109   index.puts '</noautolink>'
110   index.close
111 end
112
113 [
114   [Mlt::Consumer_type, $repo.consumers, 'Consumer'],
115   [Mlt::Filter_type, $repo.filters, 'Filter'],
116   [Mlt::Producer_type, $repo.producers, 'Producer'],
117   [Mlt::Transition_type, $repo.transitions, 'Transition']
118 ].each {|x| output *x}