digicus_web_frontend 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 4ec87fdb73b204abed2ae50fd2436d96270577276aa00b22019d0da8cdfa50bc
4
+ data.tar.gz: 1920f383e67bdac78978a778fe8aae9c48a9abe58294d73f3aff208e27f49dea
5
+ SHA512:
6
+ metadata.gz: 438a13b1df9faf5405c2bd770faecdfbdc76b819ffba4fa5a962cdc43a1ec0108db59006f7d911ed34d243d6d45278885cd475610d739e003f6d5c442636d280
7
+ data.tar.gz: 9b2f722fa7d9646203d34880872cb9b16ca951cb897352352cbfb2ab1efee037569db749f90f20a29c96c25be8e367ef14d637f5a48bf58dce22f282ec79a9b9
@@ -0,0 +1,83 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'dtr_core'
4
+ require 'json'
5
+
6
+ module DigicusWebFrontend
7
+ # This is a simple compiler class that takes a DTR code and transpiles it to JSON.
8
+ class Compiler
9
+ attr_reader :json_code
10
+
11
+ def initialize(json_code)
12
+ @json_code = JSON.parse(json_code)
13
+ end
14
+
15
+ def self.to_dtr(json_code)
16
+ new(json_code).to_dtr
17
+ end
18
+
19
+ def to_dtr
20
+ DTRCore::Contract.new(
21
+ json_code['contract_name'],
22
+ form_state(json_code['contract_state']),
23
+ form_functions(json_code['contract_interface']),
24
+ form_user_defined_types(json_code['contract_user_defined_types']),
25
+ form_functions(json_code['contract_helpers']),
26
+ nil # non_translatables
27
+ ).to_s
28
+ end
29
+
30
+ private
31
+
32
+ def form_state(state)
33
+ return [] if state.nil? || state.empty?
34
+
35
+ state.map do |s|
36
+ json_s = JSON.parse(s)
37
+
38
+ DTRCore::State.new(
39
+ json_s['name'],
40
+ json_s['type'],
41
+ json_s['initial_value']
42
+ )
43
+ end
44
+ end
45
+
46
+ def form_functions(functions)
47
+ return [] if functions.nil? || functions.empty?
48
+
49
+ functions.map do |f|
50
+ json_f = JSON.parse(f)
51
+
52
+ DTRCore::Function.new(
53
+ json_f['name'],
54
+ json_f['inputs'].map { |i| i.transform_keys(&:to_sym) },
55
+ json_f['output'],
56
+ json_f['instructions'].map do |i|
57
+ ins = JSON.parse(i)
58
+ DTRCore::Instruction.new(
59
+ ins['instruction'],
60
+ ins['inputs'],
61
+ ins['assign'],
62
+ ins['scope'],
63
+ ins['id']
64
+ )
65
+ end
66
+ )
67
+ end
68
+ end
69
+
70
+ def form_user_defined_types(user_defined_types)
71
+ return [] if user_defined_types.nil? || user_defined_types.empty?
72
+
73
+ user_defined_types.map do |t|
74
+ json_t = JSON.parse(t)
75
+
76
+ DTRCore::UserDefinedType.new(
77
+ json_t['name'],
78
+ json_t['attributes']
79
+ )
80
+ end
81
+ end
82
+ end
83
+ end
@@ -0,0 +1,44 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Core logic for consuming Digicus Textual Representation (DTR) files.
4
+ module DigicusWebFrontend
5
+ autoload :Compiler, './lib/digicus_web_frontend/compiler'
6
+ end
7
+
8
+ def silence_streams
9
+ original_stdout = $stdout
10
+ original_stderr = $stderr
11
+ $stdout = File.new('/dev/null', 'w')
12
+ $stderr = File.new('/dev/null', 'w')
13
+ yield
14
+ ensure
15
+ $stdout = original_stdout
16
+ $stderr = original_stderr
17
+ end
18
+
19
+ if __FILE__ == $PROGRAM_NAME
20
+ input = ARGV[0]
21
+
22
+ if input == 'version'
23
+ gemspec_path = 'digicus_web_frontend.gemspec'
24
+
25
+ # Extract version from gemspec
26
+ gemspec = File.read(gemspec_path)
27
+ version_match = gemspec.match(/\.version\s*=\s*["']([^"']+)["']/)
28
+ version = version_match[1] if version_match
29
+
30
+ puts version
31
+ else
32
+
33
+ if input.nil?
34
+ puts 'Usage: ./digicus_web_frontend <file_path>'
35
+ exit(1)
36
+ end
37
+
38
+ json_for_web = silence_streams do
39
+ DigicusWebFrontend::Compiler.to_dtr(File.read(input))
40
+ end
41
+
42
+ puts json_for_web
43
+ end
44
+ end
metadata ADDED
@@ -0,0 +1,46 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: digicus_web_frontend
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Rob Durst
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2024-07-17 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: DTR to JSON compiler.
14
+ email:
15
+ - me@robdurst.com
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - lib/digicus_web_frontend.rb
21
+ - lib/digicus_web_frontend/compiler.rb
22
+ homepage: https://spaced-out-thoughts-dev-foundation.github.io/digicus/
23
+ licenses:
24
+ - MIT
25
+ metadata:
26
+ rubygems_mfa_required: 'true'
27
+ post_install_message:
28
+ rdoc_options: []
29
+ require_paths:
30
+ - lib
31
+ required_ruby_version: !ruby/object:Gem::Requirement
32
+ requirements:
33
+ - - ">="
34
+ - !ruby/object:Gem::Version
35
+ version: 3.2.0
36
+ required_rubygems_version: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ requirements: []
42
+ rubygems_version: 3.5.13
43
+ signing_key:
44
+ specification_version: 4
45
+ summary: DTR to JSON compiler.
46
+ test_files: []