netlinx-erb 1.1.0 → 2.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.
@@ -100,35 +100,47 @@
100
100
 
101
101
 
102
102
  <li class="r1 ">
103
- <span class='object_link'><a href="NetLinx/ERB/Helpers.html#execute_erb-instance_method" title="NetLinx::ERB::Helpers#execute_erb (method)">#execute_erb</a></span>
104
- <small>NetLinx::ERB::Helpers</small>
103
+ <span class='object_link'><a href="NetLinx/ERB.html#execute-class_method" title="NetLinx::ERB.execute (method)">execute</a></span>
104
+ <small>NetLinx::ERB</small>
105
105
  </li>
106
106
 
107
107
 
108
108
  <li class="r2 ">
109
+ <span class='object_link'><a href="NetLinx/ERB.html#generate_axi_files_from_template-class_method" title="NetLinx::ERB.generate_axi_files_from_template (method)">generate_axi_files_from_template</a></span>
110
+ <small>NetLinx::ERB</small>
111
+ </li>
112
+
113
+
114
+ <li class="r1 ">
109
115
  <span class='object_link'><a href="NetLinx/ERB/Helpers.html#generate_constant_ivars-instance_method" title="NetLinx::ERB::Helpers#generate_constant_ivars (method)">#generate_constant_ivars</a></span>
110
116
  <small>NetLinx::ERB::Helpers</small>
111
117
  </li>
112
118
 
113
119
 
114
- <li class="r1 ">
120
+ <li class="r2 ">
115
121
  <span class='object_link'><a href="NetLinx/ERB/Helpers.html#generate_variable_ivars-instance_method" title="NetLinx::ERB::Helpers#generate_variable_ivars (method)">#generate_variable_ivars</a></span>
116
122
  <small>NetLinx::ERB::Helpers</small>
117
123
  </li>
118
124
 
119
125
 
120
- <li class="r2 ">
126
+ <li class="r1 ">
121
127
  <span class='object_link'><a href="NetLinx/ERB/Helpers.html#group-instance_method" title="NetLinx::ERB::Helpers#group (method)">#group</a></span>
122
128
  <small>NetLinx::ERB::Helpers</small>
123
129
  </li>
124
130
 
125
131
 
126
- <li class="r1 ">
132
+ <li class="r2 ">
127
133
  <span class='object_link'><a href="NetLinx/ERB/Helpers.html#hiqnet_empty-instance_method" title="NetLinx::ERB::Helpers#hiqnet_empty (method)">#hiqnet_empty</a></span>
128
134
  <small>NetLinx::ERB::Helpers</small>
129
135
  </li>
130
136
 
131
137
 
138
+ <li class="r1 ">
139
+ <span class='object_link'><a href="NetLinx/Rake/ERB/GenerateERB.html#initialize-instance_method" title="NetLinx::Rake::ERB::GenerateERB#initialize (method)">#initialize</a></span>
140
+ <small>NetLinx::Rake::ERB::GenerateERB</small>
141
+ </li>
142
+
143
+
132
144
  <li class="r2 ">
133
145
  <span class='object_link'><a href="NetLinx/Rake/ERB/Lines.html#initialize-instance_method" title="NetLinx::Rake::ERB::Lines#initialize (method)">#initialize</a></span>
134
146
  <small>NetLinx::Rake::ERB::Lines</small>
@@ -136,14 +148,14 @@
136
148
 
137
149
 
138
150
  <li class="r1 ">
139
- <span class='object_link'><a href="NetLinx/Rake/ERB/GenerateRPC.html#initialize-instance_method" title="NetLinx::Rake::ERB::GenerateRPC#initialize (method)">#initialize</a></span>
140
- <small>NetLinx::Rake::ERB::GenerateRPC</small>
151
+ <span class='object_link'><a href="NetLinx/Rake/ERB/Push.html#initialize-instance_method" title="NetLinx::Rake::ERB::Push#initialize (method)">#initialize</a></span>
152
+ <small>NetLinx::Rake::ERB::Push</small>
141
153
  </li>
142
154
 
143
155
 
144
156
  <li class="r2 ">
145
- <span class='object_link'><a href="NetLinx/Rake/ERB/GenerateERB.html#initialize-instance_method" title="NetLinx::Rake::ERB::GenerateERB#initialize (method)">#initialize</a></span>
146
- <small>NetLinx::Rake::ERB::GenerateERB</small>
157
+ <span class='object_link'><a href="NetLinx/Rake/ERB/GenerateRPC.html#initialize-instance_method" title="NetLinx::Rake::ERB::GenerateRPC#initialize (method)">#initialize</a></span>
158
+ <small>NetLinx::Rake::ERB::GenerateRPC</small>
147
159
  </li>
148
160
 
149
161
 
@@ -154,8 +166,8 @@
154
166
 
155
167
 
156
168
  <li class="r2 ">
157
- <span class='object_link'><a href="NetLinx/Rake/ERB/GenerateERB.html#name-instance_method" title="NetLinx::Rake::ERB::GenerateERB#name (method)">#name</a></span>
158
- <small>NetLinx::Rake::ERB::GenerateERB</small>
169
+ <span class='object_link'><a href="NetLinx/Rake/ERB/GenerateRPC.html#name-instance_method" title="NetLinx::Rake::ERB::GenerateRPC#name (method)">#name</a></span>
170
+ <small>NetLinx::Rake::ERB::GenerateRPC</small>
159
171
  </li>
160
172
 
161
173
 
@@ -166,66 +178,72 @@
166
178
 
167
179
 
168
180
  <li class="r2 ">
169
- <span class='object_link'><a href="NetLinx/Rake/ERB/GenerateRPC.html#name-instance_method" title="NetLinx::Rake::ERB::GenerateRPC#name (method)">#name</a></span>
170
- <small>NetLinx::Rake::ERB::GenerateRPC</small>
181
+ <span class='object_link'><a href="NetLinx/Rake/ERB/Push.html#name-instance_method" title="NetLinx::Rake::ERB::Push#name (method)">#name</a></span>
182
+ <small>NetLinx::Rake::ERB::Push</small>
171
183
  </li>
172
184
 
173
185
 
174
186
  <li class="r1 ">
187
+ <span class='object_link'><a href="NetLinx/Rake/ERB/GenerateERB.html#name-instance_method" title="NetLinx::Rake::ERB::GenerateERB#name (method)">#name</a></span>
188
+ <small>NetLinx::Rake::ERB::GenerateERB</small>
189
+ </li>
190
+
191
+
192
+ <li class="r2 ">
175
193
  <span class='object_link'><a href="NetLinx/ERB/Helpers.html#print_constant_hash-instance_method" title="NetLinx::ERB::Helpers#print_constant_hash (method)">#print_constant_hash</a></span>
176
194
  <small>NetLinx::ERB::Helpers</small>
177
195
  </li>
178
196
 
179
197
 
180
- <li class="r2 ">
198
+ <li class="r1 ">
181
199
  <span class='object_link'><a href="NetLinx/ERB/Helpers.html#print_device_hash-instance_method" title="NetLinx::ERB::Helpers#print_device_hash (method)">#print_device_hash</a></span>
182
200
  <small>NetLinx::ERB::Helpers</small>
183
201
  </li>
184
202
 
185
203
 
186
- <li class="r1 ">
204
+ <li class="r2 ">
187
205
  <span class='object_link'><a href="NetLinx/ERB/Helpers.html#print_variable_hash-instance_method" title="NetLinx::ERB::Helpers#print_variable_hash (method)">#print_variable_hash</a></span>
188
206
  <small>NetLinx::ERB::Helpers</small>
189
207
  </li>
190
208
 
191
209
 
192
- <li class="r2 ">
210
+ <li class="r1 ">
193
211
  <span class='object_link'><a href="Hash.html#remap-instance_method" title="Hash#remap (method)">#remap</a></span>
194
212
  <small>Hash</small>
195
213
  </li>
196
214
 
197
215
 
198
- <li class="r1 ">
216
+ <li class="r2 ">
199
217
  <span class='object_link'><a href="String.html#remove_comma_after_last_item-instance_method" title="String#remove_comma_after_last_item (method)">#remove_comma_after_last_item</a></span>
200
218
  <small>String</small>
201
219
  </li>
202
220
 
203
221
 
204
- <li class="r2 ">
222
+ <li class="r1 ">
205
223
  <span class='object_link'><a href="NetLinx/ERB/Helpers.html#show_control-instance_method" title="NetLinx::ERB::Helpers#show_control (method)">#show_control</a></span>
206
224
  <small>NetLinx::ERB::Helpers</small>
207
225
  </li>
208
226
 
209
227
 
210
- <li class="r1 ">
228
+ <li class="r2 ">
211
229
  <span class='object_link'><a href="NetLinx/ERB/HashHelpers.html#tmpl_suffix-instance_method" title="NetLinx::ERB::HashHelpers#tmpl_suffix (method)">#tmpl_suffix</a></span>
212
230
  <small>NetLinx::ERB::HashHelpers</small>
213
231
  </li>
214
232
 
215
233
 
216
- <li class="r2 ">
234
+ <li class="r1 ">
217
235
  <span class='object_link'><a href="NetLinx/ERB/HashHelpers.html#tmpl_var_suffix-instance_method" title="NetLinx::ERB::HashHelpers#tmpl_var_suffix (method)">#tmpl_var_suffix</a></span>
218
236
  <small>NetLinx::ERB::HashHelpers</small>
219
237
  </li>
220
238
 
221
239
 
222
- <li class="r1 ">
240
+ <li class="r2 ">
223
241
  <span class='object_link'><a href="Array.html#to_h-instance_method" title="Array#to_h (method)">#to_h</a></span>
224
242
  <small>Array</small>
225
243
  </li>
226
244
 
227
245
 
228
- <li class="r2 ">
246
+ <li class="r1 ">
229
247
  <span class='object_link'><a href="String.html#to_hiqnet-instance_method" title="String#to_hiqnet (method)">#to_hiqnet</a></span>
230
248
  <small>String</small>
231
249
  </li>
@@ -105,7 +105,7 @@
105
105
  </div>
106
106
 
107
107
  <div id="footer">
108
- Generated on Wed Feb 25 14:28:07 2015 by
108
+ Generated on Mon Jun 29 16:09:05 2015 by
109
109
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
110
110
  0.8.7.6 (ruby-2.1.3).
111
111
  </div>
@@ -1,22 +1,5 @@
1
1
 
2
- require 'erb'
2
+ # This file is here for 1.x legacy support of projects that
3
+ # require 'netlinx-erb'
3
4
 
4
- require_relative 'netlinx/erb/erb'
5
- require_relative 'netlinx/erb/hash_helpers'
6
- require_relative 'netlinx/erb/helpers'
7
- require_relative 'netlinx/erb/rpc'
8
-
9
-
10
- # :nodoc:
11
- module NetLinx
12
- # NetLinx code generation.
13
- module ERB
14
- end
15
-
16
- # :nodoc:
17
- module Rake
18
- # NetLinx code generation rake tasks.
19
- module ERB
20
- end
21
- end
22
- end
5
+ require_relative 'netlinx/erb'
@@ -0,0 +1,22 @@
1
+
2
+ require 'erb'
3
+
4
+ require_relative 'erb/erb'
5
+ require_relative 'erb/hash_helpers'
6
+ require_relative 'erb/helpers'
7
+ require_relative 'erb/rpc'
8
+
9
+
10
+ # :nodoc:
11
+ module NetLinx
12
+ # NetLinx code generation.
13
+ module ERB
14
+ end
15
+
16
+ # :nodoc:
17
+ module Rake
18
+ # NetLinx code generation rake tasks.
19
+ module ERB
20
+ end
21
+ end
22
+ end
@@ -5,14 +5,79 @@ module NetLinx
5
5
  module ERB
6
6
 
7
7
  # @return a binding for ERB to evaluate code in.
8
+ # @yieldparam [Module] module the object whose binding is returned.
8
9
  # @example
9
10
  # ERB.new(buffer, nil, '%<>-').result(NetLinx::ERB.binding)
10
- def self.binding
11
- @b ||= Module.new.instance_eval {
12
- extend NetLinx::ERB::Helpers
13
- # TODO: _config.rb instance variables should be injected here.
14
- binding
15
- }
11
+ def self.binding &block
12
+ Module.new.tap { |mod|
13
+ mod.instance_eval { extend NetLinx::ERB::Helpers }
14
+ block.call mod if block_given?
15
+ }.instance_eval { binding }
16
+ end
17
+
18
+ # Run ERB on the given template file.
19
+ # @param template_file [String] file path
20
+ # @param binding [Binding]
21
+ # @return [String] ERB output.
22
+ # @raise [LoadError] template not found
23
+ def self.execute template_file, binding: NetLinx::ERB.binding
24
+ raise LoadError, "Template not found: #{template_file}" unless File.exists? template_file
25
+ $AUTOGEN_HEADER + ::ERB.new(File.read(template_file), nil, '%<>-')
26
+ .result(binding)
27
+ end
28
+
29
+ # Generate AXI files for multiple devices based on a template file.
30
+ # @param devices [Hash] device names, each with a corresponding hash of
31
+ # k/v pairs that will be turned into `@tmpl_(key)` for use in the template.
32
+ # @option kwargs [String] :template_dir ('./include/ui/template') directory
33
+ # containing `.axi.erb.tmpl` template files.
34
+ # @yieldparam [Module] module the object whose binding is used when evaluating
35
+ # the template. This can be used to add customized data during evaluation.
36
+ #
37
+ # @example
38
+ # # Sample input for `devices` parameter:
39
+ # touch_panels = {
40
+ # WALL: { dps: 10001 },
41
+ # FLOATING: { dps: 10002 },
42
+ # }
43
+ def self.generate_axi_files_from_template devices, **kwargs, &block
44
+ template_dir = File.expand_path kwargs.fetch(:template_dir, './include/ui/template')
45
+ template_files = Dir["#{template_dir}/*.axi.erb.tmpl"]
46
+
47
+ devices.each do |name, params|
48
+ b = self.binding do |m|
49
+ m.instance_eval {
50
+ extend NetLinx::ERB::Helpers
51
+
52
+ # Generate template instance variables.
53
+ @tmpl_suffix = name.to_s
54
+ @tmpl_var_suffix = name.to_s.downcase # Variable suffix.
55
+
56
+ @tmpl_suffixes = devices.keys
57
+ @tmpl_var_suffixes = devices.keys.map &:downcase
58
+
59
+ params.each { |k,v| instance_variable_set :"@tmpl_#{k.to_s.downcase}", v }
60
+
61
+ @dvTP = "dvTP_#{@tmpl_suffix}"
62
+
63
+ # Inject suffix into Hash for helper methods.
64
+ Hash.instance_variable_set :@tmpl_suffix, @tmpl_suffix
65
+ Hash.instance_variable_set :@tmpl_var_suffix, @tmpl_var_suffix
66
+ }
67
+
68
+ block.call m if block_given?
69
+ end
70
+
71
+ # Generate files.
72
+ template_files.each do |path|
73
+ file_base_name = File.basename(path).gsub(/\..*/, '')
74
+ output_dir = File.expand_path "#{template_dir}/.."
75
+ output_path = "#{output_dir}/#{file_base_name}-#{name.to_s.downcase.gsub('_', '-')}.axi"
76
+
77
+ puts ' ' + output_path.gsub(Dir.pwd, '')[1..-1] # Print canonical path.
78
+ File.write output_path, execute(path, binding: b)
79
+ end
80
+ end
16
81
  end
17
82
 
18
83
  end
@@ -313,16 +313,6 @@ EOS
313
313
  str += "\";"
314
314
  end
315
315
 
316
- # Run ERB on the given template file.
317
- # @param template_file [String] file path
318
- # @return [String] ERB output.
319
- # @raise [LoadError] template not found
320
- def execute_erb template_file
321
- raise LoadError, "Template not found: #{template_file}" unless File.exists? template_file
322
- $AUTOGEN_HEADER + ::ERB.new(File.read(template_file), nil, '%<>-')
323
- .result(NetLinx::ERB.binding)
324
- end
325
-
326
316
 
327
317
  # @group Other
328
318
 
@@ -8,6 +8,7 @@ require 'netlinx/rake/src'
8
8
  require_relative 'erb/generate_erb'
9
9
  require_relative 'erb/generate_rpc'
10
10
  require_relative 'erb/lines'
11
+ require_relative 'erb/push'
11
12
 
12
13
 
13
14
  task :default=>[:generate_rpc, :check_for_docs, :compile, :pack]
@@ -15,6 +16,7 @@ task :default=>[:generate_rpc, :check_for_docs, :compile, :pack]
15
16
  NetLinx::Rake::ERB::Lines.new
16
17
  NetLinx::Rake::ERB::GenerateERB.new
17
18
  NetLinx::Rake::ERB::GenerateRPC.new :generate_rpc => :generate_apw
19
+ NetLinx::Rake::ERB::Push.new
18
20
 
19
21
  NetLinx::Rake::Workspace::CreateWorkspaceConfig.new
20
22
  NetLinx::Rake::Workspace::GenerateAPW.new :generate_apw => :generate_erb
@@ -24,14 +24,12 @@ module NetLinx
24
24
  puts "------------------------------------"
25
25
 
26
26
  templates = Dir['include/**/*.erb']
27
-
28
- outputs = templates.map { |str| str.gsub /\.erb$/, '' }
29
-
27
+
30
28
  templates.each do |template|
31
29
  file_name = template.gsub /\.erb$/, ''
32
30
  puts " #{file_name}"
33
31
 
34
- header = $AUTOGEN_HEADER = <<-HEADER
32
+ $AUTOGEN_HEADER = <<-HEADER
35
33
  (***********************************************************)
36
34
  (* WARNING *)
37
35
  (***********************************************************}
@@ -48,11 +46,9 @@ module NetLinx
48
46
  {***********************************************************)
49
47
 
50
48
  HEADER
51
- buffer = header + File.read(template)
52
49
 
53
50
  File.open file_name, 'w+' do |file|
54
- file.write ::ERB.new(buffer, nil, '%<>-')
55
- .result(NetLinx::ERB.binding)
51
+ file.write NetLinx::ERB.execute(template)
56
52
  end
57
53
  end
58
54
 
@@ -0,0 +1,65 @@
1
+
2
+ require 'rake'
3
+ require 'rake/tasklib'
4
+
5
+ module NetLinx
6
+ module Rake
7
+ module ERB
8
+
9
+ # Push project to NetLinx master(s).
10
+ class Push < ::Rake::TaskLib
11
+
12
+ attr_accessor :name
13
+
14
+ def initialize name = :push
15
+ @name = name
16
+ yield self if block_given?
17
+
18
+ desc "Push project to NetLinx master(s)."
19
+
20
+ task(name) do
21
+ require 'netlinx-erb'
22
+
23
+ puts "Pushing files to master(s)..."
24
+
25
+ # AMX BUG:
26
+ # Make sure FileTransfer isn't running when FTCon.exe is executed.
27
+ # FileTransfer2.exe fails to terminate if it fails to connect to
28
+ # a master controller. This causes the first workspace to remain
29
+ # in memory, even if the workspace settings are changed and
30
+ # FileTransfer2.exe is executed again. Sometimes it ignores the
31
+ # kill signal, so the /f flag is used to force termination.
32
+ #
33
+ # Reported to AMX support on 2015-03-30.
34
+ # Escalation# 26107
35
+ # If you encounter this bug, report it to AMX:
36
+ # Support@amx.com or 1-800-932-6993
37
+ if Gem.win_platform?
38
+ IO.popen "taskkill /f /im FileTransfer2.exe 2> nul"
39
+ else
40
+ IO.popen "killall -q -s KILL FileTransfer2.exe"
41
+ end
42
+
43
+ sleep 0.25 # Let process terminate.
44
+
45
+ # TODO: Implement ENV['NETLINX_ACTIVE_SYSTEM_ONLY']
46
+ # TODO: Implement filtering by type:
47
+ # code, master files (code, IR), touch panels,
48
+ # specific touch panel/device
49
+
50
+ Dir["*.apw"].first.tap do |apw_file|
51
+ unless apw_file
52
+ puts "NetLinx workspace file not found."
53
+ exit
54
+ end
55
+
56
+ system "FTCon \"#{apw_file}\""
57
+ puts "Done.\n\n"
58
+ end
59
+ end
60
+ end
61
+
62
+ end
63
+ end
64
+ end
65
+ end
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: netlinx-erb
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alex McLain
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-02-25 00:00:00.000000000 Z
12
+ date: 2015-06-29 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: netlinx-compile
@@ -176,6 +176,7 @@ files:
176
176
  - doc/NetLinx/Rake/ERB/GenerateERB.html
177
177
  - doc/NetLinx/Rake/ERB/GenerateRPC.html
178
178
  - doc/NetLinx/Rake/ERB/Lines.html
179
+ - doc/NetLinx/Rake/ERB/Push.html
179
180
  - doc/NetLinx/Rake/Lines.html
180
181
  - doc/RPC.html
181
182
  - doc/String.html
@@ -195,6 +196,7 @@ files:
195
196
  - doc/method_list.html
196
197
  - doc/top-level-namespace.html
197
198
  - lib/netlinx-erb.rb
199
+ - lib/netlinx/erb.rb
198
200
  - lib/netlinx/erb/erb.rb
199
201
  - lib/netlinx/erb/hash_helpers.rb
200
202
  - lib/netlinx/erb/helpers.rb
@@ -203,6 +205,7 @@ files:
203
205
  - lib/netlinx/rake/erb/generate_erb.rb
204
206
  - lib/netlinx/rake/erb/generate_rpc.rb
205
207
  - lib/netlinx/rake/erb/lines.rb
208
+ - lib/netlinx/rake/erb/push.rb
206
209
  - license.txt
207
210
  - template.zip
208
211
  homepage: https://github.com/amclain/netlinx-erb
@@ -225,7 +228,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
225
228
  version: '0'
226
229
  requirements: []
227
230
  rubyforge_project:
228
- rubygems_version: 2.4.6
231
+ rubygems_version: 2.4.8
229
232
  signing_key:
230
233
  specification_version: 4
231
234
  summary: A code generation utility for AMX NetLinx control systems.