Permalink
Browse files

Merge branch 'release/0.2.2'

  • Loading branch information...
2 parents 7b0bcee + 34ffc7c commit 71e79bcba33a1839c1c7aff9eecb751cc87245ea @benlangfeld benlangfeld committed Sep 12, 2011
Showing with 126 additions and 13 deletions.
  1. +43 −11 CHANGELOG.md
  2. +1 −1 README.md
  3. +15 −0 lib/ruby_speech/ssml/element.rb
  4. +1 −1 lib/ruby_speech/version.rb
  5. +66 −0 spec/ruby_speech/ssml_spec.rb
View
@@ -1,25 +1,57 @@
+# 0.2.2
+ * Feature: The SSML DSL now supports embedding SSML documents, elements or strings via the `embed` method. This behaves as you might expect:
+
+ ```ruby
+ doc1 = RubySpeech::SSML.draw do
+ string "Hi, I'm Fred. The time is currently "
+ say_as :interpret_as => 'date', :format => 'dmy' do
+ "01/02/1960"
+ end
+ end
+
+ doc2 = RubySpeech::SSML.draw do
+ voice :gender => :male, :name => 'fred' do
+ embed doc1
+ end
+ end
+
+ doc2.to_s
+ ```
+
+ ```xml
+ <speak xmlns="http://www.w3.org/2001/10/synthesis" version="1.0" xml:lang="en-US">
+ <voice gender="male" name="fred">
+ Hi, I'm Fred. The time is currently
+ <say-as interpret-as="date" format="dmy">
+ 01/02/1960
+ </say-as>
+ </voice>
+ </speak>
+ ```
+
# 0.2.1
- Bugfix: SSML element's children now include any text content, and text content is copied when importing/concatenating documents
+ * Bugfix: SSML element's children now include any text content, and text content is copied when importing/concatenating documents
# 0.2.0
- Feature: SSML elements can now be imported from a Nokogiri Node or a string
- Feature: SSML elements now respond to #children with an array of SSML elements, rather than a Nokogiri NodeSet
- Bugfix/Feature: Comparing SSML elements now compares children
+ * API Change: SSML::SayAs.new (and the DSL method `say_as`) now take `:interpret_as` in the options hash, rather than a separate first argument. This is for consistency with the other element types.
+ * Feature: SSML elements can now be imported from a Nokogiri Node or a string
+ * Feature: SSML elements now respond to #children with an array of SSML elements, rather than a Nokogiri NodeSet
+ * Bugfix/Feature: Comparing SSML elements now compares children
# 0.1.5
- Feature: Now added support for SSML <audio/>
+ * Feature: Now added support for SSML `<audio/>`
# 0.1.4
- Bugfix: Speak#+ now returns a brand new Speak rather than modifying the original object
- Bugfix: Speak#+ now re-sets the namespace on child elements to ensure no default namespace prefix is added
+ * Bugfix: Speak#+ now returns a brand new Speak rather than modifying the original object
+ * Bugfix: Speak#+ now re-sets the namespace on child elements to ensure no default namespace prefix is added
# 0.1.3
- Bugfix: Strings included via the DSL (both as a block return value and by calling #string) are now properly escaped
+ * 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
- Feature: Speak objects can now be concatenated such that children are merged together
+ * API Change: SSML.draw now returns a Speak
+ * Feature: Speak objects can be turned into an XML document using #to_doc
+ * Feature: Speak objects can now be concatenated such that children are merged together
# 0.1.1
* Bugfix: DSL now allows for nesting all allowed elements within each other
View
@@ -13,7 +13,7 @@ require 'ruby_speech'
speak = RubySpeech::SSML.draw do
voice gender: :male, name: 'fred' do
string "Hi, I'm Fred. The time is currently "
- say_as 'date', format: 'dmy' do
+ say_as interpret_as: 'date', format: 'dmy' do
"01/02/1960"
end
end
@@ -70,6 +70,21 @@ def children
super.map { |c| Element.import c }
end
+ def embed(other)
+ case other
+ when String
+ self << encode_special_chars(other)
+ when Speak
+ other.children.each do |child|
+ self << child
+ end
+ when Element
+ self << other
+ else
+ raise ArgumentError, "Can only embed a String or an SSML element"
+ 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
@@ -1,3 +1,3 @@
module RubySpeech
- VERSION = "0.2.1"
+ VERSION = "0.2.2"
end
@@ -56,6 +56,72 @@ module RubySpeech
doc.should == expected_doc
end
+ describe "embedding" do
+ it "SSML documents" do
+ doc1 = RubySpeech::SSML.draw do
+ string "Hi, I'm Fred. The time is currently "
+ say_as :interpret_as => 'date', :format => 'dmy' do
+ "01/02/1960"
+ end
+ end
+
+ doc2 = RubySpeech::SSML.draw do
+ voice :gender => :male, :name => 'fred' do
+ embed doc1
+ end
+ end
+
+ expected_doc = RubySpeech::SSML.draw do
+ voice :gender => :male, :name => 'fred' do
+ string "Hi, I'm Fred. The time is currently "
+ say_as :interpret_as => 'date', :format => 'dmy' do
+ "01/02/1960"
+ end
+ end
+ end
+
+ doc2.should == expected_doc
+ end
+
+ it "SSML elements" do
+ element = SSML::Emphasis.new(:content => "HELLO?")
+
+ doc = RubySpeech::SSML.draw do
+ voice :gender => :male, :name => 'fred' do
+ embed element
+ end
+ end
+
+ expected_doc = RubySpeech::SSML.draw do
+ voice :gender => :male, :name => 'fred' do
+ emphasis do
+ "HELLO?"
+ end
+ end
+ end
+
+ doc.should == expected_doc
+ end
+
+ it "strings" do
+ string = "How now, brown cow?"
+
+ doc = RubySpeech::SSML.draw do
+ voice :gender => :male, :name => 'fred' do
+ embed string
+ end
+ end
+
+ expected_doc = RubySpeech::SSML.draw do
+ voice :gender => :male, :name => 'fred' do
+ string "How now, brown cow?"
+ end
+ end
+
+ doc.should == expected_doc
+ end
+ end
+
it "should properly escape string input" do
doc = RubySpeech::SSML.draw do
voice { string "I <3 nachos." }

0 comments on commit 71e79bc

Please sign in to comment.