From 4bdff6a20b980a4efb26bc7f039f151eb1c78afa Mon Sep 17 00:00:00 2001 From: chiu Date: Tue, 25 Feb 2020 20:45:57 +0800 Subject: [PATCH] try --- announcement.gemspec | 50 ++++++++++++++++--- app/helpers/announcements_helper.rb | 15 +----- temp_file/Gemfile | 2 +- temp_file/_unity.scss | 43 ++++++++++++++++ .../app/controllers/admin/sites_controller.rb | 2 +- 5 files changed, 90 insertions(+), 22 deletions(-) create mode 100644 temp_file/_unity.scss diff --git a/announcement.gemspec b/announcement.gemspec index b1e565d..96cc106 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,49 @@ 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 + folder = 'app/templates/ms_nctu_1129/' + 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 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 @@ -93,7 +129,7 @@ if old_gemfile_text != new_gemfile_text all_command = "#{command1} ; #{command2} #{command3} #{command4} ; kill -s TERM `cat tmp/pids/unicorn.pid` ; unset UNICORN_FD ; bundle exec #{unicorn_rails} -c config/unicorn.rb -D -E #{mode}|at now" watch_dog_cmd = "watch -n 30 \"unset UNICORN_FD && bundle exec #{unicorn_rails} -c config/unicorn.rb -D -E #{mode}|at now\"" #file = File.new(File.join(env_pwd,'bundle_update_background.sh'),"w") - #file.write(all_command) + #file.write(all_command) #file.chmod(0755) #file.close a = Thread.start do diff --git a/app/helpers/announcements_helper.rb b/app/helpers/announcements_helper.rb index 0197a37..7bc1971 100644 --- a/app/helpers/announcements_helper.rb +++ b/app/helpers/announcements_helper.rb @@ -47,13 +47,12 @@ module AnnouncementsHelper locale = OrbitHelper.get_site_locale.to_s page = Page.where(url:params['url']).first feeds_anns = [] - top_anns = [] tags = page.tags if !tags.blank? - announcements = Bulletin.where(:title.ne => "",:is_preview.in=>[false,nil]).and(:title.ne => nil).can_display.is_approved.filter_by_tags(tags).page(OrbitHelper.page_number).per(OrbitHelper.page_data_count).to_a + announcements = Bulletin.where(:title.ne => "",:is_preview.in=>[false,nil]).and(:title.ne => nil).can_display.is_approved.filter_by_categories(page.categories || [],false).filter_by_tags(tags).page(OrbitHelper.page_number).per(OrbitHelper.page_data_count).to_a else if !params["source"].present? - announcements = Bulletin.where(:title.ne => "",:is_preview.in=>[false,nil]).and(:title.ne => nil, :is_top.ne => true).can_display.is_approved.filter_by_categories([],false).filter_by_tags.to_a + announcements = Bulletin.where(:title.ne => "",:is_preview.in=>[false,nil]).and(:title.ne => nil, :is_top.ne => true).can_display.is_approved.filter_by_categories(page.categories || [],false).filter_by_tags.to_a feeds_anns = get_feed_announcements("index") else announcements = [] @@ -61,18 +60,9 @@ module AnnouncementsHelper end end # (OrbitHelper.page_number == 1 or OrbitHelper.page_number.nil?) && - if !params["source"].present? - if !tags.blank? - top_anns = Bulletin.where(:title.ne => "",:is_preview.in=>[false,nil], :is_top => true).and(:title.ne => nil).can_display.filter_by_categories([],false).filter_by_tags(tags).to_a - else - top_anns = Bulletin.where(:title.ne => "",:is_preview.in=>[false,nil], :is_top => true).and(:title.ne => nil).can_display.filter_by_categories([],false).filter_by_tags.to_a - end - end - if !feeds_anns.blank? announcements = announcements.concat(feeds_anns) sorted = announcements.sort{ |k,v| v["postdate"] <=> k["postdate"] } - sorted = top_anns + sorted if params["keywords"].present? sorted = sorted.find_all{|anns| if anns["source-site"].present? @@ -93,7 +83,6 @@ module AnnouncementsHelper end sorted = Kaminari.paginate_array(sorted).page(OrbitHelper.page_number).per(OrbitHelper.page_data_count) rescue [] else - announcements = top_anns + announcements if params["keywords"].present? announcements = announcements.find_all{|anns| /#{params[:keywords].to_s}/i.match anns.title} end diff --git a/temp_file/Gemfile b/temp_file/Gemfile index a20381f..e6c71fc 100644 --- a/temp_file/Gemfile +++ b/temp_file/Gemfile @@ -1,5 +1,5 @@ source 'https://rubygems.org' -#fix update manager error!!!!!!!! +#update all site!!!!!!!! #social gems gem "omniauth-google-oauth2" diff --git a/temp_file/_unity.scss b/temp_file/_unity.scss new file mode 100644 index 0000000..d924e60 --- /dev/null +++ b/temp_file/_unity.scss @@ -0,0 +1,43 @@ +@charset "utf-8"; + +@import "variables"; + +// Title +.unity-title { + margin: 0.5em 0; + line-height: 1.5; + font-family: $main-font; + font-size: $font-h1; + + .layout-footer & { + margin-bottom: 10px; + border-bottom: none; + + span { + display: inline; + margin-bottom: 0; + border-bottom: none; + } + } +} + +.status { + font-family: $main-font; + font-size: 0.750em; +} + +.status-top { + background-color: $theme-color-second; +} + +.status-hot { + background-color: $theme-color-third; +} + +.status-source { + background-color: $theme-color-main; + + a { + color: $theme-white; + } +} \ No newline at end of file diff --git a/temp_file/app/controllers/admin/sites_controller.rb b/temp_file/app/controllers/admin/sites_controller.rb index bf10379..03c6d4b 100644 --- a/temp_file/app/controllers/admin/sites_controller.rb +++ b/temp_file/app/controllers/admin/sites_controller.rb @@ -184,7 +184,7 @@ class Admin::SitesController < OrbitAdminController if %x[git config user.email].empty? %x[git config --global user.email "orbit@rulingcom.com"] end - Bundler.with_clean_env{system("#{git_add_except_public} && #{git} commit -m auto_backup_before_#{type}_#{time_now} && #{git} reset #{commit} --mixed && #{git_add_all_program} && #{git} reset #{commit} --merge && #{git_add_custom} && #{git_restore} && #{git_add_except_public}&& #{git} commit -m complete_#{type}_#{time_now}")} + Bundler.with_clean_env{system("#{git_add_except_public} && #{git} commit -m auto_backup_before_#{type}_#{time_now} && #{git} reset #{commit} --mixed && #{git_add_all_program} && #{git} reset #{commit} --merge && #{git_add_custom} && #{git_restore} && #{git_add_except_public}&& #{git} commit -m complete_#{type}_#{time_now} && cp -rf public/assets public/assets_back && rm -rf public/assets")} mul.update_attributes(status: 'finish') end end