Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/twbs/bootstrap-rubygem.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJan Stevens <jan@playpass.be>2015-08-20 12:03:54 +0300
committerJan Stevens <jan@playpass.be>2015-08-20 12:03:54 +0300
commite66545f886d0bab97e2b6c63cebbd03b993cb2e3 (patch)
tree501f33bf1d3d20889b25fad6a6b6bb747044f03d /tasks/updater
parent151274ca21cf28e87ce9330323942d271db2b91a (diff)
Removed unused rake tasks
Diffstat (limited to 'tasks/updater')
-rw-r--r--tasks/updater/js_conversion.rb47
-rw-r--r--tasks/updater/logger.rb57
-rw-r--r--tasks/updater/network.rb97
-rw-r--r--tasks/updater/scss_conversion.rb38
4 files changed, 239 insertions, 0 deletions
diff --git a/tasks/updater/js_conversion.rb b/tasks/updater/js_conversion.rb
new file mode 100644
index 0000000..0bc322a
--- /dev/null
+++ b/tasks/updater/js_conversion.rb
@@ -0,0 +1,47 @@
+class Converter
+ module JsConversion
+ def process_javascript_assets
+ log_status 'Processing javascripts...'
+ save_to = @save_to[:js]
+ contents = {}
+ read_files('js/dist', bootstrap_js_files).each do |name, file|
+ contents[name] = file
+ save_file("#{save_to}/#{name}", file)
+ end
+ log_processed "#{bootstrap_js_files * ' '}"
+
+ log_status 'Updating javascript manifest'
+ manifest = ''
+ bootstrap_js_files.each do |name|
+ name = name.gsub(/\.js$/, '')
+ manifest << "//= require ./bootstrap/#{name}\n"
+ end
+ dist_js = read_files('dist/js', %w(bootstrap.js bootstrap.min.js))
+ {
+ 'assets/javascripts/bootstrap-sprockets.js' => manifest,
+ 'assets/javascripts/bootstrap.js' => dist_js['bootstrap.js'],
+ 'assets/javascripts/bootstrap.min.js' => dist_js['bootstrap.min.js'],
+ }.each do |path, content|
+ save_file path, content
+ log_processed path
+ end
+ end
+
+ def bootstrap_js_files
+ @bootstrap_js_files ||= begin
+ files = get_paths_by_type('js/dist', /\.js$/)
+ files.sort_by { |f|
+ case f
+ # tooltip depends on popover and must be loaded earlier
+ when /tooltip/ then
+ 1
+ when /popover/ then
+ 2
+ else
+ 0
+ end
+ }
+ end
+ end
+ end
+end
diff --git a/tasks/updater/logger.rb b/tasks/updater/logger.rb
new file mode 100644
index 0000000..66a9e31
--- /dev/null
+++ b/tasks/updater/logger.rb
@@ -0,0 +1,57 @@
+class Converter
+ class Logger
+ include Term::ANSIColor
+
+ def log_status(status)
+ puts bold status
+ end
+
+ def log_file_info(s)
+ puts " #{magenta s}"
+ end
+
+ def log_transform(*args, from: caller[1][/`.*'/][1..-2].sub(/^block in /, ''))
+ puts " #{cyan from}#{cyan ": #{args * ', '}" unless args.empty?}"
+ end
+
+ def log_processing(name)
+ puts yellow " #{File.basename(name)}"
+ end
+
+ def log_processed(name)
+ puts green " #{name}"
+ end
+
+ def log_http_get_file(url, cached = false)
+ s = " #{'CACHED ' if cached}GET #{url}..."
+ if cached
+ puts dark green s
+ else
+ puts dark cyan s
+ end
+ end
+
+ def log_http_get_files(files, from, cached = false)
+ return if files.empty?
+ s = " #{'CACHED ' if cached}GET #{files.length} files from #{from} #{files * ' '}..."
+ if cached
+ puts dark green s
+ else
+ puts dark cyan s
+ end
+ end
+
+ def puts(*args)
+ STDERR.puts *args unless @silence
+ end
+
+ alias log puts
+
+ def silence_log
+ @silence = true
+ yield
+ ensure
+ @silence = false
+ end
+ end
+end
diff --git a/tasks/updater/network.rb b/tasks/updater/network.rb
new file mode 100644
index 0000000..cc60276
--- /dev/null
+++ b/tasks/updater/network.rb
@@ -0,0 +1,97 @@
+require 'shellwords'
+class Converter
+ module Network
+ protected
+
+ def get_paths_by_type(dir, file_re, recursive = true)
+ get_file_paths(dir, recursive).select { |path| path =~ file_re }
+ end
+
+ def get_file_paths(dir, recursive = true)
+ get_tree(get_tree_sha(dir), recursive)['tree'].select { |f| f['type'] == 'blob' }.map { |f| f['path'] }
+ end
+
+ def read_files(path, files)
+ full_path = "https://raw.githubusercontent.com/#@repo/#@branch_sha/#{path}"
+ contents = read_cached_files(path, files)
+ log_http_get_files contents.keys, full_path, true if contents.keys
+ files -= contents.keys
+ log_http_get_files files, full_path, false
+ files.map do |name|
+ Thread.start {
+ contents[name] = open("#{full_path}/#{name}").read
+ Thread.exclusive { write_cached_files path, name => contents[name] }
+ }
+ end.each(&:join)
+ contents
+ end
+
+ def read_cached_files(path, files)
+ full_path = "#@cache_path/#@branch_sha/#{path}"
+ contents = {}
+ if File.directory?(full_path)
+ files.each do |name|
+ path = "#{full_path}/#{name}"
+ contents[name] = File.read(path, mode: 'rb') if File.exists?(path)
+ end
+ end
+ contents
+ end
+
+ def write_cached_files(path, files)
+ full_path = "./#@cache_path/#@branch_sha/#{path}"
+ files.each do |name, content|
+ FileUtils.mkdir_p File.dirname(File.join(full_path, name))
+ File.open("#{full_path}/#{name}", 'wb') { |f| f.write content }
+ end
+ end
+
+
+ def get_file(url)
+ uri = URI(url)
+ cache_path = "./#@cache_path#{uri.path}#{uri.query.tr('?&=', '-') if uri.query}"
+ FileUtils.mkdir_p File.dirname(cache_path)
+ if File.exists?(cache_path)
+ log_http_get_file url, true
+ File.read(cache_path, mode: 'rb')
+ else
+ log_http_get_file url, false
+ content = open(url).read
+ File.open(cache_path, 'wb') { |f| f.write content }
+ content
+ end
+ end
+
+ # get sha of the branch (= the latest commit)
+ def get_branch_sha
+ @branch_sha ||= begin
+ if @branch + "\n" == %x[git rev-parse #@branch]
+ @branch
+ else
+ cmd = "git ls-remote #{Shellwords.escape "https://github.com/#@repo"} #@branch"
+ log cmd
+ result = %x[#{cmd}]
+ raise 'Could not get branch sha!' unless $?.success? && !result.empty?
+ result.split(/\s+/).first
+ end
+ end
+ end
+
+ # Get the sha of a dir
+ def get_tree_sha(dir, tree = get_trees)
+ tree['tree'].find { |t| t['path'] == dir }['sha']
+ end
+
+ def get_trees
+ @trees ||= get_tree(@branch_sha)
+ end
+
+ def get_tree(sha, recursive = true)
+ get_json("https://api.github.com/repos/#@repo/git/trees/#{sha}#{'?recursive=1' if recursive}")
+ end
+
+ def get_json(url)
+ JSON.parse get_file(url)
+ end
+ end
+end
diff --git a/tasks/updater/scss_conversion.rb b/tasks/updater/scss_conversion.rb
new file mode 100644
index 0000000..c42782b
--- /dev/null
+++ b/tasks/updater/scss_conversion.rb
@@ -0,0 +1,38 @@
+class Converter
+ module ScssConversion
+ def process_scss_assets
+ log_status 'Processing scss...'
+ save_to = @save_to[:scss]
+ contents = {}
+ read_files('scss', bootstrap_scss_files).each do |name, file|
+ contents[name] = file
+ save_file("#{save_to}/#{name}", file)
+ end
+ log_processed "#{bootstrap_scss_files * ' '}"
+
+ log_status 'Updating scss main files'
+
+ %w(bootstrap bootstrap-flex bootstrap-grid bootstrap-reboot).each do |file_name|
+ main_from = "#{save_to}/#{file_name}.scss"
+ main_to = File.expand_path("#{save_to}/../_#{file_name}.scss")
+ if file_name == 'bootstrap-flex'
+ save_file main_to, File.read(main_from)
+ else
+ save_file main_to, File.read(main_from).gsub(/ "/, ' "bootstrap/')
+ end
+ File.delete(main_from)
+ end
+
+ log_status 'Generating variable template file'
+
+ save_file 'templates/project/_bootstrap-variables.sass',
+ "// Override Bootstrap variables here (defaults from bootstrap-sass v#{Bootstrap::VERSION}):\n\n" +
+ File.read("#{save_to}/_variables.scss").lines[1..-1].join.gsub(/^(?=\$|\))/, '// ').gsub(/ !default/, '')
+
+ end
+ end
+
+ def bootstrap_scss_files
+ @bootstrap_scss_files ||= get_paths_by_type('scss', /\.scss$/)
+ end
+end