Rakefile in infopark_fiona7-1.5.3.2.0 vs Rakefile in infopark_fiona7-1.5.4.3.0

- old
+ new

@@ -16,18 +16,47 @@ namespace "package" do desc "Package javascript" task "js" do - puts "Transpiling javascript files" require 'babel/transpiler' + require 'handlebars_assets' + + puts "Transpiling javascript files" Dir["app/**/*"].each do |fname| if /\.es6\.js$/ =~ fname nfname = ::File.join(::File.dirname(fname), ::File.basename(fname, '.es6.js') + '.js') puts "#{fname} -> #{nfname}" ::File.open(nfname, 'w') do |f| f.write Babel::Transpiler.transform(File.read(fname))["code"] end + end + end + puts "Processing handlebars templates" + templates = [] + template_namespace = 'ScrivitoHandlebarsTemplates' + + Dir["app/assets/javascripts/fiona7/templates/**/*"].each do |fname| + if /\.hbs$/ =~ fname + puts "Compiling #{fname}" + template_name = fname.sub(/.*javascripts\/fiona7\/templates\//, '').sub(/\.hbs$/, '').dump + precompiled = HandlebarsAssets::Handlebars.precompile(File.read(fname)) + template = "Handlebars.template(#{precompiled})" + + templates << <<-TEMPLATE + (function() { + this.#{template_namespace} || (this.#{template_namespace} = {}); + this.#{template_namespace}[#{template_name}] = #{template}; + return this.#{template_namespace}[#{template_name}]; + }).call(this); + TEMPLATE + end + end + + puts "Writing app/assets/javascripts/fiona7/templates.js" + File.open('app/assets/javascripts/fiona7/templates.js', 'w') do |f| + templates.each do |t| + f.write(t) end end end end