Class: Ulmul

Inherits:
Object
  • Object
show all
Includes:
AASM, HTML, HTML5, Itemize, XHTML
Defined in:
lib/ulmul.rb,
lib/ulmul.rb

Constant Summary collapse

VERSION =
'0.5.3'
PARAGRAPH_INITIATOR =
'<p>'
PARAGRAPH_TERMINATOR =
'</p>'
VERBATIM_INITIATOR =
'<pre>'
VERBATIM_TERMINATOR =
'</pre>'

Constants included from HTML

HTML::CONTENTS_HERE

Constants included from Itemize

Itemize::ITEMIZE_INITIATOR, Itemize::ITEMIZE_TERMINATOR, Itemize::ITEM_INITIATOR, Itemize::ITEM_TERMINATOR

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from HTML5

#cb_env_end2, #file

Methods included from XHTML

#cb_env_end2, #file

Methods included from HTML

#body, #cb_env_end2code, #cb_env_end2table, #cb_equation_end2, #cb_heading

Methods included from Itemize

#cb_itemize_add_item, #cb_itemize_begin, #cb_itemize_continue_item, #cb_itemize_end

Constructor Details

#initializeUlmul

Returns a new instance of Ulmul.



283
284
285
286
287
288
289
290
291
292
# File 'lib/ulmul.rb', line 283

def initialize()
  @toc = Table_of_Contents.new()
  @body = ''
  @level_of_heading = 0
  @i_th_heading     = 0
  @equations       = []
  @figures         = []
  @tables          = []
  @codes           = []
end

Instance Attribute Details

#subs_rulesObject

Returns the value of attribute subs_rules.



293
294
295
# File 'lib/ulmul.rb', line 293

def subs_rules
  @subs_rules
end

Instance Method Details

#cb_env_begin(filename = nil, lnumber = nil, line = nil) ⇒ Object



204
205
206
207
208
209
210
211
212
213
214
215
216
# File 'lib/ulmul.rb', line 204

def cb_env_begin(filename=nil, lnumber=nil, line=nil)
  @env_label, @env_file = line.split
  @env_label.sub!(/^\\/,'')
  @env_caption =''
  case @env_label
  when /^Fig:/
    @figures << @env_label
  when /^Table:/
    @tables << @env_label
  when /^Code:/
    @codes << @env_label
  end
end

#cb_env_continues(filename = nil, lnumber = nil, line = nil) ⇒ Object



218
219
220
# File 'lib/ulmul.rb', line 218

def cb_env_continues(filename=nil, lnumber=nil, line=nil)
  @env_caption << line
end

#cb_env_end(filename = nil, lnumber = nil, line = nil) ⇒ Object



222
223
224
225
226
227
228
229
230
# File 'lib/ulmul.rb', line 222

def cb_env_end(filename=nil, lnumber=nil, line=nil)
  if line.chomp.sub(/^\//,'') != @env_label
    STDERR << filename << ":#{lnumber}: Current environment is #{@env_label}, but it is terminated with: #{line}"
    exit 1
  end
  cb_env_end2()
  @env_caption =''
  @env_label =''
end

#cb_env_in_env_error(filename = nil, lnumber = nil, line = nil) ⇒ Object



232
233
234
235
# File 'lib/ulmul.rb', line 232

def cb_env_in_env_error(filename=nil, lnumber=nil, line=nil)
  STDERR << filename << ":#{lnumber}: It is already/still in the environment of #{@env_label}, but you tried: #{line}"
  exit 1
end

#cb_env_not_in_env_error(filename = nil, lnumber = nil, line = nil) ⇒ Object



237
238
239
240
# File 'lib/ulmul.rb', line 237

def cb_env_not_in_env_error(filename=nil, lnumber=nil, line=nil)
  STDERR << filename << ":#{lnumber}: It is not in any environment, but you tried: #{line}"
  exit 1
end

#cb_equation_begin(filename = nil, lnumber = nil, line = nil) ⇒ Object



242
243
244
245
246
# File 'lib/ulmul.rb', line 242

def cb_equation_begin(filename=nil, lnumber=nil, line=nil)
  @equation_label = line.strip.sub!(/^\\/,'')
  @equations << @equation_label
  @equation_contents = ''
end

#cb_equation_continues(filename = nil, lnumber = nil, line = nil) ⇒ Object



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

def cb_equation_continues(filename=nil, lnumber=nil, line=nil)
  @equation_contents << line
end

#cb_equation_end(filename = nil, lnumber = nil, line = nil) ⇒ Object



252
253
254
255
256
# File 'lib/ulmul.rb', line 252

def cb_equation_end(filename=nil, lnumber=nil, line=nil)
  cb_equation_end2()
  @equation_contents =''
  @equation_label =''
end

#cb_paragraph_add(filename = nil, lnumber = nil, line = nil) ⇒ Object



184
185
186
# File 'lib/ulmul.rb', line 184

def cb_paragraph_add(filename=nil, lnumber=nil, line=nil)
  @body << @subs_rules.call(line)
end

#cb_paragraph_begin(filename = nil, lnumber = nil, line = nil) ⇒ Object



180
181
182
# File 'lib/ulmul.rb', line 180

def cb_paragraph_begin(filename=nil, lnumber=nil, line=nil)
  @body << PARAGRAPH_INITIATOR << "\n"
end

#cb_paragraph_end(filename = nil, lnumber = nil, line = nil) ⇒ Object



188
189
190
# File 'lib/ulmul.rb', line 188

def cb_paragraph_end(filename=nil, lnumber=nil, line=nil)
  @body << PARAGRAPH_TERMINATOR << "\n"
end

#cb_verbatim_add(filename = nil, lnumber = nil, line = nil) ⇒ Object



196
197
198
# File 'lib/ulmul.rb', line 196

def cb_verbatim_add(filename=nil, lnumber=nil, line=nil)
    @body << line[1..-1].gsub(/&/,'&amp;').gsub(/</,'&lt;').gsub(/>/,'&gt;')
end

#cb_verbatim_begin(filename = nil, lnumber = nil, line = nil) ⇒ Object



192
193
194
# File 'lib/ulmul.rb', line 192

def cb_verbatim_begin(filename=nil, lnumber=nil, line=nil)
  @body << VERBATIM_INITIATOR << "\n"
end

#cb_verbatim_end(filename = nil, lnumber = nil, line = nil) ⇒ Object



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

def cb_verbatim_end(filename=nil, lnumber=nil, line=nil)
  @body << VERBATIM_TERMINATOR << "\n"
end

#parse(fd) ⇒ Object



258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
# File 'lib/ulmul.rb', line 258

def parse(fd)
  while true
    if line = fd.gets
      lnumber = ARGF.file.lineno
    else
      line = "=end\n"
    end
    case line
    when /^=begin/,/^#/ then    ev_ignore(nil, $FILENAME, lnumber, line)
    when /^=end/        then   ev_heading(nil, $FILENAME, lnumber, line); break
    when /^=+ /         then   ev_heading(nil, $FILENAME, lnumber, line)
    when /^ +\*/        then  ev_asterisk(nil, $FILENAME, lnumber, line)
    when /^$/           then     ev_empty(nil, $FILENAME, lnumber, line)
    when /^\s+/         then    ev_offset(nil, $FILENAME, lnumber, line)
    when /^\\(Fig|Table|Code):/
                        then ev_env_begin(nil, $FILENAME, lnumber, line)
    when /^\/(Fig|Table|Code):/
                        then   ev_env_end(nil, $FILENAME, lnumber, line)
    when /^\\Eq:/  then ev_equation_begin(nil, $FILENAME, lnumber, line)
    when /^\/Eq:/  then   ev_equation_end(nil, $FILENAME, lnumber, line)
    else                        ev_normal(nil, $FILENAME, lnumber, line)
    end
  end
end