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}.encode("UTF-8", "UTF-8", invalid: :replace, replace: "???") next if (c.include?("???") rescue true) 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