saxon 0.1.0-java → 0.2.0-java

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 19f0e9fb8c21c339568c774ffc0c3020f39d45f896c1bf009c9d1052bed65412
4
- data.tar.gz: 92ec755ab385c2ab0509db7a4e5846f22979be58a12cc1fe7fefcc8f1350899f
3
+ metadata.gz: 9a66efc7aa5610d1826b3f6762061353e44bdd97f13aad85e2339195883a64bc
4
+ data.tar.gz: bd0b05fb1814f2863efba80651cb2cbce75f7d2f7ae3202ffcdc9a74685e985c
5
5
  SHA512:
6
- metadata.gz: a8154c57826865c13c48347ab517f9c9fa8c0499f0ee1693c063a381571d8401275c0c8718a25f3fcb4e37910423c1b7ca670b9cd490464d8bbd396e66a74379
7
- data.tar.gz: 63a5ca988ee42631bf7f02158c8ce377015269716a54c194e8756a4c158e602a00c67965538cf59136517f0785de226155b05b7e56b8699a58009d76a0e19d1c
6
+ metadata.gz: d9cbe86dad9cf8db64909057cbcc116642305b7d1287b2762872e1d23dae3f2d59f4476563486f650e7a2f0fd6053448724da4ed2e50907517709bb4cddb8f21
7
+ data.tar.gz: ff553975c4ace0ce9bc763510bcffc8ccb044b7fc642ba3aba9a46c02e2542103d22eb3da8178fbde4ce4e13cfcf09ddc4fc51cacd856ca7ddf7d81f7bc80451
@@ -26,6 +26,47 @@ module Saxon
26
26
  new(s9_qname)
27
27
  end
28
28
 
29
+ # Resolve a QName string into a {Saxon::QName}.
30
+ #
31
+ # If the arg is a {Saxon::QName} already, it just gets returned. If
32
+ # it's an instance of the underlying Saxon Java QName, it'll be wrapped
33
+ # into a {Saxon::QName}
34
+ #
35
+ # If the arg is a string, it's resolved by using {resolve_variable_name}
36
+ #
37
+ # @param qname_or_string [String, Symbol, Saxon::QName] the qname to resolve
38
+ # @param namespaces [Hash<String => String>] the set of namespaces as a hash of <tt>"prefix" => "namespace-uri"</tt>
39
+ # @return [Saxon::QName]
40
+ def self.resolve(qname_or_string, namespaces = {})
41
+ case qname_or_string
42
+ when String, Symbol
43
+ resolve_qname_string(qname_or_string, namespaces)
44
+ when self
45
+ qname_or_string
46
+ when Saxon::S9API::QName
47
+ new(qname_or_string)
48
+ end
49
+ end
50
+
51
+ # Resolve a QName string of the form <tt>"prefix:local-name"</tt> into a
52
+ # {Saxon::QName} by looking up the namespace URI in a hash of
53
+ # <tt>"prefix" => "namespace-uri"</tt>
54
+ #
55
+ # @param qname_string [String, Symbol] the QName as a <tt>"prefix:local-name"</tt> string
56
+ # @param namespaces [Hash<String => String>] the set of namespaces as a hash of <tt>"prefix" => "namespace-uri"</tt>
57
+ # @return [Saxon::QName]
58
+ def self.resolve_qname_string(qname_string, namespaces = {})
59
+ local_name, prefix = qname_string.to_s.split(':').reverse
60
+ uri = nil
61
+
62
+ if prefix
63
+ uri = namespaces[prefix]
64
+ raise self::PrefixedStringWithoutNSURIError.new(qname_string, prefix) if uri.nil?
65
+ end
66
+
67
+ create(prefix: prefix, uri: uri, local_name: local_name)
68
+ end
69
+
29
70
  attr_reader :s9_qname
30
71
  private :s9_qname
31
72
 
@@ -92,6 +133,13 @@ module Saxon
92
133
  end
93
134
 
94
135
  class PrefixedStringWithoutNSURIError < RuntimeError
136
+ def initialize(qname_string, prefix)
137
+ @qname_string, @prefix = qname_string, prefix
138
+ end
139
+
140
+ def to_s
141
+ "Namespace prefix ‘#{@prefix}’ for QName ‘#{@qname_string}’ is not bound to a URI"
142
+ end
95
143
  end
96
144
  end
97
145
  end
@@ -1,3 +1,3 @@
1
1
  module Saxon
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
@@ -41,49 +41,6 @@ module Saxon
41
41
  end
42
42
  end
43
43
 
44
- # methods for resolving a QName represented as a <tt>prefix:local-name</tt> string into a {Saxon::QName} by looking the prefix up in declared namespaces
45
- module Resolver
46
- # Resolve a QName string into a {Saxon::QName}.
47
- #
48
- # If the arg is a {Saxon::QName} already, it just gets returned. If
49
- # it's an instance of the underlying Saxon Java QName, it'll be wrapped
50
- # into a {Saxon::QName}
51
- #
52
- # If the arg is a string, it's resolved by using {resolve_variable_name}
53
- #
54
- # @param qname_or_string [String, Saxon::QName] the qname to resolve
55
- # @return [Saxon::QName]
56
- def self.resolve_variable_qname(qname_or_string, namespaces)
57
- case qname_or_string
58
- when String
59
- resolve_variable_name(qname_or_string, namespaces)
60
- when Saxon::QName
61
- qname_or_string
62
- when Saxon::S9API::QName
63
- Saxon::QName.new(qname_or_string)
64
- end
65
- end
66
-
67
- # Resolve a QName string of the form <tt>"prefix:local-name"</tt> into a
68
- # {Saxon::QName} by looking up the namespace URI in a hash of
69
- # <tt>"prefix" => "namespace-uri"</tt>
70
- #
71
- # @param qname_string [String] the QName as a <tt>"prefix:local-name"</tt> string
72
- # @param namespaces [Hash<String => String>] the set of namespaces as a hash of <tt>"prefix" => "namespace-uri"</tt>
73
- # @return [Saxon::QName]
74
- def self.resolve_variable_name(qname_string, namespaces)
75
- local_name, prefix = qname_string.split(':').reverse
76
- uri = nil
77
-
78
- if prefix
79
- uri = namespaces[prefix]
80
- raise MissingVariableNamespaceError.new(qname_string, prefix) if uri.nil?
81
- end
82
-
83
- Saxon::QName.create(prefix: prefix, uri: uri, local_name: local_name)
84
- end
85
- end
86
-
87
44
  # Provides the hooks for constructing a {StaticContext} with a DSL.
88
45
  # @api private
89
46
  class DSL
@@ -141,7 +98,7 @@ module Saxon
141
98
  private
142
99
 
143
100
  def resolve_variable_qname(qname_or_string)
144
- Resolver.resolve_variable_qname(qname_or_string, @declared_namespaces)
101
+ Saxon::QName.resolve(qname_or_string, @declared_namespaces)
145
102
  end
146
103
 
147
104
  def resolve_variable_type_decl(type_decl)
@@ -1,6 +1,6 @@
1
1
  require 'forwardable'
2
- require_relative './static_context'
3
- # require_relative './executable'
2
+ require_relative './evaluation_context'
3
+ require_relative './executable'
4
4
 
5
5
  module Saxon
6
6
  module XSLT
@@ -14,39 +14,45 @@ module Saxon
14
14
  # @yield An XSLT compiler DSL block
15
15
  # @return [Saxon::XSLT::Compiler] the new compiler instance
16
16
  def self.create(processor, &block)
17
- static_context = XSLT::StaticContext.define(block)
18
- new(processor.to_java, static_context)
17
+ evaluation_context = XSLT::EvaluationContext.define(block)
18
+ new(processor.to_java, evaluation_context)
19
19
  end
20
20
 
21
21
  extend Forwardable
22
22
 
23
- attr_reader :static_context
24
- private :static_context
23
+ attr_reader :evaluation_context
24
+ private :evaluation_context
25
25
 
26
26
  # @api private
27
27
  # @param s9_processor [net.sf.saxon.s9api.Processor] the Saxon
28
28
  # <tt>Processor</tt> to wrap
29
- # @param static_context [Saxon::XPath::StaticContext] the static context
29
+ # @param evaluation_context [Saxon::XSLT::EvaluationContext] the static context
30
30
  # XPaths compiled using this compiler will have
31
- def initialize(s9_processor, static_context)
32
- @s9_processor, @static_context = s9_processor, static_context
31
+ def initialize(s9_processor, evaluation_context)
32
+ @s9_processor, @evaluation_context = s9_processor, evaluation_context
33
33
  end
34
34
 
35
- def_delegators :static_context, :default_collation
35
+ def_delegators :evaluation_context, :default_collation, :static_parameters, :global_parameters, :initial_template_parameters, :initial_template_tunnel_parameters
36
36
  # @!attribute [r] declared_collations
37
37
  # @return [Hash<String => java.text.Collator>] declared collations as URI => Collator hash
38
38
  # @!attribute [r] default_collation
39
39
  # @return [String] the URI of the default declared collation
40
+ # @!attribute [r] static_parameters
41
+ # @return [Hash<Saxon::QName => Saxon::XdmValue, Saxon::XdmNode,
42
+ # Saxon::XdmAtomicValue>] parameters required at compile time as QName => value hash
40
43
 
41
- # @param expression [String] the expression to compile
42
- # @return [Saxon::XSLT::Executable] the executable query
43
- def compile(expression)
44
- Saxon::XSLT::Executable.new(new_compiler.compile(expression), static_context)
44
+ # @param expression [Saxon::Source] the Source to compile
45
+ # @return [Saxon::XSLT::Executable] the executable stylesheet
46
+ def compile(source, &block)
47
+ Saxon::XSLT::Executable.new(
48
+ new_compiler.compile(source.to_java),
49
+ evaluation_context.define(block)
50
+ )
45
51
  end
46
52
 
47
53
  def create(&block)
48
- new_static_context = static_context.define(block)
49
- self.class.new(@s9_processor, new_static_context)
54
+ new_evaluation_context = evaluation_context.define(block)
55
+ self.class.new(@s9_processor, new_evaluation_context)
50
56
  end
51
57
 
52
58
  private
@@ -54,6 +60,9 @@ module Saxon
54
60
  def new_compiler
55
61
  compiler = @s9_processor.newXsltCompiler
56
62
  compiler.declareDefaultCollation(default_collation) unless default_collation.nil?
63
+ static_parameters.each do |qname, value|
64
+ compiler.setParameter(qname.to_java, value.to_java)
65
+ end
57
66
  compiler
58
67
  end
59
68
  end
@@ -0,0 +1,174 @@
1
+ require 'set'
2
+ require_relative '../qname'
3
+
4
+ module Saxon
5
+ module XSLT
6
+ # Represents the evaluation context for an XSLT compiler, and stylesheets
7
+ # compiled using one. {EvaluationContext}s are immutable.
8
+ class EvaluationContext
9
+ # methods used by both {EvaluationContext} and {EvaluationContext::DSL}
10
+ module Common
11
+ # @param args [Hash]
12
+ # @option args [String] default_collation URI of the default collation
13
+ # @option args [Hash<String,Symbol,Saxon::QName =>
14
+ # Object,Saxon::XdmValue] static_parameters Hash of QName => value
15
+ # bindings for static (compile-time) parameters for this compiler
16
+ def initialize(args = {})
17
+ @default_collation = args.fetch(:default_collation, nil).freeze
18
+ @static_parameters = args.fetch(:static_parameters, {}).freeze
19
+ @global_parameters = args.fetch(:global_parameters, {}).freeze
20
+ @initial_template_parameters = args.fetch(:initial_template_parameters, {}).freeze
21
+ @initial_template_tunnel_parameters = args.fetch(:initial_template_tunnel_parameters, {}).freeze
22
+ end
23
+
24
+ # returns the context details in a hash suitable for initializing a new one
25
+ # @return [Hash<Symbol => Hash,null>] the args hash
26
+ def args_hash
27
+ check_for_clashing_parameters!
28
+ {
29
+ default_collation: @default_collation,
30
+ static_parameters: @static_parameters,
31
+ global_parameters: @global_parameters,
32
+ initial_template_parameters: @initial_template_parameters,
33
+ initial_template_tunnel_parameters: @initial_template_tunnel_parameters
34
+ }
35
+ end
36
+
37
+ private
38
+
39
+ def check_for_clashing_parameters!
40
+ @checked ||= begin
41
+ if Set.new(@static_parameters.keys).intersect?(Set.new(@global_parameters.keys))
42
+ raise GlobalAndStaticParameterClashError
43
+ else
44
+ true
45
+ end
46
+ end
47
+ end
48
+ end
49
+
50
+ # Provides the hooks for constructing a {EvaluationContext} with a DSL.
51
+ # @api private
52
+ class DSL
53
+ include Common
54
+
55
+ # Create an instance based on the args hash, and execute the passed in Proc/lambda against it using <tt>#instance_exec</tt> and return a
56
+ # new {EvaluationContext} with the results
57
+ # @param block [Proc] a Proc/lambda (or <tt>to_proc</tt>'d containing DSL calls
58
+ # @return [Saxon::XSLT::EvaluationContext]
59
+ def self.define(block, args = {})
60
+ dsl = new(args)
61
+ dsl.instance_exec(&block) unless block.nil?
62
+ EvaluationContext.new(dsl.args_hash)
63
+ end
64
+
65
+ # Set the default Collation to use. This should be one of the special
66
+ # collation URIs Saxon recognises, or one that has been registered
67
+ # using Saxon::Processor#declare_collations on the Processor that
68
+ # created the {XSLT::Compiler} this context is for.
69
+ #
70
+ # @param collation_uri [String] The URI of the Collation to set as the default
71
+ def default_collation(collation_uri)
72
+ @default_collation = collation_uri
73
+ end
74
+
75
+ # Set the value for static parameters (those that must be known at
76
+ # compile-time to avoid an error), as a hash of QName => Value pairs.
77
+ # Parameter QNames can be declared as Strings or Symbols if they are
78
+ # not in any namespace, otherwise an explicit {Saxon::QName} must be
79
+ # used. Values can be provided as explicit XdmValues:
80
+ # {Saxon::XdmValue}, {Saxon::XdmNode}, and {Saxon::XdmAtomicValue}, or
81
+ # as Ruby objects which will be converted to {Saxon::XdmAtomicValue}s
82
+ # in the usual way.
83
+ #
84
+ # @param parameters [Hash<String,Symbol,Saxon::QName =>
85
+ # Object,Saxon::XdmValue>] Hash of QName => value
86
+ def static_parameters(parameters = {})
87
+ @static_parameters = @static_parameters.merge(process_parameters(parameters)).freeze
88
+ end
89
+
90
+ # Set the values for global parameters (those that are available to all templates and functions).
91
+ #
92
+ # @see EvaluationContext#static_parameters for details of the argument format
93
+ #
94
+ # @param parameters [Hash<String,Symbol,Saxon::QName =>
95
+ # Object,Saxon::XdmValue>] Hash of QName => value
96
+ def global_parameters(parameters = {})
97
+ @global_parameters = @global_parameters.merge(process_parameters(parameters)).freeze
98
+ end
99
+
100
+ # Set the values for parameters made available only to the initial
101
+ # template invoked (either via apply_templates or call_template),
102
+ # effectively as if <tt><xsl:with-param tunnel="no"></tt> was being used.
103
+ #
104
+ # @see EvaluationContext#static_parameters for details of the argument format
105
+ #
106
+ # @param parameters [Hash<String,Symbol,Saxon::QName =>
107
+ # Object,Saxon::XdmValue>] Hash of QName => value
108
+ def initial_template_parameters(parameters = {})
109
+ @initial_template_parameters = @initial_template_parameters.merge(process_parameters(parameters))
110
+ end
111
+
112
+ # Set the values for tunneling parameters made available only to the initial
113
+ # template invoked (either via apply_templates or call_template),
114
+ # effectively as if <tt><xsl:with-param tunnel="yes"></tt> was being used.
115
+ #
116
+ # @see EvaluationContext#static_parameters for details of the argument format
117
+ #
118
+ # @param parameters [Hash<String,Symbol,Saxon::QName =>
119
+ # Object,Saxon::XdmValue>] Hash of QName => value
120
+ def initial_template_tunnel_parameters(parameters = {})
121
+ @initial_template_tunnel_parameters = @initial_template_tunnel_parameters.merge(process_parameters(parameters))
122
+ end
123
+
124
+ private
125
+
126
+ def process_parameters(parameters)
127
+ XSLT::ParameterHelper.process_parameters(parameters)
128
+ end
129
+ end
130
+
131
+ include Common
132
+
133
+ # Executes the Proc/lambda passed in with a new instance of
134
+ # {EvaluationContext} as <tt>self</tt>, allowing the DSL methods to be
135
+ # called in a DSL-ish way
136
+ #
137
+ # @param block [Proc] the block of DSL calls to be executed
138
+ # @return [Saxon::XSLT::EvaluationContext] the static context created by the block
139
+ def self.define(block)
140
+ DSL.define(block)
141
+ end
142
+
143
+ attr_reader :default_collation, :static_parameters, :global_parameters, :initial_template_parameters, :initial_template_tunnel_parameters
144
+
145
+ def define(block)
146
+ block.nil? ? self : DSL.define(block, args_hash)
147
+ end
148
+ end
149
+
150
+ class GlobalAndStaticParameterClashError < StandardError
151
+ end
152
+
153
+ module ParameterHelper
154
+ def self.process_parameters(parameters)
155
+ Hash[parameters.map { |qname, value|
156
+ [Saxon::QName.resolve(qname), process_xdm_value(value)]
157
+ }]
158
+ end
159
+
160
+ def self.process_xdm_value(value)
161
+ case value
162
+ when Saxon::XdmValue, Saxon::XdmNode, Saxon::XdmAtomicValue
163
+ value
164
+ else
165
+ Saxon::XdmAtomicValue.create(value)
166
+ end
167
+ end
168
+
169
+ def self.to_java(parameters)
170
+ Hash[parameters.map { |k,v| [k.to_java, v.to_java] }].to_java
171
+ end
172
+ end
173
+ end
174
+ end
@@ -1,24 +1,29 @@
1
- require_relative 'static_context'
1
+ require 'forwardable'
2
+ require_relative 'evaluation_context'
2
3
  require_relative '../serializer'
3
4
  require_relative '../xdm_value'
4
5
  require_relative '../qname'
5
6
 
6
7
  module Saxon
7
8
  module XSLT
8
- # Represents a compiled XPaGth query ready to be executed
9
+ # Represents a compiled XSLT stylesheet ready to be executed
9
10
  class Executable
10
- # @return [XSLT::StaticContext] the XPath's static context
11
- attr_reader :static_context
11
+ extend Forwardable
12
+
13
+ attr_reader :evaluation_context
14
+ private :evaluation_context
12
15
 
13
16
  # @api private
14
17
  # @param s9_xslt_executable [net.sf.saxon.s9api.XsltExecutable] the
15
- # Saxon compiled XPath object
16
- # @param static_context [XPath::StaticContext] the XPath's static
18
+ # Saxon compiled XSLT object
19
+ # @param evaluation_context [XSLT::EvaluationContext] the XSLT's evaluation
17
20
  # context
18
- def initialize(s9_xslt_executable, static_context)
19
- @s9_xslt_executable, @static_context = s9_xslt_executable, static_context
21
+ def initialize(s9_xslt_executable, evaluation_context)
22
+ @s9_xslt_executable, @evaluation_context = s9_xslt_executable, evaluation_context
20
23
  end
21
24
 
25
+ def_delegators :evaluation_context, :global_parameters, :initial_template_parameters, :initial_template_tunnel_parameters
26
+
22
27
  def apply_templates(source, opts = {})
23
28
  transformation(opts).apply_templates(source)
24
29
  end
@@ -36,10 +41,32 @@ module Saxon
36
41
  private
37
42
 
38
43
  def transformation(opts)
39
- Transformation.new(opts.merge({
44
+ Transformation.new(params_merged_opts(opts).merge({
40
45
  s9_transformer: @s9_xslt_executable.load30,
41
46
  }))
42
47
  end
48
+
49
+ def params_merged_opts(opts)
50
+ merged_opts = params_hash.dup
51
+ opts.each do |key, value|
52
+ if [:global_parameters, :initial_template_parameters, :initial_template_tunnel_parameters].include?(key)
53
+ merged_opts[key] = merged_opts.fetch(key, {}).merge(XSLT::ParameterHelper.process_parameters(value))
54
+ else
55
+ merged_opts[key] = value
56
+ end
57
+ end
58
+ merged_opts
59
+ end
60
+
61
+ def params_hash
62
+ @params_hash ||= begin
63
+ params_hash = {}
64
+ params_hash[:global_parameters] = global_parameters unless global_parameters.empty?
65
+ params_hash[:initial_template_parameters] = initial_template_parameters unless initial_template_parameters.empty?
66
+ params_hash[:initial_template_tunnel_parameters] = initial_template_tunnel_parameters unless initial_template_tunnel_parameters.empty?
67
+ params_hash
68
+ end.freeze
69
+ end
43
70
  end
44
71
 
45
72
  class Result
@@ -72,7 +99,7 @@ module Saxon
72
99
  end
73
100
 
74
101
  def call_template(template_name)
75
- transformation_result(:callTemplate, resolve_qname(template_name))
102
+ transformation_result(:callTemplate, Saxon::QName.resolve(template_name))
76
103
  end
77
104
 
78
105
  private
@@ -110,17 +137,19 @@ module Saxon
110
137
  end
111
138
 
112
139
  def mode(mode_name)
113
- s9_transformer.setInitialMode(resolve_qname(mode_name).to_java)
140
+ s9_transformer.setInitialMode(Saxon::QName.resolve(mode_name).to_java)
114
141
  end
115
142
 
116
- def resolve_qname(qname)
117
- case qname
118
- when Saxon::QName
119
- qname
120
- else
121
- raise Saxon::QName::PrefixedStringWithoutNSURIError if qname.to_s.include?(':')
122
- Saxon::QName.create(local_name: qname.to_s)
123
- end
143
+ def global_parameters(parameters)
144
+ s9_transformer.setStylesheetParameters(XSLT::ParameterHelper.to_java(parameters))
145
+ end
146
+
147
+ def initial_template_parameters(parameters)
148
+ s9_transformer.setInitialTemplateParameters(XSLT::ParameterHelper.to_java(parameters) , false)
149
+ end
150
+
151
+ def initial_template_tunnel_parameters(parameters)
152
+ s9_transformer.setInitialTemplateParameters(XSLT::ParameterHelper.to_java(parameters) , true)
124
153
  end
125
154
  end
126
155
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: saxon
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: java
6
6
  authors:
7
7
  - Matt Patterson
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-04-12 00:00:00.000000000 Z
11
+ date: 2019-04-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  requirement: !ruby/object:Gem::Requirement
@@ -183,8 +183,8 @@ files:
183
183
  - lib/saxon/xpath/variable_declaration.rb
184
184
  - lib/saxon/xslt.rb
185
185
  - lib/saxon/xslt/compiler.rb
186
+ - lib/saxon/xslt/evaluation_context.rb
186
187
  - lib/saxon/xslt/executable.rb
187
- - lib/saxon/xslt/static_context.rb
188
188
  - lib/saxon_jars.rb
189
189
  - saxon.gemspec
190
190
  homepage: https://github.com/fidothe/saxon-rb
@@ -1,69 +0,0 @@
1
- require_relative '../qname'
2
- module Saxon
3
- module XSLT
4
- # Represents the static context for an XSLT compiler. {StaticContext}s are immutable.
5
- class StaticContext
6
- # methods used by both {StaticContext} and {StaticContext::DSL}
7
- module Common
8
- # @param args [Hash]
9
- # @option args [Hash<String => java.text.Collator>] :declared_collations Hash of URI => Collator bindings
10
- # @option args [String] :default_collation URI of the default collation
11
- def initialize(args = {})
12
- @default_collation = args.fetch(:default_collation, nil).freeze
13
- end
14
-
15
- # returns the context details in a hash suitable for initializing a new one
16
- # @return [Hash<Symbol => Hash,null>] the args hash
17
- def args_hash
18
- {
19
- default_collation: @default_collation
20
- }
21
- end
22
- end
23
-
24
- # Provides the hooks for constructing a {StaticContext} with a DSL.
25
- # @api private
26
- class DSL
27
- include Common
28
-
29
- # Create an instance based on the args hash, and execute the passed in Proc/lambda against it using <tt>#instance_exec</tt> and return a
30
- # new {StaticContext} with the results
31
- # @param block [Proc] a Proc/lambda (or <tt>to_proc</tt>'d containing DSL calls
32
- # @return [Saxon::XPath::StaticContext]
33
- def self.define(block, args = {})
34
- dsl = new(args)
35
- dsl.instance_exec(&block) unless block.nil?
36
- StaticContext.new(dsl.args_hash)
37
- end
38
-
39
- # Set the default Collation to use. This should be one of the special
40
- # collation URIs Saxon recognises, or one that has been registered
41
- # using Saxon::Processor#declare_collations on the Processor that
42
- # created the {XSLT::Compiler} this context is for.
43
- #
44
- # @param collation_uri [String] The URI of the Collation to set as the default
45
- def default_collation(collation_uri)
46
- @default_collation = collation_uri
47
- end
48
- end
49
-
50
- include Common
51
-
52
- # Executes the Proc/lambda passed in with a new instance of
53
- # {StaticContext} as <tt>self</tt>, allowing the DSL methods to be
54
- # called in a DSL-ish way
55
- #
56
- # @param block [Proc] the block of DSL calls to be executed
57
- # @return [Saxon::XSLT::StaticContext] the static context created by the block
58
- def self.define(block)
59
- DSL.define(block)
60
- end
61
-
62
- attr_reader :default_collation
63
-
64
- def define(block)
65
- DSL.define(block, args_hash)
66
- end
67
- end
68
- end
69
- end