livetext 0.9.17 → 0.9.22

Sign up to get free protection for your applications and to get access to all the features.
Files changed (84) hide show
  1. checksums.yaml +4 -4
  2. data/README.lt3 +2 -0
  3. data/README.md +330 -339
  4. data/bin/livetext +0 -2
  5. data/imports/bookish.rb +286 -0
  6. data/imports/calibre.rb +28 -0
  7. data/imports/livemagick.rb +133 -0
  8. data/imports/markdown.rb +44 -0
  9. data/imports/markdown_importable.rb +45 -0
  10. data/imports/pyggish.rb +172 -0
  11. data/imports/tutorial.rb +95 -0
  12. data/lib/cmdargs.rb +28 -20
  13. data/lib/formatline.rb +103 -75
  14. data/lib/functions.rb +16 -1
  15. data/lib/handler/{icanhaz.rb → import.rb} +1 -1
  16. data/lib/handler.rb +1 -1
  17. data/lib/helpers.rb +34 -8
  18. data/lib/livetext.rb +12 -5
  19. data/lib/parser/general.rb +1 -1
  20. data/lib/parser/set.rb +3 -5
  21. data/lib/parser/string.rb +11 -10
  22. data/lib/processor.rb +25 -13
  23. data/lib/standard.rb +16 -16
  24. data/lib/userapi.rb +6 -4
  25. data/livetext.gemspec +2 -1
  26. data/plugin/bookish.rb +4 -5
  27. data/plugin/markdown.rb +6 -6
  28. data/plugin/pyggish.rb +45 -77
  29. data/plugin/tutorial.rb +3 -3
  30. data/test/snapshots/error_inc_line_num/actual-error.txt +14 -0
  31. data/test/snapshots/error_inc_line_num/actual-output.txt +7 -0
  32. data/test/snapshots/error_inc_line_num/out-sdiff.txt +14 -0
  33. data/test/snapshots/error_invalid_name/actual-error.txt +10 -0
  34. data/test/snapshots/{icanhaz2/expected-error.txt → error_invalid_name/actual-output.txt} +0 -0
  35. data/test/snapshots/error_invalid_name/out-sdiff.txt +6 -0
  36. data/test/snapshots/error_missing_end/actual-error.txt +10 -0
  37. data/test/snapshots/error_missing_end/actual-output.txt +0 -0
  38. data/test/snapshots/error_missing_end/out-sdiff.txt +6 -0
  39. data/test/snapshots/error_no_such_copy/actual-error.txt +10 -0
  40. data/test/snapshots/error_no_such_copy/actual-output.txt +0 -0
  41. data/test/snapshots/error_no_such_inc/actual-error.txt +10 -0
  42. data/test/snapshots/error_no_such_inc/actual-output.txt +0 -0
  43. data/test/snapshots/error_no_such_mixin/actual-error.txt +13 -0
  44. data/test/snapshots/error_no_such_mixin/actual-output.txt +0 -0
  45. data/test/snapshots/error_no_such_mixin/out-sdiff.txt +6 -0
  46. data/test/snapshots/import/actual-error.txt +13 -0
  47. data/test/snapshots/import/actual-output.txt +0 -0
  48. data/test/snapshots/{icanhaz → import}/expected-output.txt +0 -0
  49. data/test/snapshots/{icanhaz → import}/match-error.txt +0 -0
  50. data/test/snapshots/import/out-sdiff.txt +6 -0
  51. data/test/snapshots/{icanhaz → import}/simple_import.rb +0 -0
  52. data/test/snapshots/{icanhaz → import}/source.lt3 +2 -2
  53. data/test/snapshots/import2/expected-error.txt +0 -0
  54. data/test/snapshots/{icanhaz2 → import2}/expected-output.txt +3 -1
  55. data/test/snapshots/{icanhaz2/simple_canhaz.rb → import2/simple_import.rb} +0 -0
  56. data/test/snapshots/import2/source.lt3 +8 -0
  57. data/test/snapshots/more_functions/expected-error.txt +0 -0
  58. data/test/snapshots/more_functions/expected-output.txt +37 -0
  59. data/test/snapshots/more_functions/source.lt3 +40 -0
  60. data/test/snapshots/simple_import/expected-output.txt +2 -0
  61. data/test/snapshots/simple_import/source.lt3 +3 -1
  62. data/test/snapshots/subset.txt +83 -0
  63. data/test/snapshots/wtf_bookish/expected-error.txt +0 -0
  64. data/test/snapshots/wtf_bookish/expected-output.txt +10 -0
  65. data/test/snapshots/wtf_bookish/source.lt3 +7 -0
  66. data/test/snapshots/wtf_bookish/toc.tmp +0 -0
  67. data/test/snapshots.rb +71 -46
  68. data/test/unit/formatline.rb +252 -135
  69. data/test/unit/parser/set.rb +20 -22
  70. data/test/unit/parser/string.rb +45 -6
  71. data/test/unit/standard.rb +0 -1
  72. metadata +44 -22
  73. data/lib/livetext/importable.rb +0 -2
  74. data/lib/parser/import.rb +0 -15
  75. data/test/affirm/kbks.jpg +0 -0
  76. data/test/affirm/lm-kbks.lt +0 -19
  77. data/test/cleanup +0 -1
  78. data/test/newtest +0 -14
  79. data/test/sdtest +0 -6
  80. data/test/snapshots/OMIT.txt +0 -11
  81. data/test/snapshots/clusion.txt +0 -70
  82. data/test/snapshots/crap +0 -16
  83. data/test/snapshots/fixit +0 -6
  84. data/test/snapshots/icanhaz2/source.lt3 +0 -6
data/lib/helpers.rb CHANGED
@@ -4,6 +4,9 @@ module Helpers
4
4
  Space = " "
5
5
  Sigil = "." # Can't change yet
6
6
 
7
+ ESCAPING = { "'" => ''', '&' => '&', '"' => '"',
8
+ '<' => '&lt;', '>' => '&gt;' }
9
+
7
10
  def escape_html(string)
8
11
  enc = string.encoding
9
12
  unless enc.ascii_compatible?
@@ -12,12 +15,12 @@ module Helpers
12
15
  enc = Encoding::Converter.asciicompat_encoding(enc)
13
16
  string = enc ? string.encode(enc) : string.b
14
17
  end
15
- table = Hash[TABLE_FOR_ESCAPE_HTML__.map {|pair|pair.map {|s|s.encode(enc)}}]
18
+ table = Hash[ESCAPING.map {|pair|pair.map {|s|s.encode(enc)}}]
16
19
  string = string.gsub(/#{"['&\"<>]".encode(enc)}/, table)
17
20
  string.encode!(origenc) if origenc
18
21
  return string
19
22
  end
20
- string.gsub(/['&\"<>]/, TABLE_FOR_ESCAPE_HTML__)
23
+ string.gsub(/['&\"<>]/, ESCAPING)
21
24
  end
22
25
 
23
26
  def find_file(name, ext=".rb")
@@ -52,16 +55,16 @@ module Helpers
52
55
  @backtrace = btrace
53
56
  @main.source(enum, fname, 0)
54
57
  line = nil
55
- loop do
58
+ loop do
56
59
  line = @main.nextline
57
60
  break if line.nil?
58
61
  process_line(line)
59
62
  end
60
- val = @main.finalize if @main.respond_to? :finalize
63
+ val = @main.finalize rescue nil
61
64
  @body
62
65
  end
63
66
 
64
- def process_line(line) # FIXME inefficient?
67
+ def process_line(line)
65
68
  nomarkup = true
66
69
  case line # must apply these in order
67
70
  when Comment
@@ -90,6 +93,29 @@ module Helpers
90
93
  raise EndWithoutOpening()
91
94
  when @main.respond_to?(name)
92
95
  result = @main.send(name)
96
+
97
+ # NOTE: The above line is where the magic happens!
98
+ # A name like 'foobar' results in an invocation of
99
+ # @main.foobar (where @main is a Processor, and any
100
+ # new methods (e.g. from a mixin) are added to @main
101
+ #
102
+ # So all the functionality from _args and _raw_args
103
+ # and _data (among others?) will be encapsulated in
104
+ # 'some' kind of PORO which handles access to all
105
+ # these things as well as the 'body' between the
106
+ # command and its corresponding .end
107
+ #
108
+ # The 'body' functionality is so commonly used, I plan
109
+ # to pass it in separately as needed (even though the
110
+ # args object should make it available also).
111
+ #
112
+ # Every method corresponding to a dot commmand will
113
+ # get args and body passed in as needed. Every one of
114
+ # the signatures already has (args = nil, body = nil)
115
+ # but nothing is being passed in that way yet.
116
+ #
117
+ # Refer to lib/cmdargs.rb for more! This is *strictly*
118
+ # experimental and a "work in progress."
93
119
  else
94
120
  puts @body # earlier correct output, not flushed yet
95
121
  raise "Name '#{name}' is unknown"
@@ -105,8 +131,8 @@ module Helpers
105
131
  name, data = line.split(" ", 2)
106
132
  name = name[1..-1] # chop off sigil
107
133
  name = "dot_" + name if %w[include def].include?(name)
108
- @main.data = data
109
134
  @main.check_disallowed(name)
135
+ @main.data = data
110
136
  name
111
137
  end
112
138
 
@@ -143,10 +169,10 @@ module Helpers
143
169
  value = path if File.exist?(path)
144
170
  break if value
145
171
  end
146
- STDERR.puts "Cannot find #{file.inspect} from #{Dir.pwd}" unless value
172
+ ::STDERR.puts "Cannot find #{file.inspect} from #{Dir.pwd}" unless value
147
173
  return value
148
174
  rescue
149
- STDERR.puts "Can't find #{file.inspect} from #{Dir.pwd}"
175
+ ::STDERR.puts "Can't find #{file.inspect} from #{Dir.pwd}"
150
176
  return nil
151
177
  end
152
178
 
data/lib/livetext.rb CHANGED
@@ -1,17 +1,25 @@
1
1
  # Class Livetext skeleton (top level).
2
2
 
3
3
  class Livetext
4
- VERSION = "0.9.17"
4
+ VERSION = "0.9.22"
5
5
  Path = File.expand_path(File.join(File.dirname(__FILE__)))
6
6
 
7
7
  module Handler
8
8
  end
9
9
  end
10
10
 
11
- # $LOAD_PATH << Livetext::Path
12
-
13
11
  require 'fileutils'
14
12
 
13
+ class Object
14
+ def send?(meth, *args)
15
+ if self.respond_to?(meth)
16
+ self.send(meth, *args)
17
+ else
18
+ return nil
19
+ end
20
+ end
21
+ end
22
+
15
23
  require_relative 'errors'
16
24
  require_relative 'functions'
17
25
  require_relative 'userapi'
@@ -62,8 +70,7 @@ class Livetext
62
70
  def customize(mix: [], call: [], vars: {})
63
71
  mix = Array(mix)
64
72
  call = Array(call)
65
- # FIXME HF won't this break??
66
- mix.each {|lib| mixin(lib) }
73
+ mix.each {|lib| mixin(lib) } # FIXME HF won't this break??
67
74
  call.each {|cmd| @main.send(cmd[1..-1]) } # ignores leading dot, no param
68
75
  vars.each_pair {|var, val| setvar(var, val.to_s) }
69
76
  self
@@ -27,7 +27,7 @@ class Livetext::ParseGeneral < StringParser
27
27
  lines.each do |line|
28
28
  next if line.strip.empty?
29
29
  var, value = line.split(" ", 2)
30
- val = FormatLine.var_func_parse(value)
30
+ val = Livetext.interpolate(value)
31
31
  var = prefix + "." + var if prefix
32
32
  pairs << [var, value]
33
33
  end
data/lib/parser/set.rb CHANGED
@@ -31,8 +31,8 @@ class Livetext::ParseSet < StringParser
31
31
  pairs = []
32
32
  char = nil
33
33
  loop do
34
- break if eos? # end of string
35
34
  char = skip_spaces
35
+ break if eos? # end of string
36
36
  raise "Expected alpha to start var name" unless char =~ /[a-z]/i
37
37
  pairs << assignment
38
38
  char = skip_spaces
@@ -56,7 +56,7 @@ class Livetext::ParseSet < StringParser
56
56
  var = get_var
57
57
  skip_equal
58
58
  value = get_value
59
- value = FormatLine.var_func_parse(value) # FIXME broken now?
59
+ value = Livetext.interpolate(value)
60
60
  pair = [var, value]
61
61
  pair
62
62
  end
@@ -107,7 +107,6 @@ class Livetext::ParseSet < StringParser
107
107
  char = grab
108
108
  break if eos?
109
109
  break if char == quote
110
- # break if char.nil?
111
110
  char = escaped if char == "\\"
112
111
  value << char
113
112
  end
@@ -123,8 +122,7 @@ class Livetext::ParseSet < StringParser
123
122
  value = ""
124
123
  loop do
125
124
  char = peek
126
- break if eos? # FIXME oops???
127
- # break if char.nil?
125
+ break if eos?
128
126
  break if char == " " || char == ","
129
127
  value << char
130
128
  char = grab
data/lib/parser/string.rb CHANGED
@@ -15,15 +15,16 @@ class StringParser
15
15
  return nil if @eos
16
16
  char = @line[@i]
17
17
  @i += 1
18
- @eos = true if @i > @len
18
+ check_eos
19
19
  char
20
20
  end
21
21
 
22
22
  def ungrab
23
- @i -= 1 # FIXME what about eos...?
23
+ @i -= 1
24
+ check_eos
24
25
  end
25
26
 
26
- def next!
27
+ def lookahead
27
28
  @line[@i + 1]
28
29
  end
29
30
 
@@ -32,12 +33,7 @@ class StringParser
32
33
  @line[@i-1]
33
34
  end
34
35
 
35
- def last?
36
- @i > @len - 1
37
- end
38
-
39
36
  def eos?
40
- @eos = true if last? # duh?
41
37
  @eos
42
38
  end
43
39
 
@@ -52,16 +48,21 @@ class StringParser
52
48
  char = peek
53
49
  break if eos?
54
50
  break if char != " "
55
- grab
51
+ char = grab
56
52
  end
57
53
  char
58
54
  end
59
55
 
56
+ private
57
+
58
+ def check_eos
59
+ @eos = @i >= @len
60
+ end
60
61
  end
61
62
 
62
63
  =begin
63
64
  skip
64
- next! skip! peek!(?)
65
+ lookahead skip! peek!(?)
65
66
  expect_alpha
66
67
  expect_number
67
68
  skip_spaces
data/lib/processor.rb CHANGED
@@ -2,6 +2,10 @@
2
2
 
3
3
  class Livetext
4
4
 
5
+ def self.interpolate(str)
6
+ FormatLine.var_func_parse(str)
7
+ end
8
+
5
9
  # Class Processor does the actual work of processing input.
6
10
 
7
11
  class Processor
@@ -11,17 +15,21 @@ class Livetext
11
15
  include Livetext::Standard
12
16
  include Livetext::UserAPI
13
17
 
14
- Disallowed = %i[ ! != !~ <=> == === =~ __binding__ __id__ __send__ class
15
- clone define_singleton_method display dup enum_for eql?
16
- equal? extend freeze frozen? hash inspect instance_eval
17
- instance_exec instance_of? instance_variable_defined?
18
- instance_variable_get instance_variable_set instance_variables is_a?
19
- kind_of? method methods nil? object_id
20
- pretty_inspect private_methods protected_methods public_method
21
- public_methods public_send remove_instance_variable
22
- respond_to? send singleton_class singleton_method
23
- singleton_methods taint tainted? tap to_enum
24
- to_s trust untaint untrust untrusted?]
18
+ Disallowed =
19
+ %i[ __binding__ __id__ __send__ class
20
+ clone display dup enum_for
21
+ eql? equal? extend freeze
22
+ frozen? hash inspect instance_eval
23
+ instance_exec instance_of? is_a? kind_of?
24
+ method methods nil? object_id
25
+ pretty_inspect private_methods protected_methods public_method
26
+ public_methods public_send respond_to? send
27
+ singleton_class singleton_method singleton_methods taint
28
+ tainted? tap to_enum to_s
29
+ trust untaint untrust untrusted?
30
+ define_singleton_method instance_variable_defined?
31
+ instance_variable_get instance_variable_set
32
+ remove_instance_variable instance_variables ]
25
33
 
26
34
  def initialize(parent, output = nil)
27
35
  @parent = parent
@@ -38,10 +46,14 @@ class Livetext
38
46
  @output = io
39
47
  end
40
48
 
49
+ def error(*args)
50
+ ::STDERR.puts *args
51
+ end
52
+
41
53
  def _error!(err, raise_error=false, trace=false) # FIXME much bullshit happens here
42
54
  where = @sources.last || @save_location
43
- STDERR.puts "Error: #{err} (at #{where[1]} line #{where[2]})"
44
- STDERR.puts err.backtrace if err.respond_to?(:backtrace) # && trace
55
+ error "Error: #{err} (at #{where[1]} line #{where[2]})"
56
+ error(err.backtrace) rescue nil
45
57
  raise GenericError.new("Error: #{err}") if raise_error
46
58
  end
47
59
 
data/lib/standard.rb CHANGED
@@ -101,7 +101,7 @@ module Livetext::Standard
101
101
  end
102
102
 
103
103
  def errout(args = nil, body = nil)
104
- STDERR.puts @_data.chomp
104
+ ::STDERR.puts @_data.chomp
105
105
  _optional_blank_line
106
106
  end
107
107
 
@@ -187,7 +187,7 @@ module Livetext::Standard
187
187
  text = _body.join("\n")
188
188
  rhs = ""
189
189
  text.each_line do |line|
190
- str = FormatLine.var_func_parse(line.chomp)
190
+ str = Livetext.interpolate(line.chomp)
191
191
  rhs << str + "<br>"
192
192
  end
193
193
  indent = @parent.indentation.last
@@ -225,32 +225,25 @@ module Livetext::Standard
225
225
 
226
226
  def mixin(args = nil, body = nil)
227
227
  name = @_args.first # Expect a module name
228
+ # TTY.puts "#{__method__}: name = #{name}"
228
229
  return if @_mixins.include?(name)
229
230
  @_mixins << name
230
- mod = Livetext::ParseMixin.get_module(name) # FIXME??
231
+ mod = Livetext::ParseMixin.get_module(name)
232
+ # TTY.puts "#{__method__}: mod = #{mod.inspect}"
231
233
  self.extend(mod)
232
234
  init = "init_#{name}"
233
- self.send(init) if self.respond_to? init
235
+ self.send(init) rescue nil # if self.respond_to? init
234
236
  _optional_blank_line
235
237
  end
236
238
 
237
- def icanhaz(args = nil, body = nil)
239
+ def import(args = nil, body = nil)
238
240
  name = @_args.first # Expect a module name
239
241
  return if @_mixins.include?(name)
240
242
  @_mixins << name
241
- mod = Livetext::Handler::ICanHaz.get_module(name) # FIXME??
243
+ mod = Livetext::Handler::Import.get_module(name)
242
244
  self.extend(mod)
243
245
  init = "init_#{name}"
244
- self.send(init) if self.respond_to? init
245
- _optional_blank_line
246
- end
247
-
248
- def import(args = nil, body = nil)
249
- name = @_args.first # Expect a module name
250
- return if @_mixins.include?(name)
251
- @_mixins << name
252
- mod = Livetext::ParseImport.get_module(name)
253
- parse.use_import(name)
246
+ self.send(init) rescue nil # if self.respond_to? init
254
247
  _optional_blank_line
255
248
  end
256
249
 
@@ -367,4 +360,11 @@ module Livetext::Standard
367
360
  _out out
368
361
  end
369
362
 
363
+ def reflection # strictly experimental!
364
+ list = self.methods
365
+ obj = Object.instance_methods
366
+ diff = (list - obj).sort
367
+ _out "#{diff.size} methods:"
368
+ _out diff.inspect
369
+ end
370
370
  end
data/lib/userapi.rb CHANGED
@@ -1,11 +1,13 @@
1
- # User API
2
-
3
1
  require_relative 'formatline'
4
2
 
5
3
  # UserAPI deals mostly with user-level methods.
6
4
 
7
5
  module Livetext::UserAPI
8
6
 
7
+ # FIXME I am tired of all my leading underscores...
8
+ # FIXME Q: Could this be converted into a class?? What about its
9
+ # interaction thru instance vars?
10
+
9
11
  def setvar(var, val)
10
12
  str, sym = var.to_s, var.to_sym
11
13
  Livetext::Vars[str] = val
@@ -114,9 +116,9 @@ module Livetext::UserAPI
114
116
  end
115
117
 
116
118
  def _format(line)
117
- return "" if line == "\n"
119
+ return "" if line == "\n" || line.nil?
118
120
  line2 = FormatLine.parse!(line)
119
- line.replace(line2) unless line.nil?
121
+ line.replace(line2)
120
122
  line
121
123
  end
122
124
 
data/livetext.gemspec CHANGED
@@ -15,7 +15,8 @@ Gem::Specification.new do |s|
15
15
  s.executables << "livetext"
16
16
 
17
17
  # Files...
18
- main = Find.find("bin").to_a + Find.find("lib").to_a + Find.find("plugin").to_a
18
+ main = Find.find("bin").to_a + Find.find("lib").to_a +
19
+ Find.find("plugin").to_a + Find.find("imports").to_a
19
20
  misc = %w[./README.lt3 ./README.md livetext.gemspec]
20
21
  test = Find.find("test").to_a
21
22
 
data/plugin/bookish.rb CHANGED
@@ -18,7 +18,7 @@ def h2; _out "<h2>#{@_data}</h2>"; end
18
18
  def h3; _out "<h3>#{@_data}</h3>"; end
19
19
 
20
20
  def alpha_columns(args = nil, body = nil)
21
- n = @_args.first.to_i # FIXME: what if missing?
21
+ n = @_args.first.to_i # FIXME: what if it's missing?
22
22
  words = []
23
23
  _body do |line|
24
24
  words << line.chomp
@@ -50,8 +50,8 @@ def _slug(str)
50
50
  s2
51
51
  end
52
52
 
53
-
54
53
  # FIXME duplicated?
54
+
55
55
  def image(args = nil, body = nil)
56
56
  name = @_args[0]
57
57
  _out "<img src='#{name}'></img>"
@@ -67,7 +67,6 @@ def figure(args = nil, body = nil)
67
67
  end
68
68
 
69
69
  def chapter(args = nil, body = nil)
70
- # _errout("chapter")
71
70
  @chapter = @_args.first.to_i
72
71
  @sec = @sec2 = 0
73
72
  title = @_data.split(" ",2)[1]
@@ -108,7 +107,7 @@ def sec(args = nil, body = nil)
108
107
  next_output
109
108
  _out "<h3>#@section #{title}</h3>\n"
110
109
  rescue => err
111
- STDERR.puts "#{err}\n#{err.backtrace}"
110
+ ::STDERR.puts "#{err}\n#{err.backtrace}"
112
111
  exit
113
112
  end
114
113
 
@@ -275,7 +274,7 @@ def quote(args = nil, body = nil)
275
274
  _body {|line| _out line }
276
275
  _out "</blockquote>"
277
276
  rescue => err
278
- STDERR.puts "#{err}\n#{err.backtrace}"
277
+ ::STDERR.puts "#{err}\n#{err.backtrace}"
279
278
  exit
280
279
  end
281
280
 
data/plugin/markdown.rb CHANGED
@@ -8,12 +8,12 @@ SimpleFormats[:t] = %w[` `]
8
8
  SimpleFormats[:s] = %w[<strike> </strike>]
9
9
 
10
10
 
11
- def h1(args = nil, body = nil); _out "# #{FormatLine.var_func_parse(@_data)}"; _optional_blank_line end # atx style for now
12
- def h2(args = nil, body = nil); _out "## #{FormatLine.var_func_parse(@_data)}"; _optional_blank_line end
13
- def h3(args = nil, body = nil); _out "### #{FormatLine.var_func_parse(@_data)}"; _optional_blank_line end
14
- def h4(args = nil, body = nil); _out "#### #{FormatLine.var_func_parse(@_data)}"; _optional_blank_line end
15
- def h5(args = nil, body = nil); _out "##### #{FormatLine.var_func_parse(@_data)}"; _optional_blank_line end
16
- def h6(args = nil, body = nil); _out "###### #{FormatLine.var_func_parse(@_data)}"; _optional_blank_line end
11
+ def h1(args = nil, body = nil); _out "# #{Livetext.interpolate(@_data)}"; _optional_blank_line end # atx style for now
12
+ def h2(args = nil, body = nil); _out "## #{Livetext.interpolate(@_data)}"; _optional_blank_line end
13
+ def h3(args = nil, body = nil); _out "### #{Livetext.interpolate(@_data)}"; _optional_blank_line end
14
+ def h4(args = nil, body = nil); _out "#### #{Livetext.interpolate(@_data)}"; _optional_blank_line end
15
+ def h5(args = nil, body = nil); _out "##### #{Livetext.interpolate(@_data)}"; _optional_blank_line end
16
+ def h6(args = nil, body = nil); _out "###### #{Livetext.interpolate(@_data)}"; _optional_blank_line end
17
17
 
18
18
  def title(args = nil, body = nil)
19
19
  h1
data/plugin/pyggish.rb CHANGED
@@ -1,59 +1,56 @@
1
1
  require 'rouge'
2
2
 
3
- def self.pyg_change(code, klass, style)
4
- color = style[0..6]
5
- modifier = style[8]
6
- mod_open = modifier ? "<#{modifier}>" : ""
7
- mod_close = modifier ? "</#{modifier}>" : ""
8
- rx = /<span class="#{klass}">(?<cname>[^<]+?)<\/span>/
9
- loop do
10
- md = rx.match(code)
11
- break if md.nil?
12
- str = md[:cname]
13
- result = code.sub!(rx, "<font color=#{color}>#{mod_open}#{str}#{mod_close}</font>")
14
- break if result.nil?
15
- end
16
- end
17
-
18
- def self._codebar_color(lexer)
19
- color = case lexer
20
- when :elixir
21
- "#fc88fc"
22
- when :ruby
23
- "#fc8888"
24
- else
25
- raise "Unknown lexer"
26
- end
3
+ # FIXME This whole file has a weird vibe. It has dead code and
4
+ # also exposes methods that are not dot commands...
5
+
6
+ def self.pyg_change(code, klass, style)
7
+ color = style[0..6]
8
+ modifier = style[8]
9
+ mod_open = modifier ? "<#{modifier}>" : ""
10
+ mod_close = modifier ? "</#{modifier}>" : ""
11
+ rx = /<span class="#{klass}">(?<cname>[^<]+?)<\/span>/
12
+ loop do
13
+ md = rx.match(code)
14
+ break if md.nil?
15
+ str = md[:cname]
16
+ result = code.sub!(rx, "<font color=#{color}>#{mod_open}#{str}#{mod_close}</font>")
17
+ break if result.nil?
27
18
  end
19
+ end
28
20
 
29
- def self.pyg_finalize(code, lexer=:elixir)
30
- Styles.each_pair {|klass, style| pyg_change(code, klass, style) }
31
- File.open("debug-pf1", "w") {|f| f.puts code }
32
- code.sub!(/<pre>/, "<pre>\n")
33
- code.gsub!(/<span class="[np]">/, "")
34
- code.gsub!(/<\/span>/, "")
35
- color = _codebar_color(lexer)
36
- code.sub!(/<td class="linenos"/, "<td width=2%></td><td width=5% bgcolor=#{color}")
37
- code.gsub!(/<td/, "<td valign=top ")
38
- code.gsub!(/ class="[^"]*?"/, "") # Get rid of remaining Pygments CSS
39
- File.open("debug-pf2", "w") {|f| f.puts code }
40
- lines = code.split("\n")
41
- # lines.each {|line| line << "\n" }
42
- n1 = lines.index {|x| x =~ /<pre>/ }
43
- n2 = lines.index {|x| x =~ /<\/pre>/ }
44
- # FIXME ?
45
- n1 ||= 0
46
- n2 ||= -1
47
- lines[n1].sub!(/ 1$/, " 1 ")
48
- (n1+1).upto(n2) {|n| lines[n].replace(" " + lines[n] + " ") }
49
- code = lines.join("\n")
50
- File.open("debug-pf3", "w") {|f| f.puts code }
51
- code
21
+ def self._codebar_color(lexer)
22
+ color = case lexer
23
+ when :elixir
24
+ "#fc88fc"
25
+ when :ruby
26
+ "#fc8888"
27
+ else
28
+ raise "Unknown lexer"
52
29
  end
30
+ end
53
31
 
32
+ def self.pyg_finalize(code, lexer=:elixir)
33
+ Styles.each_pair {|klass, style| pyg_change(code, klass, style) }
34
+ code.sub!(/<pre>/, "<pre>\n")
35
+ code.gsub!(/<span class="[np]">/, "")
36
+ code.gsub!(/<\/span>/, "")
37
+ color = _codebar_color(lexer)
38
+ code.sub!(/<td class="linenos"/, "<td width=2%></td><td width=5% bgcolor=#{color}")
39
+ code.gsub!(/<td/, "<td valign=top ")
40
+ code.gsub!(/ class="[^"]*?"/, "") # Get rid of remaining Pygments CSS
41
+ lines = code.split("\n")
42
+ n1 = lines.index {|x| x =~ /<pre>/ }
43
+ n2 = lines.index {|x| x =~ /<\/pre>/ }
44
+ # FIXME ?
45
+ n1 ||= 0
46
+ n2 ||= -1
47
+ lines[n1].sub!(/ 1$/, " 1 ")
48
+ (n1+1).upto(n2) {|n| lines[n].replace(" " + lines[n] + " ") }
49
+ code = lines.join("\n")
50
+ code
51
+ end
54
52
 
55
53
  def _process_code(text)
56
- File.open("debug-pc1", "w") {|f| f.puts text }
57
54
  lines = text.split("\n")
58
55
  lines = lines.select {|x| x !~ /##~ omit/ }
59
56
  @refs = {}
@@ -66,7 +63,6 @@ File.open("debug-pc1", "w") {|f| f.puts text }
66
63
  end
67
64
  lines.map! {|line| " " + line }
68
65
  text2 = lines.join("\n")
69
- File.open("debug-pc2", "w") {|f| f.puts text2 }
70
66
  text.replace(text2)
71
67
  end
72
68
 
@@ -86,34 +82,6 @@ def _colorize!(code, lexer=:elixir)
86
82
  result
87
83
  end
88
84
 
89
- def OLD_ruby
90
- file = @_args.first
91
- if file.nil?
92
- code = "# Ruby code\n"
93
- _body {|line| code << line + "\n" }
94
- else
95
- code = "# Ruby code\n\n" + ::File.read(file)
96
- end
97
-
98
- _process_code(code)
99
- html = _colorize(code, :ruby)
100
- _out "\n#{html}\n "
101
- end
102
-
103
- def OLD_elixir
104
- file = @_args.first
105
- if file.nil?
106
- code = ""
107
- _body {|line| code << line + "\n" }
108
- else
109
- code = ::File.read(file)
110
- end
111
-
112
- _process_code(code)
113
- html = _colorize(code, :elixir)
114
- _out "\n#{html}\n "
115
- end
116
-
117
85
  def fragment
118
86
  lang = @_args.empty? ? :elixir : @_args.first.to_sym # ruby or elixir
119
87
  @_args = []
data/plugin/tutorial.rb CHANGED
@@ -52,8 +52,8 @@ def inout(args = nil, body = nil)
52
52
  end
53
53
 
54
54
  def put_table(src, exp)
55
- t1 = ::File.readlines(src) rescue (abort "t1 = #{src}")
56
- t2 = ::File.readlines(exp) rescue (abort "t2 = #{out}")
55
+ t1 = ::File.readlines(src) rescue (abort "Fail - src = #{src} t1 = #{src}")
56
+ t2 = ::File.readlines(exp) rescue (abort "Fail - src = #{exp} t2 = #{out}")
57
57
  t1 = t1.map {|x| " " + x.sub(/ +$/,"").gsub(/_/, "\\_") }.join
58
58
  t2 = t2.map {|x| " " + x.sub(/ +$/,"").gsub(/_/, "\\_") }.join
59
59
 
@@ -80,7 +80,7 @@ end
80
80
  def testcase(args = nil, body = nil)
81
81
  name = _args.first
82
82
  _out "\n<font size=+1><b>Test: </font><font size=+2><tt>#{name}</tt></font></b></h3><br>"
83
- src, exp = "test/data/#{name}/source.lt3", "test/data/#{name}/expected-output.txt"
83
+ src, exp = "test/snapshots/#{name}/source.lt3", "test/snapshots/#{name}/expected-output.txt"
84
84
  @_args = [src, exp] # Better way to do this??
85
85
  put_table(src, exp)
86
86
  _out "<br>"
@@ -0,0 +1,14 @@
1
+ /Users/Hal/Dropbox/topx/git/livetext/lib/helpers.rb:121:in `handle_dotcmd': Name 'foobar' is unknown (RuntimeError)
2
+ from /Users/Hal/Dropbox/topx/git/livetext/lib/helpers.rb:73:in `process_line'
3
+ from /Users/Hal/Dropbox/topx/git/livetext/lib/helpers.rb:61:in `block in process_file'
4
+ from /Users/Hal/Dropbox/topx/git/livetext/lib/helpers.rb:58:in `loop'
5
+ from /Users/Hal/Dropbox/topx/git/livetext/lib/helpers.rb:58:in `process_file'
6
+ from /Users/Hal/Dropbox/topx/git/livetext/lib/standard.rb:210:in `dot_include'
7
+ from /Users/Hal/Dropbox/topx/git/livetext/lib/helpers.rb:95:in `handle_dotcmd'
8
+ from /Users/Hal/Dropbox/topx/git/livetext/lib/helpers.rb:73:in `process_line'
9
+ from /Users/Hal/Dropbox/topx/git/livetext/lib/helpers.rb:61:in `block in process_file'
10
+ from /Users/Hal/Dropbox/topx/git/livetext/lib/helpers.rb:58:in `loop'
11
+ from /Users/Hal/Dropbox/topx/git/livetext/lib/helpers.rb:58:in `process_file'
12
+ from ../../../bin/livetext:86:in `block in <main>'
13
+ from ../../../bin/livetext:57:in `loop'
14
+ from ../../../bin/livetext:57:in `<main>'
@@ -0,0 +1,7 @@
1
+ This is my
2
+ source file
3
+ which includes file2 here:
4
+ This is file2
5
+ which has an error
6
+ about an unknown command
7
+ in line 5