File: theme_online.rb

package info (click to toggle)
tdiary 5.4.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 3,088 kB
  • sloc: ruby: 23,031; javascript: 1,029; xml: 325; makefile: 26; sh: 4
file content (31 lines) | stat: -rw-r--r-- 935 bytes parent folder | download | duplicates (6)
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
# theme_online.rb: choice theme from online repository on tDiary.org
#
# options:
#    @options['theme_online.url']: top level URL of another theme site
#
# Copyright (C) 2014 by TADA Tadashi <t@tdtds.jp>
# You can distribute and/or modify it under GPL2 or any later version.
#
require 'json'
require 'open-uri'

def theme_list_online(list)
	url = @options['theme_online.url'] || '//tdiary.github.io/tdiary-theme/'
	url = "http:#{url}" if url =~ %r|\A//|
	begin
		online_list = JSON.load(open(File.join(url, 'themes.json'), &:read))['themes']
		list + online_list.keys.map do |t|
			title = online_list[t]['title']
			label = t == title ? '' : " (#{title})"
			["online/#{t}", "#{t}#{label}"]
		end
	rescue
		@logger.error "could not get theme list from online: #$!"
		list
	end
end

def theme_url_online(theme)
	url = @options['theme_online.url'] || '//tdiary.github.io/tdiary-theme/'
	File.join(url, "#{h theme}/#{h theme}.css")
end