59 lines
2.0 KiB
Ruby
59 lines
2.0 KiB
Ruby
|
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}}}((?:(?!<tr).)*){{#{value_key}}})/m) do |c1|
|
||
|
flag = true
|
||
|
s,e = $~.offset(0)
|
||
|
tag_gs = c1[1].scan(/<(\/)*(\w+)(?:(?!<|>).)*>/)
|
||
|
tag_gs.each do |tag_g|
|
||
|
if tag_g[0]
|
||
|
s = s - c[0...s].reverse.match(/>(?:(?!<|>).)*#{tag_g[1].reverse}</).offset(0)[1]
|
||
|
else
|
||
|
e = c[e..-1].match(/<\/#{tag_g[1]}(?:(?!<|>).)*>/).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}</).offset(0)[1]
|
||
|
outer_c = c[s...e]
|
||
|
ext_vars = outer_c.scan(/{{((?:(?!}).)*)}}/).flatten-[head_key,value_key]
|
||
|
#tmp << [outer_c,inner_c,ext_vars]
|
||
|
if ext_vars.length==0
|
||
|
outer_c_new = outer_c.gsub(/(<\w+)((?:(?!>).)*)(>.*)/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,"<span style=\"{{#{css_key}}}\">#{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
|