forked from elementary/appcenter-web
-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate-eos-apps.rb
66 lines (51 loc) · 1.56 KB
/
generate-eos-apps.rb
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
require 'zlib'
require 'yaml'
require 'uri'
require 'open-uri'
require 'nokogiri'
require 'cgi'
require 'rubygems'
require 'json'
require 'crack'
xmlData = File.open("appstream.xml").read
componentsData = Nokogiri::XML(xmlData,&:noblanks)
parsedXML = Crack::XML.parse(xmlData)
convertedToJSON = parsedXML.to_json
File.open("_data/apps.json", "w+") do |file|
file.write(convertedToJSON)
end
template = '---
app_id: ((id))
title: "((title))"
summary: "((summary))"
dist: flatpak
screenshots:
((screenshots))
redirect_from: ((redirect))
---
((description))'
componentsData.css("components component").each do |component|
next unless (component.get_attribute("type") == "desktop" || component.get_attribute("type") == "desktop-application")
puts "\nGenerating #{component.at_css('name').content}"
appFile = template.dup
name = component.at_css('name')
appFile.sub!('((title))', CGI.escapeHTML(name.content))
summary = component.at_css('summary')
appFile.sub!('((summary))', CGI.escapeHTML(summary.content))
description = component.at_css('description')
appFile.sub!('((description))', description.inner_html)
id = component.at_css('id').content.sub(/\.desktop$/, '')
puts " id: #{id}"
appFile.sub!('((id))', id)
appFile.sub!('((redirect))', "/" + id + ".desktop/")
screenshots = ''
image = component.at_css('image')
if not image.nil?
screenshots += ' - ' + image.content + "\n"
end
# TODO: multiple screenshots
appFile.sub!('((screenshots))', screenshots.rstrip)
File.open("_apps/#{id}.md", "w+") do |file|
file.write(appFile)
end
end