openhab-jrubyscripting 5.0.0.rc10 → 5.0.0.rc12

Sign up to get free protection for your applications and to get access to all the features.
Files changed (97) hide show
  1. checksums.yaml +4 -4
  2. data/lib/openhab/core/actions/audio.rb +47 -0
  3. data/lib/openhab/core/actions/ephemeris.rb +39 -0
  4. data/lib/openhab/core/actions/exec.rb +51 -0
  5. data/lib/openhab/core/actions/http.rb +80 -0
  6. data/lib/openhab/core/actions/ping.rb +30 -0
  7. data/lib/openhab/core/actions/transformation.rb +32 -0
  8. data/lib/openhab/core/actions/voice.rb +36 -0
  9. data/lib/openhab/core/actions.rb +23 -120
  10. data/lib/openhab/core/{events → dto}/item_channel_link.rb +1 -4
  11. data/lib/openhab/core/{events → dto}/thing.rb +10 -12
  12. data/lib/openhab/core/dto.rb +11 -0
  13. data/lib/openhab/core/entity_lookup.rb +1 -1
  14. data/lib/openhab/core/events/abstract_event.rb +1 -0
  15. data/lib/openhab/core/events/abstract_item_registry_event.rb +36 -0
  16. data/lib/openhab/core/events/abstract_thing_registry_event.rb +40 -0
  17. data/lib/openhab/core/events/item_command_event.rb +1 -1
  18. data/lib/openhab/core/events/item_state_changed_event.rb +6 -6
  19. data/lib/openhab/core/events/item_state_event.rb +6 -6
  20. data/lib/openhab/core/events/thing_status_info_event.rb +8 -6
  21. data/lib/openhab/core/items/date_time_item.rb +3 -2
  22. data/lib/openhab/core/items/generic_item.rb +92 -1
  23. data/lib/openhab/core/items/item.rb +9 -8
  24. data/lib/openhab/core/items/metadata/hash.rb +1 -1
  25. data/lib/openhab/core/items/metadata/namespace_hash.rb +10 -2
  26. data/lib/openhab/core/items/metadata/provider.rb +2 -2
  27. data/lib/openhab/core/items/persistence.rb +99 -21
  28. data/lib/openhab/core/items/player_item.rb +1 -1
  29. data/lib/openhab/core/items/proxy.rb +20 -14
  30. data/lib/openhab/core/items/registry.rb +12 -1
  31. data/lib/openhab/core/items/state_storage.rb +2 -2
  32. data/lib/openhab/core/items.rb +3 -3
  33. data/lib/openhab/core/profile_factory.rb +3 -1
  34. data/lib/openhab/core/proxy.rb +130 -0
  35. data/lib/openhab/core/registry.rb +12 -2
  36. data/lib/openhab/core/rules.rb +1 -1
  37. data/lib/openhab/core/things/links/provider.rb +39 -1
  38. data/lib/openhab/core/things/proxy.rb +8 -0
  39. data/lib/openhab/core/things/registry.rb +4 -0
  40. data/lib/openhab/core/timer.rb +3 -19
  41. data/lib/openhab/core/types/date_time_type.rb +3 -2
  42. data/lib/openhab/core/types/decimal_type.rb +1 -1
  43. data/lib/openhab/core/types/un_def_type.rb +2 -2
  44. data/lib/openhab/core/value_cache.rb +1 -1
  45. data/lib/openhab/core.rb +3 -3
  46. data/lib/openhab/core_ext/ephemeris.rb +53 -0
  47. data/lib/openhab/core_ext/java/class.rb +1 -1
  48. data/lib/openhab/core_ext/java/duration.rb +27 -1
  49. data/lib/openhab/core_ext/java/local_date.rb +17 -7
  50. data/lib/openhab/core_ext/java/local_time.rb +13 -3
  51. data/lib/openhab/core_ext/java/month.rb +1 -1
  52. data/lib/openhab/core_ext/java/month_day.rb +15 -3
  53. data/lib/openhab/core_ext/java/period.rb +1 -1
  54. data/lib/openhab/core_ext/java/temporal_amount.rb +1 -1
  55. data/lib/openhab/core_ext/java/time.rb +5 -1
  56. data/lib/openhab/core_ext/java/zoned_date_time.rb +100 -2
  57. data/lib/openhab/core_ext/ruby/date.rb +4 -2
  58. data/lib/openhab/core_ext/ruby/date_time.rb +1 -0
  59. data/lib/openhab/core_ext/ruby/numeric.rb +6 -1
  60. data/lib/openhab/core_ext/ruby/time.rb +1 -0
  61. data/lib/openhab/dsl/debouncer.rb +259 -0
  62. data/lib/openhab/dsl/items/builder.rb +29 -14
  63. data/lib/openhab/dsl/items/timed_command.rb +31 -13
  64. data/lib/openhab/dsl/rules/automation_rule.rb +30 -44
  65. data/lib/openhab/dsl/rules/builder.rb +404 -39
  66. data/lib/openhab/dsl/rules/guard.rb +12 -54
  67. data/lib/openhab/dsl/rules/name_inference.rb +11 -0
  68. data/lib/openhab/dsl/rules/property.rb +3 -4
  69. data/lib/openhab/dsl/rules/terse.rb +4 -1
  70. data/lib/openhab/dsl/rules/triggers/conditions/duration.rb +5 -6
  71. data/lib/openhab/dsl/rules/triggers/cron/cron.rb +1 -0
  72. data/lib/openhab/dsl/rules/triggers/cron/cron_handler.rb +19 -31
  73. data/lib/openhab/dsl/rules/triggers/watch/watch.rb +1 -0
  74. data/lib/openhab/dsl/rules/triggers/watch/watch_handler.rb +22 -30
  75. data/lib/openhab/dsl/things/builder.rb +1 -1
  76. data/lib/openhab/dsl/thread_local.rb +1 -0
  77. data/lib/openhab/dsl/version.rb +1 -1
  78. data/lib/openhab/dsl.rb +251 -14
  79. data/lib/openhab/rspec/helpers.rb +3 -2
  80. data/lib/openhab/rspec/hooks.rb +6 -2
  81. data/lib/openhab/rspec/karaf.rb +7 -0
  82. data/lib/openhab/rspec/mocks/instance_method_stasher.rb +22 -0
  83. data/lib/openhab/rspec/mocks/space.rb +23 -0
  84. data/lib/openhab/rspec/mocks/timer.rb +33 -0
  85. data/lib/openhab/rspec/openhab/core/actions.rb +16 -4
  86. data/lib/openhab/rspec/openhab/core/items/proxy.rb +1 -13
  87. data/lib/openhab/rspec/suspend_rules.rb +1 -14
  88. data/lib/openhab/rspec.rb +9 -0
  89. data/lib/openhab/yard/base_helper.rb +19 -0
  90. data/lib/openhab/yard/code_objects/group_object.rb +9 -3
  91. data/lib/openhab/yard/coderay.rb +17 -0
  92. data/lib/openhab/yard/handlers/jruby/base.rb +10 -1
  93. data/lib/openhab/yard/handlers/jruby/java_import_handler.rb +3 -0
  94. data/lib/openhab/yard/html_helper.rb +49 -15
  95. data/lib/openhab/yard/markdown_helper.rb +135 -0
  96. data/lib/openhab/yard.rb +6 -0
  97. metadata +36 -4
@@ -1,17 +1,62 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "nokogiri"
4
+
3
5
  module OpenHAB
4
6
  module YARD
5
7
  # @!visibility private
6
8
  module HtmlHelper
9
+ def base_url
10
+ if serializer.is_a?(::YARD::Server::DocServerSerializer)
11
+ abs_url(base_path(router.docs_prefix), "")
12
+ else
13
+ u = url_for("")
14
+ u = "#{u}/" if !u.empty? && u[-1] != "/"
15
+ u
16
+ end
17
+ end
18
+
19
+ def url_for_search_index
20
+ if serializer.is_a?(::YARD::Server::DocServerSerializer)
21
+ url_for_list("index")
22
+ else
23
+ url_for("index.json")
24
+ end
25
+ end
26
+
7
27
  def html_markup_markdown(text)
8
- result = super
28
+ result = super(text)
9
29
 
30
+ html = Nokogiri::HTML5.fragment(result)
10
31
  # re-link files in docs/*.md. They're written so they work on github without any
11
32
  # processing
12
- result.gsub!(%r{<a href="(?:[A-Za-z0-9_/-]+/)*([A-Za-z0-9_-]+).md(#[A-Za-z0-9_/-]+)?"},
13
- "<a href=\"file.\\1.html\\2\"")
14
- result
33
+ unless serializer.is_a?(::YARD::Server::DocServerSerializer)
34
+ html.css("a[href!='']").each do |link|
35
+ uri = URI.parse(link["href"])
36
+ next unless uri.relative? && File.extname(uri.path) == ".md"
37
+
38
+ basename = File.basename(uri.path, ".md")
39
+ uri.path = "file.#{basename}.html"
40
+ link["href"] = uri.to_s
41
+ end
42
+ end
43
+
44
+ # wtf commonmarker, you don't generate anchors?!
45
+ html.css("h1, h2, h3, h4, h5, h6").each do |header|
46
+ next if header["id"]
47
+
48
+ id = header.text.strip.downcase.delete(%(.?"')).tr(" ", "-")
49
+ header["id"] = id
50
+ header.prepend_child(%(<a href="##{id}" class="header-anchor">#</a>))
51
+ end
52
+
53
+ html.to_s
54
+ end
55
+
56
+ def link_url(url, title = nil, params = {})
57
+ params.merge!(@link_attrs) if defined?(@link_attrs) && @link_attrs
58
+ params[:class] = params.delete(:classes).join(" ") if params[:classes]
59
+ super
15
60
  end
16
61
 
17
62
  # have to completely replace this method. only change is the regex splitting
@@ -28,17 +73,6 @@ module OpenHAB
28
73
  list.empty? ? "" : (brackets ? "(#{list.join(", ")})" : list.join(", "))
29
74
  end
30
75
  # rubocop:enable Style/NestedTernaryOperator, Style/StringConcatenation, Style/TernaryParentheses
31
-
32
- def link_object(obj, title = nil, *)
33
- ::YARD::Handlers::JRuby::Base.infer_java_class(obj) if obj.is_a?(String)
34
- obj = ::YARD::Registry.resolve(object, obj, true, true) if obj.is_a?(String)
35
- if obj.is_a?(::YARD::CodeObjects::Java::Base) && (see = obj.docstring.tag(:see))
36
- # link to the first see tag
37
- return linkify(see.name, title&.to_s || see.text)
38
- end
39
-
40
- super
41
- end
42
76
  end
43
77
  end
44
78
  end
@@ -0,0 +1,135 @@
1
+ # frozen_string_literal: true
2
+
3
+ module OpenHAB
4
+ module YARD
5
+ # @!visibility private
6
+ module MarkdownHelper
7
+ include ::YARD::Templates::Helpers::HtmlHelper
8
+ # @group Linking Objects and URLs
9
+
10
+ def diskfile
11
+ resolve_links(super)
12
+ end
13
+
14
+ # mostly copied from HTMLHelper
15
+ def resolve_links(text)
16
+ blockquotes = false
17
+ text.gsub(%r{(```)|(\\|!)?\{(?!\})(\S+?)(?:\s([^\}]*?\S))?\}(?=[\W<]|.+</|$)}m) do |str|
18
+ blockquote = $1
19
+ escape = $2
20
+ name = $3
21
+ title = $4
22
+ match = $&
23
+ if blockquote
24
+ blockquotes = !blockquotes
25
+ next str
26
+ end
27
+ next str if blockquotes
28
+
29
+ next(match[1..]) if escape
30
+
31
+ next(match) if name[0, 1] == "|"
32
+
33
+ if object.is_a?(String)
34
+ object
35
+ else
36
+ link = linkify(name, title)
37
+ if (link == name || link == title) && ("#{name} #{link}" !~ /\A<a\s.*>/)
38
+ match = /(.+)?(\{#{Regexp.quote name}(?:\s.*?)?\})(.+)?/.match(text)
39
+ file = ((defined?(@file) && @file) ? @file.filename : object.file) || "(unknown)"
40
+ line = (if defined?(@file) && @file
41
+ 1
42
+ else
43
+ (object.docstring.line_range ? object.docstring.line_range.first : 1)
44
+ end) + (match ? $`.count("\n") : 0)
45
+ if match
46
+ log.warn "In file `#{file}':#{line}: Cannot resolve link to #{name} from text#{match ? ":" : "."}\n" \
47
+ "\t#{match[1] ? "..." : ""}#{match[2].delete("\n")}#{match[3] ? "..." : ""}"
48
+ end
49
+ end
50
+
51
+ link
52
+ end
53
+ end
54
+ end
55
+
56
+ # mostly copied from HTMLHelper
57
+ def link_object(obj, title = nil, anchor = nil, relative = true) # rubocop:disable Style/OptionalBooleanParameter
58
+ return title if obj.nil?
59
+
60
+ obj = ::YARD::Registry.resolve(object, obj, true, true) if obj.is_a?(String)
61
+
62
+ was_const = false
63
+ # Re-link references to constants that are aliases to their target. But keep
64
+ # their current title.
65
+ while obj.is_a?(::YARD::CodeObjects::ConstantObject) && obj.target
66
+ title ||= h(object.relative_path(obj)).to_s
67
+ was_const = true
68
+ obj = obj.target
69
+ end
70
+ return link_object(obj, title, anchor, relative) if was_const
71
+
72
+ title = if title
73
+ title.to_s
74
+ elsif object.is_a?(::YARD::CodeObjects::Base)
75
+ # Check if we're linking to a class method in the current
76
+ # object. If we are, create a title in the format of
77
+ # "CurrentClass.method_name"
78
+ if obj.is_a?(::YARD::CodeObjects::MethodObject) && obj.scope == :class && obj.parent == object
79
+ h([object.name, obj.sep, obj.name].join)
80
+ elsif obj.title != obj.path
81
+ h(obj.title)
82
+ else
83
+ h(object.relative_path(obj))
84
+ end
85
+ else
86
+ h(obj.title)
87
+ end
88
+ return title unless serializer
89
+ return title if obj.is_a?(::YARD::CodeObjects::Proxy)
90
+
91
+ link = url_for(obj, anchor, relative)
92
+ link ? link_url(link, title, title: h("#{obj.title} (#{obj.type})")) : title
93
+ rescue ::YARD::Parser::UndocumentableError
94
+ log.warn "The namespace of link #{obj.inspect} is a constant or invalid."
95
+ title || obj.to_s
96
+ end
97
+
98
+ def url_for(obj, anchor = nil, relative = true) # rubocop:disable Style/OptionalBooleanParameter
99
+ link = nil
100
+ return link unless serializer
101
+ return link if obj.is_a?(::YARD::CodeObjects::Base) && run_verifier([obj]).empty?
102
+
103
+ if obj.is_a?(::YARD::CodeObjects::Base) && !obj.is_a?(::YARD::CodeObjects::NamespaceObject)
104
+ # If the obj is not a namespace obj make it the anchor.
105
+ anchor = obj
106
+ obj = obj.namespace
107
+ end
108
+
109
+ objpath = serializer.serialized_path(obj)
110
+ return link unless objpath
111
+
112
+ relative = false if object == ::YARD::Registry.root
113
+ if relative
114
+ fromobj = object
115
+ if object.is_a?(::YARD::CodeObjects::Base) &&
116
+ !object.is_a?(::YARD::CodeObjects::NamespaceObject)
117
+ fromobj = owner
118
+ end
119
+
120
+ from = serializer.serialized_path(fromobj)
121
+ link = File.relative_path(from, objpath)
122
+ else
123
+ link = File.join(serializer.basepath, objpath)
124
+ end
125
+
126
+ link + (anchor ? "##{urlencode(anchor_for(anchor))}" : "")
127
+ end
128
+
129
+ def link_url(url, title = nil, _params = nil)
130
+ title ||= url
131
+ "[#{title}](#{url})"
132
+ end
133
+ end
134
+ end
135
+ end
data/lib/openhab/yard.rb CHANGED
@@ -6,10 +6,16 @@ Dir[File.expand_path("yard/**/*.rb", __dir__)].sort.each do |f|
6
6
  require f
7
7
  end
8
8
 
9
+ YARD::Templates::Template.extra_includes << OpenHAB::YARD::BaseHelper
10
+ YARD::Templates::Template.extra_includes << ->(opts) { OpenHAB::YARD::CodeRay::HtmlHelper if opts.format == :html }
9
11
  YARD::Templates::Template.extra_includes << ->(opts) { OpenHAB::YARD::HtmlHelper if opts.format == :html }
12
+ YARD::Templates::Template.extra_includes << ->(opts) { OpenHAB::YARD::MarkdownHelper if opts.format == :markdown }
13
+
10
14
  YARD::Templates::Engine.register_template_path File.expand_path("../../templates", __dir__)
11
15
  YARD::Tags::Library.define_tag "Java Interface", :interface
12
16
 
17
+ YARD::Server.register_static_path(".")
18
+
13
19
  #
14
20
  # @!parse
15
21
  # # @!visibility private
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: openhab-jrubyscripting
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.0.0.rc10
4
+ version: 5.0.0.rc12
5
5
  platform: ruby
6
6
  authors:
7
7
  - Cody Cutrer
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-12-06 00:00:00.000000000 Z
11
+ date: 2023-01-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -164,6 +164,20 @@ dependencies:
164
164
  - - "~>"
165
165
  - !ruby/object:Gem::Version
166
166
  version: '1.4'
167
+ - !ruby/object:Gem::Dependency
168
+ name: nokogiri
169
+ requirement: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - "~>"
172
+ - !ruby/object:Gem::Version
173
+ version: 1.13.9
174
+ type: :development
175
+ prerelease: false
176
+ version_requirements: !ruby/object:Gem::Requirement
177
+ requirements:
178
+ - - "~>"
179
+ - !ruby/object:Gem::Version
180
+ version: 1.13.9
167
181
  - !ruby/object:Gem::Dependency
168
182
  name: persistent_httparty
169
183
  requirement: !ruby/object:Gem::Requirement
@@ -327,16 +341,26 @@ extra_rdoc_files: []
327
341
  files:
328
342
  - lib/openhab/core.rb
329
343
  - lib/openhab/core/actions.rb
344
+ - lib/openhab/core/actions/audio.rb
345
+ - lib/openhab/core/actions/ephemeris.rb
346
+ - lib/openhab/core/actions/exec.rb
347
+ - lib/openhab/core/actions/http.rb
348
+ - lib/openhab/core/actions/ping.rb
349
+ - lib/openhab/core/actions/transformation.rb
350
+ - lib/openhab/core/actions/voice.rb
330
351
  - lib/openhab/core/dependency_tracking.rb
352
+ - lib/openhab/core/dto.rb
353
+ - lib/openhab/core/dto/item_channel_link.rb
354
+ - lib/openhab/core/dto/thing.rb
331
355
  - lib/openhab/core/entity_lookup.rb
332
356
  - lib/openhab/core/events.rb
333
357
  - lib/openhab/core/events/abstract_event.rb
334
- - lib/openhab/core/events/item_channel_link.rb
358
+ - lib/openhab/core/events/abstract_item_registry_event.rb
359
+ - lib/openhab/core/events/abstract_thing_registry_event.rb
335
360
  - lib/openhab/core/events/item_command_event.rb
336
361
  - lib/openhab/core/events/item_event.rb
337
362
  - lib/openhab/core/events/item_state_changed_event.rb
338
363
  - lib/openhab/core/events/item_state_event.rb
339
- - lib/openhab/core/events/thing.rb
340
364
  - lib/openhab/core/events/thing_status_info_event.rb
341
365
  - lib/openhab/core/items.rb
342
366
  - lib/openhab/core/items/accepted_data_types.rb
@@ -369,6 +393,7 @@ files:
369
393
  - lib/openhab/core/lazy_array.rb
370
394
  - lib/openhab/core/profile_factory.rb
371
395
  - lib/openhab/core/provider.rb
396
+ - lib/openhab/core/proxy.rb
372
397
  - lib/openhab/core/registry.rb
373
398
  - lib/openhab/core/rules.rb
374
399
  - lib/openhab/core/rules/module.rb
@@ -413,6 +438,7 @@ files:
413
438
  - lib/openhab/core/value_cache.rb
414
439
  - lib/openhab/core_ext.rb
415
440
  - lib/openhab/core_ext/between.rb
441
+ - lib/openhab/core_ext/ephemeris.rb
416
442
  - lib/openhab/core_ext/java/class.rb
417
443
  - lib/openhab/core_ext/java/duration.rb
418
444
  - lib/openhab/core_ext/java/list.rb
@@ -435,6 +461,7 @@ files:
435
461
  - lib/openhab/core_ext/ruby/symbol.rb
436
462
  - lib/openhab/core_ext/ruby/time.rb
437
463
  - lib/openhab/dsl.rb
464
+ - lib/openhab/dsl/debouncer.rb
438
465
  - lib/openhab/dsl/events.rb
439
466
  - lib/openhab/dsl/events/watch_event.rb
440
467
  - lib/openhab/dsl/gems.rb
@@ -477,8 +504,10 @@ files:
477
504
  - lib/openhab/rspec/mocks/bundle_install_support.rb
478
505
  - lib/openhab/rspec/mocks/bundle_resolver.rb
479
506
  - lib/openhab/rspec/mocks/event_admin.rb
507
+ - lib/openhab/rspec/mocks/instance_method_stasher.rb
480
508
  - lib/openhab/rspec/mocks/persistence_service.rb
481
509
  - lib/openhab/rspec/mocks/safe_caller.rb
510
+ - lib/openhab/rspec/mocks/space.rb
482
511
  - lib/openhab/rspec/mocks/synchronous_executor.rb
483
512
  - lib/openhab/rspec/mocks/thing_handler.rb
484
513
  - lib/openhab/rspec/mocks/timer.rb
@@ -488,6 +517,7 @@ files:
488
517
  - lib/openhab/rspec/shell.rb
489
518
  - lib/openhab/rspec/suspend_rules.rb
490
519
  - lib/openhab/yard.rb
520
+ - lib/openhab/yard/base_helper.rb
491
521
  - lib/openhab/yard/cli/stats.rb
492
522
  - lib/openhab/yard/code_objects/group_object.rb
493
523
  - lib/openhab/yard/code_objects/java/base.rb
@@ -496,12 +526,14 @@ files:
496
526
  - lib/openhab/yard/code_objects/java/interface_object.rb
497
527
  - lib/openhab/yard/code_objects/java/package_object.rb
498
528
  - lib/openhab/yard/code_objects/java/proxy.rb
529
+ - lib/openhab/yard/coderay.rb
499
530
  - lib/openhab/yard/handlers/jruby/base.rb
500
531
  - lib/openhab/yard/handlers/jruby/class_handler.rb
501
532
  - lib/openhab/yard/handlers/jruby/constant_handler.rb
502
533
  - lib/openhab/yard/handlers/jruby/java_import_handler.rb
503
534
  - lib/openhab/yard/handlers/jruby/mixin_handler.rb
504
535
  - lib/openhab/yard/html_helper.rb
536
+ - lib/openhab/yard/markdown_helper.rb
505
537
  - lib/openhab/yard/tags/constant_directive.rb
506
538
  - lib/openhab/yard/tags/group_directive.rb
507
539
  - lib/openhab/yard/tags/library.rb