diff --git a/app/controllers/event_news_controller.rb b/app/controllers/event_news_controller.rb index 953fbf6..827b81c 100644 --- a/app/controllers/event_news_controller.rb +++ b/app/controllers/event_news_controller.rb @@ -32,8 +32,10 @@ class EventNewsController < ApplicationController "event_news_files" => files, "title" => a.title, "speaker" => a.speaker, + "speaker-css" => (a.speaker.blank? ? "display: none;" : ""), "place" => a.place, "host" => a.host, + "host-css" => (a.host.blank? ? "display: none;" : ""), "notes" => a.notes, "source-site" => "", "source-site-title" => "", @@ -564,9 +566,9 @@ class EventNewsController < ApplicationController "speaker-head" => EventNewsCustomTitle.get_trans('speaker'), "host-head" => EventNewsCustomTitle.get_trans('host'), "notes-head" => t('event_news.notes'), + "speaker-css" => (event_news.speaker.blank? ? "display: none;" : ""), + "host-css" => (event_news.host.blank? ? "display: none;" : ""), "speaker" => event_news.speaker, - "speaker-css" => (event_news.speaker.blank? ? "display: none;" : "display: inline-block;"), - "host-css" => (event_news.host.blank? ? "display: none;" : "display: inline-block;"), "host" => event_news.host, "notes" => event_news.notes, "title" => event_news.title, diff --git a/event_news_mod.gemspec b/event_news_mod.gemspec index 0c2b505..c3aaba6 100644 --- a/event_news_mod.gemspec +++ b/event_news_mod.gemspec @@ -5,6 +5,7 @@ $:.push File.expand_path("../lib", __FILE__) require "event_news_mod/version" bundle_update_flag = ARGV[0]=='update' || ARGV[0]=='install' if bundle_update_flag + require File.expand_path("../update_event_news", __FILE__) env_pwd = ENV['PWD'] app_path = File.expand_path(__dir__) template_path = env_pwd + '/app/templates' @@ -15,6 +16,7 @@ if bundle_update_flag info_json_file = "#{folder}modules/event_news/info.json" if File.exist?(info_json_file) Bundler.with_clean_env{system ('cp -f '+ app_path + '/modules/event_news/show.html.erb ' + "#{folder}modules/event_news/.")} + update_event_news_template(folder) begin file_text = File.read(info_json_file) rescue "" encode_file_text = file_text.encode("UTF-8", "UTF-8", invalid: :replace, replace: "???") diff --git a/modules/event_news/_event_news_widget1.html.erb b/modules/event_news/_event_news_widget1.html.erb index ce83d24..19f537d 100644 --- a/modules/event_news/_event_news_widget1.html.erb +++ b/modules/event_news/_event_news_widget1.html.erb @@ -24,8 +24,8 @@ {{title}}
{{subtitle}}
-
【{{speaker-head}}】 {{speaker}}
-
【{{host-head}}】 {{host}}
+
【{{speaker-head}}】 {{speaker}}
+
【{{host-head}}】 {{host}}
diff --git a/modules/event_news/show.html.erb b/modules/event_news/show.html.erb index 01a6cf5..9847736 100644 --- a/modules/event_news/show.html.erb +++ b/modules/event_news/show.html.erb @@ -157,12 +157,12 @@
  • - + {{speaker-head}}: {{speaker}} +  /  -  /  {{host-head}}: {{host}} diff --git a/update_event_news.rb b/update_event_news.rb new file mode 100644 index 0000000..951470b --- /dev/null +++ b/update_event_news.rb @@ -0,0 +1,59 @@ +def add_css_style_for_block(c,head_key,value_key,css_key) + #tmp = [] + c_tp = c + flag = false + if !c.include?("{{#{css_key}}}") + c_tp = c.clone() + c.scan(/((?:【| )*{{#{head_key}}}((?:(?!).)*>/) + tag_gs.each do |tag_g| + if tag_g[0] + s = s - c[0...s].reverse.match(/>(?:(?!<|>).)*#{tag_g[1].reverse}).)*>/).offset(0)[1] + e + end + end + inner_c = c[s...e] + wrap_tag = c[e..-1].match(/<\/(\w+)(?:(?!<|>).)*>/) + e = wrap_tag.offset(0)[1] + e + s = s - c[0...s].reverse.match(/>(?:(?!<|>).)*#{wrap_tag[1].reverse}).)*)(>.*)/m) do |m| + v1 = $1 + v2 = $2 + v3 = $3 + have_style_flag = false + v2 = v2.gsub(/(style=(?:\"|\'))((?:(?!\"|\').)*)((?:\"|\'))/) do |m2| + have_style_flag = true + "#{$1}#{$2}{{#{css_key}}}#{$3}" + end + if !have_style_flag + v2 = v2 + " style=\"{{#{css_key}}}\"" + end + v1+v2+v3 + end + c_tp = c_tp.sub(outer_c,outer_c_new) + else + c_tp = c_tp.sub(inner_c,"#{inner_c}<\/span>") + end + end + end + #[tmp,c_tp] + [flag,c_tp] +end +def update_event_news_template(folder) + Dir["#{folder}modules/event_news/*.html.erb"].each do |f| + c = File.open(f,'r'){|f1| f1.read} + flag1,c = add_css_style_for_block(c,'speaker-head','speaker','speaker-css') + flag2,c = add_css_style_for_block(c,'host-head','host','host-css') + if flag1 || flag2 + puts ['update file:',f] + File.open(f,'w'){|f1| f1.write(c)} + end + end +end \ No newline at end of file