Class: SiSU_XHTML_EPUB2_Format::FormatTextObject

Inherits:
Object
  • Object
show all
Includes:
SiSU_Parts_XHTML
Defined in:
lib/sisu/xhtml_epub2_format.rb

Direct Known Subclasses

FormatScroll, FormatSeg, FormatToc

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from SiSU_Parts_XHTML

#css, #home, #num_css, #paragraph_font_small, #paragraph_font_tiny, #set_fonts, #set_small, #set_tiny, #site, #the_font, #the_line_break, #the_margin, #the_nav, #the_table_close, #the_url, #the_url_decoration, #txt_0, #txt_1, #txt_2, #txt_3, #txt_close, #txt_concordance, #txt_manifest, #txt_open, #txt_toc_link, #xml_close, #xml_open

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) ⇒ FormatTextObject

Returns a new instance of FormatTextObject.



1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
# File 'lib/sisu/xhtml_epub2_format.rb', line 1863

def initialize(md,t_o)
  @md,@t_o=md,t_o
  if t_o.is_a?(Hash)
    @txt            =t_o[:txt]            || nil
    @ocn            =t_o[:ocn]            || nil
    @ocn_display    =t_o[:ocn_display]    || nil
    @headname       =t_o[:headname]       || nil
    @trailer        =t_o[:trailer]        || nil
    @endnote_part_a =t_o[:endnote_part_a] || nil
    @endnote_part_b =t_o[:endnote_part_b] || nil
    @lnk_url        =t_o[:lnk_url]        || nil
    @lnk_txt        =t_o[:lnk_txt]        || nil
    @format         =t_o[:format]         || nil
    @target         =t_o[:target]         || nil #occasionally passed but not used
    if @format and not @format.empty?
      if @format=~/^\d:(\S+)/ #need more reliable marker #if @format =~ /#{Rx[:lv]}/
        headname=$1 #format[/\d~(\S+)/m,1]
        @headname=(headname =~/^[a-zA-Z]/) \
        ? %{<id="#{headname}">}
        : %{<id="h#{headname}"></a>}
        @headname=(headname =~/^[a-zA-Z]/) \
        ? %{<a name="#{headname}" id="#{headname}"></a>}
        : %{<a name="h#{headname}" id="h#{headname}"></a>}
      end
    end
  elsif t_o.class.inspect =~/Object/
    @dob=t_o if defined? t_o.is
    @named=nametags_seg(@dob)
    @txt=((defined? t_o.obj) ? t_o.obj : nil)
    @ocn=((defined? t_o.ocn) ? t_o.ocn.to_s : nil)
    @headname=((t_o.is==:heading and defined? t_o.name) ? t_o.name : nil)
  else
    if @md.opt.act[:maintenance][:set]==:on
      p __FILE__ << ':' << __LINE__.to_s
      p t_o.class
      p caller
    end
  end
  if @txt and not @txt.empty?
    @txt=@txt.gsub(/#{Mx[:mk_o]}[-~]##{Mx[:mk_c]}/,'')
  end
  @p_num=ParagraphNumber.new(@md,@ocn)
end

Instance Attribute Details

Returns the value of attribute banner.



1862
1863
1864
# File 'lib/sisu/xhtml_epub2_format.rb', line 1862

def banner
  @banner
end

#format(tag, attrib) ⇒ Object

Returns the value of attribute format.



1862
1863
1864
# File 'lib/sisu/xhtml_epub2_format.rb', line 1862

def format
  @format
end

#headnameObject

Returns the value of attribute headname.



1862
1863
1864
# File 'lib/sisu/xhtml_epub2_format.rb', line 1862

def headname
  @headname
end

Returns the value of attribute link.



1862
1863
1864
# File 'lib/sisu/xhtml_epub2_format.rb', line 1862

def link
  @link
end

#linknameObject

Returns the value of attribute linkname.



1862
1863
1864
# File 'lib/sisu/xhtml_epub2_format.rb', line 1862

def linkname
  @linkname
end

#mdObject

Returns the value of attribute md.



1862
1863
1864
# File 'lib/sisu/xhtml_epub2_format.rb', line 1862

def md
  @md
end

#ocnObject

Returns the value of attribute ocn.



1862
1863
1864
# File 'lib/sisu/xhtml_epub2_format.rb', line 1862

def ocn
  @ocn
end

#p_numObject

Returns the value of attribute p_num.



1862
1863
1864
# File 'lib/sisu/xhtml_epub2_format.rb', line 1862

def p_num
  @p_num
end

#paranumObject

Returns the value of attribute paranum.



1862
1863
1864
# File 'lib/sisu/xhtml_epub2_format.rb', line 1862

def paranum
  @paranum
end

#t_oObject

Returns the value of attribute t_o.



1862
1863
1864
# File 'lib/sisu/xhtml_epub2_format.rb', line 1862

def t_o
  @t_o
end

#tableObject

Returns the value of attribute table.



1862
1863
1864
# File 'lib/sisu/xhtml_epub2_format.rb', line 1862

def table
  @table
end

#txtObject

Returns the value of attribute txt.



1862
1863
1864
# File 'lib/sisu/xhtml_epub2_format.rb', line 1862

def txt
  @txt
end

#urlObject

Returns the value of attribute url.



1862
1863
1864
# File 'lib/sisu/xhtml_epub2_format.rb', line 1862

def url
  @url
end

Instance Method Details

#altObject



1961
1962
1963
# File 'lib/sisu/xhtml_epub2_format.rb', line 1961

def alt
  para_form_css('p','alt',@txt)
end

#blockObject



1958
1959
1960
# File 'lib/sisu/xhtml_epub2_format.rb', line 1958

def block
  para_form_css('p','block',@txt)
end

#boldObject



1973
1974
1975
# File 'lib/sisu/xhtml_epub2_format.rb', line 1973

def bold
  para_form_css('p','bold',@txt)
end

#bold_headingObject

unused



2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
# File 'lib/sisu/xhtml_epub2_format.rb', line 2089

def bold_heading #unused
  @txt=@txt.gsub(/[1-9]~\S+/,'').
    gsub(/[1-9]~/,'')
  %{<p class="bold">
#{@txt}
  </p>
#{the_margin.num_css}
  #{$ep[:hsp]*3}
#{the_table_close}}
end

#bold_paraObject



2080
2081
2082
2083
2084
2085
2086
2087
2088
# File 'lib/sisu/xhtml_epub2_format.rb', line 2080

def bold_para
  %{#{the_margin.txt_0}
  <p class="bold">
#{@txt}
  </p>
#{the_margin.num_css}
  #{$ep[:hsp]*3}
#{the_table_close}}
end

#breakObject



1987
1988
1989
1990
1991
# File 'lib/sisu/xhtml_epub2_format.rb', line 1987

def break
  @txt=@txt.gsub(/#{Mx[:br_page_new]}|#{Mx[:br_page]}|#{Mx[:br_page_line]}/,'<hr /><br />').
    gsub(/#{Mx[:br_obj]}/,'<hr style="width:30%" /><br />')
  para_form_css('p','norm',@txt)
end

#bulletObject



1976
1977
1978
# File 'lib/sisu/xhtml_epub2_format.rb', line 1976

def bullet
  para_form_css('li','bullet',@txt)
end

#centerObject



1970
1971
1972
# File 'lib/sisu/xhtml_epub2_format.rb', line 1970

def center
  para_form_css('p','center',@txt)
end

#center_boldObject



2111
2112
2113
2114
# File 'lib/sisu/xhtml_epub2_format.rb', line 2111

def center_bold
  @txt=SanitizeXML.xml(@txt)
  %{<p class="centerbold">#{@txt}</p>\n}
end

#codeObject



1967
1968
1969
# File 'lib/sisu/xhtml_epub2_format.rb', line 1967

def code
  para_form_css('p','code',@txt)
end

#dlObject

check :trailer



2057
2058
2059
# File 'lib/sisu/xhtml_epub2_format.rb', line 2057

def dl #check :trailer
  "<dl><b>#{@txt}</b> #{@trailer}</dl>"
end

#endnote_bodyObject



1916
1917
1918
1919
1920
1921
1922
# File 'lib/sisu/xhtml_epub2_format.rb', line 1916

def endnote_body
  %{
<p class="endnote">
  #{@txt}
</p>
}
end

#endnote_body_indentObject



1923
1924
1925
1926
1927
1928
1929
# File 'lib/sisu/xhtml_epub2_format.rb', line 1923

def endnote_body_indent
  %{
  <p class="endnote_indent">
#{@txt}
  </p>
}
end

#groupObject



1955
1956
1957
# File 'lib/sisu/xhtml_epub2_format.rb', line 1955

def group
  para_form_css('p','group',@txt)
end

#gsub_bodyObject

unused



2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
# File 'lib/sisu/xhtml_epub2_format.rb', line 2065

def gsub_body #unused
  @txt=case @txt
  when /^(?:#{Mx[:pa_o]}i[1-9]#{Mx[:pa_c]}\s*)?\((i+|iv|v|vi+|ix|x|xi+)\)/
    @txt.gsub(/^\((i+|iv|v|vi+|ix|x|xi+)\)/,'<b>(\1)</b>').
      gsub(/^(#{Mx[:pa_o]}i[1-9]#{Mx[:pa_c]})\s*\((i+|iv|v|vi+|ix|x|xi+)\)/,'\1<b>(\2)</b>')
  when /^(?:#{Mx[:pa_o]}i[1-9]#{Mx[:pa_c]}\s*)?\(?(\d|[a-z])+\)/
    @txt.gsub(/^\((\d+|[a-z])+\)/,'<b>(\1)</b>').
      gsub(/^(#{Mx[:pa_o]}i[1-9]#{Mx[:pa_c]})\s*\((\d+|[a-z])+\)/,'\1<b>(\2)</b>')
  when /^\s*\d{1,3}\.\s/
    @txt.gsub(/^\s*(\d+\.)/,'<b>\1</b>')
  when /^\s*[A-Z]\.\s/
    @txt.gsub(/^\s*([A-Z]\.)/,'<b>\1</b>')
  else @txt
  end
end

#nametags_seg(dob) ⇒ Object

FIX



1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
# File 'lib/sisu/xhtml_epub2_format.rb', line 1906

def nametags_seg(dob) #FIX
  tags=''
  if defined? dob.tags \
  and dob.tags.length > 0 # insert tags "hypertargets"
    dob.tags.each do |t|
      tags=tags << %{<a name="#{t}" />}
    end
  end
  tags
end

#no_paranumObject



1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
# File 'lib/sisu/xhtml_epub2_format.rb', line 1930

def no_paranum
  %{
<div class="substance">
  <label class="ocn">#{$ep[:hsp]}</label>
  <p class="norm">
#{@txt}
  </p>
</div>
}
end

#paraObject



1952
1953
1954
# File 'lib/sisu/xhtml_epub2_format.rb', line 1952

def para
  para_form_css('p','norm',@txt)
end

#para_form_css(tag, attrib, txt) ⇒ Object

regular paragraphs shaped here



1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
# File 'lib/sisu/xhtml_epub2_format.rb', line 1940

def para_form_css(tag,attrib,txt)                                                    # regular paragraphs shaped here
  ul=ulc=''
  ul,ulc="<ul>\n  ","\n  </ul>" if @tag =~/li/
  %{
<div class="substance">
  #{@p_num.ocn_display}
  #{ul}<#{tag} class="#{attrib}" #{@p_num.id}>
#{@named}#{txt}
  </#{tag}>#{ulc}
</div>
}
end

#seg_heading4Object



2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
# File 'lib/sisu/xhtml_epub2_format.rb', line 2038

def seg_heading4
  %{
<div class="substance">
  #{@p_num.ocn_display}
  <h1 class="norm" #{@p_num.id}>
#{@txt}
  </h1>
</div>
}
end

#seg_heading5Object



2048
2049
2050
# File 'lib/sisu/xhtml_epub2_format.rb', line 2048

def seg_heading5
  seg_heading_sub('p','bold',@txt)
end

#seg_heading6Object



2051
2052
2053
# File 'lib/sisu/xhtml_epub2_format.rb', line 2051

def seg_heading6
  seg_heading_sub('p','bold',@txt)
end

#seg_heading7Object



2054
2055
2056
# File 'lib/sisu/xhtml_epub2_format.rb', line 2054

def seg_heading7
  seg_heading_sub('p','bold',@txt)
end

#seg_heading_sub(tag, attrib, txt) ⇒ Object



2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
# File 'lib/sisu/xhtml_epub2_format.rb', line 2027

def seg_heading_sub(tag,attrib,txt)
  txt=txt.gsub(/(?:#{Mx[:en_a_o]}.+?#{Mx[:en_a_c]}|#{Mx[:en_b_o]}.+?#{Mx[:en_b_c]})\s*/m,' ')
  %{
<div class="substance">
  #{@p_num.ocn_display}
  <#{tag} class="#{attrib}" #{@p_num.id}>#{@p_num.name}
#{@named}#{@txt}
  </#{tag}>
</div>
}
end

#table_css_endObject



2060
2061
2062
2063
2064
# File 'lib/sisu/xhtml_epub2_format.rb', line 2060

def table_css_end
  '</table>
</p>
  </div>'
end

#title_heading(tag, attrib) ⇒ Object



1995
1996
1997
1998
1999
2000
2001
2002
2003
# File 'lib/sisu/xhtml_epub2_format.rb', line 1995

def title_heading(tag,attrib)
  %{
<div class="content">
<#{tag} class="#{attrib}">
#{@named}#{@txt}
  </#{tag}>
</div>
}
end

#title_heading0Object



2004
2005
2006
2007
2008
# File 'lib/sisu/xhtml_epub2_format.rb', line 2004

def title_heading0
  DISABLE[:epub][:per_section_title] \
  ? ''
  : title_heading('h1','tiny')
end

#title_heading1Object



2009
2010
2011
2012
2013
# File 'lib/sisu/xhtml_epub2_format.rb', line 2009

def title_heading1
  DISABLE[:epub][:per_section_title] \
  ? ''
  : title_heading('h1','tiny')
end

#title_heading2Object



2014
2015
2016
2017
2018
# File 'lib/sisu/xhtml_epub2_format.rb', line 2014

def title_heading2
  DISABLE[:epub][:per_section_title] \
  ? ''
  : title_heading('h2','tiny')
end

#title_heading3Object



2019
2020
2021
2022
2023
# File 'lib/sisu/xhtml_epub2_format.rb', line 2019

def title_heading3
  DISABLE[:epub][:per_section_title] \
  ? ''
  : title_heading('h3','tiny')
end

#title_heading4Object



2024
2025
2026
# File 'lib/sisu/xhtml_epub2_format.rb', line 2024

def title_heading4
  ''
end

#toc_head_copy_atObject



2099
2100
2101
2102
# File 'lib/sisu/xhtml_epub2_format.rb', line 2099

def toc_head_copy_at
  @txt=SanitizeXML.xml(@txt)
  %{<p class="center">#{@txt}</p>\n}
end

#verseObject



1964
1965
1966
# File 'lib/sisu/xhtml_epub2_format.rb', line 1964

def verse
  para_form_css('p','verse',@txt)
end