ruby_speech 0.3.3 → 0.3.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,8 @@
1
+ # 0.3.4
2
+ * Eager-autoload all elements so that importing will work with elements that havn't been used yet directly
3
+ * Allow using the DSL with method calls out of the block
4
+ * Fix inspection/comparison of some elements that don't have a language attribute
5
+
1
6
  # 0.3.3
2
7
  * Allow `SSML::Element.import` and `GRXML::Element.import` to take a string as well as a Nokogiri::XML::Node
3
8
  * Allow importing GRXML/SSML documents via their respective modules (eg `RubySpeech::GRXML.import '<grammar ... />'`)
@@ -10,8 +10,12 @@ module RubySpeech
10
10
 
11
11
  autoload :Version
12
12
 
13
- autoload :GenericElement
14
- autoload :SSML
15
- autoload :GRXML
16
- autoload :XML
13
+ eager_autoload do
14
+ autoload :GenericElement
15
+ autoload :SSML
16
+ autoload :GRXML
17
+ autoload :XML
18
+ end
17
19
  end
20
+
21
+ ActiveSupport::Autoload.eager_autoload!
@@ -54,7 +54,7 @@ module RubySpeech
54
54
  def new(element_name, atts = {}, &block)
55
55
  blk_proc = lambda do |new_node|
56
56
  atts.each_pair { |k, v| new_node.send :"#{k}=", v }
57
- block_return = new_node.instance_eval &block if block_given?
57
+ block_return = new_node.eval_dsl_block &block
58
58
  new_node << new_node.encode_special_chars(block_return) if block_return.is_a?(String)
59
59
  end
60
60
 
@@ -71,6 +71,12 @@ module RubySpeech
71
71
  end
72
72
  end
73
73
 
74
+ def eval_dsl_block(&block)
75
+ return unless block_given?
76
+ @block_binding = eval "self", block.binding
77
+ instance_eval &block
78
+ end
79
+
74
80
  def children
75
81
  super.map { |c| self.class.import c }
76
82
  end
@@ -92,13 +98,17 @@ module RubySpeech
92
98
 
93
99
  def method_missing(method_name, *args, &block)
94
100
  const_name = method_name.to_s.sub('ssml', '').titleize.gsub(' ', '')
95
- const = self.class.module.const_get const_name
96
- if const && self.class::VALID_CHILD_TYPES.include?(const)
97
- if const == String
98
- self << encode_special_chars(args.first)
99
- else
100
- self << const.new(*args, &block)
101
+ if self.class.module.const_defined? const_name
102
+ const = self.class.module.const_get const_name
103
+ if self.class::VALID_CHILD_TYPES.include?(const)
104
+ if const == String
105
+ self << encode_special_chars(args.first)
106
+ else
107
+ self << const.new(*args, &block)
108
+ end
101
109
  end
110
+ elsif @block_binding# && @block_binding.respond_to?(method_name)
111
+ @block_binding.send method_name, *args, &block
102
112
  else
103
113
  super
104
114
  end
@@ -2,14 +2,16 @@ module RubySpeech
2
2
  module GRXML
3
3
  extend ActiveSupport::Autoload
4
4
 
5
- autoload :Element
6
- autoload :Grammar
7
- autoload :Rule
8
- autoload :Item
9
- autoload :OneOf
10
- autoload :Ruleref
11
- autoload :Tag
12
- autoload :Token
5
+ eager_autoload do
6
+ autoload :Element
7
+ autoload :Grammar
8
+ autoload :Rule
9
+ autoload :Item
10
+ autoload :OneOf
11
+ autoload :Ruleref
12
+ autoload :Tag
13
+ autoload :Token
14
+ end
13
15
 
14
16
  InvalidChildError = Class.new StandardError
15
17
 
@@ -17,7 +19,7 @@ module RubySpeech
17
19
 
18
20
  def self.draw(attributes = {}, &block)
19
21
  Grammar.new(attributes).tap do |grammar|
20
- block_return = grammar.instance_eval(&block) if block_given?
22
+ block_return = grammar.eval_dsl_block &block
21
23
  grammar << block_return if block_return.is_a?(String)
22
24
  end
23
25
  end
@@ -27,3 +29,5 @@ module RubySpeech
27
29
  end
28
30
  end # GRXML
29
31
  end # RubySpeech
32
+
33
+ ActiveSupport::Autoload.eager_autoload!
@@ -32,7 +32,7 @@ module RubySpeech
32
32
  new_node[:version] = '1.0'
33
33
  new_node.namespace = GRXML_NAMESPACE
34
34
  new_node.language ||= "en-US"
35
- new_node.instance_eval &block if block_given?
35
+ new_node.eval_dsl_block &block
36
36
  new_node
37
37
  end
38
38
 
@@ -128,7 +128,7 @@ module RubySpeech
128
128
  end
129
129
 
130
130
  def eql?(o)
131
- super o, :weight, :repeat, :language
131
+ super o, :weight, :repeat
132
132
  end
133
133
  end # Item
134
134
  end # GRXML
@@ -33,10 +33,6 @@ module RubySpeech
33
33
  raise InvalidChildError, "A OneOf can only accept Item as children" unless VALID_CHILD_TYPES.include? arg.class
34
34
  super
35
35
  end
36
-
37
- def eql?(o)
38
- super o, :language
39
- end
40
36
  end # OneOf
41
37
  end # GRXML
42
38
  end # RubySpeech
@@ -29,10 +29,6 @@ module RubySpeech
29
29
  raise InvalidChildError, "A Token can only accept Strings as children" unless VALID_CHILD_TYPES.include? arg.class
30
30
  super
31
31
  end
32
-
33
- def eql?(o)
34
- super o, :language
35
- end
36
32
  end # Token
37
33
  end # GRXML
38
34
  end # RubySpeech
@@ -2,14 +2,16 @@ module RubySpeech
2
2
  module SSML
3
3
  extend ActiveSupport::Autoload
4
4
 
5
- autoload :Audio
6
- autoload :Break
7
- autoload :Element
8
- autoload :Emphasis
9
- autoload :Prosody
10
- autoload :SayAs
11
- autoload :Speak
12
- autoload :Voice
5
+ eager_autoload do
6
+ autoload :Audio
7
+ autoload :Break
8
+ autoload :Element
9
+ autoload :Emphasis
10
+ autoload :Prosody
11
+ autoload :SayAs
12
+ autoload :Speak
13
+ autoload :Voice
14
+ end
13
15
 
14
16
  InvalidChildError = Class.new StandardError
15
17
 
@@ -17,7 +19,7 @@ module RubySpeech
17
19
 
18
20
  def self.draw(&block)
19
21
  Speak.new.tap do |speak|
20
- block_return = speak.instance_eval(&block) if block_given?
22
+ block_return = speak.eval_dsl_block &block
21
23
  speak << block_return if block_return.is_a?(String)
22
24
  end
23
25
  end
@@ -27,3 +29,5 @@ module RubySpeech
27
29
  end
28
30
  end # SSML
29
31
  end # RubySpeech
32
+
33
+ ActiveSupport::Autoload.eager_autoload!
@@ -24,7 +24,7 @@ module RubySpeech
24
24
  new_node[:version] = '1.0'
25
25
  new_node.namespace = SSML_NAMESPACE
26
26
  new_node.language ||= "en-US"
27
- new_node.instance_eval &block if block_given?
27
+ new_node.eval_dsl_block &block
28
28
  new_node
29
29
  end
30
30
 
@@ -1,3 +1,3 @@
1
1
  module RubySpeech
2
- VERSION = "0.3.3"
2
+ VERSION = "0.3.4"
3
3
  end
@@ -2,6 +2,10 @@ module RubySpeech
2
2
  module XML
3
3
  extend ActiveSupport::Autoload
4
4
 
5
- autoload :Language
5
+ eager_autoload do
6
+ autoload :Language
7
+ end
6
8
  end # XML
7
9
  end # RubySpeech
10
+
11
+ ActiveSupport::Autoload.eager_autoload!
@@ -28,6 +28,21 @@ module RubySpeech
28
28
  doc.should == expected_doc
29
29
  end
30
30
 
31
+ it "should allow accessing methods defined outside the block" do
32
+ def foo
33
+ 'bar'
34
+ end
35
+
36
+ doc = GRXML.draw do
37
+ rule :id => foo
38
+ end
39
+
40
+ expected_doc = GRXML::Grammar.new
41
+ rule = GRXML::Rule.new(:id => foo)
42
+ expected_doc << rule
43
+ doc.should == expected_doc
44
+ end
45
+
31
46
  it "should raise error if given an empty rule" do
32
47
  pending 'Reject empty rules -- http://www.w3.org/TR/2002/CR-speech-grammar-20020626/#S3.1 http://www.w3.org/Voice/2003/srgs-ir/test/rule-no-empty.grxml'
33
48
  lambda { GRXML.draw { rule :id => 'main' }}.should raise_error
@@ -56,6 +56,19 @@ module RubySpeech
56
56
  doc.should == expected_doc
57
57
  end
58
58
 
59
+ it "should allow accessing methods defined outside the block" do
60
+ def foo
61
+ 'bar'
62
+ end
63
+
64
+ doc = SSML.draw do
65
+ string foo
66
+ end
67
+
68
+ expected_doc = SSML::Speak.new :content => foo
69
+ doc.should == expected_doc
70
+ end
71
+
59
72
  describe "embedding" do
60
73
  it "SSML documents" do
61
74
  doc1 = RubySpeech::SSML.draw do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby_speech
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.3
4
+ version: 0.3.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2011-12-16 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: niceogiri
16
- requirement: &2157143800 !ruby/object:Gem::Requirement
16
+ requirement: &2156730280 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 0.1.1
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *2157143800
24
+ version_requirements: *2156730280
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: activesupport
27
- requirement: &2157143180 !ruby/object:Gem::Requirement
27
+ requirement: &2156729680 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: 3.0.7
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *2157143180
35
+ version_requirements: *2156729680
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: bundler
38
- requirement: &2157142500 !ruby/object:Gem::Requirement
38
+ requirement: &2156728960 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ~>
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: 1.0.0
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *2157142500
46
+ version_requirements: *2156728960
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: rspec
49
- requirement: &2157141800 !ruby/object:Gem::Requirement
49
+ requirement: &2156728320 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: 2.7.0
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *2157141800
57
+ version_requirements: *2156728320
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: ci_reporter
60
- requirement: &2157141220 !ruby/object:Gem::Requirement
60
+ requirement: &2156727580 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ! '>='
@@ -65,10 +65,10 @@ dependencies:
65
65
  version: 1.6.3
66
66
  type: :development
67
67
  prerelease: false
68
- version_requirements: *2157141220
68
+ version_requirements: *2156727580
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: yard
71
- requirement: &2157140600 !ruby/object:Gem::Requirement
71
+ requirement: &2156726900 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - ~>
@@ -76,10 +76,10 @@ dependencies:
76
76
  version: 0.7.0
77
77
  type: :development
78
78
  prerelease: false
79
- version_requirements: *2157140600
79
+ version_requirements: *2156726900
80
80
  - !ruby/object:Gem::Dependency
81
81
  name: rake
82
- requirement: &2157140000 !ruby/object:Gem::Requirement
82
+ requirement: &2156726240 !ruby/object:Gem::Requirement
83
83
  none: false
84
84
  requirements:
85
85
  - - ! '>='
@@ -87,10 +87,10 @@ dependencies:
87
87
  version: '0'
88
88
  type: :development
89
89
  prerelease: false
90
- version_requirements: *2157140000
90
+ version_requirements: *2156726240
91
91
  - !ruby/object:Gem::Dependency
92
92
  name: mocha
93
- requirement: &2157139300 !ruby/object:Gem::Requirement
93
+ requirement: &2156725500 !ruby/object:Gem::Requirement
94
94
  none: false
95
95
  requirements:
96
96
  - - ! '>='
@@ -98,10 +98,10 @@ dependencies:
98
98
  version: '0'
99
99
  type: :development
100
100
  prerelease: false
101
- version_requirements: *2157139300
101
+ version_requirements: *2156725500
102
102
  - !ruby/object:Gem::Dependency
103
103
  name: i18n
104
- requirement: &2157138760 !ruby/object:Gem::Requirement
104
+ requirement: &2156724880 !ruby/object:Gem::Requirement
105
105
  none: false
106
106
  requirements:
107
107
  - - ! '>='
@@ -109,7 +109,7 @@ dependencies:
109
109
  version: '0'
110
110
  type: :development
111
111
  prerelease: false
112
- version_requirements: *2157138760
112
+ version_requirements: *2156724880
113
113
  description: Prepare SSML and GRXML documents with ease
114
114
  email:
115
115
  - ben@langfeld.me
@@ -186,7 +186,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
186
186
  version: '0'
187
187
  segments:
188
188
  - 0
189
- hash: -3968593317999839588
189
+ hash: -1285553440311979925
190
190
  required_rubygems_version: !ruby/object:Gem::Requirement
191
191
  none: false
192
192
  requirements:
@@ -195,7 +195,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
195
195
  version: '0'
196
196
  segments:
197
197
  - 0
198
- hash: -3968593317999839588
198
+ hash: -1285553440311979925
199
199
  requirements: []
200
200
  rubyforge_project: ruby_speech
201
201
  rubygems_version: 1.8.10