2016-05-16 19:29:04 +02:00
require_relative 'osia_helper'
2016-05-13 16:58:49 +02:00
require 'date'
2016-05-11 16:22:10 +02:00
2016-05-13 17:50:39 +02:00
README = 'README.md'
2016-05-11 16:22:10 +02:00
2016-05-13 18:22:57 +02:00
ARCHIVE = 'ARCHIVE.md'
ARCHIVE_TAG = 'archive'
def apps_archived ( apps )
a = apps . select { | a | a [ 'tags' ] != nil } . select { | b | b [ 'tags' ] . include? ARCHIVE_TAG }
a . sort_by { | k , v | k [ 'title' ] }
end
2016-05-11 16:22:10 +02:00
def apps_for_cat ( apps , id )
2016-05-13 18:22:57 +02:00
f = apps . select do | a |
tags = a [ 'tags' ]
if tags . nil?
true
else
! ( tags . include? ARCHIVE_TAG )
end
end
s = f . select do | a |
2016-05-11 17:07:03 +02:00
cat = a [ 'category' ]
cat . class == Array ? cat . include? ( id ) : ( cat == id )
end
2016-05-11 17:19:04 +02:00
s . sort_by { | k , v | k [ 'title' ] }
2016-05-11 17:07:03 +02:00
end
def output_apps ( apps )
2016-05-11 16:22:10 +02:00
o = ''
2016-05-11 17:07:03 +02:00
apps . each do | a |
2016-05-11 16:22:10 +02:00
name = a [ 'title' ]
link = a [ 'source' ]
itunes = a [ 'itunes' ]
2016-05-11 17:19:04 +02:00
homepage = a [ 'homepage' ]
2016-05-11 16:22:10 +02:00
desc = a [ 'description' ]
tags = a [ 'tags' ]
stars = a [ 'stars' ]
lang = a [ 'lang' ]
o << " - #{ name } "
if desc . nil?
o << ' '
else
o << " : #{ desc } " if desc . size > 0
end
unless tags . nil?
o << " 🔶 " if tags . include? 'swift'
end
unless lang . nil?
o << output_flag ( lang )
end
unless stars . nil?
o << output_stars ( stars )
end
o << " \n "
o << " - #{ link } \n "
2016-05-11 17:19:04 +02:00
o << " - #{ homepage } \n " unless homepage . nil?
2016-05-11 16:22:10 +02:00
o << " - #{ itunes } \n " unless itunes . nil?
end
o
end
2016-05-16 19:29:04 +02:00
def output_flag ( lang )
case lang
2016-05-31 16:22:29 +02:00
when 'ger'
'🇩🇪'
2016-05-16 19:29:04 +02:00
when 'jpn'
'🇯🇵'
when 'ltz'
'🇱🇺'
2016-05-20 17:28:20 +02:00
when 'nld'
'🇳🇱'
2016-05-16 19:29:04 +02:00
when 'por'
'🇧🇷'
when 'spa'
'🇪🇸'
when 'zho'
'🇨🇳'
else
''
end
end
def output_stars ( number )
case number
when 100 ... 200
'🔥'
when 200 ... 500
'🔥🔥'
when 500 ... 1000
'🔥🔥🔥'
when 1000 ... 2000
'🔥🔥🔥🔥'
when 2000 ... 100000
'🔥🔥🔥🔥🔥'
else
''
end
end
2016-05-13 17:50:39 +02:00
def write_readme ( j )
t = j [ 'title' ]
desc = j [ 'description' ]
h = j [ 'header' ]
f = j [ 'footer' ]
cats = j [ 'categories' ]
apps = j [ 'projects' ]
2016-05-11 16:22:10 +02:00
2016-05-13 17:50:39 +02:00
date = DateTime . now
date_display = date . strftime " %B %d, %Y "
2016-05-11 16:22:10 +02:00
2016-05-13 17:50:39 +02:00
output = '# ' + t
output << " \n \n "
output << desc
output << " \n \n A collaborative list of ** #{ apps . count } ** open-source iOS apps, your [contribution](https://github.com/dkhamsing/open-source-ios-apps/blob/master/.github/CONTRIBUTING.md) is welcome :smile: "
output << " (last update * #{ date_display } *). "
2016-05-13 16:58:49 +02:00
2016-05-13 17:50:39 +02:00
output << " \n \n Jump to \n \n "
2016-05-13 16:58:49 +02:00
2016-05-13 17:50:39 +02:00
cats . each do | c |
temp = " #{ ' ' unless c [ 'parent' ] == nil } - [ #{ c [ 'title' ] } ]( \# #{ c [ 'id' ] } ) \n "
output << temp
end
2016-05-11 16:22:10 +02:00
2016-05-13 17:50:39 +02:00
output << " - [Bonus]( # bonus) \n "
2016-05-11 16:22:10 +02:00
2016-05-13 17:50:39 +02:00
output << " \n "
output << h
output << " \n "
2016-05-11 16:22:10 +02:00
2016-05-13 17:50:39 +02:00
cats . each do | c |
temp = " \n # \# #{ '#' unless c [ 'parent' ] == nil } #{ c [ 'title' ] } \n \n "
2016-05-11 16:22:10 +02:00
2016-05-13 17:50:39 +02:00
d = c [ 'description' ]
temp << " #{ d } — " unless d . nil?
2016-05-11 19:53:59 +02:00
2016-05-13 17:50:39 +02:00
temp << " [back to top]( # readme) \n \n "
output << temp
2016-05-11 19:53:59 +02:00
2016-05-13 17:50:39 +02:00
cat_apps = apps_for_cat ( apps , c [ 'id' ] )
output << output_apps ( cat_apps )
end
output << " \n "
output << f
2016-05-11 16:22:10 +02:00
2016-05-13 17:50:39 +02:00
File . open ( README , 'w' ) { | f | f . write output }
puts " wrote #{ README } ✨ "
2016-05-11 16:22:10 +02:00
end
2016-05-13 18:22:57 +02:00
def write_archive ( j )
t = j [ 'title' ]
desc = " This is an archive of the [main list](https://github.com/dkhamsing/open-source-ios-apps) for projects that are no longer maintained / old. \n \n "
f = " # # Contact \n \n - [github.com/dkhamsing](https://github.com/dkhamsing) \n - [twitter.com/dkhamsing](https://twitter.com/dkhamsing) \n "
apps = j [ 'projects' ]
archived = apps_archived apps
output = " \# #{ t } Archive \n \n "
output << desc
archived . each do | a |
t = a [ 'title' ]
s = a [ 'source' ]
output << " - #{ t } #{ s } \n "
# output <<
end
output << " \n "
output << f
file = ARCHIVE
File . open ( file , 'w' ) { | f | f . write output }
puts " wrote #{ file } ✨ "
end
2016-05-16 19:29:04 +02:00
j = get_json
2016-05-11 16:22:10 +02:00
2016-05-13 17:50:39 +02:00
write_readme ( j )
2016-05-13 18:22:57 +02:00
write_archive ( j )