netlinx-erb 1.0.0
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 +7 -0
- data/README.md +9 -0
- data/doc/Array.html +213 -0
- data/doc/Hash.html +266 -0
- data/doc/HashHelpers.html +413 -0
- data/doc/Helpers.html +2154 -0
- data/doc/NetLinx.html +128 -0
- data/doc/NetLinx/ERB.html +233 -0
- data/doc/NetLinx/ERB/HashHelpers.html +413 -0
- data/doc/NetLinx/ERB/Helpers.html +2157 -0
- data/doc/NetLinx/Rake.html +117 -0
- data/doc/NetLinx/Rake/ERB.html +117 -0
- data/doc/NetLinx/Rake/ERB/Compile.html +354 -0
- data/doc/NetLinx/Rake/ERB/GenerateERB.html +419 -0
- data/doc/NetLinx/Rake/ERB/GenerateRPC.html +349 -0
- data/doc/NetLinx/Rake/ERB/Lines.html +381 -0
- data/doc/NetLinx/Rake/Lines.html +381 -0
- data/doc/RPC.html +683 -0
- data/doc/String.html +322 -0
- data/doc/_index.html +248 -0
- data/doc/class_list.html +58 -0
- data/doc/css/common.css +1 -0
- data/doc/css/full_list.css +57 -0
- data/doc/css/style.css +339 -0
- data/doc/file.README.html +84 -0
- data/doc/file.license.html +73 -0
- data/doc/file_list.html +63 -0
- data/doc/frames.html +26 -0
- data/doc/index.html +84 -0
- data/doc/js/app.js +219 -0
- data/doc/js/full_list.js +181 -0
- data/doc/js/jquery.js +4 -0
- data/doc/method_list.html +237 -0
- data/doc/top-level-namespace.html +114 -0
- data/lib/netlinx-erb.rb +14 -0
- data/lib/netlinx/erb/erb.rb +19 -0
- data/lib/netlinx/erb/hash_helpers.rb +42 -0
- data/lib/netlinx/erb/helpers.rb +399 -0
- data/lib/netlinx/erb/rpc.rb +270 -0
- data/lib/netlinx/rake/erb.rb +26 -0
- data/lib/netlinx/rake/erb/generate_erb.rb +66 -0
- data/lib/netlinx/rake/erb/generate_rpc.rb +31 -0
- data/lib/netlinx/rake/erb/lines.rb +47 -0
- data/license.txt +21 -0
- data/template/Gemfile +9 -0
- data/template/README.md +130 -0
- data/template/Rakefile +11 -0
- data/template/rpc.axi +148 -0
- metadata +234 -0
@@ -0,0 +1,270 @@
|
|
1
|
+
# -----------------------------------------------------------------------------
|
2
|
+
# The MIT License (MIT)
|
3
|
+
|
4
|
+
# Copyright (c) 2014 Alex McLain and Joe McIlvain
|
5
|
+
|
6
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
7
|
+
# of this software and associated documentation files (the "Software"), to deal
|
8
|
+
# in the Software without restriction, including without limitation the rights
|
9
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
10
|
+
# copies of the Software, and to permit persons to whom the Software is
|
11
|
+
# furnished to do so, subject to the following conditions:
|
12
|
+
|
13
|
+
# The above copyright notice and this permission notice shall be included in
|
14
|
+
# all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
17
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
18
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
19
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
20
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
21
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
22
|
+
# THE SOFTWARE.
|
23
|
+
# -----------------------------------------------------------------------------
|
24
|
+
|
25
|
+
require 'netlinx/workspace'
|
26
|
+
|
27
|
+
# :nodoc:
|
28
|
+
class RPC
|
29
|
+
|
30
|
+
# :nodoc:
|
31
|
+
def self.build
|
32
|
+
fn_exp = /
|
33
|
+
(?#
|
34
|
+
Pull out comment\\description above the function, enclosed in slash\\star syntax.
|
35
|
+
Does not have to exist.
|
36
|
+
)
|
37
|
+
^(?<desc>[\t ]*\/\*(?:[^\*]|\*[^\/])*\*\/)?\s*
|
38
|
+
|
39
|
+
(?# Find the function definition. )
|
40
|
+
define_function\s+
|
41
|
+
|
42
|
+
(?# Capture function's return type, if it exists.)
|
43
|
+
(?<rtn>\w+(?<width>\[\d+\])?)??\s*
|
44
|
+
|
45
|
+
(?# Capture the function name. )
|
46
|
+
(?<name>\w+)
|
47
|
+
|
48
|
+
(?#
|
49
|
+
Capture the function parameters.
|
50
|
+
Run this through another regex to get the type\\name pairs.
|
51
|
+
)
|
52
|
+
\(\s*(?<params>.*?)\s*\)\s*
|
53
|
+
|
54
|
+
(?# Capture the function's source code. )
|
55
|
+
{[\r\n]*(?<code>(?:.|\r|\n)*?)?[\r\n]*}
|
56
|
+
/x
|
57
|
+
|
58
|
+
param_exp = /\s*(?:(?<type>\w+)\s+(?<name>\w+(?<width>\[\d*\])?)),?\s*/
|
59
|
+
|
60
|
+
sections = {} # Collect a set of matches for each file, separated by file.
|
61
|
+
|
62
|
+
|
63
|
+
# Pull file list from workspace.
|
64
|
+
workspace_path = Dir['*.apw'].first
|
65
|
+
workspace = NetLinx::Workspace.new file: workspace_path
|
66
|
+
|
67
|
+
file_paths = workspace.projects.first.systems.first.files
|
68
|
+
.map(&:path)
|
69
|
+
.select { |path| path =~ /(\.axi|\.axs)$/ }
|
70
|
+
.reject { |path| path =~ /rpc(?:-|_.*?)?\.axi/ } # Remove RPC files.
|
71
|
+
|
72
|
+
# file_paths = Dir['**/*.axi']
|
73
|
+
|
74
|
+
file_paths.each do |f|
|
75
|
+
str = File.open(f.gsub('\\', '/'), "r:iso-8859-1").read
|
76
|
+
matches = []
|
77
|
+
|
78
|
+
while str =~ fn_exp
|
79
|
+
matches << $~
|
80
|
+
str = $'
|
81
|
+
end
|
82
|
+
|
83
|
+
sections[f] = matches
|
84
|
+
end
|
85
|
+
|
86
|
+
# -----------------------
|
87
|
+
# Documentation Generator
|
88
|
+
# -----------------------
|
89
|
+
|
90
|
+
# output = ''
|
91
|
+
# sections.each do |name, matches|
|
92
|
+
|
93
|
+
# output << "--------------------------------------------------\n"
|
94
|
+
# output << "FILE: '#{name}'\n"
|
95
|
+
# output << "--------------------------------------------------\n"
|
96
|
+
# output << "\n\n"
|
97
|
+
|
98
|
+
# matches.each do |m|
|
99
|
+
# output << m[:desc].to_s
|
100
|
+
# output << "\n"
|
101
|
+
# output << m[:name].to_s
|
102
|
+
# output << "\n\n\n"
|
103
|
+
# end
|
104
|
+
|
105
|
+
# end
|
106
|
+
|
107
|
+
# File.open('functions.axi', 'w+') { |f| f << output }
|
108
|
+
|
109
|
+
|
110
|
+
# ----------------------
|
111
|
+
# RPC Function Generator
|
112
|
+
# ----------------------
|
113
|
+
|
114
|
+
# Generate list of included and excluded files for sanity check.
|
115
|
+
directory_files = Dir['**/*.axi'] + Dir['**/*.axs']
|
116
|
+
|
117
|
+
included_files = ''
|
118
|
+
file_paths.each { |path| included_files << path.to_s.gsub('\\', '/') + "\n" } # TODO: As string.
|
119
|
+
|
120
|
+
excluded_files = ''
|
121
|
+
(directory_files - file_paths.map { |path| path.gsub '\\', '/' }).each { |path| excluded_files << path.to_s.gsub('\\', '/') + "\n" }
|
122
|
+
|
123
|
+
fn_symbols = [] # Symbol names to avoid duplicates.
|
124
|
+
output = ''
|
125
|
+
|
126
|
+
output << <<-EOS
|
127
|
+
(***********************************************************)
|
128
|
+
(* WARNING *)
|
129
|
+
(***********************************************************)
|
130
|
+
(* This file is automatically generated. *)
|
131
|
+
(***********************************************************)
|
132
|
+
|
133
|
+
/*
|
134
|
+
Included Files:
|
135
|
+
---------------
|
136
|
+
#{included_files}
|
137
|
+
|
138
|
+
Excluded Files:
|
139
|
+
---------------
|
140
|
+
#{excluded_files}
|
141
|
+
*/
|
142
|
+
|
143
|
+
|
144
|
+
#if_not_defined RPC_FUNCTION_LIST
|
145
|
+
#define RPC_FUNCTION_LIST 1
|
146
|
+
|
147
|
+
DEFINE_EVENT
|
148
|
+
|
149
|
+
data_event[vdvRPC]
|
150
|
+
{
|
151
|
+
string:
|
152
|
+
{
|
153
|
+
char f_name[255];
|
154
|
+
f_name = rpc_function_name(data.text);
|
155
|
+
|
156
|
+
EOS
|
157
|
+
|
158
|
+
sections.each do |name, matches|
|
159
|
+
output << " /*------------------------------------------------------------------/\n"
|
160
|
+
output << " FILE: '#{name}'\n"
|
161
|
+
output << " /------------------------------------------------------------------*/\n\n"
|
162
|
+
|
163
|
+
|
164
|
+
matches.each do |fn|
|
165
|
+
function_valid = true
|
166
|
+
fn_output = ''
|
167
|
+
return_type = fn[:rtn].nil? ? nil : fn[:rtn].downcase.to_sym
|
168
|
+
# TODO: Calculate return value width.
|
169
|
+
params = []
|
170
|
+
|
171
|
+
# Store function name as symbol and check for duplicates.
|
172
|
+
fn_sym = fn[:name].downcase.to_sym
|
173
|
+
|
174
|
+
if fn_symbols.include? fn_sym
|
175
|
+
output << " // Already defined.\n"
|
176
|
+
function_valid = false
|
177
|
+
else
|
178
|
+
fn_symbols << fn_sym
|
179
|
+
end
|
180
|
+
|
181
|
+
# Retrieve params.
|
182
|
+
str = fn[:params]
|
183
|
+
while str =~ param_exp
|
184
|
+
params << $~
|
185
|
+
str = $'
|
186
|
+
end
|
187
|
+
|
188
|
+
# Generate function handler.
|
189
|
+
fn_output << " if(compare_string(f_name, '#{fn[:name].downcase}'))\n"
|
190
|
+
fn_output << " {\n"
|
191
|
+
|
192
|
+
# Generate return value.
|
193
|
+
if return_type
|
194
|
+
case return_type
|
195
|
+
when :integer
|
196
|
+
fn_output << " #{return_type.to_s} return_value;\n"
|
197
|
+
end
|
198
|
+
|
199
|
+
fn_output << " \n"
|
200
|
+
end
|
201
|
+
|
202
|
+
fn_output << " print(LOG_LEVEL_INFO, 'RPC: #{fn[:name]}()');\n"
|
203
|
+
fn_output << " \n"
|
204
|
+
|
205
|
+
# Set return value equal to function if return value exists.
|
206
|
+
fn_output << " "
|
207
|
+
fn_output << "return_value = " if return_type
|
208
|
+
|
209
|
+
fn_output << "#{fn[:name]}("
|
210
|
+
fn_output << ");\n" if params.empty?
|
211
|
+
|
212
|
+
function_valid = false unless [nil, :integer].include? return_type
|
213
|
+
|
214
|
+
# Generate parameters.
|
215
|
+
param_index = 0
|
216
|
+
params.each do |param|
|
217
|
+
param_index += 1
|
218
|
+
|
219
|
+
valid_params = [:integer]
|
220
|
+
type = param[:type].downcase.to_sym
|
221
|
+
|
222
|
+
unless valid_params.include? type
|
223
|
+
function_valid = false
|
224
|
+
break
|
225
|
+
end
|
226
|
+
|
227
|
+
case type
|
228
|
+
when :integer
|
229
|
+
fn_output << "\n rpc_get_arg_i(#{param_index}, data.text),"
|
230
|
+
end
|
231
|
+
end
|
232
|
+
|
233
|
+
# Remove trailing comma from last arg.
|
234
|
+
fn_output.chop! unless params.empty?
|
235
|
+
|
236
|
+
# Close function.
|
237
|
+
fn_output << "\n );\n" unless params.empty?
|
238
|
+
|
239
|
+
# Print return value if exists.
|
240
|
+
if return_type
|
241
|
+
fn_output << " \n"
|
242
|
+
|
243
|
+
case return_type
|
244
|
+
when :integer
|
245
|
+
fn_output << " print(LOG_LEVEL_INFO, \"'RPC RTN: ', itoa(return_value)\");\n"
|
246
|
+
end
|
247
|
+
end
|
248
|
+
|
249
|
+
fn_output << " }\n\n"
|
250
|
+
|
251
|
+
# Store function string.
|
252
|
+
if function_valid
|
253
|
+
output << fn_output
|
254
|
+
else
|
255
|
+
output << " // Skipped:\n"
|
256
|
+
output << " // #{fn[:name]}(#{fn[:params]})\n\n"
|
257
|
+
end
|
258
|
+
end
|
259
|
+
|
260
|
+
end
|
261
|
+
|
262
|
+
output << " }\n"
|
263
|
+
output << "}\n"
|
264
|
+
output << "#end_if\n\n"
|
265
|
+
|
266
|
+
|
267
|
+
File.open('include/rpc-functions.axi', 'w+') { |f| f << output }
|
268
|
+
end
|
269
|
+
|
270
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
|
2
|
+
require 'yard'
|
3
|
+
require 'netlinx/rake/compile'
|
4
|
+
require 'netlinx/rake/src'
|
5
|
+
|
6
|
+
require_relative 'erb/generate_erb'
|
7
|
+
require_relative 'erb/generate_rpc'
|
8
|
+
require_relative 'erb/lines'
|
9
|
+
|
10
|
+
|
11
|
+
task :default=>[:generate_rpc, :check_for_docs, :compile, :pack]
|
12
|
+
|
13
|
+
NetLinx::Rake::ERB::Lines.new
|
14
|
+
NetLinx::Rake::ERB::GenerateERB.new
|
15
|
+
NetLinx::Rake::ERB::GenerateRPC.new :generate_rpc => :generate_erb
|
16
|
+
|
17
|
+
# Generate Ruby documentation.
|
18
|
+
YARD::Rake::YardocTask.new :doc do |t|
|
19
|
+
puts "\n"
|
20
|
+
# t.options = %w(- README.md)
|
21
|
+
end
|
22
|
+
|
23
|
+
# Make sure the readme has been converted to HTML.
|
24
|
+
task :check_for_docs do
|
25
|
+
Rake::Task[:doc].invoke unless Dir.exists? 'doc'
|
26
|
+
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
|
2
|
+
require 'rake'
|
3
|
+
require 'rake/tasklib'
|
4
|
+
|
5
|
+
module NetLinx
|
6
|
+
module Rake
|
7
|
+
module ERB
|
8
|
+
|
9
|
+
# Generate Netlinx source code files from the erb template files.
|
10
|
+
class GenerateERB < ::Rake::TaskLib
|
11
|
+
|
12
|
+
attr_accessor :name
|
13
|
+
|
14
|
+
def initialize name = :generate_erb
|
15
|
+
@name = name
|
16
|
+
yield self if block_given?
|
17
|
+
|
18
|
+
desc "Generate Netlinx source code files from the erb template files."
|
19
|
+
|
20
|
+
task(name) do
|
21
|
+
require 'netlinx-erb'
|
22
|
+
|
23
|
+
puts "Generating NetLinx files from ERB..."
|
24
|
+
puts "------------------------------------"
|
25
|
+
|
26
|
+
templates = Dir['include/**/*.erb']
|
27
|
+
|
28
|
+
outputs = templates.map { |str| str.gsub /\.erb$/, '' }
|
29
|
+
|
30
|
+
templates.each do |template|
|
31
|
+
file_name = template.gsub /\.erb$/, ''
|
32
|
+
puts " #{file_name}"
|
33
|
+
|
34
|
+
header = $AUTOGEN_HEADER = <<-HEADER
|
35
|
+
(***********************************************************)
|
36
|
+
(* WARNING *)
|
37
|
+
(***********************************************************}
|
38
|
+
This file was generated from the following template
|
39
|
+
and should NOT be edited directly:
|
40
|
+
|
41
|
+
#{template}
|
42
|
+
|
43
|
+
See the documentation at `doc/index.html` for
|
44
|
+
information about maintaining this project.
|
45
|
+
|
46
|
+
Generated with netlinx-erb:
|
47
|
+
https://github.com/amclain/netlinx-erb
|
48
|
+
{***********************************************************)
|
49
|
+
|
50
|
+
HEADER
|
51
|
+
buffer = header + File.read(template)
|
52
|
+
|
53
|
+
File.open file_name, 'w+' do |file|
|
54
|
+
file.write ::ERB.new(buffer, nil, '%<>-')
|
55
|
+
.result(NetLinx::ERB.binding)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
puts "\nDone."
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
|
2
|
+
require 'rake'
|
3
|
+
require 'rake/tasklib'
|
4
|
+
|
5
|
+
module NetLinx
|
6
|
+
module Rake
|
7
|
+
module ERB
|
8
|
+
|
9
|
+
# Generate NetLinx RPC file.
|
10
|
+
class GenerateRPC < ::Rake::TaskLib
|
11
|
+
|
12
|
+
attr_accessor :name
|
13
|
+
|
14
|
+
def initialize name = :generate_rpc
|
15
|
+
@name = name
|
16
|
+
yield self if block_given?
|
17
|
+
|
18
|
+
desc "Generate NetLinx RPC file."
|
19
|
+
|
20
|
+
task(name) do
|
21
|
+
require 'netlinx-erb'
|
22
|
+
puts "\n\nGenerating RPC functions..."
|
23
|
+
RPC.build
|
24
|
+
puts "Done.\n\n"
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
|
2
|
+
require 'rake'
|
3
|
+
require 'rake/tasklib'
|
4
|
+
|
5
|
+
module NetLinx
|
6
|
+
module Rake
|
7
|
+
module ERB
|
8
|
+
|
9
|
+
# Show lines of code for .axi files.
|
10
|
+
class Lines < ::Rake::TaskLib
|
11
|
+
|
12
|
+
attr_accessor :name
|
13
|
+
|
14
|
+
def initialize name = :lines
|
15
|
+
@name = name
|
16
|
+
yield self if block_given?
|
17
|
+
|
18
|
+
desc "Show lines of code for .axi files."
|
19
|
+
|
20
|
+
task(name) do
|
21
|
+
require 'netlinx/workspace'
|
22
|
+
|
23
|
+
workspace_path = Dir['*.apw'].first
|
24
|
+
workspace = NetLinx::Workspace.new file: workspace_path
|
25
|
+
file_paths = workspace.projects.first.systems.first.files
|
26
|
+
.map(&:path)
|
27
|
+
.select { |path| File.extname(path) == '.axs' or File.extname(path) == '.axi' }
|
28
|
+
|
29
|
+
puts "\n\nLines of code..."
|
30
|
+
puts "----------------"
|
31
|
+
|
32
|
+
lines_by_path = file_paths.map { |path| {path: path, lines: File.read(path).lines.count} }
|
33
|
+
lines_by_path.each do |line_by_path|
|
34
|
+
puts "#{line_by_path[:lines]}\t#{line_by_path[:path]}"
|
35
|
+
end
|
36
|
+
|
37
|
+
puts "-----\t--------------------"
|
38
|
+
total = 0
|
39
|
+
lines_by_path.map { |l| l[:lines] }.each { |lines| total += lines }
|
40
|
+
puts "#{total}\tTotal"
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
data/license.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015 Alex McLain and Joe McIlvain
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|