2015-12-03 00:02:51 +03:00
|
|
|
require 'json'
|
|
|
|
require 'yaml'
|
|
|
|
|
|
|
|
module Variables
|
|
|
|
class Generator < Jekyll::Generator
|
|
|
|
safe true
|
|
|
|
|
|
|
|
def generate(site)
|
2015-12-24 00:58:24 +03:00
|
|
|
|
|
|
|
# indicate to use min or development assets
|
|
|
|
baseurl = site.config['baseurl']
|
|
|
|
minified = true
|
|
|
|
if baseurl.eql? ''
|
|
|
|
minified = false
|
|
|
|
end
|
2015-12-24 18:32:36 +03:00
|
|
|
|
|
|
|
# minified = true # debug minified
|
2015-12-24 00:58:24 +03:00
|
|
|
site.data['minified'] = minified
|
|
|
|
|
2015-12-03 00:02:51 +03:00
|
|
|
metadata_files = {
|
|
|
|
'bower' => '../bower.json',
|
|
|
|
'package' => '../package.json',
|
2015-12-24 02:53:20 +03:00
|
|
|
'bower_jquery' => '../bower_components/jquery/bower.json',
|
|
|
|
'bower_tether' => '../bower_components/tether/bower.json'
|
2015-12-03 00:02:51 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
metadata_files.each do |metadata, path|
|
|
|
|
contents = JSON.parse(File.read(File.join(site.source, path)))
|
|
|
|
site.data[metadata] = contents
|
|
|
|
end
|
|
|
|
|
|
|
|
# some quick access to common variables (instead of diving into package and bower)
|
|
|
|
name = site.data['package']['name']
|
|
|
|
version = site.data['package']['version']
|
|
|
|
bootstrap_version = site.data['bower']['dependencies']['bootstrap']
|
2015-12-24 02:53:20 +03:00
|
|
|
tether_version = site.data['bower_tether']['version']
|
2015-12-03 00:02:51 +03:00
|
|
|
jquery_version = site.data['bower_jquery']['version']
|
|
|
|
|
|
|
|
site.data['name'] = name
|
|
|
|
site.data['version'] = version
|
|
|
|
site.data['bootstrap_version'] = bootstrap_version
|
2015-12-24 02:53:20 +03:00
|
|
|
site.data['tether_version'] = tether_version
|
2015-12-03 00:02:51 +03:00
|
|
|
site.data['jquery_version'] = jquery_version
|
|
|
|
|
|
|
|
|
|
|
|
# fabricate the archive and release links based on the site.repo and version
|
2015-12-24 00:58:24 +03:00
|
|
|
repo = site.config['repo']
|
2015-12-03 00:02:51 +03:00
|
|
|
site.data['download'] = {
|
|
|
|
'source' => "#{repo}/archive/v#{version}.zip",
|
|
|
|
'dist' => "#{repo}/releases/download/v#{version}/#{name}-#{version}-dist.zip"
|
|
|
|
}
|
|
|
|
|
|
|
|
site.data['cdn'] = {
|
2015-12-24 00:58:24 +03:00
|
|
|
'jquery' => site.config['cdn']['jquery'].gsub(/VERSION/, jquery_version),
|
2015-12-24 02:53:20 +03:00
|
|
|
'bootstrap' => site.config['cdn']['bootstrap'].gsub(/VERSION/, bootstrap_version),
|
|
|
|
'tether' => site.config['cdn']['tether'].gsub(/VERSION/, tether_version)
|
2015-12-03 00:02:51 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
#
|
2015-12-24 01:25:04 +03:00
|
|
|
# puts "\n---------------------"
|
|
|
|
# puts "site.config: #{site.config.to_yaml}"
|
|
|
|
# puts "baseurl: #{baseurl}"
|
|
|
|
# puts "minified: #{site.data['minified']}"
|
|
|
|
|
2015-12-24 00:58:24 +03:00
|
|
|
# puts "site: #{site.to_yaml}"
|
2015-12-03 00:02:51 +03:00
|
|
|
# puts site.data[:package]['version']
|
|
|
|
# puts site.data.to_yaml
|
2015-12-03 23:15:52 +03:00
|
|
|
# puts repo
|
|
|
|
# puts version
|
2015-12-03 00:02:51 +03:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|