livetext 0.9.61 → 0.9.62
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/livetext/function_caller.rb +5 -1
- data/lib/livetext/function_registry.rb +12 -0
- data/lib/livetext/functions.rb +1 -0
- data/lib/livetext/userapi.rb +1 -1
- data/lib/livetext/version.rb +1 -1
- data/test/snapshots/simple_func_api/match-output.txt +1 -1
- data/test/snapshots/simple_func_api/source.lt3 +1 -0
- data/test/snapshots/system_info/match-output.txt +1 -1
- data/test/unit/all.rb +1 -0
- data/test/unit/function_api_access.rb +82 -0
- data/test/unit/function_caller.rb +2 -1
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 61c11b22070e565c5c25735ea1134d58249a5f441f0ed3c1f9eeb0f8bbf7c628
|
4
|
+
data.tar.gz: feff45c934b1ecb8757dcd1ea3fad4947e7383063faa9f3f68506dc73c99ff9e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6e9fa6aeec991337d703e223f20daef4b65b0d261be3cdcfbce99854ab263c0660e2288de725411ba3eaa29c1e8e65ae421dddd433c187e813b10b052f658f1b
|
7
|
+
data.tar.gz: f899d4de12921521b8d06adb35d10ed1f530cab3f9bc1d8c665ddb9bd7eb54b397d6bf7bc0a8686ecdfbd71a9aba18b470da0da38f2687d09ca03ba662b30f7b
|
@@ -1,7 +1,8 @@
|
|
1
1
|
# FunctionCaller - Provides simple method-style access to Livetext functions
|
2
2
|
class Livetext::FunctionCaller
|
3
|
-
def initialize(function_registry)
|
3
|
+
def initialize(function_registry, api)
|
4
4
|
@registry = function_registry
|
5
|
+
@api = api
|
5
6
|
end
|
6
7
|
|
7
8
|
# Dynamically handle method calls to function names
|
@@ -10,6 +11,9 @@ class Livetext::FunctionCaller
|
|
10
11
|
function_name = name.to_s
|
11
12
|
param = args.first || ""
|
12
13
|
|
14
|
+
# Set api on Livetext::Functions so all functions can access it
|
15
|
+
Livetext::Functions.api = @api
|
16
|
+
|
13
17
|
@registry.call(function_name, param)
|
14
18
|
rescue => e
|
15
19
|
"[Error calling function #{function_name}: #{e.message}]"
|
@@ -28,6 +28,18 @@ class Livetext::FunctionRegistry
|
|
28
28
|
elsif @builtin_functions[name_sym]
|
29
29
|
call_function(name, @builtin_functions[name_sym], param)
|
30
30
|
else
|
31
|
+
# Fall back to Livetext::Functions for backward compatibility
|
32
|
+
fobj = ::Livetext::Functions.new
|
33
|
+
if fobj.respond_to?(name_sym)
|
34
|
+
method = fobj.method(name_sym)
|
35
|
+
if method.parameters.empty?
|
36
|
+
result = fobj.send(name_sym)
|
37
|
+
else
|
38
|
+
result = fobj.send(name_sym, param)
|
39
|
+
end
|
40
|
+
return result.to_s if result
|
41
|
+
end
|
42
|
+
|
31
43
|
"[Error evaluating $$#{name}(#{param})]"
|
32
44
|
end
|
33
45
|
end
|
data/lib/livetext/functions.rb
CHANGED
data/lib/livetext/userapi.rb
CHANGED
@@ -20,7 +20,7 @@ class Livetext::UserAPI
|
|
20
20
|
@vars = live.vars
|
21
21
|
@html = Livetext::HTML.new(self)
|
22
22
|
@expander = Livetext::Expansion.new(live)
|
23
|
-
@funcs = Livetext::FunctionCaller.new(live.function_registry)
|
23
|
+
@funcs = Livetext::FunctionCaller.new(live.function_registry, self)
|
24
24
|
end
|
25
25
|
|
26
26
|
def api
|
data/lib/livetext/version.rb
CHANGED
@@ -4,7 +4,7 @@
|
|
4
4
|
4 /<p>Directory: .*livetext.*</p>/
|
5
5
|
5 <p>Platform: universal.x86_64-darwin22</p>
|
6
6
|
6 <p>Ruby version: 2.6.10</p>
|
7
|
-
7 <p>Livetext version: 0.9.
|
7
|
+
7 <p>Livetext version: 0.9.61</p>
|
8
8
|
8 <p>Reverse of 'hello': olleh</p>
|
9
9
|
9 <p>Square root of 16: 4</p>
|
10
10
|
10 /<p>Random \(1-10\): \d+</p>/
|
data/test/unit/all.rb
CHANGED
@@ -11,6 +11,7 @@ require_relative 'variable_manager'
|
|
11
11
|
require_relative 'functions'
|
12
12
|
require_relative 'function_registry'
|
13
13
|
require_relative 'function_caller'
|
14
|
+
require_relative 'function_api_access'
|
14
15
|
require_relative 'mixin_functions_class'
|
15
16
|
require_relative 'formatter'
|
16
17
|
require_relative 'formatter_component'
|
@@ -0,0 +1,82 @@
|
|
1
|
+
require 'minitest/autorun'
|
2
|
+
require_relative '../../lib/livetext'
|
3
|
+
|
4
|
+
class TestFunctionAPIAccess < Minitest::Test
|
5
|
+
def setup
|
6
|
+
@live = Livetext.new
|
7
|
+
@live.vars.set(:View, "test_view")
|
8
|
+
@live.vars.set(:"post.id", "0001")
|
9
|
+
end
|
10
|
+
|
11
|
+
def test_scriptorium_image_scenario
|
12
|
+
# This test mimics the exact scenario from Scriptorium's image function
|
13
|
+
# Define the asset function directly in Livetext::Functions (like in Scriptorium)
|
14
|
+
Livetext::Functions.class_eval do
|
15
|
+
def asset(param)
|
16
|
+
# Get view and post information (exactly like in Scriptorium)
|
17
|
+
vname = self.class.api.vars.to_h[:View]
|
18
|
+
postid = self.class.api.vars.to_h[:"post.id"]
|
19
|
+
"assets/#{postid}/#{param}" # Simplified version of the asset function
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
# Test calling it through api.funcs (like the image function in Scriptorium)
|
24
|
+
result = @live.api.funcs.asset("test.jpg")
|
25
|
+
|
26
|
+
assert_equal "assets/0001/test.jpg", result
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_function_can_access_api_vars
|
30
|
+
# Define a function that needs access to api.vars (like the asset function in Scriptorium)
|
31
|
+
Livetext::Functions.class_eval do
|
32
|
+
def test_asset_function(param)
|
33
|
+
# This mimics the asset function from Scriptorium that needs api.vars
|
34
|
+
vname = self.class.api.vars.to_h[:View]
|
35
|
+
postid = self.class.api.vars.to_h[:"post.id"]
|
36
|
+
"view=#{vname}, post=#{postid}, file=#{param}"
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
# Test calling it through api.funcs (like the image function in Scriptorium)
|
41
|
+
result = @live.api.funcs.test_asset_function("test.jpg")
|
42
|
+
|
43
|
+
assert_equal "view=test_view, post=0001, file=test.jpg", result
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_function_can_access_api_vars_without_params
|
47
|
+
# Define a function that needs access to api.vars but takes no parameters
|
48
|
+
Livetext::Functions.class_eval do
|
49
|
+
def test_view_info
|
50
|
+
vname = self.class.api.vars.to_h[:View]
|
51
|
+
postid = self.class.api.vars.to_h[:"post.id"]
|
52
|
+
"view=#{vname}, post=#{postid}"
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
# Test calling it through api.funcs
|
57
|
+
result = @live.api.funcs.test_view_info()
|
58
|
+
|
59
|
+
assert_equal "view=test_view, post=0001", result
|
60
|
+
end
|
61
|
+
|
62
|
+
def test_function_handles_missing_api_gracefully
|
63
|
+
# Define a function that tries to access api but it's not set
|
64
|
+
Livetext::Functions.class_eval do
|
65
|
+
def test_no_api
|
66
|
+
if self.class.api
|
67
|
+
"api available"
|
68
|
+
else
|
69
|
+
"no api"
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
# Clear the api to test the fallback
|
75
|
+
Livetext::Functions.api = nil
|
76
|
+
|
77
|
+
# Test calling it through api.funcs - should still work because we set it in method_missing
|
78
|
+
result = @live.api.funcs.test_no_api()
|
79
|
+
|
80
|
+
assert_equal "api available", result
|
81
|
+
end
|
82
|
+
end
|
@@ -5,7 +5,8 @@ require_relative '../../lib/livetext/function_caller'
|
|
5
5
|
class TestFunctionCaller < Minitest::Test
|
6
6
|
def setup
|
7
7
|
@registry = Livetext::FunctionRegistry.new
|
8
|
-
@
|
8
|
+
@api = Object.new # Mock api object for testing
|
9
|
+
@caller = Livetext::FunctionCaller.new(@registry, @api)
|
9
10
|
end
|
10
11
|
|
11
12
|
def test_calls_builtin_functions
|
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.9.
|
4
|
+
version: 0.9.62
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Hal Fulton
|
@@ -241,6 +241,7 @@ files:
|
|
241
241
|
- test/unit/double.rb
|
242
242
|
- test/unit/formatter.rb
|
243
243
|
- test/unit/formatter_component.rb
|
244
|
+
- test/unit/function_api_access.rb
|
244
245
|
- test/unit/function_caller.rb
|
245
246
|
- test/unit/function_registry.rb
|
246
247
|
- test/unit/functions.rb
|