livetext 0.5.9 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: db1c4c67b59a4f9386d624c09e3ba3bd0a1f4ed7
4
- data.tar.gz: 9d36cfe4d798dfb355d45dc024e2f38a41572d7c
3
+ metadata.gz: 342432e589fbafc4dea447d96303c9da09f88b3b
4
+ data.tar.gz: 364013916fd421dd922424ad1d9e709a1260723a
5
5
  SHA512:
6
- metadata.gz: f46d91a2cb182faf39f1e5b129bf56c94773c5fa9448074899eb4a02707521224bb02923fba6198bd4dd4c49d00fabef39fe343bfe43df416beeded4ea280c17
7
- data.tar.gz: 791b5256347e641ffdd378e566bf06affcdb3844ee7557555865606ecbcabfd1dbb640086233b64b054d1e4a662fb942795fe19926d81c05b9328b272daae7ca
6
+ metadata.gz: f60a26574a8bb62ebb2060c5566643321b2719a70998a7b594ecce614128717b95f8f02edfe1f4eb68dbd4547cd04e06ac70c472f6f6d00895dd6457a6eca49b
7
+ data.tar.gz: 46098f43661bc4d4eb0a3c22b499996a230f3f56a5636fd53528bf54632ed59af6f6357f19fffb08d8448aa790f5b88980087302fbe53cbe12b8c50980762e05
data/lib/livetext.rb CHANGED
@@ -15,7 +15,7 @@ class Enumerator
15
15
  end
16
16
 
17
17
  class Livetext
18
- VERSION = "0.5.9"
18
+ VERSION = "0.6.0"
19
19
 
20
20
  Space = " "
21
21
 
@@ -101,12 +101,12 @@ class Livetext
101
101
  def self.handle_sname(sigil, line)
102
102
  obj = @main # Livetext::Objects[sigil]
103
103
  name = _get_name(obj, sigil, line)
104
- unless obj.respond_to?(name)
105
- abort "#{obj.where}: '#{name}' is unknown"
106
- return
107
- end
104
+ # unless obj.respond_to?(name)
105
+ # abort "#{obj.where}: '#{name}' is unknown"
106
+ # return
107
+ # end
108
108
 
109
- if name == "notes"
109
+ if name == "notes" # FIXME wtf
110
110
  obj.notes
111
111
  else
112
112
  obj.send(name)
@@ -134,6 +134,11 @@ class Livetext::Functions # Functions will go here... user-def AND pre-def??
134
134
  end
135
135
 
136
136
  module Livetext::Helpers
137
+
138
+ def _check_existence(file)
139
+ raise "No such file found" unless File.exist?(file)
140
+ end
141
+
137
142
  def _source
138
143
  @input
139
144
  end
@@ -497,6 +502,25 @@ module Livetext::Standard
497
502
  end
498
503
 
499
504
  def mixin
505
+ name = _args.first # Expect a module name
506
+ file = "#{Plugins}/" + name.downcase + ".rb"
507
+ return if @_mixins.include?(file)
508
+ file = "./#{name}.rb" unless File.exist?(file)
509
+ _check_existence(file)
510
+
511
+ @_mixins << file
512
+ _pushfile(file)
513
+ newmod = Module.new
514
+ $mods << newmod
515
+ Object.const_set(name.capitalize, newmod)
516
+ newmod.instance_eval(File.read(file))
517
+ init = "init_#{name}"
518
+ self.send(init) if self.respond_to? init
519
+ _optional_blank_line
520
+ _popfile
521
+ end
522
+
523
+ def old_mixin
500
524
  name = _args.first
501
525
  file = "#{Plugins}/" + name + ".rb"
502
526
  return if @_mixins.include?(file)
@@ -510,7 +534,6 @@ module Livetext::Standard
510
534
  self.class.class_eval(::File.read(file))
511
535
  m1 = main.methods.reject {|x| x.to_s[0] == "_" }
512
536
  $meths[file] = m1 - m0
513
- TTY.puts "commands = #{$meths.inspect}"
514
537
  init = "init_#{name}"
515
538
  self.send(init) if self.respond_to? init
516
539
  _optional_blank_line
@@ -520,8 +543,8 @@ TTY.puts "commands = #{$meths.inspect}"
520
543
  def copy
521
544
  file = _args.first
522
545
  _pushfile(file)
523
- # TTY.puts "copy: ****** file = #{file}"
524
- @output.puts ::File.readlines(file)
546
+ text = ::File.readlines(file)
547
+ @output.puts text
525
548
  _optional_blank_line
526
549
  _popfile
527
550
  end
@@ -606,14 +629,22 @@ class Livetext::System < BasicObject
606
629
  end
607
630
 
608
631
  def method_missing(name, *args)
609
- # Idea: Capture source line for error messages
632
+ # TTY.puts $mods.inspect
633
+ $mods.reverse.each do |mod|
634
+ #TTY.puts "mod methods = #{mod.module_methods.inspect}"
635
+ if mod.respond_to?(name)
636
+ mod.send(name, *args)
637
+ return
638
+ end
639
+ end
640
+ TTY.puts "Got here"
610
641
  _puts " Error: Method '#{name}' is not defined."
611
642
  puts caller.map {|x| " " + x }
612
643
  exit
613
644
  end
614
645
  end
615
646
 
616
- $meths = {}
647
+ $mods = []
617
648
 
618
649
  if $0 == __FILE__
619
650
  Livetext.handle_file(ARGV[0] || STDIN)
data/livetext.gemspec CHANGED
@@ -1,7 +1,9 @@
1
+ require_relative "./lib/livetext"
2
+
1
3
  Gem::Specification.new do |s|
2
4
  system("rm -f *.gem")
3
5
  s.name = 'livetext'
4
- s.version = '0.5.9'
6
+ s.version = Livetext::VERSION
5
7
  s.date = '2017-03-09'
6
8
  s.summary = "A smart processor for text"
7
9
  s.description = "A smart text processor extensible in Ruby"
@@ -28,9 +30,6 @@ Gem::Specification.new do |s|
28
30
  ./test
29
31
  ./test/cleanup
30
32
  ./test/newtest
31
- ./test/rawtext.inc
32
- ./test/simple_mixin.rb
33
- ./test/simplefile.inc
34
33
  ./test/test.rb
35
34
  ./test/testfiles
36
35
  ./test/testfiles/basic_formatting
data/test/test.rb CHANGED
@@ -7,27 +7,29 @@ require 'livetext'
7
7
 
8
8
  class TestingLiveText < MiniTest::Test
9
9
 
10
+ TTY = File.open("/dev/tty","w")
11
+
10
12
  def external_files
11
13
  tag = caller[0]
12
14
  n1, n2 = tag.index("`")+6, tag.index("'")-1
13
15
  base = tag[n1..n2]
14
- name = "test/testfiles/#{base}/xxx"
15
-
16
- src, out, exp = name.sub(/xxx/, "source.ltx"), name.sub(/xxx/, "actual-output.txt"), name.sub(/xxx/, "expected-output.txt")
17
- err, erx = name.sub(/xxx/, "actual-error.txt"), name.sub(/xxx/, "expected-error.txt")
18
- cmd = "./bin/livetext #{src} >#{out} 2>#{err}"
19
- # puts cmd
20
- system(cmd)
21
- output, expected, errors, errexp = File.read(out), File.read(exp), File.read(err), File.read(erx)
22
-
23
- out_ok = output == expected
24
- err_ok = errors == errexp
25
- bad_out = "--- Expected: \n#{expected}\n--- Output: \n#{output}\n"
26
- bad_err = "--- Error Expected: \n#{errexp}\n--- Error Output: \n#{errors}\n"
27
-
28
- assert(out_ok, bad_out)
29
- assert(err_ok, bad_err)
30
- system("rm -f #{out} #{err}") # only on success
16
+ origin = Dir.pwd
17
+ Dir.chdir("test/testfiles/#{base}") do
18
+ src, out, exp = "source.ltx", "actual-output.txt", "expected-output.txt"
19
+ err, erx = "actual-error.txt", "expected-error.txt"
20
+ cmd = "../../../bin/livetext #{src} >#{out} 2>#{err}"
21
+ system(cmd)
22
+ output, expected, errors, errexp = File.read(out), File.read(exp), File.read(err), File.read(erx)
23
+
24
+ out_ok = output == expected
25
+ err_ok = errors == errexp
26
+ bad_out = "--- Expected: \n#{expected}\n--- Output: \n#{output}\n"
27
+ bad_err = "--- Error Expected: \n#{errexp}\n--- Error Output: \n#{errors}\n"
28
+
29
+ assert(out_ok, bad_out)
30
+ assert(err_ok, bad_err)
31
+ system("rm -f #{out} #{err}") # only on success
32
+ end
31
33
  end
32
34
 
33
35
  def test_hello_world; external_files end
@@ -39,8 +41,6 @@ class TestingLiveText < MiniTest::Test
39
41
  def test_simple_vars; external_files end
40
42
  def test_more_complex_vars; external_files end
41
43
 
42
- # def test_sigil_can_change; external_files end
43
-
44
44
  def test_def_method; external_files end
45
45
 
46
46
  def test_single_raw_line; external_files end
@@ -1,4 +1,4 @@
1
1
  A copy command
2
2
  does not interpret its input:
3
- .copy test/rawtext.inc
3
+ .copy rawtext.inc
4
4
  That's all.
@@ -2,5 +2,5 @@ The copy command
2
2
  copies any file
3
3
  without interpretation,
4
4
  such as:
5
- .copy test/simplefile.inc
5
+ .copy simplefile.inc
6
6
  That is all.
@@ -1,6 +1,6 @@
1
1
  Here I am
2
2
  trying to
3
3
  include
4
- .include test/simplefile.inc
4
+ .include simplefile.inc
5
5
  I hope that
6
6
  worked.
@@ -1,6 +1,6 @@
1
1
  Here I am
2
2
  testing a simple mixin
3
- .mixin test/simple_mixin
3
+ .mixin simple_mixin
4
4
  Now call it:
5
5
  .hello_world
6
6
  That's all.
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: livetext
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.9
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hal Fulton
@@ -32,9 +32,6 @@ files:
32
32
  - "./notes.txt"
33
33
  - "./test/cleanup"
34
34
  - "./test/newtest"
35
- - "./test/rawtext.inc"
36
- - "./test/simple_mixin.rb"
37
- - "./test/simplefile.inc"
38
35
  - "./test/test.rb"
39
36
  - "./test/testfiles/basic_formatting/expected-error.txt"
40
37
  - "./test/testfiles/basic_formatting/expected-output.txt"
@@ -105,9 +102,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
105
102
  version: '0'
106
103
  requirements: []
107
104
  rubyforge_project:
108
- rubygems_version: 2.4.2
105
+ rubygems_version: 2.2.2
109
106
  signing_key:
110
107
  specification_version: 4
111
108
  summary: A smart processor for text
112
109
  test_files: []
113
- has_rdoc:
data/test/rawtext.inc DELETED
@@ -1,4 +0,0 @@
1
- This is not a comment:
2
- .comment woohoo!
3
- This is not a method:
4
- .no_such_method
data/test/simple_mixin.rb DELETED
@@ -1,3 +0,0 @@
1
- def hello_world
2
- puts "Hello, world."
3
- end
data/test/simplefile.inc DELETED
@@ -1,2 +0,0 @@
1
- a simple
2
- include file.