Permalink
Browse files

Merge branch 'release/0.1.3'

  • Loading branch information...
benlangfeld committed Jul 10, 2011
2 parents 1b83d46 + efd2f75 commit 709a57e4bdc0173b6a6348b7ca3d7af559a7e485
View
@@ -1,3 +1,6 @@
+# 0.1.3
+ Bugfix: Strings included via the DSL (both as a block return value and by calling #string) are now properly escaped
+
# 0.1.2
API Change: SSML.draw now returns a Speak
Feature: Speak objects can be turned into an XML document using #to_doc
@@ -2,18 +2,22 @@ module RubySpeech
module SSML
class Element < Niceogiri::XML::Node
def self.new(element_name, atts = {}, &block)
- super element_name do |new_node|
+ super(element_name) do |new_node|
atts.each_pair { |k, v| new_node.send :"#{k}=", v }
block_return = new_node.instance_eval &block if block_given?
- new_node << block_return if block_return.is_a?(String)
+ new_node << new_node.encode_special_chars(block_return) if block_return.is_a?(String)
end
end
def method_missing(method_name, *args, &block)
const_name = method_name.to_s.sub('ssml', '').titleize.gsub(' ', '')
const = SSML.const_get const_name
if const && self.class::VALID_CHILD_TYPES.include?(const)
- self << const.new(*args, &block)
+ if const == String
+ self << encode_special_chars(args.first)
+ else
+ self << const.new(*args, &block)
+ end
else
super
end
@@ -32,7 +32,7 @@ class SayAs < Element
# @return [Prosody] an element for use in an SSML document
#
def self.new(interpret_as, atts = {}, &block)
- super 'say-as', atts.merge(interpret_as: interpret_as), &block
+ super 'say-as', atts.merge(:interpret_as => interpret_as), &block
end
##
@@ -18,12 +18,12 @@ class Speak < Element
# @return [Speak] an element for use in an SSML document
#
def self.new(atts = {}, &block)
- super('speak', atts) do
- self[:version] = '1.0'
- self.namespace = 'http://www.w3.org/2001/10/synthesis'
- self.language ||= "en-US"
- instance_eval &block if block_given?
- end
+ new_node = super('speak', atts)
+ new_node[:version] = '1.0'
+ new_node.namespace = 'http://www.w3.org/2001/10/synthesis'
+ new_node.language ||= "en-US"
+ new_node.instance_eval &block if block_given?
+ new_node
end
##
@@ -1,3 +1,3 @@
module RubySpeech
- VERSION = "0.1.2"
+ VERSION = "0.1.3"
end
@@ -59,24 +59,24 @@ module SSML
describe "comparing objects" do
it "should be equal if the content, strength and base uri are the same" do
- Break.new(strength: :strong, time: 1.second, content: "Hello there").should == Break.new(strength: :strong, time: 1.second, content: "Hello there")
+ Break.new(:strength => :strong, :time => 1.second, :content => "Hello there").should == Break.new(:strength => :strong, :time => 1.second, :content => "Hello there")
end
describe "when the content is different" do
it "should not be equal" do
- Break.new(content: "Hello").should_not == Break.new(content: "Hello there")
+ Break.new(:content => "Hello").should_not == Break.new(:content => "Hello there")
end
end
describe "when the strength is different" do
it "should not be equal" do
- Break.new(strength: :strong).should_not == Break.new(strength: :weak)
+ Break.new(:strength => :strong).should_not == Break.new(:strength => :weak)
end
end
describe "when the time is different" do
it "should not be equal" do
- Break.new(time: 1.second).should_not == Break.new(time: 2.seconds)
+ Break.new(:time => 1.second).should_not == Break.new(:time => 2.seconds)
end
end
end
@@ -30,18 +30,18 @@ module SSML
describe "comparing objects" do
it "should be equal if the content and level are the same" do
- Emphasis.new(level: :strong, content: "Hello there").should == Emphasis.new(level: :strong, content: "Hello there")
+ Emphasis.new(:level => :strong, :content => "Hello there").should == Emphasis.new(:level => :strong, :content => "Hello there")
end
describe "when the content is different" do
it "should not be equal" do
- Emphasis.new(content: "Hello").should_not == Emphasis.new(content: "Hello there")
+ Emphasis.new(:content => "Hello").should_not == Emphasis.new(:content => "Hello there")
end
end
describe "when the level is different" do
it "should not be equal" do
- Emphasis.new(level: :strong).should_not == Emphasis.new(level: :reduced)
+ Emphasis.new(:level => :strong).should_not == Emphasis.new(:level => :reduced)
end
end
end
@@ -186,48 +186,48 @@ module SSML
describe "comparing objects" do
it "should be equal if the content, strength and base uri are the same" do
- Prosody.new(pitch: :medium, contour: "something", range: '20Hz', rate: 2, duration: 10.seconds, volume: :loud, content: "Hello there").should == Prosody.new(pitch: :medium, contour: "something", range: '20Hz', rate: 2, duration: 10.seconds, volume: :loud, content: "Hello there")
+ Prosody.new(:pitch => :medium, :contour => "something", :range => '20Hz', :rate => 2, :duration => 10.seconds, :volume => :loud, :content => "Hello there").should == Prosody.new(:pitch => :medium, :contour => "something", :range => '20Hz', :rate => 2, :duration => 10.seconds, :volume => :loud, :content => "Hello there")
end
describe "when the content is different" do
it "should not be equal" do
- Prosody.new(content: "Hello").should_not == Prosody.new(content: "Hello there")
+ Prosody.new(:content => "Hello").should_not == Prosody.new(:content => "Hello there")
end
end
describe "when the pitch is different" do
it "should not be equal" do
- Prosody.new(pitch: :medium).should_not == Prosody.new(pitch: :high)
+ Prosody.new(:pitch => :medium).should_not == Prosody.new(:pitch => :high)
end
end
describe "when the contour is different" do
it "should not be equal" do
- Prosody.new(contour: 'foo').should_not == Prosody.new(contour: 'bar')
+ Prosody.new(:contour => 'foo').should_not == Prosody.new(:contour => 'bar')
end
end
describe "when the range is different" do
it "should not be equal" do
- Prosody.new(range: '20Hz').should_not == Prosody.new(range: '30Hz')
+ Prosody.new(:range => '20Hz').should_not == Prosody.new(:range => '30Hz')
end
end
describe "when the rate is different" do
it "should not be equal" do
- Prosody.new(rate: 2).should_not == Prosody.new(rate: 3)
+ Prosody.new(:rate => 2).should_not == Prosody.new(:rate => 3)
end
end
describe "when the duration is different" do
it "should not be equal" do
- Prosody.new(duration: 10.seconds).should_not == Prosody.new(duration: 20.seconds)
+ Prosody.new(:duration => 10.seconds).should_not == Prosody.new(:duration => 20.seconds)
end
end
describe "when the volume is different" do
it "should not be equal" do
- Prosody.new(volume: :loud).should_not == Prosody.new(volume: :soft)
+ Prosody.new(:volume => :loud).should_not == Prosody.new(:volume => :soft)
end
end
end
@@ -3,7 +3,7 @@
module RubySpeech
module SSML
describe SayAs do
- subject { SayAs.new 'one', format: 'two', detail: 'three' }
+ subject { SayAs.new 'one', :format => 'two', :detail => 'three' }
its(:name) { should == 'say-as' }
@@ -19,12 +19,12 @@ module SSML
describe "comparing objects" do
it "should be equal if the content, interpret_as, format, age, variant, name are the same" do
- SayAs.new('jp', format: 'foo', detail: 'bar', content: "hello").should == SayAs.new('jp', format: 'foo', detail: 'bar', content: "hello")
+ SayAs.new('jp', :format => 'foo', :detail => 'bar', :content => "hello").should == SayAs.new('jp', :format => 'foo', :detail => 'bar', :content => "hello")
end
describe "when the content is different" do
it "should not be equal" do
- SayAs.new('jp', content: "Hello").should_not == SayAs.new('jp', content: "Hello there")
+ SayAs.new('jp', :content => "Hello").should_not == SayAs.new('jp', :content => "Hello there")
end
end
@@ -36,13 +36,13 @@ module SSML
describe "when the format is different" do
it "should not be equal" do
- SayAs.new('jp', format: 'foo').should_not == SayAs.new('jp', format: 'bar')
+ SayAs.new('jp', :format => 'foo').should_not == SayAs.new('jp', :format => 'bar')
end
end
describe "when the detail is different" do
it "should not be equal" do
- SayAs.new('jp', detail: 'foo').should_not == SayAs.new('jp', detail: 'bar')
+ SayAs.new('jp', :detail => 'foo').should_not == SayAs.new('jp', :detail => 'bar')
end
end
end
@@ -29,33 +29,33 @@ module SSML
describe "comparing objects" do
it "should be equal if the content, language and base uri are the same" do
- Speak.new(language: 'en-GB', base_uri: 'blah', content: "Hello there").should == Speak.new(language: 'en-GB', base_uri: 'blah', content: "Hello there")
+ Speak.new(:language => 'en-GB', :base_uri => 'blah', :content => "Hello there").should == Speak.new(:language => 'en-GB', :base_uri => 'blah', :content => "Hello there")
end
describe "when the content is different" do
it "should not be equal" do
- Speak.new(content: "Hello").should_not == Speak.new(content: "Hello there")
+ Speak.new(:content => "Hello").should_not == Speak.new(:content => "Hello there")
end
end
describe "when the language is different" do
it "should not be equal" do
- Speak.new(language: 'en-US').should_not == Speak.new(language: 'en-GB')
+ Speak.new(:language => 'en-US').should_not == Speak.new(:language => 'en-GB')
end
end
describe "when the base URI is different" do
it "should not be equal" do
- Speak.new(base_uri: 'foo').should_not == Speak.new(base_uri: 'bar')
+ Speak.new(:base_uri => 'foo').should_not == Speak.new(:base_uri => 'bar')
end
end
end
it "should allow creating child SSML elements" do
s = Speak.new
- s.voice gender: :male, content: 'Hello'
+ s.voice :gender => :male, :content => 'Hello'
expected_s = Speak.new
- expected_s << Voice.new(gender: :male, content: 'Hello')
+ expected_s << Voice.new(:gender => :male, :content => 'Hello')
s.should == expected_s
end
@@ -133,15 +133,15 @@ module SSML
it "should allow concatenation" do
speak1 = Speak.new
- speak1 << Voice.new(name: 'frank', content: "Hi, I'm Frank")
+ speak1 << Voice.new(:name => 'frank', :content => "Hi, I'm Frank")
speak2 = Speak.new
- speak2 << Voice.new(name: 'millie', content: "Hi, I'm Millie")
+ speak2 << Voice.new(:name => 'millie', :content => "Hi, I'm Millie")
expected_concat = Speak.new
- expected_concat << Voice.new(name: 'frank', content: "Hi, I'm Frank")
- expected_concat << Voice.new(name: 'millie', content: "Hi, I'm Millie")
+ expected_concat << Voice.new(:name => 'frank', :content => "Hi, I'm Frank")
+ expected_concat << Voice.new(:name => 'millie', :content => "Hi, I'm Millie")
- (speak1 + speak2).to_s.should == expected_concat.to_s
+ (speak1 + speak2).should == expected_concat
end
end # Speak
end # SSML
@@ -84,42 +84,42 @@ module SSML
describe "comparing objects" do
it "should be equal if the content, language, gender, age, variant, name are the same" do
- Voice.new(language: 'jp', gender: :male, age: 25, variant: 2, name: "paul", content: "hello").should == Voice.new(language: 'jp', gender: :male, age: 25, variant: 2, name: "paul", content: "hello")
+ Voice.new(:language => 'jp', :gender => :male, :age => 25, :variant => 2, :name => "paul", :content => "hello").should == Voice.new(:language => 'jp', :gender => :male, :age => 25, :variant => 2, :name => "paul", :content => "hello")
end
describe "when the content is different" do
it "should not be equal" do
- Voice.new(content: "Hello").should_not == Voice.new(content: "Hello there")
+ Voice.new(:content => "Hello").should_not == Voice.new(:content => "Hello there")
end
end
describe "when the language is different" do
it "should not be equal" do
- Voice.new(language: "Hello").should_not == Voice.new(language: "Hello there")
+ Voice.new(:language => "Hello").should_not == Voice.new(:language => "Hello there")
end
end
describe "when the gender is different" do
it "should not be equal" do
- Voice.new(gender: :male).should_not == Voice.new(gender: :female)
+ Voice.new(:gender => :male).should_not == Voice.new(:gender => :female)
end
end
describe "when the age is different" do
it "should not be equal" do
- Voice.new(age: 20).should_not == Voice.new(age: 30)
+ Voice.new(:age => 20).should_not == Voice.new(:age => 30)
end
end
describe "when the variant is different" do
it "should not be equal" do
- Voice.new(variant: 1).should_not == Voice.new(variant: 2)
+ Voice.new(:variant => 1).should_not == Voice.new(:variant => 2)
end
end
describe "when the name is different" do
it "should not be equal" do
- Voice.new(name: "Hello").should_not == Voice.new(name: "Hello there")
+ Voice.new(:name => "Hello").should_not == Voice.new(:name => "Hello there")
end
end
end
Oops, something went wrong.

0 comments on commit 709a57e

Please sign in to comment.