Class: SiSU_FormatShared::CSS_Format

Inherits:
Object
  • Object
show all
Includes:
SiSU_Parts_HTML
Defined in:
lib/sisu/html_lite_shared.rb

Constant Summary collapse

@@fns =
nil

Instance Method Summary collapse

Methods included from SiSU_Parts_HTML

#_url_path_image_base, #band1, #band2, #banner_band, #black, #blue_ink, #blue_tinge, #css, #grey, #grey_medium, #grey_pale, #home_button_only, #ico, #instrument_cover_band_scr, #instrument_cover_band_seg, #num, #num_css, #numless, #paragraph_font_small, #paragraph_font_tiny, #png_home, #png_home_button, #set_color, #set_face, #set_fonts, #set_size_endnote, #set_small, #set_tiny, #table1, #table2, #table_txt, #table_txt_r, #the_banner, #the_color, #the_font, #the_line_break, #the_margin, #the_nav, #the_png, #the_table_cellpad_box, #the_table_close, #the_url_decoration, #the_width, #txt_0, #txt_1, #txt_2, #txt_3, #txt_close, #txt_concordance, #txt_doc_link, #txt_homepage, #txt_manifest, #txt_open, #txt_toc_link, #white, #xml_close, #xml_open, #yellow_light

Methods included from SiSU_Parts_Generic

#footer_signature, #home, #home_txt, #i_choice, #i_home_button, #i_ico, #i_new, #rl_root, #root_http, #sisu, #sisu_txt, #sisudoc, #site, #the_icon, #the_text, #the_url, #txt_home, #txt_hp, #txt_hp_alias, #txt_signature, #urify, #url_close, #url_open

Constructor Details

#initialize(md, t_o) ⇒ CSS_Format

Returns a new instance of CSS_Format.



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/sisu/html_lite_shared.rb', line 62

def initialize(md,t_o)
  @md,@t_o=md,t_o
  @txt=@t_o.obj
  @id=@ocn=@t_o.ocn if defined? @t_o.ocn
  @lv=@t_o.lv.to_s if @t_o.is==:heading
  if @md.fns != @@fns
    @@fns,@@hname=@md.fns,''
  end
  @hname=if defined? @t_o.name \
  and not @t_o.name.to_s.empty?
    @@hname=@t_o.name
  else @@hname
  end
  @tab="\t"
  @@tablehead,@@tablefoot=[],[]
  @env=SiSU_Env::InfoEnv.new(@md.fns)
  @base_url="#{@env.url.root}/#{@md.fnb}/#{@hname}.html"
end

Instance Method Details

#codeObject



229
230
231
232
233
# File 'lib/sisu/html_lite_shared.rb', line 229

def code
  txt=markup_object(@t_o)
  h={ txt: "<tt>#{txt}</tt>", class: 'code', type: 'substantive', id: @ocn }
  tag_para(h)
end

#endnote(nr, en) ⇒ Object

used only by db



189
190
191
192
193
194
195
196
# File 'lib/sisu/html_lite_shared.rb', line 189

def endnote(nr,en) #used only by db
  txt=markup_note(en)
  <<GSUB
<p class="endnote" name="note_#{nr}" from="#{@t_o.ocn}">
<a href="#{@base_url}#-#{nr}" name="_#{nr}">#{nr}.</a> <note>#{txt}</note>
</p>
GSUB
end

#hang_indent(f, t) ⇒ Object



239
240
241
242
243
244
# File 'lib/sisu/html_lite_shared.rb', line 239

def hang_indent(f,t)
  txt=markup_object(@t_o)
  h={ txt: txt, class: "hang#{f}indent#{t}", type: 'substantive', id: @ocn }
  #h={ txt: txt, class: "h#{f}i#{t}", type: 'substantive', id: @ocn }
  tag_para(h)
end

#html_tableObject

get rid of use html_table



251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
# File 'lib/sisu/html_lite_shared.rb', line 251

def html_table # get rid of use html_table
  @new_content=[]
  @txt.split(/\n/).each do |parablock|
    m=parablock[/<!f(.+?)!>/,1]
    @@tablefoot << m if m
    parablock=parablock.gsub(/<!f.+?!>/,'')
    @@tablehead=1 if parablock =~/#{Mx[:gr_o]}Th#{Mx[:tc_p]}/u
    parablock=parablock.gsub(/#{Mx[:gr_o]}Th?#{Mx[:tc_p]}.+?#{Mx[:tc_p]}~(\d+)#{Mx[:gr_c]}/,
      %{<table summary="normal text css" width="100%" border="0" cellpadding="2" align="center">})
    if parablock =~/#{Mx[:gr_o]}TZ#{Mx[:gr_c]}/
      tablefoot=[]
      @@tablefoot.each {|x| tablefoot << %{<p align="center"><font size=2><i>#{x}</i></font></p>\n}}
      @@tablefoot=[]
      parablock=parablock.gsub(/#{Mx[:gr_o]}TZ#{Mx[:gr_c]}/,
        %{#{the_table_close}\n}) # +
    end
    if @@tablehead==1
      if parablock =~/#{Mx[:tc_p]}#{Mx[:tc_p]}/u
        parablock=parablock.gsub(/#{Mx[:tc_o]}#{Mx[:tc_p]}#{Mx[:tc_p]}(\d+?)#{Mx[:tc_p]}/u,
            %{\n<tr>} +
            %{\n<td width="\\1%" valign="top">} +
            %{#{para_table}<b>}).
          gsub(/#{Mx[:tc_p]}#{Mx[:tc_p]}(\d+?)#{Mx[:tc_p]}/u,
            %{</b></td><td width="\\1%" valign="top">} +
            %{#{para_table}<b>}).
          gsub(/#{Mx[:tc_c]}/, '</b></td></tr>')
        @@tablehead=0
      end
      parablock
    else
      parablock=parablock.gsub(/#{Mx[:tc_o]}#{Mx[:tc_p]}#{Mx[:tc_p]}(\d+?)#{Mx[:tc_p]}/u,
          %{\n<tr>} +
          %{\n<td width="\\1%" valign="top">} +
          %{#{para_table}}).
        gsub(/#{Mx[:tc_p]}#{Mx[:tc_p]}(\d+?)#{Mx[:tc_p]}/u,
          %{</td><td width="\\1%" valign="top">} +
          %{#{para_table}}).
        gsub(/#{Mx[:tc_c]}/, '</td></tr>')
      parablock
    end
    @new_content << parablock
  end
  @new_content.join
end

#indent(t) ⇒ Object



234
235
236
237
238
# File 'lib/sisu/html_lite_shared.rb', line 234

def indent(t)
  txt=markup_object(@t_o)
  h={ txt: txt, class: "indent#{t}", type: 'substantive', id: @ocn }
  tag_para(h)
end

#lev4_minusObject



215
216
217
218
219
# File 'lib/sisu/html_lite_shared.rb', line 215

def lev4_minus
  txt=markup_object(@t_o)
  h={ txt: txt, class: "h#{@t_o.ln}", type: 'substantive', id: @ocn }
  tag_para(h)
end

#lev4_plusObject



210
211
212
213
214
# File 'lib/sisu/html_lite_shared.rb', line 210

def lev4_plus
  txt=markup_object(@t_o)
  h={ txt: txt, class: "h#{@lv}", type: 'substantive', id: @ocn, header: @hname }
  tag_header(h)
end

#lev_tocObject



206
207
208
209
# File 'lib/sisu/html_lite_shared.rb', line 206

def lev_toc
  h={ txt: txt, class: "toc#{@lv}", type: 'toc' }
  tag_para(h)
end

#lev_toc_hnameObject



203
204
205
# File 'lib/sisu/html_lite_shared.rb', line 203

def lev_toc_hname
  %{<p class="toc#{@lv}" header="#{@hname}"><a href="##{@ocn}">#{@txt}</a></p>\n}  #<< "\n"
end

#markup_generic(s) ⇒ Object



141
142
143
144
145
146
147
148
149
150
151
152
# File 'lib/sisu/html_lite_shared.rb', line 141

def markup_generic(s)
  s=s.gsub(/#{Mx[:fa_bold_o]}(.+?)#{Mx[:fa_bold_c]}/,'<b>\1</b>').
    gsub(/#{Mx[:fa_italics_o]}(.+?)#{Mx[:fa_italics_c]}/,'<i>\1</i>').
    gsub(/#{Mx[:fa_underscore_o]}(.+?)#{Mx[:fa_underscore_c]}/,'<u>\1</u>').
    gsub(/#{Mx[:fa_cite_o]}(.+?)#{Mx[:fa_cite_c]}/,'"\1"').
    gsub(/#{Mx[:fa_insert_o]}(.+?)#{Mx[:fa_insert_c]}/,'+{\1}+').
    gsub(/#{Mx[:fa_strike_o]}(.+?)#{Mx[:fa_strke_c]}/,'-{\1}-').
    gsub(/#{Mx[:fa_superscript_o]}(.+?)#{Mx[:fa_superscript_c]}/,'<sup>\1</sup>').
    gsub(/#{Mx[:fa_subscript_o]}(.+?)#{Mx[:fa_subscript_c]}/,'<sub>\1</sub>').
    gsub(/#{Mx[:fa_monospace_o]}(.+?)#{Mx[:fa_monospace_c]}/,'<tt>\1</tt>'). # tt, kbd
    gsub(/#{Mx[:gl_o]}#(?:126|152)#{Mx[:gl_c]}/i,'~')
end

#markup_note(s) ⇒ Object



173
174
175
176
177
178
179
180
181
182
183
184
185
# File 'lib/sisu/html_lite_shared.rb', line 173

def markup_note(s)
  s=markup_generic(s)
  if s =~/#{Mx[:lnk_o]}.+?#{Mx[:lnk_c]}(#{Mx[:url_o]}\S+?#{Mx[:url_c]}|#{Mx[:rel_o]}\S+?#{Mx[:rel_c]}|image)/
    wm=s.scan(/#{Mx[:lnk_o]}.+?#{Mx[:lnk_c]}(?:#{Mx[:url_o]}\S+?#{Mx[:url_c]}|#{Mx[:rel_o]}\S+?#{Mx[:rel_c]}|image)|\S+/)
    words=urls(wm)
    s=s.gsub(/.+/m,words)
  end
  s=s.gsub(/#{Mx[:gl_o]}(#[0-9]{3})#{Mx[:gl_c]}/u,'&\1;').
    gsub(/#{Mx[:gl_o]}#([a-z]{2,4})#{Mx[:gl_c]}/u,'&\1;').
    gsub(/#{Mx[:url_o]}_(\S+?)#{Mx[:url_c]}/,'<a href="\1" target="_top">\1</a>\2'). #http ftp matches escaped, no decoration
    gsub(/(#{Mx[:lnk_c]})#{Mx[:url_o]}(\S+?)#{Mx[:url_c]}/,'\1<a href="\2" target="_top">\2</a>'). #special case \{ e.g. \}http://url
    gsub(/#{Mx[:url_o]}(\S+?)#{Mx[:url_c]}/,%{#{the_url_decoration.xml_open}<a href="\\1" target="_top">\\1</a>#{the_url_decoration.xml_close}}) #http ftp matches with decoration
end

#markup_object(t_o) ⇒ Object



153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
# File 'lib/sisu/html_lite_shared.rb', line 153

def markup_object(t_o)
  s=t_o.obj
  s=if t_o.is !=:code
    s=markup_generic(s)
    if s =~/#{Mx[:lnk_o]}.+?#{Mx[:lnk_c]}(?:#{Mx[:url_o]}\S+?#{Mx[:url_c]}|#{Mx[:rel_o]}\S+?#{Mx[:rel_c]}|image)/
      wm=s.scan(/#{Mx[:lnk_o]}.+?#{Mx[:lnk_c]}(?:#{Mx[:url_o]}\S+?#{Mx[:url_c]}|#{Mx[:rel_o]}\S+?#{Mx[:rel_c]}|image)|\S+/)
      words=urls(wm)
      s=s.gsub(/.+/m,words)
    end
    s.gsub(/#{Mx[:gl_o]}(#[0-9]{3})#{Mx[:gl_c]}/u,'&\1;').
      gsub(/#{Mx[:gl_o]}#([a-z]{2,4})#{Mx[:gl_c]}/u,'&\1;').
      gsub(/#{Mx[:url_o]}[_\\](\S+?)#{Mx[:url_c]}/,'<a href="\1" target="_top">\1</a>'). #http ftp matches escaped, no decoration
      gsub(/(#{Mx[:lnk_c]})#{Mx[:url_o]}(\S+?)#{Mx[:url_c]}/,'\1<a href="\2" target="_top">\2</a>'). #special case \{ e.g. \}http://url
      gsub(/(^|#{Mx[:gl_c]}|\s)#{Mx[:url_o]}(\S+?)#{Mx[:url_c]}/,%{\\1#{the_url_decoration.xml_open}<a href="\\2" target="_top">\\2</a>#{the_url_decoration.xml_close}\\3}) #http ftp matches with decoration
  else
    s.gsub(/</m,'&lt;').
      gsub(/>/m,'&gt;')
  end
  s
end

#normObject



224
225
226
227
228
# File 'lib/sisu/html_lite_shared.rb', line 224

def norm
  txt=markup_object(@t_o)
  h={ txt: txt, class: 'norm', type: 'substantive', id: @ocn }
  tag_para(h)
end

#norm_commentObject



220
221
222
223
# File 'lib/sisu/html_lite_shared.rb', line 220

def norm_comment
  h={ txt: @t_o.obj, class: 'norm', type: 'comment' }
  tag_para(h)
end

#ocnObject



248
249
250
# File 'lib/sisu/html_lite_shared.rb', line 248

def ocn
  %{<label class="ocn">#{@ocn}</label>} << "\n"
end

#para_tableObject



245
246
247
# File 'lib/sisu/html_lite_shared.rb', line 245

def para_table
  %{<p class="norm" align="left"><font #{the_font.set_small} #{the_font.set_color} #{the_font.set_face}>}
end

#paragraphObject



186
187
188
# File 'lib/sisu/html_lite_shared.rb', line 186

def paragraph
  %{<p class="h#{@lv}" type="substantive" header="#{@hname}">#{@txt}</p>\n} # << "\n"
end

#tag_header(h) ⇒ Object



197
198
199
# File 'lib/sisu/html_lite_shared.rb', line 197

def tag_header(h)
  %{<p class="#{h[:class]}" type="#{h[:type]}" header="#{h[:header]}">#{h[:txt]}</a></p>\n} # << "\n"
end

#tag_para(h) ⇒ Object



200
201
202
# File 'lib/sisu/html_lite_shared.rb', line 200

def tag_para(h)
  %{<p class="#{h[:class]}" type="#{h[:type]}">#{h[:txt]}</a></p>\n}  << "\n"
end

#urls(data) ⇒ Object



80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
# File 'lib/sisu/html_lite_shared.rb', line 80

def urls(data)
  @words=[]
  map_nametags=SiSU_Particulars::CombinedSingleton.instance.get_map_nametags(@md).nametags_map
  data.each do |word|
    @words << if word=~/#{Mx[:lnk_o]}(.+?)#{Mx[:lnk_c]}(#{Mx[:url_o]}\S+?#{Mx[:url_c]}|#{Mx[:rel_o]}\S+?#{Mx[:rel_c]}|image)/
      if word =~/#{Mx[:lnk_o]}.+?#{Mx[:lnk_c]}#{Mx[:url_o]}\S+?#{Mx[:url_c]}/
        m,u=/#{Mx[:lnk_o]}(.+?)#{Mx[:lnk_c]}#{Mx[:url_o]}(\S+?)#{Mx[:url_c]}/.match(word).captures
      elsif word =~/#{Mx[:lnk_o]}.+?#{Mx[:lnk_c]}#{Mx[:rel_o]}\S+?#{Mx[:rel_c]}/
        m,u=/#{Mx[:lnk_o]}(.+?)#{Mx[:lnk_c]}#{Mx[:rel_o]}(\S+?)#{Mx[:rel_c]}/.match(word).captures
      elsif word =~/#{Mx[:lnk_o]}.+?#{Mx[:lnk_c]}image/
        m,u=/#{Mx[:lnk_o]}(.+?)#{Mx[:lnk_c]}(image)/.match(word).captures
      end
      word=case m
      when /\.png|\.jpg|\.gif|c=|\d+x\d+/
        w,h=/(\d+)x(\d+)/.match(m).captures if m =~/\d+x\d+/
        w=%{width="#{w}"} if w
        h=%{height="#{h}"} if h
        c=m[/"(.+?)"/m,1]
        caption=%{<br><p class="caption">#{c}</p>} if c
        png=m.scan(/\S+/)[0]
        ins=if u \
        and u.strip !~/^image$/
          %{<a href="#{u}">[#{png}]</a>#{caption}}
        else %{[#{png}] #{caption}}
        end
        word=word.gsub(/#{Mx[:lnk_o]}.+?#{Mx[:lnk_c]}(#{Mx[:url_o]}\S+?#{Mx[:url_c]}|image)/,ins)
      else
        u=case u
        when /^https?:\/\//
          u
        when /^:/
          u=u.gsub(/^:/,'')
          "#{@env.url.root}/#{u}"
        when /^\.\.\// # can remove
          u=u.gsub(/^\.\.\//,'')
          "#{@env.url.root}/#{u}"
        else
          if not map_nametags[u].nil?
            @env.url.root + '/' \
            + @md.fnb + '/' \
            + map_nametags[u][:segname] \
            + Sfx[:html] \
            + '#' + u
          else ''
          end
        end
        link=m[/(.+)/m]
        png=m.scan(/\S+/)[0].strip
        link=link.strip
        ins=%{<a href="#{u}">#{link}</a>}
        word=word.gsub(/#{Mx[:lnk_o]}.+?#{Mx[:lnk_c]}#{Mx[:url_o]}\S+?#{Mx[:url_c]}/,ins).
          gsub(/#{Mx[:lnk_o]}.+?#{Mx[:lnk_c]}#{Mx[:rel_o]}\S+?#{Mx[:rel_c]}/,ins)
        word
      end
      word
    else word
    end
    word
  end
  @words=@words.join(' ')
end