Sha256: 5b94f74c5921743b13ba880c6bb35cbd6b80abed06f9c999d6db119fc5191988
Contents?: true
Size: 1.94 KB
Versions: 8
Compression:
Stored size: 1.94 KB
Contents
module Capucine class Incloudr require 'cdnjs.rb' require 'npm.rb' require 'open-uri' require 'fileutils' require 'packr' def initialize(capucine) @cap = capucine end def run_once files = @cap.settings.conf['incloudr_libs'] return false if files.length == 0 dir = File.join(@cap.settings.working_dir, @cap.settings.conf['incloudr_output_dir']) FileUtils.rm_r dir if File.exist?(dir) FileUtils.mkdir_p dir @file = nil files.each {|file| self.pack file} puts "[incloudr] - Packaged" end def pack file @file = file @file['version'] = @file['version'].to_s if @file['version'] @file['type'] = @file['type'] || 'cdnjs' @file['type'] = 'url' if @file['source'] name = @file['file_name'] || @file['name'] @dir = @cap.settings.working_dir @conf = @cap.settings.conf @output = File.join(@dir, @conf['incloudr_output_dir'], name.gsub(/$/, '.js')) @output_min = File.join(@dir, @conf['incloudr_output_dir'], name.gsub(/$/, '.min.js')) self.cdnjs if @file['type'] == 'cdnjs' self.url if @file['type'] == 'url' # self.npm if @file['type'] == 'npm' end def url raw_content = nil if not raw_content begin content = open(@file['source']).read rescue => e puts "Error" return e end else content = raw_content end content_min = "" content_min << Packr.pack(content) f1 = File.open(@output, 'w+') f1.write(content) f1.close f2 = File.open(@output_min, 'w+') f2.write(content_min) f2.close end def cdnjs api = Capucine::CDNJS.new(@file['name'], @file['version'], content = false) if not api.result[:error] self.url api.result[:content] else puts "Error on #{@file['name']}" end end def npm # TODO ! end end end
Version data entries
8 entries across 8 versions & 1 rubygems