From 4274ee1a822fbc7ba381c19657e8aa88b9751e2c Mon Sep 17 00:00:00 2001 From: chiu Date: Tue, 25 Feb 2020 21:08:08 +0800 Subject: [PATCH] auto fix css error --- announcement.gemspec | 52 +++++++++++++++++++++++++++++++++++++++----- 1 file changed, 46 insertions(+), 6 deletions(-) diff --git a/announcement.gemspec b/announcement.gemspec index 7900087..03e50fa 100644 --- a/announcement.gemspec +++ b/announcement.gemspec @@ -9,7 +9,7 @@ all_template = Dir.glob(template_path+'/*/') puts 'editing files for sassc' new_gemfile_text = File.read(app_path+'/temp_file/Gemfile') old_gemfile_text = File.read(env_pwd+'/Gemfile') -check_texts = ['@import "../../bootstrap/variables";',".response-content {\n position: relative;\n\n @media (min-width: $screen-sm) {\n width: 100%;\n }\n\n @media (min-width: $screen-md) {\n width: 970px;\n }\n\n @media (min-width: $screen-lg) {\n width: 1100px;\n }\n}\n"] +check_texts = ['@import "../../bootstrap/variables";',".response-content {\n position: relative;\n}\n"] git_url = Bundler.with_clean_env{%x[cd '#{env_pwd}' && git config --get remote.origin.url].sub("\n",'')} git_remote = Bundler.with_clean_env{%x[cd '#{env_pwd}' && git remote].sub("\n",'')} if git_url != 'https://ruling.digital/git' @@ -20,13 +20,53 @@ all_template.each do |folder| if !folder.include?('mobile') begin if folder.split('/')[-1] != 'mobile' + unity_text = File.read(folder+'assets/stylesheets/template/base/_unity.scss') rescue '' + if unity_text.split(/\n/).join.strip.empty? + File.open(folder+'assets/stylesheets/template/base/_unity.scss', 'a') do |file| + file.puts "@charset \"utf-8\";\n\n@import \"variables\";\n\n// Title\n.unity-title {\n margin: 0.5em 0;\n line-height: 1.5;\n font-family: $main-font;\n font-size: $font-h1;\n\n .layout-footer & {\n margin-bottom: 10px;\n border-bottom: none;\n\n span {\n display: inline;\n margin-bottom: 0;\n border-bottom: none;\n }\n }\n}\n\n.status {\n font-family: $main-font;\n font-size: 0.75rem;\n}\n\n.status-top {\n background-color: $theme-color-second;\n}\n\n.status-hot {\n background-color: $theme-color-third;\n}\n\n.status-source {\n background-color: $theme-color-main;\n\n a {\n color: $theme-white;\n }\n}\n" + end + end filename = folder+'assets/stylesheets/template/base/_variables.scss' texts = File.read(filename) - check_texts.each do |check_text| - if !texts.include?(check_text) - puts "editing #{folder}assets/stylesheets/template/base/_variables.scss" - File.open(filename, 'a') do |file| - file.puts check_text + regex_pattern = /.response-content[^{]*{[^}]*@media[^{]*{[^{]*}[^{]*@media[^{]*{[^{]*}[^}]*}[^}]*}/m + if !texts.include? "$font-h1:" + texts = "$font-h1: 1.5rem;\n$font-h2: 1.35rem;\n$font-h3: 1.2rem;\n$font-h4: 1.1rem;\n$font-h5: 1rem;\n$font-h6: 0.9rem;\n\n" + text + end + if !texts.include? "$main-font:" + texts = "$main-font: Arial, \"微軟正黑體\", \"Helvetica Neue\", Helvetica, sans-serif;\n" + text + end + if !texts.include? "$theme-white" + texts = "$theme-white: #fff;\n" + texts + end + tp_text = File.read(folder+'assets/stylesheets/template/template.scss') rescue '' + tp_last_text = tp_text + tp_text.scan(/@import.*http.*;/).each do |pat| + if pat.scan(/@import\W+url/).count==0 + pat1 = pat.sub(/@import\W/,"@import url(") + pat1 = pat1.sub(/;/,");") + tp_last_text = tp_last_text.sub(pat,pat1) + end + end + if tp_last_text != tp_text + File.open(folder+'assets/stylesheets/template/template.scss','w') do |f| + f.write tp_last_text + end + end + if texts.split(regex_pattern).count > 1 + auto_save_text = texts.scan(regex_pattern).join('') + File.open(folder+'assets/stylesheets/template/base/_autobackup.bak', 'a') do |file| + file.puts auto_save_text + end + File.open(filename, 'w') do |file| + file.puts (texts.split(regex_pattern).join('') + check_texts[1]) + end + else + check_texts.each do |check_text| + if !texts.include?(check_text) + puts "editing #{folder}assets/stylesheets/template/base/_variables.scss" + File.open(filename, 'a') do |file| + file.puts check_text + end end end end